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

33 lines
812 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 = [] }) {
super();
this.gameObjects = maps.map((item) => new Map(item));
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;
}
}