feat: full_quests_path
- Added Config::full_quests_path - Fixed quests saving in parent folder
This commit is contained in:
parent
119b7bce9c
commit
2e14614bdf
2 changed files with 21 additions and 3 deletions
|
|
@ -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.
|
/// Load [Vec]<[Quest]> from quests folder.
|
||||||
/// Also logs errors and counts successfully loaded quests.
|
/// Also logs errors and counts successfully loaded quests.
|
||||||
///
|
///
|
||||||
|
|
@ -107,8 +125,7 @@ impl Config {
|
||||||
pub fn load_quests(&self) -> Vec<Quest> {
|
pub fn load_quests(&self) -> Vec<Quest> {
|
||||||
let mut out_vec = Vec::new();
|
let mut out_vec = Vec::new();
|
||||||
|
|
||||||
let mut path = self.path.clone();
|
let path = self.full_quests_path();
|
||||||
path.push(self.quests_path.clone());
|
|
||||||
|
|
||||||
match fs::read_dir(path) {
|
match fs::read_dir(path) {
|
||||||
Ok(iter) => {
|
Ok(iter) => {
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,8 @@ impl Quest {
|
||||||
/// ```
|
/// ```
|
||||||
pub fn save(&self, path: PathBuf) -> Result<(), QuestError> {
|
pub fn save(&self, path: PathBuf) -> Result<(), QuestError> {
|
||||||
let filename = format!("{}.toml", self.id);
|
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) {
|
let str = match toml::to_string_pretty(&self) {
|
||||||
Ok(string) => string,
|
Ok(string) => string,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue