steel_registry/
painting_variant.rs1use rustc_hash::FxHashMap;
2use simdnbt::ToNbtTag;
3use simdnbt::owned::NbtTag;
4use steel_utils::Identifier;
5use text_components::TextComponent;
6
7#[derive(Debug)]
9pub struct PaintingVariant {
10 pub key: Identifier,
11 pub width: i32,
12 pub height: i32,
13 pub asset_id: Identifier,
14 pub title: Option<TextComponent>,
15 pub author: Option<TextComponent>,
16}
17
18impl ToNbtTag for &PaintingVariant {
19 fn to_nbt_tag(self) -> NbtTag {
20 use simdnbt::owned::NbtCompound;
21 let mut compound = NbtCompound::new();
22 let asset_id = self.asset_id.to_string();
23 compound.insert("asset_id", asset_id.as_str());
24 compound.insert("width", self.width);
25 compound.insert("height", self.height);
26 if let Some(title) = &self.title {
27 compound.insert(
28 "title",
29 NbtTag::Compound(title.to_nbt_tag().into_compound().unwrap()),
30 );
31 }
32 if let Some(author) = &self.author {
33 compound.insert(
34 "author",
35 NbtTag::Compound(author.to_nbt_tag().into_compound().unwrap()),
36 );
37 }
38 NbtTag::Compound(compound)
39 }
40}
41
42pub type PaintingVariantRef = &'static PaintingVariant;
43
44pub struct PaintingVariantRegistry {
45 painting_variants_by_id: Vec<PaintingVariantRef>,
46 painting_variants_by_key: FxHashMap<Identifier, usize>,
47 tags: FxHashMap<Identifier, Vec<Identifier>>,
48 allows_registering: bool,
49}
50
51impl PaintingVariantRegistry {
52 #[must_use]
53 pub fn new() -> Self {
54 Self {
55 painting_variants_by_id: Vec::new(),
56 painting_variants_by_key: FxHashMap::default(),
57 tags: FxHashMap::default(),
58 allows_registering: true,
59 }
60 }
61}
62
63crate::impl_standard_methods!(
64 PaintingVariantRegistry,
65 PaintingVariantRef,
66 painting_variants_by_id,
67 painting_variants_by_key,
68 allows_registering
69);
70
71crate::impl_registry!(
72 PaintingVariantRegistry,
73 PaintingVariant,
74 painting_variants_by_id,
75 painting_variants_by_key,
76 painting_variants
77);
78crate::impl_tagged_registry!(
79 PaintingVariantRegistry,
80 painting_variants_by_key,
81 "painting variant"
82);