forked from feather-rs/feather
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlib.rs
More file actions
91 lines (80 loc) · 2.29 KB
/
Copy pathlib.rs
File metadata and controls
91 lines (80 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! Data pack implementation for Feather.
//!
//! Data packs can register loot tables, recipes, advancements, functions,
//! etc. This implementation aims to be compatible with vanilla data packs.
//!
//! This crate also downloads vanilla JARs and assets
//! at startup; see `download_vanilla_assets`.
use std::path::Path;
use ahash::AHashMap;
use id::ParseError;
use serde::Deserialize;
use smartstring::{LazyCompact, SmartString};
mod id;
pub use id::NamespacedId;
mod serde_helpers;
pub(crate) use serde_helpers::*;
pub mod tag;
use tag::LoopError;
pub use tag::{TagRegistry, TagRegistryBuilder};
pub mod recipe;
pub use recipe::RecipeRegistry;
/// The default namespace for resource locations (NamespacedIds).
pub const DEFAULT_NAMESPACE: &str = "minecraft";
use thiserror::Error;
#[derive(Error, Debug)]
pub enum TagLoadError {
#[error("invalid namespaced id: {0}")]
Parse(#[from] ParseError),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error("io error: {0}")]
WalkDir(#[from] walkdir::Error),
#[error("loop detected when parsing tags: {0}")]
FoundLoop(#[from] LoopError),
#[error("invalid tag link: {0} references {1}")]
InvalidLink(NamespacedId, NamespacedId),
#[error("json parsing error: {0}")]
Json(#[from] serde_json::Error),
}
#[derive(Error, Debug)]
pub enum RecipeLoadError {
#[error("invalid namespaced id: {0}")]
Parse(#[from] ParseError),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error("json parsing error: {0}")]
Json(#[from] serde_json::Error),
}
/// The pack.mcmeta file at the root of a datapack.
///
/// Formatted with JSON.
#[derive(Debug, Deserialize)]
pub struct PackMeta {
pub pack_format: i32,
pub description: String,
}
/// Stores all loaded data packs and their assets.
pub struct Datapacks {
/// The metadata of loaded packs. Keyed by the datapack name.
_meta: AHashMap<SmartString<LazyCompact>, PackMeta>,
}
#[derive(Default)]
pub struct Datapack {
pub advancements: (),
pub loot_tables: (),
pub recipes: (),
pub structures: (),
pub tags: TagRegistry,
}
impl Datapack {
pub fn new() -> Self {
Self {
..Default::default()
}
}
pub fn from_folder(dir: &Path) -> Self {
assert!(dir.is_dir(), "not a directory");
todo!()
}
}