From 64f6faece5605ac644ece6f66c261540099a71df Mon Sep 17 00:00:00 2001 From: ninefox Date: Mon, 17 Jan 2022 11:22:11 -0800 Subject: [PATCH] Switched to using existing `swap_lantern` function Removed unnecessary function --- common/systems/src/controller.rs | 2 +- server/src/events/interaction.rs | 13 ------------- server/src/events/mod.rs | 15 ++++++++++----- voxygen/src/session/mod.rs | 10 +++++----- 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/common/systems/src/controller.rs b/common/systems/src/controller.rs index 49a58a9f2d..3f7ceca9f5 100644 --- a/common/systems/src/controller.rs +++ b/common/systems/src/controller.rs @@ -72,7 +72,7 @@ impl<'a> System<'a> for Sys { server_emitter.emit(ServerEvent::DisableLantern(entity)) }, ControlEvent::UpdateLantern(lantern) => { - server_emitter.emit(ServerEvent::UpdateLantern(entity, lantern)); + server_emitter.emit(ServerEvent::UpdateLantern(entity, lantern)) }, ControlEvent::Interact(npc_uid) => { if let Some(npc_entity) = read_data diff --git a/server/src/events/interaction.rs b/server/src/events/interaction.rs index c4f5bf790c..d3d92106e9 100644 --- a/server/src/events/interaction.rs +++ b/server/src/events/interaction.rs @@ -35,19 +35,6 @@ use lazy_static::lazy_static; use serde::Deserialize; use std::iter::FromIterator; -pub fn update_lantern(server: &mut Server, entity: EcsEntity, lantern: comp::item::Lantern) { - let _ = server - .state_mut() - .ecs() - .write_storage::() - .insert(entity, comp::LightEmitter { - col: lantern.color(), - strength: lantern.strength(), - flicker: 0.35, - animated: true, - }); -} - pub fn handle_lantern(server: &mut Server, entity: EcsEntity, enable: bool) { let ecs = server.state_mut().ecs(); diff --git a/server/src/events/mod.rs b/server/src/events/mod.rs index dbee7de720..55dbfb52e3 100644 --- a/server/src/events/mod.rs +++ b/server/src/events/mod.rs @@ -15,9 +15,9 @@ use group_manip::handle_group; use information::handle_site_info; use interaction::{ handle_create_sprite, handle_lantern, handle_mine_block, handle_mount, handle_npc_interaction, - handle_possess, handle_sound, handle_unmount, update_lantern, + handle_possess, handle_sound, handle_unmount, }; -use inventory_manip::handle_inventory; +use inventory_manip::{handle_inventory, swap_lantern}; use invite::{handle_invite, handle_invite_response}; use player::{handle_client_disconnect, handle_exit_ingame}; use specs::{Builder, Entity as EcsEntity, WorldExt}; @@ -107,9 +107,14 @@ impl Server { }, ServerEvent::EnableLantern(entity) => handle_lantern(self, entity, true), ServerEvent::DisableLantern(entity) => handle_lantern(self, entity, false), - ServerEvent::UpdateLantern(entity, lantern) => { - update_lantern(self, entity, lantern) - }, + ServerEvent::UpdateLantern(entity, lantern) => swap_lantern( + &mut self + .state + .ecs() + .write_storage::(), + entity, + &lantern, + ), ServerEvent::NpcInteract(interactor, target) => { handle_npc_interaction(self, interactor, target) }, diff --git a/voxygen/src/session/mod.rs b/voxygen/src/session/mod.rs index db251d09c1..af5f24704e 100644 --- a/voxygen/src/session/mod.rs +++ b/voxygen/src/session/mod.rs @@ -1234,7 +1234,7 @@ impl PlayState for SessionState { bypass_dialog, } => { let mut move_allowed = true; - let mut maybe_lantern: Option = None; + let mut lantern_opt: Option = None; if !bypass_dialog { if let Some(inventory) = self .client @@ -1248,7 +1248,7 @@ impl PlayState for SessionState { (Slot::Inventory(inv_slot), Slot::Equip(equip_slot)) | (Slot::Equip(equip_slot), Slot::Inventory(inv_slot)) => { if let EquipSlot::Lantern = equip_slot { - maybe_lantern = + lantern_opt = inventory.get(inv_slot).and_then(|item| { if let comp::item::ItemKind::Lantern(l) = item.kind() @@ -1289,10 +1289,10 @@ impl PlayState for SessionState { } } if move_allowed { - if let Some(new_lantern) = maybe_lantern { - self.client.borrow_mut().update_lantern(new_lantern); - } self.client.borrow_mut().swap_slots(slot_a, slot_b); + if let Some(lantern) = lantern_opt { + self.client.borrow_mut().update_lantern(lantern) + } } }, HudEvent::SplitSwapSlots {