[core] API: compiling Seam 1 skeleton (types, signatures, stubs)

This commit is contained in:
2026-11-22 22:58:26 +01:00
parent 8f2bf986af
commit 5c17aac8d4
19 changed files with 1084 additions and 1 deletions
+74
View File
@@ -0,0 +1,74 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
use crate::id::{GameId, Source};
use crate::launch::Launch;
use crate::path::WinPath;
use serde::{Deserialize, Serialize};
/// One game in the library.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Game {
pub id: GameId,
pub source: Source,
/// Display title: trimmed, 1 to [`crate::limits::MAX_TITLE`] characters, no control characters.
pub title: String,
pub install_dir: Option<WinPath>,
pub launch: Launch,
pub cover: Option<CoverHint>,
}
/// Where the tile's picture comes from. No online lookups, ever.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum CoverHint {
/// Steam's own local library cache for this app id (the app finds the file).
SteamLibraryCache { app_id: u32 },
/// A picture file on disk.
LocalFile(WinPath),
/// A lettered tile: the title's first letter or digit on a colour of this hue (0 to 359).
Lettered { letter: char, hue: u16 },
}
impl CoverHint {
/// The lettered tile for a game: the first letter or digit of `title` (uppercased; `#` when there is none) and a
/// hue derived from `id`, so a game keeps its colour across scans.
pub fn lettered(title: &str, id: &GameId) -> CoverHint {
crate::text::lettered(title, id)
}
}
/// The merged library, ordered by title.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct Library {
pub games: Vec<Game>,
}
impl Library {
/// The game with this id.
pub fn get(&self, id: &GameId) -> Option<&Game> {
self.games.iter().find(|g| &g.id == id)
}
pub fn len(&self) -> usize {
self.games.len()
}
pub fn is_empty(&self) -> bool {
self.games.is_empty()
}
}
/// Merges per-source scans into one library.
///
/// - The same [`GameId`] is kept once (its first occurrence).
/// - Games of different sources with the same install folder (compared ignoring case): only the highest
/// [`Source::priority`] stays (Steam > Epic > GOG > Domi > Manual). Games of the same source are never dropped
/// for sharing a folder.
/// - The result is sorted by title (ignoring case), then by id, so the order does not depend on scan order.
/// - At most [`crate::limits::MAX_GAMES`] games are considered; the rest are dropped.
pub fn merge(scans: Vec<Vec<Game>>) -> Library {
let _ = scans;
Library::default()
}