diff options
author | tom barrett <spalf0@gmail.com> | 2019-02-12 13:20:06 -0600 |
---|---|---|
committer | tom barrett <spalf0@gmail.com> | 2019-02-12 13:20:06 -0600 |
commit | 070485e093dc540a5db9650d438cffe3d18d3883 (patch) | |
tree | a0ab1f42c844b3557c7f17b11f3c7eae334e853d /src/item.rs | |
parent | 6a906ce663935e37d6dd79a2e2e31fb07ca7c2af (diff) |
added constants file, made so items are referred to by an enum, figured better ways than ship_clone
Diffstat (limited to 'src/item.rs')
-rw-r--r-- | src/item.rs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/item.rs b/src/item.rs index c51b1a2..0d655e4 100644 --- a/src/item.rs +++ b/src/item.rs @@ -1,18 +1,29 @@ +use crate::constants; +use crate::math::rand_name; + +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +pub enum ItemType { + CrudeMinerals, + Iron, +} + #[derive(Serialize, Deserialize, Debug, Clone)] pub struct Item { + pub itemtype: ItemType, pub name: String, pub size: usize, } impl Item { - pub fn new(name: &str, size: usize) -> Item { + pub fn new(itemtype: ItemType) -> Item { + let size = match itemtype { + ItemType::CrudeMinerals => constants::CRUDE_MINERALS_SIZE, + ItemType::Iron => constants::IRON_SIZE, + }; Item { - name: String::from(name), + name: serde_json::to_string(&itemtype).unwrap() + &rand_name(), + itemtype, size, } } - - pub fn is_mineral(&self) -> bool { - self.name == "Mineral" - } } |