1use std::path::{Path, PathBuf};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum Scope<'a> {
9 Game,
11 World,
13 Dimension(&'a str),
15 Player(&'a str),
17 Entity(&'a str),
19 Chunk(&'a str, i32, i32),
21}
22
23use yog_ids::storage::{CHUNK, DIMENSION, DIR, ENTITY, GAME, PLAYER, SEP, WORLD};
24
25const STORE_EXT: &str = yog_ids::Format::Data.ext();
27
28impl Scope<'_> {
29 pub fn path(self, root: &Path, mod_id: &str) -> PathBuf {
31 let base = root.join(DIR).join(file_safe(mod_id));
32 let (dir, name) = match self {
33 Scope::Game => (None, GAME.to_owned()),
34 Scope::World => (None, WORLD.to_owned()),
35 Scope::Dimension(dim) => (Some(DIMENSION), file_safe(dim)),
36 Scope::Player(uuid) => (Some(PLAYER), file_safe(uuid)),
37 Scope::Entity(uuid) => (Some(ENTITY), file_safe(uuid)),
38 Scope::Chunk(dim, x, z) => (Some(CHUNK), format!("{}{SEP}{x}{SEP}{z}", file_safe(dim))),
39 };
40 let file = format!("{name}{}{STORE_EXT}", yog_ids::sep::DOT);
41 match dir {
42 Some(dir) => base.join(dir).join(file),
43 None => base.join(file),
44 }
45 }
46}
47
48fn file_safe(name: &str) -> String {
50 name.replace(yog_ids::sep::NAMESPACE, SEP)
51 .replace(yog_ids::sep::PATH, SEP)
52}