use std::path::{Path, PathBuf};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Scope<'a> {
Game,
World,
Dimension(&'a str),
Player(&'a str),
Entity(&'a str),
Chunk(&'a str, i32, i32),
}
use yog_ids::storage::{CHUNK, DIMENSION, DIR, ENTITY, GAME, PLAYER, SEP, WORLD};
const STORE_EXT: &str = yog_ids::Format::Data.ext();
impl Scope<'_> {
pub fn path(self, root: &Path, mod_id: &str) -> PathBuf {
let base = root.join(DIR).join(file_safe(mod_id));
let (dir, name) = match self {
Scope::Game => (None, GAME.to_owned()),
Scope::World => (None, WORLD.to_owned()),
Scope::Dimension(dim) => (Some(DIMENSION), file_safe(dim)),
Scope::Player(uuid) => (Some(PLAYER), file_safe(uuid)),
Scope::Entity(uuid) => (Some(ENTITY), file_safe(uuid)),
Scope::Chunk(dim, x, z) => (Some(CHUNK), format!("{}{SEP}{x}{SEP}{z}", file_safe(dim))),
};
let file = format!("{name}{}{STORE_EXT}", yog_ids::sep::DOT);
match dir {
Some(dir) => base.join(dir).join(file),
None => base.join(file),
}
}
}
fn file_safe(name: &str) -> String {
name.replace(yog_ids::sep::NAMESPACE, SEP)
.replace(yog_ids::sep::PATH, SEP)
}