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::{
|
comp::{
|
||||||
self,
|
self,
|
||||||
chat::KillSource,
|
chat::KillSource,
|
||||||
controller::{BlockInteraction, CraftEvent},
|
controller::CraftEvent,
|
||||||
dialogue::Subject,
|
dialogue::Subject,
|
||||||
group,
|
group,
|
||||||
inventory::item::{modular, tool, ItemKind},
|
inventory::item::{modular, tool, ItemKind},
|
||||||
@ -1420,10 +1420,9 @@ impl Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_sprite_light(&mut self, pos: VolumePos, enable: bool) {
|
pub fn toggle_sprite_light(&mut self, pos: VolumePos, enable: bool) {
|
||||||
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::BlockInteraction(
|
self.send_msg(ClientGeneral::ControlEvent(
|
||||||
pos,
|
ControlEvent::ToggleSpriteLight(pos, enable),
|
||||||
BlockInteraction::ToggleLight(enable),
|
));
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_buff(&mut self, buff_id: BuffKind) {
|
pub fn remove_buff(&mut self, buff_id: BuffKind) {
|
||||||
|
@ -134,11 +134,6 @@ pub enum UtteranceKind {
|
|||||||
* sounds */
|
* sounds */
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
||||||
pub enum BlockInteraction {
|
|
||||||
ToggleLight(bool),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub enum ControlEvent {
|
pub enum ControlEvent {
|
||||||
//ToggleLantern,
|
//ToggleLantern,
|
||||||
@ -164,7 +159,7 @@ pub enum ControlEvent {
|
|||||||
new_ability: ability::AuxiliaryAbility,
|
new_ability: ability::AuxiliaryAbility,
|
||||||
},
|
},
|
||||||
ActivatePortal(Uid),
|
ActivatePortal(Uid),
|
||||||
BlockInteraction(VolumePos, BlockInteraction),
|
ToggleSpriteLight(VolumePos, bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
@ -4,7 +4,6 @@ use crate::{
|
|||||||
comp::{
|
comp::{
|
||||||
self,
|
self,
|
||||||
agent::Sound,
|
agent::Sound,
|
||||||
controller::BlockInteraction,
|
|
||||||
dialogue::Subject,
|
dialogue::Subject,
|
||||||
invite::{InviteKind, InviteResponse},
|
invite::{InviteKind, InviteResponse},
|
||||||
misc::PortalData,
|
misc::PortalData,
|
||||||
@ -339,10 +338,10 @@ pub enum ServerEvent {
|
|||||||
entity: EcsEntity,
|
entity: EcsEntity,
|
||||||
portal: EcsEntity,
|
portal: EcsEntity,
|
||||||
},
|
},
|
||||||
BlockInteraction {
|
ToggleSpriteLight {
|
||||||
entity: EcsEntity,
|
entity: EcsEntity,
|
||||||
pos: VolumePos,
|
pos: VolumePos,
|
||||||
interaction: BlockInteraction,
|
enable: bool,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,6 +157,7 @@ pub enum SpriteInteractKind {
|
|||||||
Collectible,
|
Collectible,
|
||||||
Unlock,
|
Unlock,
|
||||||
Fallback,
|
Fallback,
|
||||||
|
ToggleLight(bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<SpriteKind> for Option<SpriteInteractKind> {
|
impl From<SpriteKind> for Option<SpriteInteractKind> {
|
||||||
@ -233,6 +234,11 @@ impl SpriteInteractKind {
|
|||||||
Duration::from_secs_f32(1.0),
|
Duration::from_secs_f32(1.0),
|
||||||
Duration::from_secs_f32(0.3),
|
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 super::{sprite, SpriteKind};
|
||||||
use crate::{
|
use crate::{
|
||||||
comp::{controller::BlockInteraction, fluid_dynamics::LiquidKind, tool::ToolKind},
|
comp::{fluid_dynamics::LiquidKind, tool::ToolKind},
|
||||||
consts::FRIC_GROUND,
|
consts::FRIC_GROUND,
|
||||||
lottery::LootSpec,
|
lottery::LootSpec,
|
||||||
make_case_elim, rtsim,
|
make_case_elim, rtsim,
|
||||||
@ -634,12 +634,9 @@ impl Block {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_interaction(&self, interaction: BlockInteraction) -> Option<Self> {
|
/// Apply a light toggle to this block, if possible
|
||||||
match interaction {
|
pub fn with_toggle_light(self, enable: bool) -> Option<Self> {
|
||||||
BlockInteraction::ToggleLight(enable) => {
|
|
||||||
self.with_attr(sprite::LightDisabled(!enable)).ok()
|
self.with_attr(sprite::LightDisabled(!enable)).ok()
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -140,11 +140,11 @@ impl<'a> System<'a> for Sys {
|
|||||||
server_emitter.emit(ServerEvent::StartTeleporting { entity, portal });
|
server_emitter.emit(ServerEvent::StartTeleporting { entity, portal });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ControlEvent::BlockInteraction(pos, interaction) => {
|
ControlEvent::ToggleSpriteLight(pos, enable) => {
|
||||||
server_emitter.emit(ServerEvent::BlockInteraction {
|
server_emitter.emit(ServerEvent::ToggleSpriteLight {
|
||||||
entity,
|
entity,
|
||||||
pos,
|
pos,
|
||||||
interaction,
|
enable,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ use common::{
|
|||||||
comp::{
|
comp::{
|
||||||
self,
|
self,
|
||||||
agent::{AgentEvent, Sound, SoundKind},
|
agent::{AgentEvent, Sound, SoundKind},
|
||||||
controller::BlockInteraction,
|
|
||||||
dialogue::Subject,
|
dialogue::Subject,
|
||||||
inventory::slot::EquipSlot,
|
inventory::slot::EquipSlot,
|
||||||
item::{flatten_counted_items, MaterialStatManifest},
|
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);
|
tame_pet(server.state.ecs(), pet_entity, owner_entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_block_interaction(
|
pub fn handle_toggle_sprite_light(
|
||||||
server: &mut Server,
|
server: &mut Server,
|
||||||
entity: EcsEntity,
|
entity: EcsEntity,
|
||||||
pos: VolumePos,
|
pos: VolumePos,
|
||||||
interaction: BlockInteraction,
|
enable: bool,
|
||||||
) {
|
) {
|
||||||
let state = server.state_mut();
|
let state = server.state_mut();
|
||||||
// TODO: Implement toggling lights on volume entities
|
// TODO: Implement toggling lights on volume entities
|
||||||
@ -488,7 +487,7 @@ pub fn handle_block_interaction(
|
|||||||
.terrain()
|
.terrain()
|
||||||
.get(pos.pos)
|
.get(pos.pos)
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|block| block.apply_interaction(interaction))
|
.and_then(|block| block.with_toggle_light(enable))
|
||||||
{
|
{
|
||||||
state.set_block(pos.pos, new_block);
|
state.set_block(pos.pos, new_block);
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,8 @@ use entity_manipulation::{
|
|||||||
use group_manip::handle_group;
|
use group_manip::handle_group;
|
||||||
use information::handle_site_info;
|
use information::handle_site_info;
|
||||||
use interaction::{
|
use interaction::{
|
||||||
handle_block_interaction, handle_create_sprite, handle_lantern, handle_mine_block,
|
handle_create_sprite, handle_lantern, handle_mine_block, handle_mount, handle_npc_interaction,
|
||||||
handle_mount, handle_npc_interaction, handle_set_pet_stay, handle_sound, handle_unmount,
|
handle_set_pet_stay, handle_sound, handle_toggle_sprite_light, handle_unmount,
|
||||||
};
|
};
|
||||||
use inventory_manip::handle_inventory;
|
use inventory_manip::handle_inventory;
|
||||||
use invite::{handle_invite, handle_invite_response};
|
use invite::{handle_invite, handle_invite_response};
|
||||||
@ -305,11 +305,11 @@ impl Server {
|
|||||||
ServerEvent::StartTeleporting { entity, portal } => {
|
ServerEvent::StartTeleporting { entity, portal } => {
|
||||||
handle_start_teleporting(self, entity, portal)
|
handle_start_teleporting(self, entity, portal)
|
||||||
},
|
},
|
||||||
ServerEvent::BlockInteraction {
|
ServerEvent::ToggleSpriteLight {
|
||||||
entity,
|
entity,
|
||||||
pos,
|
pos,
|
||||||
interaction,
|
enable,
|
||||||
} => handle_block_interaction(self, entity, pos, interaction),
|
} => handle_toggle_sprite_light(self, entity, pos, enable),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user