import { BaseHUDPart } from "../base_hud_part"; import { makeDiv, removeAllChildren } from "../../../core/utils"; import { globalConfig } from "../../../core/config"; export class HUDEntityDebugger extends BaseHUDPart { createElements(parent) { this.element = makeDiv( parent, "ingame_HUD_EntityDebugger", [], ` Tile below cursor:
Chunk below cursor:
` ); this.mousePosElem = this.element.querySelector(".mousePos"); this.chunkPosElem = this.element.querySelector(".chunkPos"); this.entityInfoElem = this.element.querySelector(".entityInfo"); } initialize() { this.root.camera.downPreHandler.add(this.onMouseDown, this); } update() { const mousePos = this.root.app.mousePosition; if (!mousePos) { return; } const worldPos = this.root.camera.screenToWorld(mousePos); const worldTile = worldPos.toTileSpace(); const chunk = worldTile.divideScalar(globalConfig.mapChunkSize).floor(); this.mousePosElem.innerText = worldTile.x + " / " + worldTile.y; this.chunkPosElem.innerText = chunk.x + " / " + chunk.y; const entity = this.root.map.getTileContent(worldTile); if (entity) { removeAllChildren(this.entityInfoElem); let html = "Entity"; const flag = (name, val) => `${name} ${val}`; html += "
"; html += flag("registered", entity.registered); html += flag("uid", entity.uid); html += flag("destroyed", entity.destroyed); html += "
"; html += "
"; for (const componentId in entity.components) { const data = entity.components[componentId]; html += "
"; html += "" + componentId + ""; html += ""; html += "
"; } html += "
"; this.entityInfoElem.innerHTML = html; } } onMouseDown() {} }