mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Don't use distinct event system for handling sprite interactions
This commit is contained in:
parent
4cbec5d93c
commit
ad8965fdd7
@ -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) {
|
||||
|
@ -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)]
|
||||
|
@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -157,6 +157,7 @@ pub enum SpriteInteractKind {
|
||||
Collectible,
|
||||
Unlock,
|
||||
Fallback,
|
||||
ToggleLight(bool),
|
||||
}
|
||||
|
||||
impl From<SpriteKind> for Option<SpriteInteractKind> {
|
||||
@ -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),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Self> {
|
||||
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> {
|
||||
self.with_attr(sprite::LightDisabled(!enable)).ok()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -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,
|
||||
});
|
||||
},
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user