|
@@ -1,30 +1,27 @@
|
|
|
#[macro_use] extern crate specs_derive;
|
|
|
+#[macro_use] extern crate specs_system_macro;
|
|
|
|
|
|
use ggez::{Context, GameError, event::EventHandler};
|
|
|
use specs::prelude::*;
|
|
|
|
|
|
#[derive(Component)]
|
|
|
-struct Pos {
|
|
|
+pub struct Pos {
|
|
|
x: usize,
|
|
|
y: usize,
|
|
|
}
|
|
|
|
|
|
#[derive(Component)]
|
|
|
-struct Renderable {
|
|
|
+pub struct Renderable {
|
|
|
glyph: u8,
|
|
|
color: carpet::Color,
|
|
|
}
|
|
|
|
|
|
-struct Draw;
|
|
|
-
|
|
|
-impl<'a> System<'a> for Draw {
|
|
|
- type SystemData = (
|
|
|
- ReadStorage<'a, Pos>,
|
|
|
- ReadStorage<'a, Renderable>,
|
|
|
- WriteExpect<'a, carpet::Board>,
|
|
|
- );
|
|
|
-
|
|
|
- fn run(&mut self, (pos, renderable, mut board): Self::SystemData) {
|
|
|
+system_impl! {
|
|
|
+ Draw(
|
|
|
+ resource mut board: carpet::Board,
|
|
|
+ renderable: Renderable,
|
|
|
+ pos: Pos,
|
|
|
+ ) {
|
|
|
board.clear();
|
|
|
for (p, r) in (&pos, &renderable).join() {
|
|
|
board.set_with_color([p.x, p.y], r.glyph, r.color);
|
|
@@ -33,21 +30,17 @@ impl<'a> System<'a> for Draw {
|
|
|
}
|
|
|
|
|
|
#[derive(Component)]
|
|
|
-struct MoveLeft;
|
|
|
-
|
|
|
-impl<'a> System<'a> for MoveLeft {
|
|
|
- type SystemData = (
|
|
|
- ReadStorage<'a, MoveLeft>,
|
|
|
- WriteStorage<'a, Pos>,
|
|
|
- );
|
|
|
-
|
|
|
- fn run(&mut self, (left, mut pos): Self::SystemData) {
|
|
|
- for (_, p) in (&left, &mut pos).join() {
|
|
|
- if p.x == 0 {
|
|
|
- p.x = 79;
|
|
|
- } else {
|
|
|
- p.x -= 1;
|
|
|
- }
|
|
|
+pub struct MoveLeft;
|
|
|
+
|
|
|
+system! {
|
|
|
+ Leftward (
|
|
|
+ _left: MoveLeft,
|
|
|
+ mut pos: Pos,
|
|
|
+ ) {
|
|
|
+ if pos.x == 0 {
|
|
|
+ pos.x = 79;
|
|
|
+ } else {
|
|
|
+ pos.x -= 1;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -65,7 +58,7 @@ impl EventHandler for State {
|
|
|
|
|
|
fn update(&mut self, _ctx: &mut Context) -> Result<(), GameError> {
|
|
|
Draw.run_now(&mut self.world);
|
|
|
- MoveLeft.run_now(&mut self.world);
|
|
|
+ Leftward.run_now(&mut self.world);
|
|
|
Ok(())
|
|
|
}
|
|
|
}
|