summaryrefslogtreecommitdiff
path: root/src/item.rs
blob: 1e0e7abb3dd26619ec1ac8b94ffee428cc7c48c8 (plain)
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
use crate::constants;
use crate::math::rand_name;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub enum ItemType {
    CrudeMinerals,
    Iron,
    Hydrogen,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Item {
    pub itemtype: ItemType,
    pub name: String,
    pub size: usize,
}

impl Item {
    pub fn new(itemtype: ItemType) -> Item {
        let size = match itemtype {
            ItemType::Iron => constants::IRON_SIZE,
            ItemType::Hydrogen => constants::HYDROGEN_SIZE,
            ItemType::CrudeMinerals => constants::CRUDE_MINERALS_SIZE,
        };
        Item {
            name: serde_json::to_string(&itemtype).unwrap() + &rand_name(),
            itemtype,
            size,
        }
    }
}