diff --git a/gamercade_app/src/local_directory/image_cache.rs b/gamercade_app/src/local_directory/image_cache.rs new file mode 100644 index 0000000..4a061c7 --- /dev/null +++ b/gamercade_app/src/local_directory/image_cache.rs @@ -0,0 +1,33 @@ +use eframe::egui::{self, ImageData, ImageSource}; +use nohash_hasher::IntMap; + +use crate::GAME_DIR; + +pub struct ImageCache { + pub games: IntMap, +} + +impl ImageCache { + pub const fn default_game_image() -> &'static ImageSource<'static> { + &egui::include_image!("./../../default-logo.png") + } + + pub fn new() -> Self { + std::fs::create_dir(GAME_DIR).unwrap(); + let dir = std::fs::read_dir(GAME_DIR).unwrap(); + + let mut games = IntMap::default(); + + for file in dir.into_iter() { + if let Ok(path) = file.map(|file| file.path()) { + if let Some(extension) = path.extension() { + if extension == "png" { + // TODO: Load the image and push it into the map + } + } + } + } + + Self { games } + } +} diff --git a/gamercade_app/src/local_directory/mod.rs b/gamercade_app/src/local_directory/mod.rs index 53bcdb1..cddce1e 100644 --- a/gamercade_app/src/local_directory/mod.rs +++ b/gamercade_app/src/local_directory/mod.rs @@ -5,6 +5,7 @@ use rusqlite::{types::FromSql, Connection, Row, Statement}; mod game; mod game_footprint; +mod image_cache; mod permission_level; mod tag; mod user; @@ -14,7 +15,7 @@ pub use permission_level::{PermissionLevel, PermissionLevelId}; pub use tag::{Tag, TagId}; pub use user::{User, UserId}; -use self::{game::upsert_games_table, game_footprint::GameFootprint}; +use self::{game::upsert_games_table, game_footprint::GameFootprint, image_cache::ImageCache}; const LOCAL_DB_PATH: &str = "./local.db"; @@ -30,7 +31,7 @@ pub struct LocalDirectory { pub tags: TagDictionary, pub users: UserDictionary, pub permission_levels: PermissionLevelDictionary, - // TODO: Add Images + pub images: ImageCache, pub game_footprint: GameFootprintDictionary, } @@ -167,6 +168,7 @@ impl Default for LocalDirectory { db, cached_games: Vec::new(), cache_dirty: true, + images: ImageCache::new(), }; upsert_games_table(&output.db);