Separate handling of tutorial goals and warnings

This is more explicit and makes the code cleaner.
This commit is contained in:
Vantha
2026-02-24 16:55:09 +01:00
committed by Vantha
parent ca8a0a5611
commit dd396f19b6
3 changed files with 23 additions and 14 deletions
@@ -164,7 +164,7 @@ var g_NotificationsTypes =
},
"tutorial": function(notification, player)
{
g_Tutorial.update(notification);
g_Tutorial.handleNotification(notification);
},
"tribute": function(notification, player)
{
@@ -17,28 +17,35 @@ class Tutorial
this.panel.hidden = !this.panel.hidden || !this.text.caption;
}
update(notification)
handleNotification(notification)
{
if (notification.goal)
this.displayGoal(notification.goal);
if (notification.warning)
this.displayWarning(notification.warning);
}
displayWarning(warning)
{
this.warning.caption = coloredText(translate(warning), "orange");
}
displayGoal(goal)
{
this.panel.hidden = false;
if (notification.warning)
{
this.warning.caption = coloredText(translate(notification.warning), "orange");
return;
}
const notificationText =
notification.instructions.reduce((instructions, item) =>
goal.instructions.reduce((instructions, item) =>
instructions + (typeof item === "string" ? translate(item) : colorizeHotkey(translate(item.text), item.hotkey)),
"");
this.text.caption = this.instructions.concat(setStringTags(notificationText, this.NewInstructionTags)).join("\n");
this.instructions.push(notificationText);
if (notification.readyButton)
if (goal.readyButton)
{
this.readyButton.hidden = false;
if (notification.leave)
if (goal.leave)
{
this.warning.caption = translate("Click to quit this tutorial.");
this.readyButton.caption = translate("Quit");
@@ -85,9 +85,11 @@ Trigger.prototype.GoalMessage = function(instructions, readyButton=false, leave=
cmpGUIInterface.PushNotification({
"type": "tutorial",
"players": [1],
"instructions": typeof instructions === "string" ? [instructions] : instructions,
"readyButton": readyButton,
"leave": leave
"goal": {
"instructions": typeof instructions === "string" ? [instructions] : instructions,
"readyButton": readyButton,
"leave": leave
}
});
};