Introduce a ToolCategory so we can ignore the specific type of weapon

when deciding on the SFX to play when wielding/attacking.
This commit is contained in:
Shane Handley 2020-04-11 20:10:02 +10:00
parent 802bce1698
commit 987a025d36
7 changed files with 55 additions and 30 deletions

View File

@ -23,7 +23,7 @@
],
threshold: 0.5,
),
Attack(DashMelee, Sword(BasicSword)): (
Attack(DashMelee, Sword): (
files: [
"voxygen.audio.sfx.weapon.whoosh_normal_01",
"voxygen.audio.sfx.weapon.whoosh_normal_02",
@ -32,7 +32,7 @@
],
threshold: 1.2,
),
Attack(TripleStrike, Sword(BasicSword)): (
Attack(TripleStrike, Sword): (
files: [
"voxygen.audio.sfx.weapon.sword_triple_strike_01",
"voxygen.audio.sfx.weapon.sword_triple_strike_02",
@ -40,14 +40,14 @@
],
threshold: 0.8,
),
Attack(BasicRanged, Bow(BasicBow)): (
Attack(BasicRanged, Bow): (
files: [
"voxygen.audio.sfx.weapon.bow_attack_01",
"voxygen.audio.sfx.weapon.bow_attack_02",
],
threshold: 0.5,
),
Attack(BasicMelee, Hammer(BasicHammer)): (
Attack(BasicMelee, Hammer): (
files: [
"voxygen.audio.sfx.weapon.whoosh_low_01",
"voxygen.audio.sfx.weapon.whoosh_low_02",
@ -55,7 +55,7 @@
],
threshold: 0.5,
),
Attack(BasicMelee, Staff(BasicStaff)): (
Attack(BasicMelee, Staff): (
files: [
"voxygen.audio.sfx.weapon.whoosh_normal_01",
"voxygen.audio.sfx.weapon.whoosh_normal_02",
@ -64,13 +64,13 @@
],
threshold: 0.5,
),
Wield(Sword(BasicSword)): (
Wield(Sword): (
files: [
"voxygen.audio.sfx.weapon.sword_out",
],
threshold: 0.5,
),
Unwield(Sword(BasicSword)): (
Unwield(Sword): (
files: [
"voxygen.audio.sfx.weapon.sword_in",
],

View File

@ -2,7 +2,7 @@ pub mod armor;
pub mod tool;
// Reexports
pub use tool::{DebugKind, SwordKind, Tool, ToolKind};
pub use tool::{DebugKind, SwordKind, Tool, ToolCategory, ToolKind};
use crate::{
assets::{self, Asset},

View File

@ -115,6 +115,35 @@ pub enum ToolKind {
Empty,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ToolCategory {
Sword,
Axe,
Hammer,
Bow,
Dagger,
Staff,
Shield,
Debug,
Empty,
}
impl From<ToolKind> for ToolCategory {
fn from(kind: ToolKind) -> ToolCategory {
match kind {
ToolKind::Sword(_) => ToolCategory::Sword,
ToolKind::Axe(_) => ToolCategory::Axe,
ToolKind::Hammer(_) => ToolCategory::Hammer,
ToolKind::Bow(_) => ToolCategory::Bow,
ToolKind::Dagger(_) => ToolCategory::Dagger,
ToolKind::Staff(_) => ToolCategory::Staff,
ToolKind::Shield(_) => ToolCategory::Shield,
ToolKind::Debug(_) => ToolCategory::Debug,
ToolKind::Empty => ToolCategory::Empty,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Tool {
pub kind: ToolKind,

View File

@ -1,5 +1,5 @@
use crate::{comp, sync::Uid, util::Dir};
use comp::{item::ToolKind, CharacterAbilityType, InventoryUpdateEvent};
use comp::{item::ToolCategory, CharacterAbilityType, InventoryUpdateEvent};
use parking_lot::Mutex;
use serde::Deserialize;
use specs::Entity as EcsEntity;
@ -39,9 +39,9 @@ pub enum SfxEvent {
Fall,
ExperienceGained,
LevelUp,
Attack(CharacterAbilityType, ToolKind),
Wield(ToolKind),
Unwield(ToolKind),
Attack(CharacterAbilityType, ToolCategory),
Wield(ToolCategory),
Unwield(ToolCategory),
Inventory(InventoryUpdateEvent),
}

View File

@ -4,7 +4,7 @@ use crate::audio::sfx::{SfxTriggerItem, SfxTriggers};
use common::{
comp::{
item::{Item, ItemKind},
item::{Item, ItemKind, ToolCategory},
CharacterAbilityType, CharacterState, ItemConfig, Loadout, Pos,
},
event::{EventBus, SfxEvent, SfxEventItem},
@ -145,7 +145,7 @@ impl CombatEventMapper {
if character_state.is_attack() {
return SfxEvent::Attack(
CharacterAbilityType::from(character_state),
data.kind,
ToolCategory::from(data.kind),
);
} else {
if let Some(wield_event) = match (
@ -153,8 +153,12 @@ impl CombatEventMapper {
character_state.is_dodge(),
Self::weapon_drawn(character_state),
) {
(false, false, true) => Some(SfxEvent::Wield(data.kind)),
(true, false, false) => Some(SfxEvent::Unwield(data.kind)),
(false, false, true) => {
Some(SfxEvent::Wield(ToolCategory::from(data.kind)))
},
(true, false, false) => {
Some(SfxEvent::Unwield(ToolCategory::from(data.kind)))
},
_ => None,
} {
return wield_event;

View File

@ -2,7 +2,7 @@ use super::*;
use common::{
assets,
comp::{
item::tool::{AxeKind, BowKind, SwordKind, ToolKind},
item::tool::{AxeKind, BowKind, SwordKind, ToolCategory, ToolKind},
CharacterAbilityType, CharacterState, ItemConfig, Loadout,
},
event::SfxEvent,
@ -35,7 +35,7 @@ fn maps_wield_while_equipping() {
Some(&loadout),
);
assert_eq!(result, SfxEvent::Wield(ToolKind::Axe(AxeKind::BasicAxe)));
assert_eq!(result, SfxEvent::Wield(ToolCategory::Axe));
}
#[test]
@ -61,7 +61,7 @@ fn maps_unwield() {
Some(&loadout),
);
assert_eq!(result, SfxEvent::Unwield(ToolKind::Bow(BowKind::BasicBow)));
assert_eq!(result, SfxEvent::Unwield(ToolCategory::Bow));
}
#[test]
@ -96,10 +96,7 @@ fn maps_basic_melee() {
assert_eq!(
result,
SfxEvent::Attack(
CharacterAbilityType::BasicMelee,
ToolKind::Axe(AxeKind::BasicAxe)
)
SfxEvent::Attack(CharacterAbilityType::BasicMelee, ToolCategory::Axe)
);
}
@ -137,9 +134,6 @@ fn maps_triple_strike() {
assert_eq!(
result,
SfxEvent::Attack(
CharacterAbilityType::TripleStrike,
ToolKind::Sword(SwordKind::BasicSword)
)
SfxEvent::Attack(CharacterAbilityType::TripleStrike, ToolCategory::Sword)
);
}

View File

@ -4,9 +4,7 @@
use crate::audio::sfx::{SfxTriggerItem, SfxTriggers};
use common::{
comp::{
Body, CharacterState, PhysicsState, Pos, Vel,
},
comp::{Body, CharacterState, PhysicsState, Pos, Vel},
event::{EventBus, SfxEvent, SfxEventItem},
state::State,
};