diff options
| author | troido <troido@protonmail.com> | 2020-04-06 19:28:45 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-04-06 19:28:45 +0200 |
| commit | 7c351a0c7a497d30f4826a19e6c6e92d3e7b5065 (patch) | |
| tree | 26add4ae11f03b2435c149ef5fe95d66afd60eda /src/room.rs | |
| parent | 66a3d3131f32e7bae2f0f7c4fd0b0c876eb3e8a0 (diff) | |
improved error handling
Diffstat (limited to 'src/room.rs')
| -rw-r--r-- | src/room.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/room.rs b/src/room.rs index bc5b651..c2e635a 100644 --- a/src/room.rs +++ b/src/room.rs @@ -137,7 +137,7 @@ impl <'a, 'b>Room<'a, 'b> { } } - pub fn load_from_template(&mut self, template: &RoomTemplate) { + pub fn load_from_template(&mut self, template: &RoomTemplate) -> Result<()> { let (width, height) = template.size; self.world.fetch_mut::<Size>().width = width; @@ -150,19 +150,20 @@ impl <'a, 'b>Room<'a, 'b> { let y = (idx as i64) / width; for template in templates { - self.create_entity(template.clone().unsaved(), Pos{x, y}).unwrap(); + self.create_entity(template.clone().unsaved(), Pos{x, y})?; } } for (name, place) in &template.places { self.places.insert(name.clone(), *place); } + Ok(()) } - pub fn create(id: RoomId, encyclopedia: &Encyclopedia, template: &RoomTemplate) -> Room<'a, 'b> { + pub fn create(id: RoomId, encyclopedia: &Encyclopedia, template: &RoomTemplate) -> Result<Room<'a, 'b>> { let mut room = Self::new(id, encyclopedia.clone(), default_dispatcher()); - room.load_from_template(template); - room + room.load_from_template(template)?; + Ok(room) } pub fn view(&self) -> HashMap<PlayerId, WorldMessage> { |
