[improve] set game dir on client -> updates Play/Install button based on games existing

This commit is contained in:
2024-11-14 19:41:55 +01:00
parent c00b7dbe9c
commit 942eb8003e
12 changed files with 873 additions and 53 deletions

View File

@ -29,6 +29,8 @@ pub struct Game {
pub size: u64,
/// thumbnail image
pub thumbnail: Option<Bytes>,
/// only relevant for client (yeah... I know)
pub installed: bool,
}
impl fmt::Debug for Game {
@ -76,7 +78,7 @@ pub struct GameDB {
impl GameDB {
#[must_use]
pub fn new() -> Self {
pub fn empty() -> Self {
GameDB {
games: HashMap::new(),
}
@ -84,7 +86,7 @@ impl GameDB {
#[must_use]
pub fn from(games: Vec<Game>) -> Self {
let mut db = GameDB::new();
let mut db = GameDB::empty();
for game in games {
db.games.insert(game.id.clone(), game);
}
@ -99,6 +101,14 @@ impl GameDB {
self.games.get(id.as_ref())
}
#[must_use]
pub fn get_mut_game_by_id<S>(&mut self, id: S) -> Option<&mut Game>
where
S: AsRef<str>,
{
self.games.get_mut(id.as_ref())
}
#[must_use]
pub fn get_game_by_name(&self, name: &str) -> Option<&Game> {
self.games.values().find(|game| game.name == name)
@ -110,10 +120,16 @@ impl GameDB {
games.sort_by(|a, b| a.name.cmp(&b.name));
games
}
pub fn set_all_uninstalled(&mut self) {
for game in self.games.values_mut() {
game.installed = false;
}
}
}
impl Default for GameDB {
fn default() -> Self {
Self::new()
Self::empty()
}
}