fish_lib/data/
item_data.rs1use crate::models::item::attributes::{ItemAttributes, ItemAttributesType};
2use crate::models::item::attributes_container::{
3 ItemAttributesContainer, ItemAttributesContainerInterface,
4};
5use crate::models::item::properties::{ItemProperties, ItemPropertiesType};
6use crate::models::item::properties_container::{
7 ItemPropertiesContainer, ItemPropertiesContainerInterface,
8};
9use serde::{Deserialize, Serialize};
10use std::collections::HashMap;
11
12#[derive(Debug, Serialize, Deserialize, PartialEq)]
13pub struct ItemData {
14 #[serde(skip, default)]
15 pub id: i32,
16 pub name: String,
17 #[serde(default = "default_one")]
23 pub max_count: u32,
24 #[serde(default)]
25 pub attributes: ItemAttributesContainer,
26 #[serde(default)]
27 pub default_properties: ItemPropertiesContainer,
28}
29
30impl Default for ItemData {
31 fn default() -> Self {
32 Self {
33 id: 0,
34 name: "".to_string(),
35 max_count: 1,
36 attributes: ItemAttributesContainer::new(),
37 default_properties: ItemPropertiesContainer::new(),
38 }
39 }
40}
41
42fn default_one() -> u32 {
43 1
44}
45
46impl ItemPropertiesContainerInterface for ItemData {
47 fn get_properties(&self) -> &HashMap<ItemPropertiesType, ItemProperties> {
48 self.default_properties.get_properties()
49 }
50
51 fn get_properties_mut(&mut self) -> &mut HashMap<ItemPropertiesType, ItemProperties> {
52 self.default_properties.get_properties_mut()
53 }
54}
55
56impl ItemAttributesContainerInterface for ItemData {
57 fn get_attributes(&self) -> &HashMap<ItemAttributesType, ItemAttributes> {
58 self.attributes.get_attributes()
59 }
60}