diff --git a/src/Area.js b/src/Area.js index 2366466e..e6f1697f 100644 --- a/src/Area.js +++ b/src/Area.js @@ -87,6 +87,7 @@ class Area extends GameEntity { * @fires Area#roomRemoved */ removeRoom(room) { + this.removeRoomFromMap(room); this.rooms.delete(room.id); /** @@ -115,6 +116,21 @@ class Area extends GameEntity { floor.addRoom(x, y, room); } + removeRoomFromMap(room) { + if (!room.coordinates) { + throw new Error('Room does not have coordinates'); + } + + const {x, y, z} = room.coordinates; + + if (!this.map.has(z)) { + throw new Error(`That floor doesn't exist`); + } + + const floor = this.map.get(z); + floor.removeRoom(x, y); + } + /** * find a room at the given coordinates for this area * @param {number} x