diff options
author | Justin Worthe <justin@worthe-it.co.za> | 2018-08-12 21:00:52 +0200 |
---|---|---|
committer | Justin Worthe <justin@worthe-it.co.za> | 2018-08-12 21:00:52 +0200 |
commit | c9f09a22bc54b6275913aa3b900b402c56461c32 (patch) | |
tree | 7affa1194f2172d791028890134585e9a5fd176c /src/input | |
parent | 1f555a48c181a6ad274dd10e04d0c9a8460889db (diff) |
Reduced more duplication and removed TODOs
Diffstat (limited to 'src/input')
-rw-r--r-- | src/input/json.rs | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/input/json.rs b/src/input/json.rs index 2152fc2..843f228 100644 --- a/src/input/json.rs +++ b/src/input/json.rs @@ -72,28 +72,11 @@ struct MissileState { impl State { fn to_bitwise_engine(&self) -> bitwise_engine::BitwiseGameState { - let json_player = self.player(); - let json_opponent = self.opponent(); let mut player = bitwise_engine::Player::empty(); let mut opponent = bitwise_engine::Player::empty(); - // TODO roll the player into the playerbuildings and remove this duplication - player.health = json_player.health; - player.energy = json_player.energy; - player.iron_curtain_available = json_player.iron_curtain_available; - player.iron_curtain_remaining = if json_player.active_iron_curtain_lifetime < 0 { - 0 - } else { - json_player.active_iron_curtain_lifetime as u8 - }; - opponent.health = json_opponent.health; - opponent.energy = json_opponent.energy; - opponent.iron_curtain_available = json_opponent.iron_curtain_available; - opponent.iron_curtain_remaining = if json_opponent.active_iron_curtain_lifetime < 0 { - 0 - } else { - json_opponent.active_iron_curtain_lifetime as u8 - }; + self.player().map_onto_engine(&mut player); + self.opponent().map_onto_engine(&mut opponent); for row in &self.game_map { for cell in row { @@ -192,3 +175,17 @@ impl BuildingState { } } } + + +impl Player { + fn map_onto_engine(&self, engine_player: &mut bitwise_engine::Player) { + engine_player.health = self.health; + engine_player.energy = self.energy; + engine_player.iron_curtain_available = self.iron_curtain_available; + engine_player.iron_curtain_remaining = if self.active_iron_curtain_lifetime < 0 { + 0 + } else { + self.active_iron_curtain_lifetime as u8 + }; + } +} |