mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-08-15 14:43:32 -07:00
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:
parent
2f27dcc97d
commit
1f7d384c29
1 changed files with 22 additions and 17 deletions
|
|
@ -12,8 +12,7 @@ Trigger.prototype.InitTutorial = function(data)
|
||||||
|
|
||||||
// Register needed triggers
|
// Register needed triggers
|
||||||
this.RegisterTrigger("OnDeserialized", "DeserializedAction", { "enabled": true });
|
this.RegisterTrigger("OnDeserialized", "DeserializedAction", { "enabled": true });
|
||||||
this.RegisterTrigger("OnPlayerCommand", "PlayerCommandAction", { "enabled": false });
|
this.RegisterTrigger("OnPlayerCommand", "BasePlayerCommandAction", { "enabled": true });
|
||||||
this.tutorialEvents.push("OnPlayerCommand");
|
|
||||||
|
|
||||||
for (const step of this.tutorialSteps)
|
for (const step of this.tutorialSteps)
|
||||||
{
|
{
|
||||||
|
|
@ -49,7 +48,17 @@ Trigger.prototype.NextStep = function(deserializing = false)
|
||||||
const action = event.substring(2) + "Action";
|
const action = event.substring(2) + "Action";
|
||||||
if (step[event])
|
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);
|
this.EnableTrigger(event, action);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -57,20 +66,10 @@ Trigger.prototype.NextStep = function(deserializing = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
Trigger.prototype.IsDone = step.IsDone || (() => false);
|
Trigger.prototype.IsDone = step.IsDone || (() => false);
|
||||||
const showContinueButton =
|
const showContinueButton = this.IsDone() || (step.panelData.showContinueButton === undefined ?
|
||||||
step.panelData.showContinueButton === undefined ?
|
this.tutorialEvents.every(event => !step[event]) :
|
||||||
this.IsDone() || this.tutorialEvents.every(event => !step[event]) :
|
step.panelData.showContinueButton
|
||||||
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();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
this.DisplayStep(step, showContinueButton, ++this.stepIndex == this.tutorialSteps.length);
|
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()
|
Trigger.prototype.DeserializedAction = function()
|
||||||
{
|
{
|
||||||
this.stepIndex = Math.max(0, this.stepIndex - 1);
|
this.stepIndex = Math.max(0, this.stepIndex - 1);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue