diff --git a/client/src/lib.rs b/client/src/lib.rs index b0170f6130..0dbc475509 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -20,7 +20,7 @@ use common::{ comp::{ self, chat::KillSource, - controller::{BlockInteraction, CraftEvent}, + controller::CraftEvent, dialogue::Subject, group, inventory::item::{modular, tool, ItemKind}, @@ -1420,10 +1420,9 @@ impl Client { } pub fn toggle_sprite_light(&mut self, pos: VolumePos, enable: bool) { - self.send_msg(ClientGeneral::ControlEvent(ControlEvent::BlockInteraction( - pos, - BlockInteraction::ToggleLight(enable), - ))); + self.send_msg(ClientGeneral::ControlEvent( + ControlEvent::ToggleSpriteLight(pos, enable), + )); } pub fn remove_buff(&mut self, buff_id: BuffKind) { diff --git a/common/src/comp/controller.rs b/common/src/comp/controller.rs index 373fd29399..7c223267c4 100644 --- a/common/src/comp/controller.rs +++ b/common/src/comp/controller.rs @@ -134,11 +134,6 @@ pub enum UtteranceKind { * sounds */ } -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] -pub enum BlockInteraction { - ToggleLight(bool), -} - #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum ControlEvent { //ToggleLantern, @@ -164,7 +159,7 @@ pub enum ControlEvent { new_ability: ability::AuxiliaryAbility, }, ActivatePortal(Uid), - BlockInteraction(VolumePos, BlockInteraction), + ToggleSpriteLight(VolumePos, bool), } #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] diff --git a/common/src/event.rs b/common/src/event.rs index 369db4adf9..6597dad8ee 100644 --- a/common/src/event.rs +++ b/common/src/event.rs @@ -4,7 +4,6 @@ use crate::{ comp::{ self, agent::Sound, - controller::BlockInteraction, dialogue::Subject, invite::{InviteKind, InviteResponse}, misc::PortalData, @@ -339,10 +338,10 @@ pub enum ServerEvent { entity: EcsEntity, portal: EcsEntity, }, - BlockInteraction { + ToggleSpriteLight { entity: EcsEntity, pos: VolumePos, - interaction: BlockInteraction, + enable: bool, }, } diff --git a/common/src/states/sprite_interact.rs b/common/src/states/sprite_interact.rs index dd6af8388f..004e08fa36 100644 --- a/common/src/states/sprite_interact.rs +++ b/common/src/states/sprite_interact.rs @@ -157,6 +157,7 @@ pub enum SpriteInteractKind { Collectible, Unlock, Fallback, + ToggleLight(bool), } impl From for Option { @@ -233,6 +234,11 @@ impl SpriteInteractKind { Duration::from_secs_f32(1.0), Duration::from_secs_f32(0.3), ), + Self::ToggleLight(_) => ( + Duration::from_secs_f32(0.1), + Duration::from_secs_f32(0.2), + Duration::from_secs_f32(0.1), + ), } } } diff --git a/common/src/terrain/block.rs b/common/src/terrain/block.rs index f64de562df..0a8b89e940 100644 --- a/common/src/terrain/block.rs +++ b/common/src/terrain/block.rs @@ -1,6 +1,6 @@ use super::{sprite, SpriteKind}; use crate::{ - comp::{controller::BlockInteraction, fluid_dynamics::LiquidKind, tool::ToolKind}, + comp::{fluid_dynamics::LiquidKind, tool::ToolKind}, consts::FRIC_GROUND, lottery::LootSpec, make_case_elim, rtsim, @@ -634,12 +634,9 @@ impl Block { } } - pub fn apply_interaction(&self, interaction: BlockInteraction) -> Option { - match interaction { - BlockInteraction::ToggleLight(enable) => { - self.with_attr(sprite::LightDisabled(!enable)).ok() - }, - } + /// Apply a light toggle to this block, if possible + pub fn with_toggle_light(self, enable: bool) -> Option { + self.with_attr(sprite::LightDisabled(!enable)).ok() } #[inline] diff --git a/common/systems/src/controller.rs b/common/systems/src/controller.rs index 33397ba180..81be3a3c14 100644 --- a/common/systems/src/controller.rs +++ b/common/systems/src/controller.rs @@ -140,11 +140,11 @@ impl<'a> System<'a> for Sys { server_emitter.emit(ServerEvent::StartTeleporting { entity, portal }); } }, - ControlEvent::BlockInteraction(pos, interaction) => { - server_emitter.emit(ServerEvent::BlockInteraction { + ControlEvent::ToggleSpriteLight(pos, enable) => { + server_emitter.emit(ServerEvent::ToggleSpriteLight { entity, pos, - interaction, + enable, }); }, } diff --git a/server/src/events/interaction.rs b/server/src/events/interaction.rs index cc7923ffd6..9867de3322 100755 --- a/server/src/events/interaction.rs +++ b/server/src/events/interaction.rs @@ -6,7 +6,6 @@ use common::{ comp::{ self, agent::{AgentEvent, Sound, SoundKind}, - controller::BlockInteraction, dialogue::Subject, inventory::slot::EquipSlot, item::{flatten_counted_items, MaterialStatManifest}, @@ -471,11 +470,11 @@ pub fn handle_tame_pet(server: &mut Server, pet_entity: EcsEntity, owner_entity: tame_pet(server.state.ecs(), pet_entity, owner_entity); } -pub fn handle_block_interaction( +pub fn handle_toggle_sprite_light( server: &mut Server, entity: EcsEntity, pos: VolumePos, - interaction: BlockInteraction, + enable: bool, ) { let state = server.state_mut(); // TODO: Implement toggling lights on volume entities @@ -488,7 +487,7 @@ pub fn handle_block_interaction( .terrain() .get(pos.pos) .ok() - .and_then(|block| block.apply_interaction(interaction)) + .and_then(|block| block.with_toggle_light(enable)) { state.set_block(pos.pos, new_block); } diff --git a/server/src/events/mod.rs b/server/src/events/mod.rs index 170410fafe..c0b471f899 100644 --- a/server/src/events/mod.rs +++ b/server/src/events/mod.rs @@ -25,8 +25,8 @@ use entity_manipulation::{ use group_manip::handle_group; use information::handle_site_info; use interaction::{ - handle_block_interaction, handle_create_sprite, handle_lantern, handle_mine_block, - handle_mount, handle_npc_interaction, handle_set_pet_stay, handle_sound, handle_unmount, + handle_create_sprite, handle_lantern, handle_mine_block, handle_mount, handle_npc_interaction, + handle_set_pet_stay, handle_sound, handle_toggle_sprite_light, handle_unmount, }; use inventory_manip::handle_inventory; use invite::{handle_invite, handle_invite_response}; @@ -305,11 +305,11 @@ impl Server { ServerEvent::StartTeleporting { entity, portal } => { handle_start_teleporting(self, entity, portal) }, - ServerEvent::BlockInteraction { + ServerEvent::ToggleSpriteLight { entity, pos, - interaction, - } => handle_block_interaction(self, entity, pos, interaction), + enable, + } => handle_toggle_sprite_light(self, entity, pos, enable), } }