diff options
author | tom barrett <spalf0@gmail.com> | 2019-02-20 14:03:39 -0600 |
---|---|---|
committer | tom barrett <spalf0@gmail.com> | 2019-02-20 14:03:39 -0600 |
commit | eb920a2c85e4ce4bbf755968a42218c0eb74987f (patch) | |
tree | 95943cfb9fa4d5b20dc38af0896d5d69e9bbb706 /src/modules/construction.rs | |
parent | c6be289134c1f749884d269f955b39d39b604469 (diff) |
better mass access functions which improved testing code
Diffstat (limited to 'src/modules/construction.rs')
-rw-r--r-- | src/modules/construction.rs | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/src/modules/construction.rs b/src/modules/construction.rs index 0eec155..091ebc6 100644 --- a/src/modules/construction.rs +++ b/src/modules/construction.rs @@ -33,7 +33,7 @@ impl Construction { masses: &mut HashMap<String, Mass>, storage: &mut Storage, ) { - if !self.has_enough(storage) { + if storage.item_count(ItemType::Iron) < constants::SHIP_CONSTRUCTION_IRON_COST { self.off(); } if let Some(timer) = self.start { @@ -43,9 +43,10 @@ impl Construction { } } if self.status == Status::Constructed { - storage - .take_items(ItemType::Iron, constants::SHIP_CONSTRUCTION_IRON_COST) - .unwrap(); + for _ in 0..constants::SHIP_CONSTRUCTION_IRON_COST { + storage.take_item(ItemType::Iron).unwrap(); + } + masses.insert( "Station".to_string(), Mass::new_station( @@ -60,7 +61,8 @@ impl Construction { pub fn get_client_data(&self, storage: &Storage) -> String { let client_data = ClientData { - has_enough: self.has_enough(storage), + has_enough: storage.item_count(ItemType::Iron) + >= constants::SHIP_CONSTRUCTION_IRON_COST, status: self.status.clone(), }; serde_json::to_string(&client_data).unwrap() + "\n" @@ -72,15 +74,6 @@ impl Construction { } } - fn has_enough(&self, storage: &Storage) -> bool { - storage - .items - .iter() - .filter(|item| item.item_type == ItemType::Iron) - .count() - >= constants::SHIP_CONSTRUCTION_IRON_COST - } - fn toggle(&mut self) { match self.status { Status::None => self.on(), |