diff options
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/editor.rs | 17 | ||||
| -rw-r--r-- | src/client/map/mod.rs | 4 | ||||
| -rw-r--r-- | src/client/map/room_mark.rs | 6 |
3 files changed, 27 insertions, 0 deletions
diff --git a/src/client/editor.rs b/src/client/editor.rs index 0fb5794..e416339 100644 --- a/src/client/editor.rs +++ b/src/client/editor.rs @@ -127,6 +127,8 @@ impl Editor { snapper: &Snapper, input: &mut Input, ) { + self.poll_net(); + // Handle keybindings for tool change for (&tool_type, (_, activation_bind)) in self.tools.iter() { if input.poll_global(&activation_bind) { @@ -163,6 +165,21 @@ impl Editor { active_tool.handle_custom_bindings(&mut self.map, &self.server, input); } + fn poll_net(&mut self) { + while let Some(cargo) = self.server().next_packet() { + match cargo { + Cargo::SetRoom((id, new_room)) => { + if let Some(mark) = self.map.get_room_mut(id) { + mark.set_room(new_room); + } else { + self.map.add_room(id, new_room); + } + } + other => error!("Unknown packet received: {:?}", other), + } + } + } + /// Draw all tools and in case of the active tool also what is currently being edited by it, if /// that exists. pub fn draw_tools(&self, rld: &mut RaylibDrawHandle, transform: &Transform) { diff --git a/src/client/map/mod.rs b/src/client/map/mod.rs index 27cafc4..9589e59 100644 --- a/src/client/map/mod.rs +++ b/src/client/map/mod.rs @@ -166,6 +166,10 @@ impl Map { pub fn rooms(&self) -> &StableVec<RoomMark> { &self.rooms } + /// Get a room with the given id mutably, in case it exists. + pub fn get_room_mut(&mut self, id: usize) -> Option<&mut RoomMark> { + self.rooms.get_mut(id) + } /// Get the walls of this map. pub fn walls(&self) -> &StableVec<WallMark> { diff --git a/src/client/map/room_mark.rs b/src/client/map/room_mark.rs index a9777fb..5c0ca98 100644 --- a/src/client/map/room_mark.rs +++ b/src/client/map/room_mark.rs @@ -29,6 +29,12 @@ impl RoomMark { } } + /// Replace the room this mark describes with the new room. + pub fn set_room(&mut self, room: Room) { + self.room = room; + self.retriangulate(); + } + /* When the internal polygon changes, it must be retriangulated to be drawn on the screen * properly, so this function must be called any time that happens. */ |
