From 7dd148f8e0b371cb422f14dfe926e98642c41317 Mon Sep 17 00:00:00 2001 From: troido Date: Fri, 7 Feb 2020 19:47:49 +0100 Subject: can now load maps in the same format as the python version --- src/room.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/room.rs') diff --git a/src/room.rs b/src/room.rs index 5daad29..8d15bde 100644 --- a/src/room.rs +++ b/src/room.rs @@ -30,6 +30,7 @@ use super::systems::{ use super::componentwrapper::ComponentWrapper; use crate::encyclopedia::Encyclopedia; use crate::template::Template; +use crate::roomtemplate::RoomTemplate; @@ -41,12 +42,8 @@ pub struct Room<'a, 'b> { impl <'a, 'b>Room<'a, 'b> { - pub fn new(encyclopedia: Encyclopedia, size: (i64, i64)) -> Room<'a, 'b> { - let (width, height) = size; + pub fn new(encyclopedia: Encyclopedia) -> Room<'a, 'b> { let mut world = World::new(); - world.insert(Size{width, height}); - world.insert(Input{actions: Vec::new()}); - world.insert(Output{output: HashMap::new()}); let mut dispatcher = DispatcherBuilder::new() .with(ControlInput, "controlinput", &[]) @@ -58,6 +55,7 @@ impl <'a, 'b>Room<'a, 'b> { dispatcher.setup(&mut world); + Room { world, dispatcher, @@ -65,6 +63,24 @@ impl <'a, 'b>Room<'a, 'b> { } } + pub fn load_from_template(&mut self, template: &RoomTemplate) { + + let (width, height) = template.size; + self.world.fetch_mut::().width = width; + self.world.fetch_mut::().height = height; + + // todo: set spawn + + for (idx, templates) in template.field.iter().enumerate() { + let x = (idx as i64) % width; + let y = (idx as i64) / width; + + for template in templates { + self.add_entity(template, Pos{x, y}); + } + } + } + pub fn view(&self) -> HashMap { self.world.fetch::().output.clone() } -- cgit