From 8d166e628ceb2072e045b9ff6b1dcc1002a34d8e Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Wed, 3 Feb 2021 23:00:09 +0100 Subject: Add most of the offline functionality back --- src/client/map/mod.rs | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/client/map/mod.rs') diff --git a/src/client/map/mod.rs b/src/client/map/mod.rs index 9589e59..7a0613c 100644 --- a/src/client/map/mod.rs +++ b/src/client/map/mod.rs @@ -16,7 +16,7 @@ pub use wall_mark::*; use crate::client::Transform; use crate::stable_vec::StableVec; -use crate::world::{Room, Wall, World}; +use crate::world::{Icon, Room, Wall, World}; use icon_texture_manager::IconTextureManager; use raylib::drawing::RaylibDrawHandle; use raylib::{RaylibHandle, RaylibThread}; @@ -92,9 +92,11 @@ impl Map { } /// Add an icon with a specific id. May fail if there already is an entity with that id. - pub fn add_icon(&mut self, id: usize, icon: IconMark) -> bool { + pub fn add_icon(&mut self, id: usize, icon: Icon) -> bool { if self.used_ids.try_insert(id, ()).is_ok() { - self.icons.try_insert(id, icon).unwrap(); + self.icons + .try_insert(id, IconMark::from_icon(icon, self.icon_renderer.clone())) + .unwrap(); true } else { error!("Unable to add icon. Id already in use."); @@ -162,6 +164,14 @@ impl Map { ) } + /// Remove all items from the map. + pub fn clear(&mut self) { + self.rooms.clear(); + self.walls.clear(); + self.icons.clear(); + self.used_ids.clear(); + } + /// Get the rooms of this map. pub fn rooms(&self) -> &StableVec { &self.rooms @@ -175,11 +185,19 @@ impl Map { pub fn walls(&self) -> &StableVec { &self.walls } + /// Get a wall with the given id mutably, in case it exists. + pub fn get_wall_mut(&mut self, id: usize) -> Option<&mut WallMark> { + self.walls.get_mut(id) + } /// Get the icons of this map. pub fn icons(&self) -> &StableVec { &self.icons } + /// Get an icon with the given id mutably, in case it exists. + pub fn get_icon_mut(&mut self, id: usize) -> Option<&mut IconMark> { + self.icons.get_mut(id) + } /// Replace the internal map data with the data of the world provided. /// (Load and replace) @@ -199,10 +217,7 @@ impl Map { /// items with the same id will therefore be ignored and not added. pub fn add_data(&mut self, world: World) { for (id, i) in world.icons().iter() { - self.add_icon( - *id, - IconMark::from_icon(i.clone(), self.icon_renderer.clone()), - ); + self.add_icon(*id, i.clone()); } for (id, r) in world.rooms().iter() { self.add_room(*id, r.clone()); -- cgit v1.2.3-70-g09d2