mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
SFX and unit test fixes.
This commit is contained in:
parent
fe2aa7da7b
commit
362771be4b
@ -23,13 +23,13 @@
|
||||
],
|
||||
threshold: 0.5,
|
||||
),
|
||||
Wield(Sword(Rapier)): (
|
||||
Wield(Sword(BasicSword)): (
|
||||
files: [
|
||||
"voxygen.audio.sfx.weapon.sword_out",
|
||||
],
|
||||
threshold: 1.0,
|
||||
),
|
||||
Unwield(Sword(Rapier)): (
|
||||
Unwield(Sword(BasicSword)): (
|
||||
files: [
|
||||
"voxygen.audio.sfx.weapon.sword_in",
|
||||
],
|
||||
|
@ -32,7 +32,6 @@ pub enum SfxEvent {
|
||||
Run,
|
||||
Roll,
|
||||
Climb,
|
||||
Swim,
|
||||
GliderOpen,
|
||||
Glide,
|
||||
GliderClose,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use common::{assets, comp};
|
||||
use common::comp;
|
||||
use gfx_window_glutin::init_headless;
|
||||
use vek::*;
|
||||
use veloren_voxygen::{render, scene::simple as scene};
|
||||
@ -27,10 +27,16 @@ fn main() {
|
||||
|
||||
// Create character
|
||||
let body = comp::humanoid::Body::random();
|
||||
const STARTER_BOW: &str = "common.items.weapons.starter_bow";
|
||||
let equipment = comp::Equipment {
|
||||
main: assets::load_cloned(STARTER_BOW).ok(),
|
||||
alt: None,
|
||||
|
||||
let loadout = comp::Loadout {
|
||||
active_item: None,
|
||||
second_item: None,
|
||||
shoulder: None,
|
||||
chest: None,
|
||||
belt: None,
|
||||
hand: None,
|
||||
pants: None,
|
||||
foot: None,
|
||||
};
|
||||
|
||||
// Setup scene (using the character selection screen `Scene`)
|
||||
@ -49,7 +55,7 @@ fn main() {
|
||||
|
||||
// Render
|
||||
renderer.clear();
|
||||
scene.render(&mut renderer, 0, Some(body), &equipment);
|
||||
scene.render(&mut renderer, 0, Some(body), Some(&loadout));
|
||||
|
||||
renderer.flush();
|
||||
// Get image
|
||||
|
@ -4,7 +4,10 @@
|
||||
use crate::audio::sfx::{SfxTriggerItem, SfxTriggers};
|
||||
|
||||
use common::{
|
||||
comp::{Body, CharacterState, PhysicsState, Pos, Stats, Vel},
|
||||
comp::{
|
||||
item::{Item, ItemKind},
|
||||
Body, CharacterState, ItemConfig, Loadout, PhysicsState, Pos, Vel,
|
||||
},
|
||||
event::{EventBus, SfxEvent, SfxEventItem},
|
||||
state::State,
|
||||
};
|
||||
@ -55,13 +58,13 @@ impl MovementEventMapper {
|
||||
.get(player_entity)
|
||||
.map_or(Vec3::zero(), |pos| pos.0);
|
||||
|
||||
for (entity, pos, vel, body, stats, physics, character) in (
|
||||
for (entity, pos, vel, body, physics, loadout, character) in (
|
||||
&ecs.entities(),
|
||||
&ecs.read_storage::<Pos>(),
|
||||
&ecs.read_storage::<Vel>(),
|
||||
&ecs.read_storage::<Body>(),
|
||||
&ecs.read_storage::<Stats>(),
|
||||
&ecs.read_storage::<PhysicsState>(),
|
||||
ecs.read_storage::<Loadout>().maybe(),
|
||||
ecs.read_storage::<CharacterState>().maybe(),
|
||||
)
|
||||
.join()
|
||||
@ -77,7 +80,7 @@ impl MovementEventMapper {
|
||||
|
||||
let mapped_event = match body {
|
||||
Body::Humanoid(_) => {
|
||||
Self::map_movement_event(character, physics, state, vel.0, stats)
|
||||
Self::map_movement_event(character, physics, state, vel.0, loadout)
|
||||
},
|
||||
Body::QuadrupedMedium(_)
|
||||
| Body::QuadrupedSmall(_)
|
||||
@ -157,10 +160,37 @@ impl MovementEventMapper {
|
||||
physics_state: &PhysicsState,
|
||||
previous_state: &PreviousEntityState,
|
||||
vel: Vec3<f32>,
|
||||
_stats: &Stats,
|
||||
loadout: Option<&Loadout>,
|
||||
) -> SfxEvent {
|
||||
// Handle wield state changes
|
||||
if let Some(active_loadout) = loadout {
|
||||
if let Some(ItemConfig {
|
||||
item:
|
||||
Item {
|
||||
kind: ItemKind::Tool(data),
|
||||
..
|
||||
},
|
||||
..
|
||||
}) = active_loadout.active_item
|
||||
{
|
||||
if let Some(wield_event) = match (
|
||||
previous_state.weapon_drawn,
|
||||
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)),
|
||||
_ => None,
|
||||
} {
|
||||
return wield_event;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Match run state
|
||||
if physics_state.on_ground && vel.magnitude() > 0.1 {
|
||||
if physics_state.on_ground && vel.magnitude() > 0.1
|
||||
|| !previous_state.on_ground && physics_state.on_ground
|
||||
{
|
||||
return SfxEvent::Run;
|
||||
}
|
||||
|
||||
|
@ -2,10 +2,12 @@ use super::*;
|
||||
use common::{
|
||||
assets,
|
||||
comp::{
|
||||
bird_small, humanoid, item::ToolKind, quadruped_medium, quadruped_small, Body,
|
||||
CharacterState, PhysicsState, Stats,
|
||||
bird_small, humanoid,
|
||||
item::{AxeKind, BowKind, ToolKind},
|
||||
quadruped_medium, quadruped_small, Body, CharacterState, ItemConfig, Loadout, PhysicsState,
|
||||
},
|
||||
event::SfxEvent,
|
||||
states,
|
||||
};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
@ -40,8 +42,6 @@ fn config_but_played_since_threshold_no_emit() {
|
||||
|
||||
#[test]
|
||||
fn config_and_not_played_since_threshold_emits() {
|
||||
let event = SfxEvent::Run;
|
||||
|
||||
let trigger_item = SfxTriggerItem {
|
||||
files: vec![String::from("some.path.to.sfx.file")],
|
||||
threshold: 0.5,
|
||||
@ -84,12 +84,6 @@ fn same_previous_event_elapsed_emits() {
|
||||
|
||||
#[test]
|
||||
fn maps_idle() {
|
||||
let stats = Stats::new(
|
||||
String::from("test"),
|
||||
Body::Humanoid(humanoid::Body::random()),
|
||||
None,
|
||||
);
|
||||
|
||||
let result = MovementEventMapper::map_movement_event(
|
||||
&CharacterState::Idle {},
|
||||
&PhysicsState {
|
||||
@ -105,7 +99,7 @@ fn maps_idle() {
|
||||
on_ground: true,
|
||||
},
|
||||
Vec3::zero(),
|
||||
&stats,
|
||||
None,
|
||||
);
|
||||
|
||||
assert_eq!(result, SfxEvent::Idle);
|
||||
@ -113,12 +107,6 @@ fn maps_idle() {
|
||||
|
||||
#[test]
|
||||
fn maps_run_with_sufficient_velocity() {
|
||||
let stats = Stats::new(
|
||||
String::from("test"),
|
||||
Body::Humanoid(humanoid::Body::random()),
|
||||
None,
|
||||
);
|
||||
|
||||
let result = MovementEventMapper::map_movement_event(
|
||||
&CharacterState::Idle {},
|
||||
&PhysicsState {
|
||||
@ -134,7 +122,7 @@ fn maps_run_with_sufficient_velocity() {
|
||||
on_ground: true,
|
||||
},
|
||||
Vec3::new(0.5, 0.8, 0.0),
|
||||
&stats,
|
||||
None,
|
||||
);
|
||||
|
||||
assert_eq!(result, SfxEvent::Run);
|
||||
@ -142,12 +130,6 @@ fn maps_run_with_sufficient_velocity() {
|
||||
|
||||
#[test]
|
||||
fn does_not_map_run_with_insufficient_velocity() {
|
||||
let stats = Stats::new(
|
||||
String::from("test"),
|
||||
Body::Humanoid(humanoid::Body::random()),
|
||||
None,
|
||||
);
|
||||
|
||||
let result = MovementEventMapper::map_movement_event(
|
||||
&CharacterState::Idle {},
|
||||
&PhysicsState {
|
||||
@ -163,7 +145,7 @@ fn does_not_map_run_with_insufficient_velocity() {
|
||||
on_ground: true,
|
||||
},
|
||||
Vec3::new(0.02, 0.0001, 0.0),
|
||||
&stats,
|
||||
None,
|
||||
);
|
||||
|
||||
assert_eq!(result, SfxEvent::Idle);
|
||||
@ -171,12 +153,6 @@ fn does_not_map_run_with_insufficient_velocity() {
|
||||
|
||||
#[test]
|
||||
fn does_not_map_run_with_sufficient_velocity_but_not_on_ground() {
|
||||
let stats = Stats::new(
|
||||
String::from("test"),
|
||||
Body::Humanoid(humanoid::Body::random()),
|
||||
None,
|
||||
);
|
||||
|
||||
let result = MovementEventMapper::map_movement_event(
|
||||
&CharacterState::Idle {},
|
||||
&PhysicsState {
|
||||
@ -192,7 +168,7 @@ fn does_not_map_run_with_sufficient_velocity_but_not_on_ground() {
|
||||
on_ground: false,
|
||||
},
|
||||
Vec3::new(0.5, 0.8, 0.0),
|
||||
&stats,
|
||||
None,
|
||||
);
|
||||
|
||||
assert_eq!(result, SfxEvent::Idle);
|
||||
@ -200,14 +176,11 @@ fn does_not_map_run_with_sufficient_velocity_but_not_on_ground() {
|
||||
|
||||
#[test]
|
||||
fn maps_roll() {
|
||||
let stats = Stats::new(
|
||||
String::from("test"),
|
||||
Body::Humanoid(humanoid::Body::random()),
|
||||
None,
|
||||
);
|
||||
|
||||
let result = MovementEventMapper::map_movement_event(
|
||||
&CharacterState::Roll {},
|
||||
&CharacterState::Roll(states::roll::Data {
|
||||
remaining_duration: Duration::from_millis(300),
|
||||
was_wielded: true,
|
||||
}),
|
||||
&PhysicsState {
|
||||
on_ground: true,
|
||||
on_wall: None,
|
||||
@ -221,7 +194,7 @@ fn maps_roll() {
|
||||
on_ground: true,
|
||||
},
|
||||
Vec3::zero(),
|
||||
&stats,
|
||||
None,
|
||||
);
|
||||
|
||||
assert_eq!(result, SfxEvent::Roll);
|
||||
@ -229,12 +202,6 @@ fn maps_roll() {
|
||||
|
||||
#[test]
|
||||
fn maps_land_on_ground_to_run() {
|
||||
let stats = Stats::new(
|
||||
String::from("test"),
|
||||
Body::Humanoid(humanoid::Body::random()),
|
||||
None,
|
||||
);
|
||||
|
||||
let result = MovementEventMapper::map_movement_event(
|
||||
&CharacterState::Idle {},
|
||||
&PhysicsState {
|
||||
@ -250,7 +217,7 @@ fn maps_land_on_ground_to_run() {
|
||||
on_ground: false,
|
||||
},
|
||||
Vec3::zero(),
|
||||
&stats,
|
||||
None,
|
||||
);
|
||||
|
||||
assert_eq!(result, SfxEvent::Run);
|
||||
@ -258,12 +225,6 @@ fn maps_land_on_ground_to_run() {
|
||||
|
||||
#[test]
|
||||
fn maps_glider_open() {
|
||||
let stats = Stats::new(
|
||||
String::from("test"),
|
||||
Body::Humanoid(humanoid::Body::random()),
|
||||
None,
|
||||
);
|
||||
|
||||
let result = MovementEventMapper::map_movement_event(
|
||||
&CharacterState::Glide {},
|
||||
&PhysicsState {
|
||||
@ -279,7 +240,7 @@ fn maps_glider_open() {
|
||||
on_ground: false,
|
||||
},
|
||||
Vec3::zero(),
|
||||
&stats,
|
||||
None,
|
||||
);
|
||||
|
||||
assert_eq!(result, SfxEvent::GliderOpen);
|
||||
@ -287,12 +248,6 @@ fn maps_glider_open() {
|
||||
|
||||
#[test]
|
||||
fn maps_glide() {
|
||||
let stats = Stats::new(
|
||||
String::from("test"),
|
||||
Body::Humanoid(humanoid::Body::random()),
|
||||
None,
|
||||
);
|
||||
|
||||
let result = MovementEventMapper::map_movement_event(
|
||||
&CharacterState::Glide {},
|
||||
&PhysicsState {
|
||||
@ -308,7 +263,7 @@ fn maps_glide() {
|
||||
on_ground: false,
|
||||
},
|
||||
Vec3::zero(),
|
||||
&stats,
|
||||
None,
|
||||
);
|
||||
|
||||
assert_eq!(result, SfxEvent::Glide);
|
||||
@ -316,12 +271,6 @@ fn maps_glide() {
|
||||
|
||||
#[test]
|
||||
fn maps_glider_close_when_closing_mid_flight() {
|
||||
let stats = Stats::new(
|
||||
String::from("test"),
|
||||
Body::Humanoid(humanoid::Body::random()),
|
||||
None,
|
||||
);
|
||||
|
||||
let result = MovementEventMapper::map_movement_event(
|
||||
&CharacterState::Idle {},
|
||||
&PhysicsState {
|
||||
@ -337,20 +286,15 @@ fn maps_glider_close_when_closing_mid_flight() {
|
||||
on_ground: false,
|
||||
},
|
||||
Vec3::zero(),
|
||||
&stats,
|
||||
None,
|
||||
);
|
||||
|
||||
assert_eq!(result, SfxEvent::GliderClose);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn maps_glider_close_when_landing() {
|
||||
let stats = Stats::new(
|
||||
String::from("test"),
|
||||
Body::Humanoid(humanoid::Body::random()),
|
||||
None,
|
||||
);
|
||||
|
||||
let result = MovementEventMapper::map_movement_event(
|
||||
&CharacterState::Idle {},
|
||||
&PhysicsState {
|
||||
@ -366,24 +310,29 @@ fn maps_glider_close_when_landing() {
|
||||
on_ground: false,
|
||||
},
|
||||
Vec3::zero(),
|
||||
&stats,
|
||||
None,
|
||||
);
|
||||
|
||||
assert_eq!(result, SfxEvent::GliderClose);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn maps_wield() {
|
||||
let stats = Stats::new(
|
||||
String::from("test"),
|
||||
Body::Humanoid(humanoid::Body::random()),
|
||||
Some(assets::load_expect_cloned(
|
||||
"common.items.weapons.starter_axe",
|
||||
)),
|
||||
);
|
||||
fn maps_wield_while_equipping() {
|
||||
let mut loadout = Loadout::default();
|
||||
|
||||
loadout.active_item = Some(ItemConfig {
|
||||
item: assets::load_expect_cloned("common.items.weapons.starter_axe"),
|
||||
ability1: None,
|
||||
ability2: None,
|
||||
ability3: None,
|
||||
block_ability: None,
|
||||
dodge_ability: None,
|
||||
});
|
||||
|
||||
let result = MovementEventMapper::map_movement_event(
|
||||
&CharacterState::Equipping {},
|
||||
&CharacterState::Equipping(states::equipping::Data {
|
||||
time_left: Duration::from_millis(10),
|
||||
}),
|
||||
&PhysicsState {
|
||||
on_ground: true,
|
||||
on_wall: None,
|
||||
@ -397,21 +346,24 @@ fn maps_wield() {
|
||||
on_ground: true,
|
||||
},
|
||||
Vec3::zero(),
|
||||
&stats,
|
||||
Some(&loadout),
|
||||
);
|
||||
|
||||
assert_eq!(result, SfxEvent::Wield(ToolKind::Axe));
|
||||
assert_eq!(result, SfxEvent::Wield(ToolKind::Axe(AxeKind::BasicAxe)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn maps_unwield() {
|
||||
let stats = Stats::new(
|
||||
String::from("test"),
|
||||
Body::Humanoid(humanoid::Body::random()),
|
||||
Some(assets::load_expect_cloned(
|
||||
"common.items.weapons.starter_bow",
|
||||
)),
|
||||
);
|
||||
let mut loadout = Loadout::default();
|
||||
|
||||
loadout.active_item = Some(ItemConfig {
|
||||
item: assets::load_expect_cloned("common.items.weapons.starter_bow"),
|
||||
ability1: None,
|
||||
ability2: None,
|
||||
ability3: None,
|
||||
block_ability: None,
|
||||
dodge_ability: None,
|
||||
});
|
||||
|
||||
let result = MovementEventMapper::map_movement_event(
|
||||
&CharacterState::default(),
|
||||
@ -428,39 +380,10 @@ fn maps_unwield() {
|
||||
on_ground: true,
|
||||
},
|
||||
Vec3::zero(),
|
||||
&stats,
|
||||
Some(&loadout),
|
||||
);
|
||||
|
||||
assert_eq!(result, SfxEvent::Unwield(ToolKind::Bow));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn does_not_map_wield_when_no_main_weapon() {
|
||||
let stats = Stats::new(
|
||||
String::from("test"),
|
||||
Body::Humanoid(humanoid::Body::random()),
|
||||
None,
|
||||
);
|
||||
|
||||
let result = MovementEventMapper::map_movement_event(
|
||||
&CharacterState::Wielding {},
|
||||
&PhysicsState {
|
||||
on_ground: true,
|
||||
on_wall: None,
|
||||
touch_entity: None,
|
||||
in_fluid: false,
|
||||
},
|
||||
&PreviousEntityState {
|
||||
event: SfxEvent::Idle,
|
||||
time: Instant::now(),
|
||||
weapon_drawn: false,
|
||||
on_ground: true,
|
||||
},
|
||||
Vec3::new(0.5, 0.8, 0.0),
|
||||
&stats,
|
||||
);
|
||||
|
||||
assert_eq!(result, SfxEvent::Run);
|
||||
assert_eq!(result, SfxEvent::Unwield(ToolKind::Bow(BowKind::BasicBow)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user