game-engine/modules/game-objects/map-management.js

33 lines
847 B
JavaScript
Raw Normal View History

2024-09-13 21:45:59 -05:00
import { GameObject } from "./game-object.js";
import { Map } from "./map.js";
export class MapManagement extends GameObject {
constructor({ maps = [] }) {
2024-09-17 23:16:36 -05:00
super({ gameObjects: maps.map((item) => new Map(item)) });
2024-09-13 21:45:59 -05:00
this.elementsId = this.gameObjects.map((item) => item.elementId);
}
get selected() {
return this.gameObjects.find((item) => item.selected);
}
set selected(name) {
this.gameObjects.forEach((item) => {
item.selected = item.name === name;
});
}
onMouseClick(elementId) {
2024-09-14 18:38:50 -05:00
super.onMouseClick(elementId);
2024-09-13 21:45:59 -05:00
if (
!this.elementsId.includes(elementId) ||
this.selected.elementId === elementId
) {
return;
}
const map = this.gameObjects.find((item) => item.elementId === elementId);
this.selected = map.name;
this.eventEmitter.emit("changeLevel");
2024-09-13 21:45:59 -05:00
}
}