Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/common/OverlayCounterManager.js
/** | /** | ||||
* Since every GUI page can display the FPS or realtime counter, | * Since every GUI page can display the FPS or realtime counter, | ||||
* this manager is initialized for every GUI page. | * this manager is initialized for every GUI page. | ||||
*/ | */ | ||||
var g_OverlayCounterManager; | var g_OverlayCounterManager; | ||||
class OverlayCounterManager | class OverlayCounterManager | ||||
{ | { | ||||
constructor(dataCounter) | constructor(dataCounter) | ||||
{ | { | ||||
this.dataCounter = dataCounter; | this.dataCounter = dataCounter; | ||||
this.counters = []; | this.counters = []; | ||||
this.enabledCounters = []; | this.enabledCounters = []; | ||||
this.lastTick = undefined; | this.lastTick = undefined; | ||||
this.lastLineCount = undefined; | this.lastTextSize = undefined; | ||||
this.resizeHandlers = []; | this.resizeHandlers = []; | ||||
for (let name of this.availableCounterNames()) | for (let name of this.availableCounterNames()) | ||||
{ | { | ||||
let counterType = OverlayCounterTypes.prototype[name]; | let counterType = OverlayCounterTypes.prototype[name]; | ||||
if (counterType.IsAvailable && !counterType.IsAvailable()) | if (counterType.IsAvailable && !counterType.IsAvailable()) | ||||
continue; | continue; | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | class OverlayCounterManager | ||||
{ | { | ||||
// Don't rebuild the caption every frame | // Don't rebuild the caption every frame | ||||
let now = Date.now(); | let now = Date.now(); | ||||
if (now < this.lastTick + this.Delay) | if (now < this.lastTick + this.Delay) | ||||
return; | return; | ||||
this.lastTick = now; | this.lastTick = now; | ||||
let lineCount = 0; | |||||
let txt = ""; | let txt = ""; | ||||
for (let counter of this.enabledCounters) | for (let counter of this.enabledCounters) | ||||
{ | { | ||||
let newTxt = counter.get(); | let newTxt = counter.get(); | ||||
if (!newTxt) | if (newTxt) | ||||
continue; | |||||
++lineCount; | |||||
txt += newTxt + "\n"; | txt += newTxt + "\n"; | ||||
} | } | ||||
if (lineCount) | if (txt) | ||||
this.dataCounter.caption = txt; | this.dataCounter.caption = txt; | ||||
// The caption changes more often than not, | // The caption changes more often than not, but the size changes rarely. | ||||
// but adding or removing lines happens rarely. | let textSize = this.dataCounter.getTextSize(); | ||||
if (this.lastLineCount == lineCount) | if (this.lastTextSize && this.lastTextSize.height == textSize.height && this.lastTextSize.width == textSize.width) | ||||
return; | return; | ||||
warn("P") | |||||
Lint: ESLintBear (semi): `Missing semicolon.` | |||||
Lint: ESLintBear (indent) Expected indentation of 2 tabs but found 0. Lint: ESLintBear (indent): `Expected indentation of 2 tabs but found 0.` | |||||
Lint: JSHintBear Missing semicolon. Lint: JSHintBear: `Missing semicolon.` | |||||
this.lastTextSize = textSize; | |||||
this.lastLineCount = lineCount; | if (txt) | ||||
if (lineCount) | |||||
{ | { | ||||
let textSize = this.dataCounter.getTextSize(); | |||||
bbAuthorUnsubmitted Done Inline Actionselexis noticed this causes a bug on itself too, due to the out of scope reference below. Accidentally already fixed. bb: elexis noticed this causes a bug on itself too, due to the out of scope reference below. | |||||
let size = this.dataCounter.size; | let size = this.dataCounter.size; | ||||
size.bottom = size.top + textSize.height; | size.bottom = size.top + textSize.height; | ||||
size.left = size.right - textSize.width; | size.left = size.right - textSize.width; | ||||
this.dataCounter.size = size; | this.dataCounter.size = size; | ||||
} | } | ||||
this.dataCounter.hidden = !lineCount; | this.dataCounter.hidden = !txt; | ||||
for (let handler of this.resizeHandlers) | for (let handler of this.resizeHandlers) | ||||
handler(textSize); | handler(textSize); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* To minimize the computation performed every frame, this duration | * To minimize the computation performed every frame, this duration | ||||
* in milliseconds determines how often the caption is rebuilt. | * in milliseconds determines how often the caption is rebuilt. | ||||
*/ | */ | ||||
OverlayCounterManager.prototype.Delay = 250; | OverlayCounterManager.prototype.Delay = 250; |
Wildfire Games · Phabricator
Missing semicolon.