0ad/binaries/data/mods/public/gui/session/developer_overlay/DeveloperOverlayEntityState.js
Vantha 6deca026b3
Add player to GetTemplateData calls where necessary
If no player is provided then the function falls back to the viewed
player, which is sometimes not the right one (like for observers), which
resulted in inconsistent/incorrect data being returned. This patch fixes
that.
2026-08-12 11:51:39 +02:00

51 lines
1.3 KiB
JavaScript

/**
* This class manages the developer overlay which displays the state of the first selected entity.
*/
class DeveloperOverlayEntityState
{
constructor(selection)
{
this.developerOverlayEntityState = Engine.GetGUIObjectByName("developerOverlayEntityState");
this.selection = selection;
this.updater = this.update.bind(this);
}
setEnabled(enabled)
{
this.developerOverlayEntityState.hidden = !enabled;
if (enabled)
{
registerSimulationUpdateHandler(this.updater);
registerEntitySelectionChangeHandler(this.updater);
}
else
{
unregisterSimulationUpdateHandler(this.updater);
unregisterEntitySelectionChangeHandler(this.updater);
}
}
update()
{
const simState = clone(g_SimState);
simState.players = "<<<omitted>>>";
let text = "simulation: " + uneval(simState);
const selection = this.selection.toList();
if (selection.length)
{
const entState = GetEntityState(selection[0]);
if (entState)
{
const template = GetTemplateData(entState.template, entState.player);
text += "\n\nentity: {\n";
for (const k in entState)
text += " " + k + ":" + uneval(entState[k]) + "\n";
text += "}\n\ntemplate: " + uneval(template);
}
}
this.developerOverlayEntityState.caption = text.replace(/\[/g, "\\[");
}
}