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

31 lines
777 B
JavaScript

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) {
if (
!this.elementsId.includes(elementId) ||
this.selected.elementId === elementId
) {
return;
}
const map = this.gameObjects.find((item) => item.elementId === elementId);
this.selected = map.name;
}
}