// 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/. //! Domi games: Atrium registry entries with `kind = "game"`, launched through their `domi-://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-://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:`; `name` is the title. No install folder. pub fn game(id: &str, name: &str, launch: DomiLaunch<'_>) -> Result { 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, }) }