mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Moved sfx from common to voxygen
This commit is contained in:
parent
2b2e24be5e
commit
dc1844b489
@ -21,7 +21,6 @@ use common::{
|
||||
self, ControlAction, ControlEvent, Controller, ControllerInputs, InventoryManip,
|
||||
InventoryUpdateEvent,
|
||||
},
|
||||
event::{EventBus, SfxEvent, SfxEventItem},
|
||||
msg::{
|
||||
validate_chat_msg, ChatMsgValidationError, ClientMsg, ClientState, Notification,
|
||||
PlayerInfo, PlayerListUpdate, RegisterError, RequestStateError, ServerInfo, ServerMsg,
|
||||
@ -57,6 +56,7 @@ pub enum Event {
|
||||
Chat(comp::ChatMsg),
|
||||
Disconnect,
|
||||
DisconnectionNotification(u64),
|
||||
InventoryUpdated(InventoryUpdateEvent),
|
||||
Notification(Notification),
|
||||
SetViewDistance(u32),
|
||||
}
|
||||
@ -883,34 +883,15 @@ impl Client {
|
||||
self.clean_state();
|
||||
},
|
||||
ServerMsg::InventoryUpdate(inventory, event) => {
|
||||
// TODO: Move this SFX code to Voxygen
|
||||
let sfx_event = SfxEvent::from(&event);
|
||||
self.state
|
||||
.ecs()
|
||||
.read_resource::<EventBus<SfxEventItem>>()
|
||||
.emit_now(SfxEventItem::at_player_position(sfx_event));
|
||||
|
||||
match event {
|
||||
InventoryUpdateEvent::CollectFailed => {
|
||||
// TODO This might not be the best way to show an error
|
||||
frontend_events.push(Event::Chat(comp::ChatMsg {
|
||||
message: String::from(
|
||||
"Failed to collect item. Your inventory may be full!",
|
||||
),
|
||||
chat_type: comp::ChatType::CommandError,
|
||||
}))
|
||||
},
|
||||
InventoryUpdateEvent::CollectFailed => {},
|
||||
_ => {
|
||||
if let InventoryUpdateEvent::Collected(item) = event {
|
||||
frontend_events.push(Event::Chat(comp::ChatMsg {
|
||||
message: format!("Picked up {}", item.name()),
|
||||
chat_type: comp::ChatType::Meta,
|
||||
}));
|
||||
}
|
||||
|
||||
// Push the updated inventory component to the client
|
||||
self.state.write_component(self.entity, inventory);
|
||||
},
|
||||
}
|
||||
|
||||
frontend_events.push(Event::InventoryUpdated(event));
|
||||
},
|
||||
ServerMsg::TerrainChunkUpdate { key, chunk } => {
|
||||
if let Ok(chunk) = chunk {
|
||||
|
@ -1,95 +1,10 @@
|
||||
use crate::{
|
||||
comp,
|
||||
comp::item::{Consumable, ItemKind},
|
||||
sync::Uid,
|
||||
util::Dir,
|
||||
};
|
||||
use comp::{item::ToolCategory, CharacterAbilityType, InventoryUpdateEvent, Item};
|
||||
use crate::{comp, sync::Uid, util::Dir};
|
||||
use comp::item::Item;
|
||||
use parking_lot::Mutex;
|
||||
use serde::Deserialize;
|
||||
use specs::Entity as EcsEntity;
|
||||
use std::{collections::VecDeque, convert::TryFrom, ops::DerefMut};
|
||||
use std::{collections::VecDeque, ops::DerefMut};
|
||||
use vek::*;
|
||||
|
||||
pub struct SfxEventItem {
|
||||
pub sfx: SfxEvent,
|
||||
pub pos: Option<Vec3<f32>>,
|
||||
pub vol: Option<f32>,
|
||||
}
|
||||
|
||||
impl SfxEventItem {
|
||||
pub fn new(sfx: SfxEvent, pos: Option<Vec3<f32>>, vol: Option<f32>) -> Self {
|
||||
Self { sfx, pos, vol }
|
||||
}
|
||||
|
||||
pub fn at_player_position(sfx: SfxEvent) -> Self {
|
||||
Self {
|
||||
sfx,
|
||||
pos: None,
|
||||
vol: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Deserialize, Hash, Eq)]
|
||||
pub enum SfxEvent {
|
||||
Idle,
|
||||
Run,
|
||||
Roll,
|
||||
Climb,
|
||||
GliderOpen,
|
||||
Glide,
|
||||
GliderClose,
|
||||
Jump,
|
||||
Fall,
|
||||
ExperienceGained,
|
||||
LevelUp,
|
||||
Attack(CharacterAbilityType, ToolCategory),
|
||||
Wield(ToolCategory),
|
||||
Unwield(ToolCategory),
|
||||
Inventory(SfxInventoryEvent),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Deserialize, Hash, Eq)]
|
||||
pub enum SfxInventoryEvent {
|
||||
Collected,
|
||||
CollectedTool(ToolCategory),
|
||||
CollectFailed,
|
||||
Consumed(Consumable),
|
||||
Debug,
|
||||
Dropped,
|
||||
Given,
|
||||
Swapped,
|
||||
}
|
||||
|
||||
impl From<&InventoryUpdateEvent> for SfxEvent {
|
||||
fn from(value: &InventoryUpdateEvent) -> Self {
|
||||
match value {
|
||||
InventoryUpdateEvent::Collected(item) => {
|
||||
// Handle sound effects for types of collected items, falling back to the
|
||||
// default Collected event
|
||||
match item.kind {
|
||||
ItemKind::Tool(tool) => SfxEvent::Inventory(SfxInventoryEvent::CollectedTool(
|
||||
ToolCategory::try_from(tool.kind).unwrap(),
|
||||
)),
|
||||
_ => SfxEvent::Inventory(SfxInventoryEvent::Collected),
|
||||
}
|
||||
},
|
||||
InventoryUpdateEvent::CollectFailed => {
|
||||
SfxEvent::Inventory(SfxInventoryEvent::CollectFailed)
|
||||
},
|
||||
InventoryUpdateEvent::Consumed(consumable) => {
|
||||
SfxEvent::Inventory(SfxInventoryEvent::Consumed(*consumable))
|
||||
},
|
||||
InventoryUpdateEvent::Debug => SfxEvent::Inventory(SfxInventoryEvent::Debug),
|
||||
InventoryUpdateEvent::Dropped => SfxEvent::Inventory(SfxInventoryEvent::Dropped),
|
||||
InventoryUpdateEvent::Given => SfxEvent::Inventory(SfxInventoryEvent::Given),
|
||||
InventoryUpdateEvent::Swapped => SfxEvent::Inventory(SfxInventoryEvent::Swapped),
|
||||
_ => SfxEvent::Inventory(SfxInventoryEvent::Swapped),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum LocalEvent {
|
||||
/// Applies upward force to entity's `Vel`
|
||||
Jump(EcsEntity),
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
comp,
|
||||
event::{EventBus, LocalEvent, ServerEvent, SfxEventItem},
|
||||
event::{EventBus, LocalEvent, ServerEvent},
|
||||
region::RegionMap,
|
||||
sync::WorldSyncExt,
|
||||
sys,
|
||||
@ -170,7 +170,6 @@ impl State {
|
||||
// TODO: only register on the server
|
||||
ecs.insert(EventBus::<ServerEvent>::default());
|
||||
ecs.insert(EventBus::<LocalEvent>::default());
|
||||
ecs.insert(EventBus::<SfxEventItem>::default());
|
||||
ecs.insert(RegionMap::new());
|
||||
|
||||
ecs
|
||||
|
@ -1,6 +1,6 @@
|
||||
/// EventMapper::Combat watches the combat states of surrounding entities' and
|
||||
/// emits sfx related to weapons and attacks/abilities
|
||||
use crate::audio::sfx::{SfxTriggerItem, SfxTriggers, SFX_DIST_LIMIT_SQR};
|
||||
use crate::audio::sfx::{SfxEvent, SfxEventItem, SfxTriggerItem, SfxTriggers, SFX_DIST_LIMIT_SQR};
|
||||
|
||||
use super::EventMapper;
|
||||
|
||||
@ -9,7 +9,7 @@ use common::{
|
||||
item::{Item, ItemKind, ToolCategory},
|
||||
CharacterAbilityType, CharacterState, ItemConfig, Loadout, Pos,
|
||||
},
|
||||
event::{EventBus, SfxEvent, SfxEventItem},
|
||||
event::EventBus,
|
||||
state::State,
|
||||
};
|
||||
use hashbrown::HashMap;
|
||||
|
@ -1,8 +1,8 @@
|
||||
use super::*;
|
||||
use crate::audio::sfx::SfxEvent;
|
||||
use common::{
|
||||
assets,
|
||||
comp::{item::tool::ToolCategory, CharacterAbilityType, CharacterState, ItemConfig, Loadout},
|
||||
event::SfxEvent,
|
||||
states,
|
||||
};
|
||||
use std::time::{Duration, Instant};
|
||||
|
@ -2,11 +2,10 @@
|
||||
/// and triggers sfx related to running, climbing and gliding, at a volume
|
||||
/// proportionate to the extity's size
|
||||
use super::EventMapper;
|
||||
|
||||
use crate::audio::sfx::{SfxTriggerItem, SfxTriggers, SFX_DIST_LIMIT_SQR};
|
||||
use crate::audio::sfx::{SfxEvent, SfxEventItem, SfxTriggerItem, SfxTriggers, SFX_DIST_LIMIT_SQR};
|
||||
use common::{
|
||||
comp::{Body, CharacterState, PhysicsState, Pos, Vel},
|
||||
event::{EventBus, SfxEvent, SfxEventItem},
|
||||
event::EventBus,
|
||||
state::State,
|
||||
};
|
||||
use hashbrown::HashMap;
|
||||
|
@ -1,9 +1,9 @@
|
||||
use super::*;
|
||||
use crate::audio::sfx::SfxEvent;
|
||||
use common::{
|
||||
comp::{
|
||||
bird_small, humanoid, quadruped_medium, quadruped_small, Body, CharacterState, PhysicsState,
|
||||
},
|
||||
event::SfxEvent,
|
||||
states,
|
||||
};
|
||||
use std::time::{Duration, Instant};
|
||||
|
@ -2,13 +2,9 @@
|
||||
/// and triggers sfx for gaining experience and levelling up
|
||||
use super::EventMapper;
|
||||
|
||||
use crate::audio::sfx::SfxTriggers;
|
||||
use crate::audio::sfx::{SfxEvent, SfxEventItem, SfxTriggers};
|
||||
|
||||
use common::{
|
||||
comp::Stats,
|
||||
event::{EventBus, SfxEvent, SfxEventItem},
|
||||
state::State,
|
||||
};
|
||||
use common::{comp::Stats, event::EventBus, state::State};
|
||||
use specs::WorldExt;
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
|
@ -1,5 +1,5 @@
|
||||
use super::*;
|
||||
use common::event::SfxEvent;
|
||||
use crate::audio::sfx::SfxEvent;
|
||||
|
||||
#[test]
|
||||
fn no_change_returns_none() {
|
||||
|
@ -84,16 +84,21 @@
|
||||
mod event_mapper;
|
||||
|
||||
use crate::audio::AudioFrontend;
|
||||
|
||||
use common::{
|
||||
assets,
|
||||
comp::{Ori, Pos},
|
||||
event::{EventBus, SfxEvent, SfxEventItem},
|
||||
comp::{
|
||||
item::{Consumable, ItemKind, ToolCategory},
|
||||
CharacterAbilityType, InventoryUpdateEvent, Ori, Pos,
|
||||
},
|
||||
event::EventBus,
|
||||
state::State,
|
||||
};
|
||||
use event_mapper::SfxEventMapper;
|
||||
use hashbrown::HashMap;
|
||||
use serde::Deserialize;
|
||||
use specs::WorldExt;
|
||||
use std::convert::TryFrom;
|
||||
use tracing::warn;
|
||||
use vek::*;
|
||||
|
||||
@ -104,6 +109,85 @@ use vek::*;
|
||||
/// player.
|
||||
const SFX_DIST_LIMIT_SQR: f32 = 20000.0;
|
||||
|
||||
pub struct SfxEventItem {
|
||||
pub sfx: SfxEvent,
|
||||
pub pos: Option<Vec3<f32>>,
|
||||
pub vol: Option<f32>,
|
||||
}
|
||||
|
||||
impl SfxEventItem {
|
||||
pub fn new(sfx: SfxEvent, pos: Option<Vec3<f32>>, vol: Option<f32>) -> Self {
|
||||
Self { sfx, pos, vol }
|
||||
}
|
||||
|
||||
pub fn at_player_position(sfx: SfxEvent) -> Self {
|
||||
Self {
|
||||
sfx,
|
||||
pos: None,
|
||||
vol: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Deserialize, Hash, Eq)]
|
||||
pub enum SfxEvent {
|
||||
Idle,
|
||||
Run,
|
||||
Roll,
|
||||
Climb,
|
||||
GliderOpen,
|
||||
Glide,
|
||||
GliderClose,
|
||||
Jump,
|
||||
Fall,
|
||||
ExperienceGained,
|
||||
LevelUp,
|
||||
Attack(CharacterAbilityType, ToolCategory),
|
||||
Wield(ToolCategory),
|
||||
Unwield(ToolCategory),
|
||||
Inventory(SfxInventoryEvent),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Deserialize, Hash, Eq)]
|
||||
pub enum SfxInventoryEvent {
|
||||
Collected,
|
||||
CollectedTool(ToolCategory),
|
||||
CollectFailed,
|
||||
Consumed(Consumable),
|
||||
Debug,
|
||||
Dropped,
|
||||
Given,
|
||||
Swapped,
|
||||
}
|
||||
|
||||
impl From<&InventoryUpdateEvent> for SfxEvent {
|
||||
fn from(value: &InventoryUpdateEvent) -> Self {
|
||||
match value {
|
||||
InventoryUpdateEvent::Collected(item) => {
|
||||
// Handle sound effects for types of collected items, falling back to the
|
||||
// default Collected event
|
||||
match item.kind {
|
||||
ItemKind::Tool(tool) => SfxEvent::Inventory(SfxInventoryEvent::CollectedTool(
|
||||
ToolCategory::try_from(tool.kind).unwrap(),
|
||||
)),
|
||||
_ => SfxEvent::Inventory(SfxInventoryEvent::Collected),
|
||||
}
|
||||
},
|
||||
InventoryUpdateEvent::CollectFailed => {
|
||||
SfxEvent::Inventory(SfxInventoryEvent::CollectFailed)
|
||||
},
|
||||
InventoryUpdateEvent::Consumed(consumable) => {
|
||||
SfxEvent::Inventory(SfxInventoryEvent::Consumed(*consumable))
|
||||
},
|
||||
InventoryUpdateEvent::Debug => SfxEvent::Inventory(SfxInventoryEvent::Debug),
|
||||
InventoryUpdateEvent::Dropped => SfxEvent::Inventory(SfxInventoryEvent::Dropped),
|
||||
InventoryUpdateEvent::Given => SfxEvent::Inventory(SfxInventoryEvent::Given),
|
||||
InventoryUpdateEvent::Swapped => SfxEvent::Inventory(SfxInventoryEvent::Swapped),
|
||||
_ => SfxEvent::Inventory(SfxInventoryEvent::Swapped),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct SfxTriggerItem {
|
||||
pub files: Vec<String>,
|
||||
|
@ -1,6 +1,8 @@
|
||||
pub mod comp;
|
||||
pub mod sys;
|
||||
|
||||
use crate::audio::sfx::SfxEventItem;
|
||||
use common::event::EventBus;
|
||||
use specs::{Entity, World, WorldExt};
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
@ -25,4 +27,7 @@ pub fn init(world: &mut World) {
|
||||
world.register::<comp::HpFloaterList>();
|
||||
world.register::<comp::Interpolated>();
|
||||
world.insert(MyExpFloaterList::default());
|
||||
|
||||
// Voxygen event buses
|
||||
world.insert(EventBus::<SfxEventItem>::default());
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
use crate::{
|
||||
audio::sfx::{SfxEvent, SfxEventItem},
|
||||
ecs::MyEntity,
|
||||
hud::{DebugInfo, Event as HudEvent, Hud, HudInfo, PressBehavior},
|
||||
i18n::{i18n_asset_key, VoxygenLocalization},
|
||||
@ -14,7 +15,8 @@ use common::{
|
||||
assets::{load_watched, watch},
|
||||
clock::Clock,
|
||||
comp,
|
||||
comp::{Pos, Vel, MAX_PICKUP_RANGE_SQR},
|
||||
comp::{ChatMsg, ChatType, InventoryUpdateEvent, Pos, Vel, MAX_PICKUP_RANGE_SQR},
|
||||
event::EventBus,
|
||||
msg::ClientState,
|
||||
terrain::{Block, BlockKind},
|
||||
util::Dir,
|
||||
@ -83,6 +85,32 @@ impl SessionState {
|
||||
client::Event::Chat(m) => {
|
||||
self.hud.new_message(m);
|
||||
},
|
||||
client::Event::InventoryUpdated(inv_event) => {
|
||||
let sfx_event = SfxEvent::from(&inv_event);
|
||||
client
|
||||
.state()
|
||||
.ecs()
|
||||
.read_resource::<EventBus<SfxEventItem>>()
|
||||
.emit_now(SfxEventItem::at_player_position(sfx_event));
|
||||
|
||||
match inv_event {
|
||||
InventoryUpdateEvent::CollectFailed => {
|
||||
self.hud.new_message(ChatMsg {
|
||||
message: String::from(
|
||||
"Failed to collect item. Your inventory may be full!",
|
||||
),
|
||||
chat_type: ChatType::CommandError,
|
||||
});
|
||||
},
|
||||
InventoryUpdateEvent::Collected(item) => {
|
||||
self.hud.new_message(ChatMsg {
|
||||
message: format!("Picked up {}", item.name()),
|
||||
chat_type: ChatType::CommandInfo,
|
||||
});
|
||||
},
|
||||
_ => {},
|
||||
};
|
||||
},
|
||||
client::Event::Disconnect => return Ok(TickAction::Disconnect),
|
||||
client::Event::DisconnectionNotification(time) => {
|
||||
let message = match time {
|
||||
@ -90,8 +118,8 @@ impl SessionState {
|
||||
_ => format!("Connection lost. Kicking in {} seconds", time),
|
||||
};
|
||||
|
||||
self.hud.new_message(comp::ChatMsg {
|
||||
chat_type: comp::ChatType::CommandError,
|
||||
self.hud.new_message(ChatMsg {
|
||||
chat_type: ChatType::CommandError,
|
||||
message,
|
||||
});
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user