From 7a4a62eb2804b6b19b4e71eee42d6b3d7ad08a3a Mon Sep 17 00:00:00 2001 From: troido Date: Wed, 8 Apr 2020 09:54:20 +0200 Subject: rooms now share the same default dispatcher --- src/purgatory.rs | 3 ++- src/room.rs | 19 ++++++++----------- src/world.rs | 18 +++++++++++++----- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/purgatory.rs b/src/purgatory.rs index 12be7cc..f5f8c06 100644 --- a/src/purgatory.rs +++ b/src/purgatory.rs @@ -1,4 +1,5 @@ + use serde_json::json; use specs::{ DispatcherBuilder @@ -30,7 +31,7 @@ pub fn create_purgatory<'a, 'b>(encyclopedia: &Encyclopedia) -> Room<'a, 'b> { .with(ControlAI, "controlai", &["cool_down"]) .with(Move, "move", &["controlinput", "controlai"]) .build(); - let mut room = Room::new(purgatory_id(), encyclopedia.clone(), dispatcher); + let mut room = Room::new(purgatory_id(), encyclopedia.clone(), Some(dispatcher)); room.load_from_template(&RoomTemplate::from_json(&json!({ "width": 15, "height": 20, diff --git a/src/room.rs b/src/room.rs index 1bdb5b5..0bb2f61 100644 --- a/src/room.rs +++ b/src/room.rs @@ -94,7 +94,7 @@ pub fn default_dispatcher<'a, 'b>() -> Dispatcher<'a, 'b> { pub struct Room<'a, 'b> { world: World, - dispatcher: Dispatcher<'a, 'b>, + dispatcher: Option>, pub id: RoomId, places: HashMap } @@ -113,7 +113,7 @@ macro_rules! register_insert { impl <'a, 'b>Room<'a, 'b> { - pub fn new(id: RoomId, encyclopedia: Encyclopedia, dispatcher: Dispatcher<'a, 'b>) -> Room<'a, 'b> { + pub fn new(id: RoomId, encyclopedia: Encyclopedia, dispatcher: Option>) -> Room<'a, 'b> { let mut world = World::new(); world.insert(NewEntities::new(encyclopedia)); register_insert!( @@ -152,20 +152,17 @@ impl <'a, 'b>Room<'a, 'b> { Ok(()) } - - pub fn create(id: RoomId, encyclopedia: &Encyclopedia, template: &RoomTemplate) -> Result> { - let mut room = Self::new(id, encyclopedia.clone(), default_dispatcher()); - room.load_from_template(template)?; - Ok(room) - } - pub fn view(&self) -> HashMap { self.world.fetch::().output.clone() } - pub fn update(&mut self, timestamp: Timestamp) { + pub fn update(&mut self, timestamp: Timestamp, default_dispatcher: &mut Dispatcher) { self.world.fetch_mut::