Lantern color will now change when swapping lanterns while lantern is activated

This commit is contained in:
ninefox 2022-01-16 16:24:31 -08:00
parent 7b7ad62be9
commit fc012b4989
8 changed files with 46 additions and 3 deletions

View File

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

View File

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

View File

@ -125,6 +125,7 @@ pub enum ControlEvent {
//ToggleLantern,
EnableLantern,
DisableLantern,
UpdateLantern(crate::comp::item::Lantern),
Interact(Uid),
InitiateInvite(Uid, InviteKind),
InviteResponse(InviteResponse),

View File

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

View File

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

View File

@ -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::<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,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)
},

View File

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