43 lines
1.5 KiB
Rust
43 lines
1.5 KiB
Rust
// SPDX-License-Identifier: CPAL-1.0
|
|
// Copyright (c) 2026 Marek Novák. Built on Domi, https://aula.marek-novak.cz
|
|
|
|
//! Domi games: Atrium registry entries with `kind = "game"`, launched through their `domi-<app>://open` link, or
|
|
//! web games (Rosea, Moin) opened by URL.
|
|
|
|
use crate::error::ParseError;
|
|
use crate::id::{GameId, Source};
|
|
use crate::launch::Launch;
|
|
use crate::model::{CoverHint, Game};
|
|
use crate::text;
|
|
|
|
/// How a Domi game starts.
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum DomiLaunch<'a> {
|
|
/// `domi-<app>://open`; `app` follows the Atrium id rules.
|
|
Link { app: &'a str },
|
|
/// A web game: `https://` only, the host must be one of `allowed_hosts`.
|
|
Web { url: &'a str, allowed_hosts: &'a [&'a str] },
|
|
}
|
|
|
|
/// The game for one Domi entry. `id` follows the Atrium id rules (`[a-z0-9-]{1,32}`, no `-` at either end) and
|
|
/// becomes `domi:<id>`; `name` is the title. No install folder.
|
|
pub fn game(id: &str, name: &str, launch: DomiLaunch<'_>) -> Result<Game, ParseError> {
|
|
if !text::is_atrium_id(id) {
|
|
return Err(ParseError::BadId);
|
|
}
|
|
let title = text::title(name, "name")?;
|
|
let launch = match launch {
|
|
DomiLaunch::Link { app } => Launch::domi_link(app)?,
|
|
DomiLaunch::Web { url, allowed_hosts } => Launch::web(url, allowed_hosts)?,
|
|
};
|
|
let id = GameId::new(Source::Domi, id)?;
|
|
Ok(Game {
|
|
cover: Some(CoverHint::lettered(&title, &id)),
|
|
id,
|
|
source: Source::Domi,
|
|
title,
|
|
install_dir: None,
|
|
launch,
|
|
})
|
|
}
|