summaryrefslogtreecommitdiff
path: root/src/item.rs
blob: 006e2dc6c88bbcabb3decec94b68cc7ba91cbb90 (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 item_type: ItemType,
    pub name: String,
    pub size: usize,
}

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