From b56add981c2f520789b97d1ee6f71dae41e8c900 Mon Sep 17 00:00:00 2001 From: troido Date: Sat, 8 Feb 2020 19:22:00 +0100 Subject: no templates in the world; only pre-entities --- src/room.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/room.rs') diff --git a/src/room.rs b/src/room.rs index 84a1040..c179f61 100644 --- a/src/room.rs +++ b/src/room.rs @@ -28,22 +28,20 @@ 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> + dispatcher: Dispatcher<'a, 'b>, + encyclopedia: Encyclopedia } 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", &[]) @@ -59,7 +57,8 @@ impl <'a, 'b>Room<'a, 'b> { Room { world, - dispatcher + dispatcher, + encyclopedia } } @@ -76,11 +75,19 @@ impl <'a, 'b>Room<'a, 'b> { let y = (idx as i64) / width; for template in templates { - self.world.fetch_mut::().templates.push((Pos{x, y}, template.clone())); + if let Err(msg) = self.add_entity(Pos{x, y}, template) { + println!("{}", msg); + } } } } + 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