mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-19 14:53:56 -07:00
Using 22 classes instead of 1 class (refs 2bcf4f678b/D1928) leverages more benefit of the paradigm. In particular it means the checkboxes can own the EntityState and TimeWarp helpers and the DeveloperOverlay itself can remain independent. Improve performance by 200 microseconds per turn by unsubscribing from onSimulationUpdate when the developer overlay is not opened, refse3f43f6352/ D2378. Move TimeWarp from input.js from8ddef2fee0to independent class using hotkey release event from78bc56f33e, refs #3194. Differential Revision: https://code.wildfiregames.com/D2383 This was SVN commit r23081.
51 lines
1.2 KiB
JavaScript
51 lines
1.2 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()
|
|
{
|
|
let simState = clone(g_SimState);
|
|
simState.players = "<<<omitted>>>";
|
|
let text = "simulation: " + uneval(simState);
|
|
|
|
let selection = this.selection.toList();
|
|
if (selection.length)
|
|
{
|
|
let entState = GetEntityState(selection[0]);
|
|
if (entState)
|
|
{
|
|
let template = GetTemplateData(entState.template);
|
|
text += "\n\nentity: {\n";
|
|
for (let k in entState)
|
|
text += " " + k + ":" + uneval(entState[k]) + "\n";
|
|
text += "}\n\ntemplate: " + uneval(template);
|
|
}
|
|
}
|
|
|
|
this.developerOverlayEntityState.caption = text.replace(/\[/g, "\\[");
|
|
}
|
|
}
|