Skip to content

Commit

Permalink
feat: split cores.toml out from consoles.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
goweiwen committed Jun 6, 2024
1 parent cf5b100 commit cac34ee
Show file tree
Hide file tree
Showing 6 changed files with 345 additions and 107 deletions.
46 changes: 37 additions & 9 deletions crates/allium-launcher/src/consoles.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt;
use std::path::PathBuf;
use std::{collections::HashMap, path::Path};

Expand All @@ -7,11 +8,13 @@ use common::database::Database;
use common::game_info::GameInfo;
use serde::Deserialize;

use common::constants::{ALLIUM_CONFIG_CONSOLES, ALLIUM_RETROARCH};
use common::constants::{ALLIUM_CONFIG_CONSOLES, ALLIUM_CONFIG_CORES, ALLIUM_RETROARCH};
use log::{debug, trace};

use crate::entry::game::Game;

type CoreName = String;

#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
pub struct Console {
/// The name of the console.
Expand All @@ -21,7 +24,7 @@ pub struct Console {
pub path: Option<PathBuf>,
/// List of RetroArch cores to use. First is default.
#[serde(default)]
pub cores: Vec<String>,
pub cores: Vec<CoreName>,
/// Folder/file names to match against. If the folder/file matches exactly OR contains a parenthesized string that matches exactly, this core will be used.
/// e.g. "GBA" matches "GBA", "Game Boy Advance (GBA)"
#[serde(default)]
Expand All @@ -38,13 +41,30 @@ pub struct Console {

#[derive(Debug, Deserialize)]
struct ConsoleConfig {
cores: HashMap<String, String>,
consoles: Vec<Console>,
}

#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
pub struct Core {
pub name: String,
#[serde(default)]
pub swap: bool,
}

impl fmt::Display for Core {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.name)
}
}

#[derive(Debug, Deserialize)]
struct CoresConfig {
cores: HashMap<CoreName, Core>,
}

#[derive(Debug, Clone)]
pub struct ConsoleMapper {
cores: HashMap<String, String>,
cores: HashMap<CoreName, Core>,
consoles: Vec<Console>,
}

Expand All @@ -63,18 +83,26 @@ impl ConsoleMapper {
}

pub fn load_config(&mut self) -> Result<()> {
let config = std::fs::read_to_string(ALLIUM_CONFIG_CONSOLES.as_path()).map_err(|e| {
let consoles = std::fs::read_to_string(ALLIUM_CONFIG_CONSOLES.as_path()).map_err(|e| {
anyhow!(
"Failed to load consoles config: {:?}, {}",
&*ALLIUM_CONFIG_CONSOLES,
e
)
})?;
let config: ConsoleConfig =
toml::from_str(&config).context("Failed to parse consoles.toml.")?;
let consoles: ConsoleConfig =
toml::from_str(&consoles).context("Failed to parse consoles.toml.")?;
self.consoles = consoles.consoles;

self.cores = config.cores;
self.consoles = config.consoles;
let cores = std::fs::read_to_string(ALLIUM_CONFIG_CORES.as_path()).map_err(|e| {
anyhow!(
"Failed to load cores config: {:?}, {}",
&*ALLIUM_CONFIG_CORES,
e
)
})?;
let cores: CoresConfig = toml::from_str(&cores).context("Failed to parse cores.toml.")?;
self.cores = cores.cores;

Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions crates/common/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ lazy_static! {

// Config
pub static ref ALLIUM_CONFIG_CONSOLES: PathBuf = ALLIUM_BASE_DIR.join("config/consoles.toml");
pub static ref ALLIUM_CONFIG_CORES: PathBuf = ALLIUM_BASE_DIR.join("config/cores.toml");

// State
pub static ref ALLIUMD_STATE: PathBuf = ALLIUM_BASE_DIR.join("state/alliumd.json");
Expand Down
98 changes: 0 additions & 98 deletions static/.allium/config/consoles.toml
Original file line number Diff line number Diff line change
@@ -1,101 +1,3 @@
[cores]
"dosbox_pure_0.9.7" = "DOSBox Pure 0.9.7"
a5200 = "A5200"
atari800 = "Atari 800"
bluemsx = "blueMSX"
bsnes = "bsnes"
chailove = "ChaiLove"
chimerasnes = "ChimeraSNES"
crocods = "CrocoDS"
daphne = "Daphne"
dosbox_pure = "DOSBox Pure"
easyrpg = "EasyRPG"
ecwolf = "ECWolf"
fake08 = "FAKE-08"
fbalpha2012 = "FinalBurn Alpha 2012"
fbalpha2012_cps1 = "FBA 2012 CPS1"
fbalpha2012_cps2 = "FBA 2012 CPS2"
fbalpha2012_cps3 = "FBA 2012 CPS3"
fbalpha2012_neogeo = "FBA 2012 NeoGeo"
fbneo = "FinalBurn Neo"
fceumm = "FCEUmm"
fmsx = "fMSX"
freechaf = "FreeChaF"
freeintv = "FreeIntv"
fuse = "Fuse"
gambatte = "Gambatte"
gearboy = "Gearboy"
gearsystem = "Gearsystem"
genesis_plus_gx = "Genesis Plus GX"
gme = "Game Music Emu"
gpsp = "gpSP"
gw = "Game & Watch"
handy = "Handy"
hatari = "Hatari"
km_mame2003_xtreme = "MAME 2003 Xtreme"
lutro = "Lutro"
mame2000 = "MAME 2000"
mame2003 = "MAME 2003"
mame2003_midway = "MAME 2003 Midway"
mame2003_plus = "MAME 2003-Plus"
mba_mini = "M.B.A mini"
mednafen_lynx = "Beetle Lynx"
mednafen_ngp = "Beetle NeoGeo Pocket"
mednafen_pce_fast = "Beetle PCE FAST"
mednafen_pcfx = "Beetle PC-FX"
mednafen_supafaust = "Beetle Supafaust"
mednafen_supergrafx = "Beetle SuperGrafx"
mednafen_vb = "Beetle VB"
mednafen_wswan = "Beetle Cygne"
mgba = "mGBA"
mu = "mu"
nekop2 = "Neko Project II"
neocd = "NeoCD"
nestopia = "Nestopia"
np2kai = "Neko Project II Kai"
numero = "Numero"
nxengine = "NXEngine"
o2em = "O2EM"
opera = "Opera"
pcsx_rearmed = "PCSX ReARMed"
picodrive = "PicoDrive"
pokemini = "PokeMini"
potator = "Potator"
prboom = "PRBoom"
prosystem = "ProSystem"
puae = "PUAE"
puae2021 = "PUAE 2021"
px68k = "PX68k"
quasi88 = "QUASI88"
reminiscence = "REminiscence"
retro8 = "Retro8"
sameduck = "SameDuck"
scummvm = "ScummVM"
sh_launcher = "SH Launcher"
snes9x = "Snes9x"
snes9x2002 = "Snes9x 2002"
snes9x2005 = "Snes9x 2005"
snes9x2005_plus = "Snes9x 2005 Plus"
snes9x2010 = "Snes9x 2010"
stella2014 = "Stella 2014"
tgbdual = "TGB Dual"
theodore = "Theodore"
tic80 = "TIC-80"
tyrquake = "TyrQuake"
uae4arm = "UAE4ARM"
uw8 = "uw8"
uzem = "Uzem"
vba_next = "VBA Next"
vbam = "VBA-M"
vecx = "VecX"
vemulator = "VEmulator"
vice_x64 = "VICE x64"
vice_xvic = "VICE xvic"
virtualjaguar = "Virtual Jaguar"
x1 = "X1"
xrick = "XRick"
zx81 = "ZX81"

[[consoles]]
name = "Amstrad CPC"
cores = ["crocods"]
Expand Down
Loading

0 comments on commit cac34ee

Please sign in to comment.