Skip to content

Commit

Permalink
begin image cache
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDavenport committed Apr 23, 2024
1 parent e700295 commit 54d7ff4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
33 changes: 33 additions & 0 deletions gamercade_app/src/local_directory/image_cache.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use eframe::egui::{self, ImageData, ImageSource};
use nohash_hasher::IntMap;

use crate::GAME_DIR;

pub struct ImageCache {
pub games: IntMap<i64, ImageData>,
}

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 }
}
}
6 changes: 4 additions & 2 deletions gamercade_app/src/local_directory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";

Expand All @@ -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,
}

Expand Down Expand Up @@ -167,6 +168,7 @@ impl Default for LocalDirectory {
db,
cached_games: Vec::new(),
cache_dirty: true,
images: ImageCache::new(),
};

upsert_games_table(&output.db);
Expand Down

0 comments on commit 54d7ff4

Please sign in to comment.