Switched to using existing swap_lantern function

Removed unnecessary function
This commit is contained in:
ninefox 2022-01-17 11:22:11 -08:00
parent 889a593b13
commit 64f6faece5
4 changed files with 16 additions and 24 deletions

View File

@ -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

View File

@ -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::<comp::LightEmitter>()
.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();

View File

@ -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::<common::comp::LightEmitter>(),
entity,
&lantern,
),
ServerEvent::NpcInteract(interactor, target) => {
handle_npc_interaction(self, interactor, target)
},

View File

@ -1234,7 +1234,7 @@ impl PlayState for SessionState {
bypass_dialog,
} => {
let mut move_allowed = true;
let mut maybe_lantern: Option<comp::item::Lantern> = None;
let mut lantern_opt: Option<comp::item::Lantern> = 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 {