Avoid right-ward shift

This commit is contained in:
timokoesters 2019-08-30 21:54:33 +02:00
parent 1c7beaedae
commit 5fe2b81ec8
No known key found for this signature in database
GPG Key ID: CD80BE9AAEE78097
2 changed files with 13 additions and 19 deletions

View File

@ -81,7 +81,7 @@ pub enum Debug {
Boost, Boost,
} }
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[derive(Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Item { pub enum Item {
Tool { Tool {
kind: Tool, kind: Tool,

View File

@ -713,36 +713,30 @@ impl Server {
_ => {} _ => {}
}, },
ClientMsg::ActivateInventorySlot(x) => { ClientMsg::ActivateInventorySlot(x) => {
let item_opt = state let item = state
.ecs() .ecs()
.write_storage::<comp::Inventory>() .write_storage::<comp::Inventory>()
.get_mut(entity) .get_mut(entity)
.and_then(|inv| inv.remove(x)); .and_then(|inv| inv.remove(x));
if let Some(item) = item_opt {
match item { match item {
comp::Item::Tool { .. } | comp::Item::Debug(_) => { Some(comp::Item::Tool { .. }) | Some(comp::Item::Debug(_)) => {
if let Some(stats) = state if let Some(stats) =
.ecs() state.ecs().write_storage::<comp::Stats>().get_mut(entity)
.write_storage::<comp::Stats>()
.get_mut(entity)
{ {
state state
.ecs() .ecs()
.write_storage::<comp::Inventory>() .write_storage::<comp::Inventory>()
.get_mut(entity) .get_mut(entity)
.map(|inv| { .map(|inv| inv.insert(x, stats.equipment.main.take()));
inv.insert(x, stats.equipment.main.take())
});
stats.equipment.main = Some(item); stats.equipment.main = item;
} }
} }
_ => {} _ => {}
} }
state.write_component(entity, comp::InventoryUpdate); state.write_component(entity, comp::InventoryUpdate);
} }
}
ClientMsg::SwapInventorySlots(a, b) => { ClientMsg::SwapInventorySlots(a, b) => {
state state
.ecs() .ecs()