From 36b45aac5a0abc03503157476b393a72930df859 Mon Sep 17 00:00:00 2001 From: Niklas Kapelle Date: Mon, 2 Mar 2026 20:32:54 +0100 Subject: [PATCH] store refs for ModdedInstance in root config --- src/basic_types.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/basic_types.rs b/src/basic_types.rs index 5f34cbb..537b781 100644 --- a/src/basic_types.rs +++ b/src/basic_types.rs @@ -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, + /// All available mods + #[serde(default)] pub mods: Vec, } @@ -40,6 +45,16 @@ impl RootConfig { pub fn get_mod_by_id(&self, id: &str) -> Option { self.mods.iter().find(|e| e.id == id).cloned() } + + pub fn load_instance_by_id(&self, id: &str) -> Result> { + 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 {