diff options
| author | troido <troido@protonmail.com> | 2020-02-21 17:49:50 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-02-21 17:49:50 +0100 |
| commit | 07cc6d8919193c38cc13b2567ede5a510938db18 (patch) | |
| tree | 83588f118036fa56905043eb23c5a1d79e0497da /src/systems | |
| parent | e69d9c3b5266fd6f9215d1e3f4a761b8027a785c (diff) | |
players can now go to different rooms
Diffstat (limited to 'src/systems')
| -rw-r--r-- | src/systems/migrate.rs | 37 | ||||
| -rw-r--r-- | src/systems/mod.rs | 1 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/systems/migrate.rs b/src/systems/migrate.rs new file mode 100644 index 0000000..aecffd0 --- /dev/null +++ b/src/systems/migrate.rs @@ -0,0 +1,37 @@ + +use specs::{ + ReadStorage, + Read, + Write, + System, + Join +}; + +use crate::components::{Player, Position, Moved, RoomExit}; +use crate::resources::{Emigration, Ground}; + + +pub struct Migrate; +impl <'a> System<'a> for Migrate { + type SystemData = ( + Write<'a, Emigration>, + Read<'a, Ground>, + ReadStorage<'a, Player>, + ReadStorage<'a, Position>, + ReadStorage<'a, Moved>, + ReadStorage<'a, RoomExit>, + + ); + fn run(&mut self, (mut emigration, ground, players, positions, moved, exits): Self::SystemData) { + + for (player, position, _moved) in (&players, &positions, &moved).join() { + for ent in ground.cells.get(&position.pos).unwrap() { + if let Some(exit) = exits.get(*ent) { + emigration.emigrants.push((player.id.clone(), exit.destination.clone())); + break; + } + } + } + } +} + diff --git a/src/systems/mod.rs b/src/systems/mod.rs index 7e75706..68de813 100644 --- a/src/systems/mod.rs +++ b/src/systems/mod.rs @@ -6,3 +6,4 @@ pub mod view; pub mod remove; pub mod create; pub mod take; +pub mod migrate; |
