1
0
forked from mirrors/0ad
Files
0ad/binaries/data/mods/public/gui/common/OverlayCounter.js
T
elexis 38e06fce7e Rewrite FPS/Realtime/Gametime/Ceasefire counters to use object semantics using class notation, refs #5387.
Rebuild the counters every 250ms instead of every frame and minimize
object creation.

Differential Revision: https://code.wildfiregames.com/D2391
Comments By: Stan
This was SVN commit r23096.
2019-10-27 12:39:28 +00:00

48 lines
1.0 KiB
JavaScript

/**
* This is an abstract base class managing one counter shown.
* Classes implementing this class require a Config property and may have a Hotkey property.
*/
class OverlayCounter
{
constructor(overlayCounterManager)
{
this.overlayCounterManager = overlayCounterManager;
this.updateEnabled();
registerConfigChangeHandler(this.onConfigChange.bind(this));
if (this.Hotkey)
Engine.SetGlobalHotkey(this.Hotkey, this.toggle.bind(this));
}
onConfigChange(changes)
{
if (changes.has(this.Config))
this.updateEnabled();
}
isEnabled()
{
return Engine.ConfigDB_GetValue("user", this.Config) == "true";
}
updateEnabled()
{
this.overlayCounterManager.setCounterEnabled(this, this.isEnabled());
}
toggle()
{
Engine.ConfigDB_CreateValue("user", this.Config, String(!this.isEnabled()));
this.updateEnabled();
}
}
/**
* The properties of this prototype are defined in other files. Each of them is a class
* managing a counter shown on the current page and may extend the OverlayCounter class.
*/
class OverlayCounterTypes
{
}