Browse Source

slots need to be updated when an item leaves inventory

pbs
jake 4 years ago
parent
commit
a148d96adc
  1. 4
      src/ship/items/inventory.rs
  2. 34
      src/ship/items/manager.rs

4
src/ship/items/inventory.rs

@ -565,5 +565,9 @@ impl CharacterInventory {
(item, slot)
})
}
pub fn iter(&self) -> impl Iterator<Item = &InventoryItem> {
self.items.iter()
}
}

34
src/ship/items/manager.rs

@ -45,6 +45,35 @@ pub enum ItemManagerError {
ItemIdNotInInventory(ClientItemId)
}
async fn update_inventory_slots<EG: EntityGateway>(entity_gateway: &mut EG, character: &CharacterEntity, inventory: &CharacterInventory) {
for (slot, item) in inventory.iter().enumerate() {
match item {
InventoryItem::Individual(individual_inventory_item) => {
entity_gateway.change_item_location(
&individual_inventory_item.entity_id,
ItemLocation::Inventory {
character_id: character.id,
slot: slot,
equipped: individual_inventory_item.equipped,
}
).await
},
InventoryItem::Stacked(stacked_inventory_item) => {
for entity_id in stacked_inventory_item.entity_ids.iter() {
entity_gateway.change_item_location(
entity_id,
ItemLocation::Inventory {
character_id: character.id,
slot: slot,
equipped: false,
}).await;
}}
}
}
}
pub struct ItemManager {
id_counter: u32,
@ -449,6 +478,7 @@ impl ItemManager {
},
}
update_inventory_slots(entity_gateway, character, &inventory).await;
Ok(())
}
@ -528,6 +558,7 @@ impl ItemManager {
ItemLocation::Consumed).await;
}
update_inventory_slots(entity_gateway, character, &inventory).await;
Ok(consumed_item)
}
@ -564,6 +595,7 @@ impl ItemManager {
}
}
update_inventory_slots(entity_gateway, character, &inventory).await;
Ok(())
}
@ -640,6 +672,7 @@ impl ItemManager {
}).await;
}
update_inventory_slots(entity_gateway, character, &inventory).await;
Ok(())
}
@ -754,6 +787,7 @@ impl ItemManager {
}
_ => {}
}
update_inventory_slots(entity_gateway, character, &inventory).await;
Ok(())
}

Loading…
Cancel
Save