Go to idle state when picking items up

This commit is contained in:
timokoesters 2020-03-20 17:15:09 +01:00
parent df858cb370
commit 44ec09a8e7
3 changed files with 20 additions and 4 deletions

View File

@ -1,5 +1,5 @@
use crate::{
comp::{ControlEvent, Controller},
comp::{CharacterState, ControlEvent, Controller},
event::{EventBus, LocalEvent, ServerEvent},
state::DeltaTime,
sync::{Uid, UidAllocator},
@ -22,15 +22,27 @@ impl<'a> System<'a> for Sys {
Read<'a, EventBus<LocalEvent>>,
Read<'a, DeltaTime>,
WriteStorage<'a, Controller>,
WriteStorage<'a, CharacterState>,
ReadStorage<'a, Uid>,
);
fn run(
&mut self,
(entities, uid_allocator, server_bus, _local_bus, _dt, mut controllers, uids): Self::SystemData,
(
entities,
uid_allocator,
server_bus,
_local_bus,
_dt,
mut controllers,
mut character_states,
uids,
): Self::SystemData,
) {
let mut server_emitter = server_bus.emitter();
for (entity, _uid, controller) in (&entities, &uids, &mut controllers).join() {
for (entity, _uid, controller, character_state) in
(&entities, &uids, &mut controllers, &mut character_states).join()
{
let inputs = &mut controller.inputs;
// Update `inputs.move_dir`.
@ -59,6 +71,7 @@ impl<'a> System<'a> for Sys {
},
ControlEvent::Unmount => server_emitter.emit(ServerEvent::Unmount(entity)),
ControlEvent::InventoryManip(manip) => {
*character_state = CharacterState::Idle;
server_emitter.emit(ServerEvent::InventoryManip(entity, manip))
}, /*ControlEvent::Respawn =>
* server_emitter.emit(ServerEvent::Unmount(entity)), */

View File

@ -126,6 +126,8 @@ impl Scene {
/// Set the block position that the player is interacting with
pub fn set_select_pos(&mut self, pos: Option<Vec3<i32>>) { self.select_pos = pos; }
pub fn select_pos(&self) -> Option<Vec3<i32>> { self.select_pos }
/// Handle an incoming user input event (e.g.: cursor moved, key pressed,
/// window closed).
///

View File

@ -269,7 +269,8 @@ impl PlayState for SessionState {
} else {
self.inputs.secondary.set_state(state);
if let Some(select_pos) = select_pos {
// Check for select_block that is highlighted
if let Some(select_pos) = self.scene.select_pos() {
client.collect_block(select_pos);
}
}