94 lines
2.2 KiB
JavaScript
94 lines
2.2 KiB
JavaScript
export class FloorManager {
|
|
mainmanager;
|
|
|
|
#floors = new Map([]);
|
|
#rooms = new Map([]);
|
|
|
|
constructor() {}
|
|
|
|
async getFloors() {
|
|
const currentLocalization = this.mainmanager.getCurrentLangCode();
|
|
|
|
let allFloorsReqSend = fetch(`/data/${currentLocalization}/floors`);
|
|
|
|
let allFloorsReq = await allFloorsReqSend;
|
|
let allFloors;
|
|
if (allFloorsReq.ok) allFloors = await allFloorsReq.json();
|
|
|
|
allFloors.forEach((floor) => this.#floors.set(floor.id, floor));
|
|
}
|
|
|
|
async getRooms() {
|
|
const currentLocalization = this.mainmanager.getCurrentLangCode();
|
|
const currentFloor = this.mainmanager.getCurrentFocus("floor");
|
|
|
|
const curRoom = this.#rooms.get(currentFloor);
|
|
|
|
if (curRoom != null) return curRoom;
|
|
|
|
let allRoomsReqSend = fetch(
|
|
`/data/${currentLocalization}/rooms/${currentFloor}`
|
|
);
|
|
|
|
let allRoomsReq = await allRoomsReqSend;
|
|
let allRooms;
|
|
if (allRoomsReq.ok) allRooms = await allRoomsReq.json();
|
|
|
|
const roomMap = new Map([]);
|
|
allRooms.forEach((room) => roomMap.set(room.id, room));
|
|
|
|
this.#rooms.set(currentFloor, roomMap);
|
|
}
|
|
|
|
setCurrentFloor(id) {
|
|
const floor = this.#floors.get(id);
|
|
if (floor != null) this.mainmanager.setCurrentFocus("floor", id);
|
|
else throw "Floor does not exist";
|
|
}
|
|
|
|
get allFloors() {
|
|
return this.#floors;
|
|
}
|
|
|
|
get currentFloorId() {
|
|
return this.mainmanager.getCurrentFocus("floor");
|
|
}
|
|
|
|
get currentFloor() {
|
|
const currentFloor = this.#floors.get(
|
|
this.mainmanager.getCurrentFocus("floor")
|
|
);
|
|
return currentFloor;
|
|
}
|
|
|
|
get currentFloorRooms() {
|
|
const currentFloorRooms = this.#rooms.get(
|
|
this.mainmanager.getCurrentFocus("floor")
|
|
);
|
|
return currentFloorRooms;
|
|
}
|
|
|
|
setCurrentRoom(id) {
|
|
if (id == null) this.mainmanager.setCurrentFocus("room", id);
|
|
else {
|
|
const room = this.currentFloorRooms.get(id);
|
|
if (room != null) this.mainmanager.setCurrentFocus("room", id);
|
|
else throw "Room does not exist";
|
|
}
|
|
}
|
|
|
|
get allRooms() {
|
|
return this.#rooms;
|
|
}
|
|
|
|
get currentRoomId() {
|
|
return this.mainmanager.getCurrentFocus("room");
|
|
}
|
|
|
|
get currentRoom() {
|
|
const currentFloor = this.currentFloorRooms.get(
|
|
this.mainmanager.getCurrentFocus("room")
|
|
);
|
|
return currentFloor;
|
|
}
|
|
}
|