Files
ArenaPublic/crates/arena-core/src/domi.rs
T

44 lines
1.6 KiB
Rust

// 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-<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,
})
}