2024-06-02 05:39:23 +00:00
|
|
|
export class FloorManager {
|
|
|
|
map;
|
|
|
|
ui;
|
|
|
|
gameobj;
|
|
|
|
events;
|
|
|
|
lang;
|
|
|
|
|
|
|
|
floors = new Map([]);
|
|
|
|
rooms = new Map([]);
|
2024-06-03 03:54:02 +00:00
|
|
|
#currentFloor = "";
|
|
|
|
#currentRoom = "";
|
2024-06-02 05:39:23 +00:00
|
|
|
|
|
|
|
constructor(map, ui, gameobj, events, lang) {
|
|
|
|
this.map = map;
|
|
|
|
this.ui = ui;
|
|
|
|
this.ui.floormanager = this;
|
|
|
|
this.gameobj = gameobj;
|
|
|
|
this.gameobj.floormanager = this;
|
|
|
|
this.events = events;
|
|
|
|
this.events.floormanager = this;
|
|
|
|
this.lang = lang;
|
|
|
|
}
|
|
|
|
|
2024-06-03 03:54:02 +00:00
|
|
|
set currentFloor(floor) {
|
|
|
|
this.#currentFloor = floor;
|
|
|
|
}
|
|
|
|
|
|
|
|
get currentFloor() {
|
|
|
|
return this.#currentFloor;
|
|
|
|
}
|
|
|
|
|
|
|
|
get currentFloorItem() {
|
|
|
|
return this.floors.get(this.#currentFloor);
|
|
|
|
}
|
|
|
|
|
|
|
|
setCurrentRoom(room, maximize = true) {
|
|
|
|
this.#currentRoom = room;
|
|
|
|
this.ui.__updateEvents();
|
|
|
|
if (maximize) this.ui.eventsMaximize();
|
|
|
|
if (room == "") this.gameobj.zoomToFloor();
|
|
|
|
else this.gameobj.zoomToRoom(room);
|
|
|
|
}
|
|
|
|
|
|
|
|
get currentRoom() {
|
|
|
|
return this.#currentRoom;
|
|
|
|
}
|
|
|
|
|
|
|
|
get currentRoomItem() {
|
|
|
|
return this.currentFloorRooms.get(this.#currentRoom);
|
|
|
|
}
|
|
|
|
|
|
|
|
get currentFloorRooms() {
|
|
|
|
return this.rooms.get(this.#currentFloor);
|
|
|
|
}
|
|
|
|
|
2024-06-02 05:39:23 +00:00
|
|
|
async getFloors() {
|
|
|
|
let allFloorsReqSend = fetch(`/data/${this.lang}/map`);
|
|
|
|
|
|
|
|
this.ui.setLoading(true);
|
|
|
|
|
|
|
|
let allFloorsReq = await allFloorsReqSend;
|
|
|
|
let allFloors;
|
|
|
|
if (allFloorsReq.ok) allFloors = await allFloorsReq.json();
|
|
|
|
|
|
|
|
allFloors.forEach((floor) => this.floors.set(floor.id, floor));
|
|
|
|
|
|
|
|
this.changeFloor(allFloors[0].id);
|
|
|
|
|
|
|
|
this.ui.setLoading(false);
|
|
|
|
|
|
|
|
return this.floors;
|
|
|
|
}
|
|
|
|
|
|
|
|
async getRooms(id) {
|
|
|
|
const curRoom = this.rooms.get(id);
|
|
|
|
|
|
|
|
if (curRoom != null) return curRoom;
|
|
|
|
|
|
|
|
let allRoomsReqSend = fetch(`/data/${this.lang}/map/${id}`);
|
|
|
|
|
|
|
|
this.ui.setLoading(true);
|
|
|
|
|
|
|
|
let allRoomsReq = await allRoomsReqSend;
|
|
|
|
let allRooms;
|
|
|
|
if (allRoomsReq.ok) allRooms = await allRoomsReq.json();
|
|
|
|
|
2024-06-03 03:54:02 +00:00
|
|
|
const roomMap = new Map([]);
|
|
|
|
allRooms.forEach((room) => roomMap.set(room.id, room));
|
|
|
|
|
|
|
|
this.rooms.set(id, roomMap);
|
2024-06-02 05:39:23 +00:00
|
|
|
|
|
|
|
this.ui.setLoading(false);
|
|
|
|
|
|
|
|
return this.rooms;
|
|
|
|
}
|
|
|
|
|
|
|
|
async changeFloor(id) {
|
|
|
|
const floor = this.floors.get(id);
|
2024-06-03 03:54:02 +00:00
|
|
|
if (floor != null) this.#currentFloor = id;
|
2024-06-02 05:39:23 +00:00
|
|
|
|
|
|
|
if (this.ui.floorsEmpty) this.ui.__updateFloorsHard();
|
|
|
|
else this.ui.__updateFloorsSoft();
|
|
|
|
|
|
|
|
this.ui.setLoading(true);
|
|
|
|
|
|
|
|
this.gameobj.generateFloor();
|
|
|
|
|
|
|
|
await this.getRooms(id);
|
|
|
|
|
|
|
|
this.gameobj.generateRooms();
|
|
|
|
|
|
|
|
await this.events.getFloorEvents();
|
|
|
|
|
|
|
|
this.ui.__updateEvents();
|
|
|
|
|
2024-06-03 03:54:02 +00:00
|
|
|
this.setCurrentRoom("", false);
|
|
|
|
|
2024-06-02 05:39:23 +00:00
|
|
|
this.ui.setLoading(false);
|
|
|
|
|
|
|
|
return floor;
|
|
|
|
}
|
|
|
|
}
|