From 1f7d384c29807f9f563f1e1cab2f840271cde2b6 Mon Sep 17 00:00:00 2001 From: Vantha Date: Thu, 26 Feb 2026 18:09:11 +0100 Subject: [PATCH] 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). --- .../data/mods/public/maps/scripts/Tutorial.js | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/binaries/data/mods/public/maps/scripts/Tutorial.js b/binaries/data/mods/public/maps/scripts/Tutorial.js index 22027016ea..754440df7b 100644 --- a/binaries/data/mods/public/maps/scripts/Tutorial.js +++ b/binaries/data/mods/public/maps/scripts/Tutorial.js @@ -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);