summaryrefslogtreecommitdiff
path: root/src/systems
diff options
context:
space:
mode:
Diffstat (limited to 'src/systems')
-rw-r--r--src/systems/controlinput.rs4
-rw-r--r--src/systems/draw.rs31
-rw-r--r--src/systems/makefloor.rs4
-rw-r--r--src/systems/mod.rs1
-rw-r--r--src/systems/moving.rs6
-rw-r--r--src/systems/view.rs22
6 files changed, 20 insertions, 48 deletions
diff --git a/src/systems/controlinput.rs b/src/systems/controlinput.rs
index 663174e..b672b4c 100644
--- a/src/systems/controlinput.rs
+++ b/src/systems/controlinput.rs
@@ -14,7 +14,7 @@ use specs::{
use super::super::components::{
Controller,
Played,
- Position
+ Pos
};
use super::super::controls::{
@@ -39,7 +39,7 @@ impl <'a> System<'a> for ControlInput {
let mut leaving = HashSet::new();
for action in &input.actions {
match action {
- Action::Join(name) => {new.assemblages.push((Position{x:10, y:10}, Box::new(Player::new(&name))));}
+ Action::Join(name) => {new.assemblages.push((Pos{x:10, y:10}, Box::new(Player::new(&name))));}
Action::Leave(name) => {leaving.insert(name);}
Action::Input(name, control) => {playercontrols.insert(name, control.clone());}
}
diff --git a/src/systems/draw.rs b/src/systems/draw.rs
deleted file mode 100644
index 82400e3..0000000
--- a/src/systems/draw.rs
+++ /dev/null
@@ -1,31 +0,0 @@
-
-use specs::{
- ReadStorage,
- Write,
- System,
- Join
-};
-
-use super::super::components::{
- Position,
- Visible
-};
-
-use super::super::resources::{
- TopView
-};
-
-
-pub struct Draw;
-impl <'a> System<'a> for Draw {
-
- type SystemData = (ReadStorage<'a, Position>, ReadStorage<'a, Visible>, Write<'a, TopView>);
-
- fn run(&mut self, (pos, vis, mut view): Self::SystemData) {
- view.cells.clear();
- for (pos, vis) in (&pos, &vis).join(){
- view.cells.entry(*pos).or_insert(Vec::new()).push(vis.clone());
- view.cells.get_mut(pos).unwrap().sort_by(|a, b| b.height.partial_cmp(&a.height).unwrap());
- }
- }
-}
diff --git a/src/systems/makefloor.rs b/src/systems/makefloor.rs
index 864f204..ba3727d 100644
--- a/src/systems/makefloor.rs
+++ b/src/systems/makefloor.rs
@@ -9,7 +9,7 @@ use specs::{
};
use super::super::components::{
- Position
+ Pos
};
use super::super::resources::{
@@ -19,7 +19,7 @@ use super::super::resources::{
pub struct MakeFloor;
impl <'a> System<'a> for MakeFloor {
- type SystemData = (Entities<'a>, Write<'a, Floor>, ReadStorage<'a, Position>);
+ type SystemData = (Entities<'a>, Write<'a, Floor>, ReadStorage<'a, Pos>);
fn run(&mut self, (entities, mut floor, positions): Self::SystemData) {
floor.cells.clear();
for (ent, pos) in (&entities, &positions).join() {
diff --git a/src/systems/mod.rs b/src/systems/mod.rs
index 678941a..0382e39 100644
--- a/src/systems/mod.rs
+++ b/src/systems/mod.rs
@@ -1,7 +1,6 @@
pub mod clearcontrols;
pub mod controlinput;
-pub mod draw;
pub mod makefloor;
pub mod moving;
pub mod view;
diff --git a/src/systems/moving.rs b/src/systems/moving.rs
index c81a766..8bce8e5 100644
--- a/src/systems/moving.rs
+++ b/src/systems/moving.rs
@@ -8,7 +8,7 @@ use specs::{
};
use super::super::components::{
- Position,
+ Pos,
Controller,
Blocking
};
@@ -26,12 +26,12 @@ use super::super::resources::{
pub struct Move;
impl <'a> System<'a> for Move {
- type SystemData = (ReadStorage<'a, Controller>, WriteStorage<'a, Position>, Read<'a, Size>, ReadStorage<'a, Blocking>, Read<'a, Floor>);
+ type SystemData = (ReadStorage<'a, Controller>, WriteStorage<'a, Pos>, Read<'a, Size>, ReadStorage<'a, Blocking>, Read<'a, Floor>);
fn run(&mut self, (controller, mut pos, size, blocking, floor): Self::SystemData) {
for (controller, pos) in (&controller, &mut pos).join(){
match &controller.0 {
Control::Move(direction) => {
- let newpos = (*pos + direction.to_position()).clamp(Position::new(0, 0), Position::new(size.width - 1, size.height - 1));
+ let newpos = (*pos + direction.to_position()).clamp(Pos::new(0, 0), Pos::new(size.width - 1, size.height - 1));
let mut blocked = false;
for ent in floor.cells.get(&newpos).unwrap_or(&Vec::new()) {
if blocking.get(*ent).is_some(){
diff --git a/src/systems/view.rs b/src/systems/view.rs
index da6d6c4..144a544 100644
--- a/src/systems/view.rs
+++ b/src/systems/view.rs
@@ -10,16 +10,15 @@ use specs::{
};
use super::super::components::{
- Position,
+ Pos,
Visible,
Played
};
use super::super::resources::{
- TopView,
Size,
- Output,
+ Output
};
use super::super::worldmessages::{
@@ -32,13 +31,18 @@ use super::super::worldmessages::{
pub struct View;
impl <'a> System<'a> for View {
- type SystemData = (Read<'a, TopView>, Read<'a, Size>, ReadStorage<'a, Played>, Write<'a, Output>);
- fn run(&mut self, (topview, size, players, mut output): Self::SystemData) {
+ type SystemData = (ReadStorage<'a, Pos>, ReadStorage<'a, Visible>, Read<'a, Size>, ReadStorage<'a, Played>, Write<'a, Output>);
+ fn run(&mut self, (positions, visible, size, players, mut output): Self::SystemData) {
+ let mut cells: HashMap<Pos, Vec<Visible>> = HashMap::new();
+ for (pos, vis) in (&positions, &visible).join(){
+ cells.entry(*pos).or_insert(Vec::new()).push(vis.clone());
+ cells.get_mut(pos).unwrap().sort_by(|a, b| b.height.partial_cmp(&a.height).unwrap());
+ }
let width = size.width;
let height = size.height;
- let (values, mapping) = draw_room(&topview.cells, (width, height));
+ let (values, mapping) = draw_room(cells, (width, height));
let message = WorldMessage{updates: vec![WorldUpdate::Field(FieldMessage{
width,
@@ -54,14 +58,14 @@ impl <'a> System<'a> for View {
}
-
-fn draw_room(cells: &HashMap<Position, Vec<Visible>>, (width, height): (i32, i32)) -> (Vec<usize>, Vec<Vec<String>>){
+fn draw_room(cells: HashMap<Pos, Vec<Visible>>, (width, height): (i32, i32)) -> (Vec<usize>, Vec<Vec<String>>){
+
let size = width * height;
let mut values :Vec<usize> = Vec::with_capacity(size as usize);
let mut mapping: Vec<Vec<String>> = Vec::new();
for y in 0..height {
for x in 0..width {
- let sprites: Vec<String> = match cells.get(&Position{x: x, y: y}) {
+ let sprites: Vec<String> = match cells.get(&Pos{x: x, y: y}) {
Some(sprites) => {sprites.iter().map(|v| v.sprite.clone()).collect()}
None => {vec![]}
};