refactor: Move get_internal_path() out of savegame feature

This commit is contained in:
demenik
2025-11-26 22:17:25 +01:00
parent 57a780bff3
commit 05859d6f9c
5 changed files with 16 additions and 12 deletions

View File

@@ -1,23 +1,12 @@
use crate::prelude::*; use crate::prelude::*;
use directories::ProjectDirs;
use std::path::PathBuf; use std::path::PathBuf;
#[derive(Resource)] #[derive(Resource)]
pub struct SavegamePath(pub PathBuf); pub struct SavegamePath(pub PathBuf);
impl SavegamePath { impl SavegamePath {
pub fn get_project_path() -> Option<PathBuf> {
let project_dirs = ProjectDirs::from("de", "demenik", "pomomon-garden");
if let Some(dirs) = project_dirs {
Some(dirs.data_local_dir().to_path_buf())
} else {
None
}
}
pub fn new(name: &str) -> Self { pub fn new(name: &str) -> Self {
let base_path = Self::get_project_path().unwrap_or_else(|| { let base_path = get_internal_path().unwrap_or_else(|| {
println!( println!(
"Could not determine platform-specific save directory. Falling back to `./saves/" "Could not determine platform-specific save directory. Falling back to `./saves/"
); );

View File

@@ -1,2 +1,3 @@
pub mod features; pub mod features;
pub mod prelude; pub mod prelude;
pub mod utils;

View File

@@ -15,6 +15,7 @@ pub use crate::features::{
savegame::components::SavegamePath, savegame::components::SavegamePath,
ui::components::*, ui::components::*,
}; };
pub use crate::utils::path::get_internal_path;
pub use bevy::prelude::*; pub use bevy::prelude::*;
pub use bevy_aseprite_ultra::prelude::*; pub use bevy_aseprite_ultra::prelude::*;
pub use serde::{Deserialize, Serialize}; pub use serde::{Deserialize, Serialize};

1
src/utils/mod.rs Normal file
View File

@@ -0,0 +1 @@
pub mod path;

12
src/utils/path.rs Normal file
View File

@@ -0,0 +1,12 @@
use directories::ProjectDirs;
use std::path::PathBuf;
pub fn get_internal_path() -> Option<PathBuf> {
let project_dirs = ProjectDirs::from("de", "demenik", "pomomon-garden");
if let Some(dirs) = project_dirs {
Some(dirs.data_local_dir().to_path_buf())
} else {
None
}
}