Fix player command handling in the tutorial

Move the code that checks whether a player command is a "continue
tutorial" into a separate method, so that it never overrides the player
command action of the active tutorial step. This could previously
happen if a step had the showContinueButton flag was set to true (and
a OnPlayerCommand method defined).
This commit is contained in:
Vantha
2026-02-26 18:09:11 +01:00
committed by Vantha
parent 2f27dcc97d
commit 1f7d384c29
@@ -12,8 +12,7 @@ Trigger.prototype.InitTutorial = function(data)
// Register needed triggers
this.RegisterTrigger("OnDeserialized", "DeserializedAction", { "enabled": true });
this.RegisterTrigger("OnPlayerCommand", "PlayerCommandAction", { "enabled": false });
this.tutorialEvents.push("OnPlayerCommand");
this.RegisterTrigger("OnPlayerCommand", "BasePlayerCommandAction", { "enabled": true });
for (const step of this.tutorialSteps)
{
@@ -49,7 +48,17 @@ Trigger.prototype.NextStep = function(deserializing = false)
const action = event.substring(2) + "Action";
if (step[event])
{
Trigger.prototype[action] = step[event];
Trigger.prototype[action] =
event == "OnPlayerCommand" ?
(msg) =>
{
// Don't forward tutorial continue commands, since the step trigger actions aren't supposed to handle them,
// plus we might have already loaded in the next step.
if (msg.cmd.type != "dialog-answer" || msg.cmd.tutorial != "continue")
step.OnPlayerCommand.call(this, msg);
} :
step[event];
this.EnableTrigger(event, action);
}
else
@@ -57,20 +66,10 @@ Trigger.prototype.NextStep = function(deserializing = false)
}
Trigger.prototype.IsDone = step.IsDone || (() => false);
const showContinueButton =
step.panelData.showContinueButton === undefined ?
this.IsDone() || this.tutorialEvents.every(event => !step[event]) :
step.panelData.showContinueButton;
if (showContinueButton)
{
this.EnableTrigger("OnPlayerCommand", "PlayerCommandAction");
Trigger.prototype.PlayerCommandAction = function(msg)
{
if (msg.cmd.type == "dialog-answer" && msg.cmd.tutorial && msg.cmd.tutorial == "continue")
this.NextStep();
};
}
const showContinueButton = this.IsDone() || (step.panelData.showContinueButton === undefined ?
this.tutorialEvents.every(event => !step[event]) :
step.panelData.showContinueButton
);
this.DisplayStep(step, showContinueButton, ++this.stepIndex == this.tutorialSteps.length);
};
@@ -102,6 +101,12 @@ Trigger.prototype.DisplayWarning = function(warning)
});
};
Trigger.prototype.BasePlayerCommandAction = function(msg)
{
if (msg.cmd.type == "dialog-answer" && msg.cmd.tutorial == "continue")
this.NextStep();
};
Trigger.prototype.DeserializedAction = function()
{
this.stepIndex = Math.max(0, this.stepIndex - 1);