store refs for ModdedInstance in root config
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
|
use clap::builder::Str;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{
|
use std::{
|
||||||
error::Error,
|
error::Error,
|
||||||
fs::{self, read_to_string},
|
fs::{self, read_to_string},
|
||||||
io::Write,
|
io::{self, Write},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -20,7 +21,11 @@ pub struct RootConfig {
|
|||||||
/// Where all mods are stored
|
/// Where all mods are stored
|
||||||
pub mod_location: PathBuf,
|
pub mod_location: PathBuf,
|
||||||
|
|
||||||
|
#[serde(default)]
|
||||||
|
pub instances: Vec<InstancePointer>,
|
||||||
|
|
||||||
/// All available mods
|
/// All available mods
|
||||||
|
#[serde(default)]
|
||||||
pub mods: Vec<ModConfig>,
|
pub mods: Vec<ModConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,6 +45,16 @@ impl RootConfig {
|
|||||||
pub fn get_mod_by_id(&self, id: &str) -> Option<ModConfig> {
|
pub fn get_mod_by_id(&self, id: &str) -> Option<ModConfig> {
|
||||||
self.mods.iter().find(|e| e.id == id).cloned()
|
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
|
/// Available game
|
||||||
@@ -48,6 +63,12 @@ pub struct Game {
|
|||||||
pub install_location: PathBuf,
|
pub install_location: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize, PartialEq)]
|
||||||
|
pub struct InstancePointer {
|
||||||
|
pub id: String,
|
||||||
|
pub path: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
/// Config for an available mod
|
/// Config for an available mod
|
||||||
#[derive(Debug, Clone, Deserialize, PartialEq)]
|
#[derive(Debug, Clone, Deserialize, PartialEq)]
|
||||||
pub struct ModConfig {
|
pub struct ModConfig {
|
||||||
|
|||||||
Reference in New Issue
Block a user