store refs for ModdedInstance in root config

This commit is contained in:
2026-03-02 20:32:54 +01:00
parent 1f4691cb72
commit 36b45aac5a

View File

@@ -1,8 +1,9 @@
use clap::builder::Str;
use serde::{Deserialize, Serialize};
use std::{
error::Error,
fs::{self, read_to_string},
io::Write,
io::{self, Write},
path::{Path, PathBuf},
};
@@ -20,7 +21,11 @@ pub struct RootConfig {
/// Where all mods are stored
pub mod_location: PathBuf,
#[serde(default)]
pub instances: Vec<InstancePointer>,
/// All available mods
#[serde(default)]
pub mods: Vec<ModConfig>,
}
@@ -40,6 +45,16 @@ impl RootConfig {
pub fn get_mod_by_id(&self, id: &str) -> Option<ModConfig> {
self.mods.iter().find(|e| e.id == id).cloned()
}
pub fn load_instance_by_id(&self, id: &str) -> Result<ModdedInstance, Box<dyn Error>> {
let conf = self
.instances
.iter()
.find(|e| e.id == id)
.ok_or("ID not found in root config")?;
ModdedInstance::load_from_file(&conf.path)
}
}
/// Available game
@@ -48,6 +63,12 @@ pub struct Game {
pub install_location: PathBuf,
}
#[derive(Debug, Clone, Deserialize, PartialEq)]
pub struct InstancePointer {
pub id: String,
pub path: PathBuf,
}
/// Config for an available mod
#[derive(Debug, Clone, Deserialize, PartialEq)]
pub struct ModConfig {