summaryrefslogtreecommitdiff
path: root/src/room.rs
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-02-21 16:27:32 +0100
committertroido <troido@protonmail.com>2020-02-21 16:27:32 +0100
commite69d9c3b5266fd6f9215d1e3f4a761b8027a785c (patch)
tree148ce7e757dacbd058a36785c78a724f96b5ca7f /src/room.rs
parentada1c4571a9ba43b15027f126fada55e73901a11 (diff)
wrote world code for migrating players
Diffstat (limited to 'src/room.rs')
-rw-r--r--src/room.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/room.rs b/src/room.rs
index c813e0c..44608c8 100644
--- a/src/room.rs
+++ b/src/room.rs
@@ -19,7 +19,8 @@ use super::resources::{
Input,
NewEntities,
Spawn,
- Players
+ Players,
+ Emigrating
};
use super::systems::{
moving::Move,
@@ -62,6 +63,7 @@ impl <'a, 'b>Room<'a, 'b> {
world.insert(NewEntities::new(encyclopedia));
world.insert(Players::default());
world.insert(Spawn::default());
+ world.insert(Emigrating::default());
world.register::<Serialise>();
let mut dispatcher = DispatcherBuilder::new()
@@ -135,8 +137,8 @@ impl <'a, 'b>Room<'a, 'b> {
self.world.fetch_mut::<Players>().entities.insert(state.id.clone(), ent);
}
- pub fn remove_player(&mut self, id: PlayerId) -> Result<PlayerState>{
- let ent = self.world.fetch_mut::<Players>().entities.remove(&id).ok_or(aerr!("failed to remove player"))?;
+ pub fn remove_player(&mut self, id: &PlayerId) -> Result<PlayerState>{
+ let ent = self.world.fetch_mut::<Players>().entities.remove(id).ok_or(aerr!("failed to remove player"))?;
self.world.write_component::<Removed>().insert(ent, Removed)?;
self.save_player_ent(ent).ok_or(aerr!("failed to find player to remove"))
}
@@ -198,6 +200,12 @@ impl <'a, 'b>Room<'a, 'b> {
self.world.fetch_mut::<NewEntities>().create(pos, template)?;
Ok(())
}
+
+ pub fn emigrate(&mut self) -> Vec<(PlayerId, RoomId)> {
+ let emigrants = self.world.remove::<Emigrating>().expect("World does not have Emigrating resource").emigrants;
+ self.world.insert(Emigrating::default());
+ emigrants
+ }
}