Skip to main content

thedes_app/
lib.rs

1use std::path::PathBuf;
2
3use thiserror::Error;
4
5pub mod root;
6pub mod session;
7pub mod settings;
8
9pub const SAVE_EXTENSION: &'static str = ".save.thedes";
10
11#[derive(Debug, Error)]
12pub enum Error {
13    #[error(transparent)]
14    InitRoot(#[from] root::InitError),
15    #[error(transparent)]
16    RunRoot(#[from] root::Error),
17}
18
19#[derive(Debug, Clone)]
20pub struct Config {
21    saves_dir: PathBuf,
22    settings_path: PathBuf,
23}
24
25impl Config {
26    pub fn new() -> Self {
27        Self {
28            saves_dir: PathBuf::from("."),
29            settings_path: PathBuf::from("thedes-settings.json"),
30        }
31    }
32
33    pub fn with_saves_dir(self, saves_dir: PathBuf) -> Self {
34        Self { saves_dir, ..self }
35    }
36
37    pub fn with_settings_path(self, settings_path: PathBuf) -> Self {
38        Self { settings_path, ..self }
39    }
40
41    pub async fn run(
42        self,
43        mut app: thedes_tui::core::App,
44    ) -> Result<(), Error> {
45        let config = root::Config {
46            saves_dir: self.saves_dir,
47            settings_path: self.settings_path,
48        };
49        root::Component::new(config).await?.run(&mut app).await?;
50        Ok(())
51    }
52}