forked from mirrors/0ad
38e06fce7e
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.
48 lines
1.0 KiB
JavaScript
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
|
|
{
|
|
}
|