From fc012b49899b903c0a5a7fda167a87928fd307ff Mon Sep 17 00:00:00 2001 From: ninefox Date: Sun, 16 Jan 2022 16:24:31 -0800 Subject: [PATCH] Lantern color will now change when swapping lanterns while lantern is activated --- CHANGELOG.md | 1 + client/src/lib.rs | 6 ++++++ common/src/comp/controller.rs | 1 + common/src/event.rs | 1 + common/systems/src/controller.rs | 3 +++ server/src/events/interaction.rs | 13 +++++++++++++ server/src/events/mod.rs | 5 ++++- voxygen/src/session/mod.rs | 19 +++++++++++++++++-- 8 files changed, 46 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fb7ab61d6..af83a54a8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,6 +77,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bodies of water no longer contain black chunks on the voxel minimap. - Agents can flee once again, and more appropriately - Items in hotbar no longer change when sorting inventory +- Lantern color changes when swapping lanterns ## [0.11.0] - 2021-09-11 diff --git a/client/src/lib.rs b/client/src/lib.rs index 41f364b938..6ded5caf69 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -1081,6 +1081,12 @@ impl Client { self.send_msg(ClientGeneral::ControlEvent(ControlEvent::DisableLantern)); } + pub fn update_lantern(&mut self, lantern: comp::item::Lantern) { + self.send_msg(ClientGeneral::ControlEvent(ControlEvent::UpdateLantern( + lantern, + ))); + } + pub fn remove_buff(&mut self, buff_id: BuffKind) { self.send_msg(ClientGeneral::ControlEvent(ControlEvent::RemoveBuff( buff_id, diff --git a/common/src/comp/controller.rs b/common/src/comp/controller.rs index 7c06b42e1c..c73302c9f4 100644 --- a/common/src/comp/controller.rs +++ b/common/src/comp/controller.rs @@ -125,6 +125,7 @@ pub enum ControlEvent { //ToggleLantern, EnableLantern, DisableLantern, + UpdateLantern(crate::comp::item::Lantern), Interact(Uid), InitiateInvite(Uid, InviteKind), InviteResponse(InviteResponse), diff --git a/common/src/event.rs b/common/src/event.rs index d1e8215a11..ac7f83dd06 100644 --- a/common/src/event.rs +++ b/common/src/event.rs @@ -93,6 +93,7 @@ pub enum ServerEvent { }, EnableLantern(EcsEntity), DisableLantern(EcsEntity), + UpdateLantern(EcsEntity, comp::item::Lantern), NpcInteract(EcsEntity, EcsEntity), InviteResponse(EcsEntity, InviteResponse), InitiateInvite(EcsEntity, Uid, InviteKind), diff --git a/common/systems/src/controller.rs b/common/systems/src/controller.rs index dcc403e15f..49a58a9f2d 100644 --- a/common/systems/src/controller.rs +++ b/common/systems/src/controller.rs @@ -71,6 +71,9 @@ impl<'a> System<'a> for Sys { ControlEvent::DisableLantern => { server_emitter.emit(ServerEvent::DisableLantern(entity)) }, + ControlEvent::UpdateLantern(lantern) => { + server_emitter.emit(ServerEvent::UpdateLantern(entity, lantern)); + }, ControlEvent::Interact(npc_uid) => { if let Some(npc_entity) = read_data .uid_allocator diff --git a/server/src/events/interaction.rs b/server/src/events/interaction.rs index d3d92106e9..da4b27141a 100644 --- a/server/src/events/interaction.rs +++ b/server/src/events/interaction.rs @@ -35,6 +35,19 @@ 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 4fee80df93..dbee7de720 100644 --- a/server/src/events/mod.rs +++ b/server/src/events/mod.rs @@ -15,7 +15,7 @@ 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, + handle_possess, handle_sound, handle_unmount, update_lantern, }; use inventory_manip::handle_inventory; use invite::{handle_invite, handle_invite_response}; @@ -107,6 +107,9 @@ 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::NpcInteract(interactor, target) => { handle_npc_interaction(self, interactor, target) }, diff --git a/voxygen/src/session/mod.rs b/voxygen/src/session/mod.rs index 359a90e01c..c878cea6bc 100644 --- a/voxygen/src/session/mod.rs +++ b/voxygen/src/session/mod.rs @@ -1234,9 +1234,9 @@ impl PlayState for SessionState { bypass_dialog, } => { let mut move_allowed = true; + let mut maybe_lantern: Option = None; if !bypass_dialog { - if let Some(inventory) = self - .client + if let Some(inventory) = self.client .borrow() .state() .ecs() @@ -1246,6 +1246,18 @@ impl PlayState for SessionState { match (slot_a, slot_b) { (Slot::Inventory(inv_slot), Slot::Equip(equip_slot)) | (Slot::Equip(equip_slot), Slot::Inventory(inv_slot)) => { + if let EquipSlot::Lantern = equip_slot { + maybe_lantern = + inventory.get(inv_slot).and_then(|item| { + if let comp::item::ItemKind::Lantern(l) = + item.kind() + { + Some(l.clone()) + } else { + None + } + }); + } if !inventory.can_swap(inv_slot, equip_slot) { move_allowed = false; } else { @@ -1276,6 +1288,9 @@ 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); } },