UNPKG

blaze-2d

Version:

A fast and simple WebGL 2 2D game engine written in TypeScript

58 lines 2.32 kB
import Blaze from "../../blaze"; import BlazeDetails from "../../ui/details"; import BlazeList from "../../ui/list"; import BlazeText from "../../ui/text"; import EditorPane from "./pane"; export default class WorldPane extends EditorPane { /** * Creates a {@link WorldPane}. * * @param pos The top left corner of the pane in the editor grid * @param width The width of the pane in columns * @param height The height of the pane in rows */ constructor(pos, width, height) { super("world", pos, width, height); this.content = document.createElement("div"); this.entitiesList = new BlazeList(); this.addEntity = (event, entity) => { if (event === "remove") return; const text = new BlazeText(`${entity.name || "Entity"} ${this.entitiesList.items.length + 1}`, 1); text.element.style.marginBottom = "0.4rem"; this.entitiesList.addItems(text); }; this.removeEntity = (event, entity, index) => { if (event === "add") return; this.entitiesList.removeItem(index); }; this.content.style.display = "flex"; this.content.style.flexDirection = "column"; this.content.style.padding = "0.8rem"; this.element.appendChild(this.content); this.entitiesList.element.style.maxHeight = "40vh"; this.entitiesContainer = new BlazeDetails("Entities", this.entitiesList.element, 1.5); this.content.appendChild(this.entitiesContainer.element); } /** * Update world stats. */ update() { if (this.world !== Blaze.getScene().world) { if (this.world) { this.world.removeEntityListener(this.addEntity); this.world.removeEntityListener(this.removeEntity); } this.entitiesList.clearItems(); this.world = Blaze.getScene().world; this.world.addEntityListener(this.addEntity); this.world.addEntityListener(this.removeEntity); const entities = this.world.getEntities(); for (let i = 0; i < entities.length; i++) { this.addEntity("add", entities[i], i, entities); } } } } //# sourceMappingURL=worldPane.js.map