From e69d9c3b5266fd6f9215d1e3f4a761b8027a785c Mon Sep 17 00:00:00 2001 From: troido Date: Fri, 21 Feb 2020 16:27:32 +0100 Subject: wrote world code for migrating players --- src/room.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/room.rs') 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::(); let mut dispatcher = DispatcherBuilder::new() @@ -135,8 +137,8 @@ impl <'a, 'b>Room<'a, 'b> { self.world.fetch_mut::().entities.insert(state.id.clone(), ent); } - pub fn remove_player(&mut self, id: PlayerId) -> Result{ - let ent = self.world.fetch_mut::().entities.remove(&id).ok_or(aerr!("failed to remove player"))?; + pub fn remove_player(&mut self, id: &PlayerId) -> Result{ + let ent = self.world.fetch_mut::().entities.remove(id).ok_or(aerr!("failed to remove player"))?; self.world.write_component::().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::().create(pos, template)?; Ok(()) } + + pub fn emigrate(&mut self) -> Vec<(PlayerId, RoomId)> { + let emigrants = self.world.remove::().expect("World does not have Emigrating resource").emigrants; + self.world.insert(Emigrating::default()); + emigrants + } } -- cgit