From 105c5ab0c0e969f3fda2cd43ae5195cbdb4da016 Mon Sep 17 00:00:00 2001 From: troido Date: Sun, 9 Feb 2020 18:53:27 +0100 Subject: Revert "no templates in the world; only pre-entities" This reverts commit b56add981c2f520789b97d1ee6f71dae41e8c900. --- src/room.rs | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'src/room.rs') diff --git a/src/room.rs b/src/room.rs index 30c420a..9d3f1ed 100644 --- a/src/room.rs +++ b/src/room.rs @@ -28,20 +28,22 @@ use super::systems::{ }; use crate::encyclopedia::Encyclopedia; use crate::roomtemplate::RoomTemplate; -use crate::template::Template; pub struct Room<'a, 'b> { world: World, - dispatcher: Dispatcher<'a, 'b>, - encyclopedia: Encyclopedia + dispatcher: Dispatcher<'a, 'b> } impl <'a, 'b>Room<'a, 'b> { pub fn new(encyclopedia: Encyclopedia) -> Room<'a, 'b> { let mut world = World::new(); + world.insert(NewEntities{ + templates: Vec::new(), + encyclopedia + }); let mut dispatcher = DispatcherBuilder::new() .with(ControlInput, "controlinput", &[]) @@ -57,8 +59,7 @@ impl <'a, 'b>Room<'a, 'b> { Room { world, - dispatcher, - encyclopedia + dispatcher } } @@ -75,19 +76,11 @@ impl <'a, 'b>Room<'a, 'b> { let y = (idx as i64) / width; for template in templates { - if let Err(msg) = self.add_entity(Pos{x, y}, template) { - println!("{}", msg); - } + self.world.fetch_mut::().templates.push((Pos{x, y}, template.clone())); } } } - pub fn add_entity(&mut self, pos: Pos, template: &Template) -> Result<(), &'static str>{ - let pre_entity = self.encyclopedia.construct(template)?; - self.world.fetch_mut::().ents.push((pos, pre_entity)); - Ok(()) - } - pub fn view(&self) -> HashMap { self.world.fetch::().output.clone() } -- cgit