0ad/binaries/data/mods/public/gui/session/TimeNotificationOverlay.js
Ralph Sennhauser 50a5d4b366
Fix eslint rule 'prefer-const' in gui/session
eslint --no-config-lookup --fix --rule '"prefer-const": 1' \
    binaries/data/mods/public/gui/session

Ref: #7812
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-05-10 18:05:22 +02:00

39 lines
1.1 KiB
JavaScript

/**
* The objective of this class is to displays all active counters (messages showing the remaining time)
* for wonder-victory, ceasefire etc.
*/
class TimeNotificationOverlay
{
constructor(playerViewControl)
{
this.notificationText = Engine.GetGUIObjectByName("notificationText");
registerSimulationUpdateHandler(this.rebuild.bind(this));
playerViewControl.registerViewedPlayerChangeHandler(this.rebuild.bind(this));
}
rebuild()
{
const notifications = Engine.GuiInterfaceCall("GetTimeNotifications", g_ViewedPlayer);
let notificationText = "";
for (const notification of notifications)
{
let message = notification.message;
if (notification.translateMessage)
message = translate(message);
const parameters = notification.parameters || {};
if (notification.translateParameters)
translateObjectKeys(parameters, notification.translateParameters);
parameters.time = timeToString(notification.endTime - g_SimState.timeElapsed);
colorizePlayernameParameters(parameters);
notificationText += sprintf(message, parameters) + "\n";
}
this.notificationText.caption = notificationText;
}
}