|
@@ -1,7 +1,7 @@
|
|
|
extern crate rltk;
|
|
|
use rltk::{Point, Rltk, VirtualKeyCode};
|
|
|
extern crate specs;
|
|
|
-use super::{CombatStats, Map, Position, RunState, State, Viewshed, WantsToMelee};
|
|
|
+use super::{CombatStats, Map, Position, MoveEvent, RunState, State, Viewshed, WantsToMelee, InputEvent};
|
|
|
use specs::prelude::*;
|
|
|
|
|
|
|
|
@@ -15,13 +15,6 @@ fn clamp<T: PartialOrd>(low: T, high: T, val: T) -> T {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-#[derive(Component, Copy, Clone)]
|
|
|
-pub struct MoveEvent {
|
|
|
- destination: usize,
|
|
|
- tgt_x: i32,
|
|
|
- tgt_y: i32,
|
|
|
-}
|
|
|
-
|
|
|
pub struct HandleMoveEvent;
|
|
|
|
|
|
impl<'a> System<'a> for HandleMoveEvent {
|
|
@@ -34,8 +27,8 @@ impl<'a> System<'a> for HandleMoveEvent {
|
|
|
);
|
|
|
|
|
|
fn run(&mut self, (mut move_events, mut pos, mut viewshed, mut point, map): Self::SystemData) {
|
|
|
- for (event, pos, viewshed) in (&move_events, &mut pos, &mut viewshed).join() {
|
|
|
- let MoveEvent { destination, tgt_x, tgt_y } = *event;
|
|
|
+ for (&event, pos, viewshed) in (&move_events, &mut pos, &mut viewshed).join() {
|
|
|
+ let MoveEvent { destination, tgt_x, tgt_y } = event;
|
|
|
if !map.blocked[destination] {
|
|
|
viewshed.dirty = true;
|
|
|
pos.x = tgt_x;
|
|
@@ -85,20 +78,6 @@ impl<'a> System<'a> for HandleInputEvent {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-/// This type represents all the "low-level" actions we have available
|
|
|
-/// to us, corresponding directly to the set of actions we have bound
|
|
|
-/// on the keys
|
|
|
-#[derive(Component)]
|
|
|
-pub enum InputEvent {
|
|
|
- // attempt to move the player some amount in the given direction
|
|
|
- // (delta_x and delta_y should be -1, 0, or 1)
|
|
|
- PlayerMovement {
|
|
|
- delta_x: i32,
|
|
|
- delta_y: i32,
|
|
|
- },
|
|
|
-}
|
|
|
-
|
|
|
pub fn player_input(gs: &mut State, ctx: &mut Rltk) -> RunState {
|
|
|
let player = *gs.ecs.fetch::<Entity>();
|
|
|
let mut input = gs.ecs.write_storage::<InputEvent>();
|