aboutsummaryrefslogtreecommitdiff
path: root/src/client/map
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/map')
-rw-r--r--src/client/map/icon_mark.rs5
-rw-r--r--src/client/map/mod.rs29
-rw-r--r--src/client/map/wall_mark.rs6
3 files changed, 33 insertions, 7 deletions
diff --git a/src/client/map/icon_mark.rs b/src/client/map/icon_mark.rs
index 39fd554..02ed501 100644
--- a/src/client/map/icon_mark.rs
+++ b/src/client/map/icon_mark.rs
@@ -45,6 +45,11 @@ impl IconMark {
textures,
}
}
+
+ /// Set the inner icon this icon mark is referencing.
+ pub fn set_icon(&mut self, icon: Icon) {
+ self.icon = icon;
+ }
}
impl Mappable for IconMark {
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<RoomMark> {
&self.rooms
@@ -175,11 +185,19 @@ impl Map {
pub fn walls(&self) -> &StableVec<WallMark> {
&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<IconMark> {
&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());
diff --git a/src/client/map/wall_mark.rs b/src/client/map/wall_mark.rs
index c51af9d..76ac03b 100644
--- a/src/client/map/wall_mark.rs
+++ b/src/client/map/wall_mark.rs
@@ -32,6 +32,12 @@ impl WallMark {
}
}
+ /// Set the internal wall of this wall mark.
+ pub fn set_wall(&mut self, wall: Wall) {
+ // XXX: Rounded edges??
+ self.wall = wall;
+ }
+
/// Get the internal data for serialisation
pub fn data(&self) -> &Wall {
&self.wall