summaryrefslogtreecommitdiff
path: root/src/systems/useitem.rs
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-09-22 14:34:53 +0200
committertroido <troido@protonmail.com>2020-09-22 14:34:53 +0200
commit33c1054d528efd896415baf08d4a52e1cdd7b801 (patch)
tree9d564a101129ca800f91fa37c4c002747e06c8da /src/systems/useitem.rs
parent410de5640c76b1501240e39e725350fc58a7e094 (diff)
turned some math into if let to decrease indentation
Diffstat (limited to 'src/systems/useitem.rs')
-rw-r--r--src/systems/useitem.rs49
1 files changed, 23 insertions, 26 deletions
diff --git a/src/systems/useitem.rs b/src/systems/useitem.rs
index a560c18..8b58d75 100644
--- a/src/systems/useitem.rs
+++ b/src/systems/useitem.rs
@@ -42,41 +42,38 @@ impl <'a> System<'a> for Use {
fn run(&mut self, (entities, controllers, positions, mut inventories, mut new, mut attacked, ground, flags, roompermissions): Self::SystemData) {
for (ent, controller, position, inventory) in (&entities, &controllers, &positions, &mut inventories).join(){
- match &controller.control {
- Control::Use(rank) => {
- if let Some(entry) = inventory.items.get_mut(*rank) {
- match &entry.item.action {
- Build(template, required_flags, blocking_flags) => {
- let ground_flags = ground.flags_on(position.pos, &flags);
- if roompermissions.build && required_flags.is_subset(&ground_flags) && blocking_flags.is_disjoint(&ground_flags){
- new.create(position.pos, &template).unwrap();
- inventory.items.remove(*rank);
- }
- }
- Eat(health_diff) => {
- AttackInbox::add_message(&mut attacked, ent, AttackMessage{typ: AttackType::Heal(*health_diff), attacker: Option::None});
+ if let Control::Use(rank) = &controller.control {
+ if let Some(entry) = inventory.items.get_mut(*rank) {
+ match &entry.item.action {
+ Build(template, required_flags, blocking_flags) => {
+ let ground_flags = ground.flags_on(position.pos, &flags);
+ if roompermissions.build && required_flags.is_subset(&ground_flags) && blocking_flags.is_disjoint(&ground_flags){
+ new.create(position.pos, &template).unwrap();
inventory.items.remove(*rank);
}
- Equip(equippable) => {
- if entry.is_equipped {
- inventory.items[*rank].is_equipped = false;
- } else {
- let slot = equippable.slot;
- for otherentry in inventory.items.iter_mut() {
- if let Equip(other) = &otherentry.item.action {
- if other.slot == slot {
- otherentry.is_equipped = false;
- }
+ }
+ Eat(health_diff) => {
+ AttackInbox::add_message(&mut attacked, ent, AttackMessage{typ: AttackType::Heal(*health_diff), attacker: Option::None});
+ inventory.items.remove(*rank);
+ }
+ Equip(equippable) => {
+ if entry.is_equipped {
+ inventory.items[*rank].is_equipped = false;
+ } else {
+ let slot = equippable.slot;
+ for otherentry in inventory.items.iter_mut() {
+ if let Equip(other) = &otherentry.item.action {
+ if other.slot == slot {
+ otherentry.is_equipped = false;
}
}
- inventory.items[*rank].is_equipped = true;
}
+ inventory.items[*rank].is_equipped = true;
}
- None => {}
}
+ None => {}
}
}
- _ => {}
}
}
}