diff options
Diffstat (limited to 'src/room.rs')
| -rw-r--r-- | src/room.rs | 21 |
1 files changed, 7 insertions, 14 deletions
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::<NewEntities>().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::<NewEntities>().ents.push((pos, pre_entity)); - Ok(()) - } - pub fn view(&self) -> HashMap<String, WorldMessage> { self.world.fetch::<Output>().output.clone() } |
