Merge branch 'shandley/collect-block-keyup-fix' into 'master'

Prevent inventory collect events from firing on keyup

See merge request veloren/veloren!1252
This commit is contained in:
Imbris 2020-08-02 06:49:14 +00:00
commit aced5f9797
2 changed files with 45 additions and 36 deletions

View File

@ -14,13 +14,13 @@ pub struct KeyState {
pub auto_walk: bool, pub auto_walk: bool,
pub swap_loadout: bool, pub swap_loadout: bool,
pub respawn: bool, pub respawn: bool,
pub collect: bool,
pub analog_matrix: Vec2<f32>, pub analog_matrix: Vec2<f32>,
} }
impl KeyState { impl Default for KeyState {
#[allow(clippy::new_without_default)] // TODO: Pending review in #587 fn default() -> Self {
pub fn new() -> KeyState { Self {
KeyState {
right: false, right: false,
left: false, left: false,
up: false, up: false,
@ -34,10 +34,13 @@ impl KeyState {
auto_walk: false, auto_walk: false,
swap_loadout: false, swap_loadout: false,
respawn: false, respawn: false,
collect: false,
analog_matrix: Vec2::zero(), analog_matrix: Vec2::zero(),
} }
} }
}
impl KeyState {
pub fn dir_vec(&self) -> Vec2<f32> { pub fn dir_vec(&self) -> Vec2<f32> {
let dir = if self.analog_matrix == Vec2::zero() { let dir = if self.analog_matrix == Vec2::zero() {
Vec2::<f32>::new( Vec2::<f32>::new(

View File

@ -71,10 +71,11 @@ impl SessionState {
let walk_forward_dir = scene.camera().forward_xy(); let walk_forward_dir = scene.camera().forward_xy();
let walk_right_dir = scene.camera().right_xy(); let walk_right_dir = scene.camera().right_xy();
Self { Self {
scene, scene,
client, client,
key_state: KeyState::new(), key_state: KeyState::default(),
inputs: comp::ControllerInputs::default(), inputs: comp::ControllerInputs::default(),
hud, hud,
selected_block: Block::new(BlockKind::Normal, Rgb::broadcast(255)), selected_block: Block::new(BlockKind::Normal, Rgb::broadcast(255)),
@ -93,9 +94,7 @@ impl SessionState {
self.hud.auto_walk(false); self.hud.auto_walk(false);
self.key_state.auto_walk = false; self.key_state.auto_walk = false;
} }
}
impl SessionState {
/// Tick the session (and the client attached to it). /// Tick the session (and the client attached to it).
fn tick(&mut self, dt: Duration, global_state: &mut GlobalState) -> Result<TickAction, Error> { fn tick(&mut self, dt: Duration, global_state: &mut GlobalState) -> Result<TickAction, Error> {
self.inputs.tick(dt); self.inputs.tick(dt);
@ -357,6 +356,7 @@ impl PlayState for SessionState {
if state != self.key_state.toggle_sit => if state != self.key_state.toggle_sit =>
{ {
self.key_state.toggle_sit = state; self.key_state.toggle_sit = state;
if state { if state {
self.stop_auto_walk(); self.stop_auto_walk();
self.client.borrow_mut().toggle_sit(); self.client.borrow_mut().toggle_sit();
@ -478,7 +478,12 @@ impl PlayState for SessionState {
} }
} }
}, },
Event::InputUpdate(GameInput::Interact, state) => { Event::InputUpdate(GameInput::Interact, state)
if state != self.key_state.collect =>
{
self.key_state.collect = state;
if state {
let mut client = self.client.borrow_mut(); let mut client = self.client.borrow_mut();
// Collect terrain sprites // Collect terrain sprites
@ -493,7 +498,7 @@ impl PlayState for SessionState {
.get(client.entity()) .get(client.entity())
.copied(); .copied();
if let (Some(player_pos), true) = (player_pos, state) { if let Some(player_pos) = player_pos {
let entity = ( let entity = (
&client.state().ecs().entities(), &client.state().ecs().entities(),
&client.state().ecs().read_storage::<comp::Pos>(), &client.state().ecs().read_storage::<comp::Pos>(),
@ -512,7 +517,8 @@ impl PlayState for SessionState {
client.pick_up(entity); client.pick_up(entity);
} }
} }
}, }
}
/*Event::InputUpdate(GameInput::Charge, state) => { /*Event::InputUpdate(GameInput::Charge, state) => {
self.inputs.charge.set_state(state); self.inputs.charge.set_state(state);
},*/ },*/