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

View File

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