diff --git a/src/config/mod.rs b/src/config/mod.rs index 45fccac..407f8dc 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -88,6 +88,24 @@ impl Config { } } + /// Returns full path to quests folder + /// This path will be relative to $PWD, not to config. + /// + /// # Examples + /// ```rust + /// use squad_quest::config::Config; + /// + /// let path = "cfg/config.toml".into(); + /// let config = Config::load(path); + /// + /// let quests_path = config.full_quests_path(); + /// ``` + pub fn full_quests_path(&self) -> PathBuf { + let mut path = self.path.clone(); + path.push(self.quests_path.clone()); + path + } + /// Load [Vec]<[Quest]> from quests folder. /// Also logs errors and counts successfully loaded quests. /// @@ -107,8 +125,7 @@ impl Config { pub fn load_quests(&self) -> Vec { let mut out_vec = Vec::new(); - let mut path = self.path.clone(); - path.push(self.quests_path.clone()); + let path = self.full_quests_path(); match fs::read_dir(path) { Ok(iter) => { diff --git a/src/quest/mod.rs b/src/quest/mod.rs index d675cc1..e3a0d1b 100644 --- a/src/quest/mod.rs +++ b/src/quest/mod.rs @@ -154,7 +154,8 @@ impl Quest { /// ``` pub fn save(&self, path: PathBuf) -> Result<(), QuestError> { let filename = format!("{}.toml", self.id); - let full_path = path.with_file_name(filename); + let mut full_path = path; + full_path.push(filename); let str = match toml::to_string_pretty(&self) { Ok(string) => string,