2020-05-18 20:08:33 +00:00
|
|
|
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: <span class="mousePos"></span><br>
|
|
|
|
Chunk below cursor: <span class="chunkPos"></span><br>
|
|
|
|
<div class="entityInfo"></div>
|
|
|
|
`
|
|
|
|
);
|
|
|
|
|
2020-07-22 02:15:16 +00:00
|
|
|
/** @type {HTMLElement} */
|
2020-05-18 20:08:33 +00:00
|
|
|
this.mousePosElem = this.element.querySelector(".mousePos");
|
2020-07-22 02:15:16 +00:00
|
|
|
/** @type {HTMLElement} */
|
2020-05-18 20:08:33 +00:00
|
|
|
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;
|
2020-05-28 11:49:50 +00:00
|
|
|
if (!mousePos) {
|
|
|
|
return;
|
|
|
|
}
|
2020-05-18 20:08:33 +00:00
|
|
|
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;
|
|
|
|
|
2020-06-28 17:34:10 +00:00
|
|
|
const entity = this.root.map.getTileContent(worldTile, this.root.currentLayer);
|
2020-05-18 20:08:33 +00:00
|
|
|
if (entity) {
|
|
|
|
removeAllChildren(this.entityInfoElem);
|
|
|
|
let html = "Entity";
|
|
|
|
|
|
|
|
const flag = (name, val) =>
|
|
|
|
`<span class='flag' data-value='${val ? "1" : "0"}'><u>${name}</u> ${val}</span>`;
|
|
|
|
|
|
|
|
html += "<div class='entityFlags'>";
|
|
|
|
html += flag("registered", entity.registered);
|
|
|
|
html += flag("uid", entity.uid);
|
|
|
|
html += flag("destroyed", entity.destroyed);
|
|
|
|
html += "</div>";
|
|
|
|
|
|
|
|
html += "<div class='components'>";
|
|
|
|
|
|
|
|
for (const componentId in entity.components) {
|
|
|
|
const data = entity.components[componentId];
|
|
|
|
html += "<div class='component'>";
|
|
|
|
html += "<strong class='name'>" + componentId + "</strong>";
|
|
|
|
html += "<textarea class='data'>" + JSON.stringify(data.serialize(), null, 2) + "</textarea>";
|
|
|
|
|
|
|
|
html += "</div>";
|
|
|
|
}
|
|
|
|
|
|
|
|
html += "</div>";
|
|
|
|
|
|
|
|
this.entityInfoElem.innerHTML = html;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onMouseDown() {}
|
|
|
|
}
|