From 722714a0e1257f3b065e9e5b291f2b9441285ce7 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Mon, 23 Jun 2014 12:12:08 +0100 Subject: [PATCH] Moved text substitution step to Dialog commands. --- Assets/Fungus/Legacy/PageCommands.cs | 7 ++++--- Assets/Fungus/Legacy/PageController.cs | 9 +++------ Assets/Fungus/Scripts/Commands/DialogCommands.cs | 14 +++++++++----- Assets/Fungus/Scripts/Dialog.cs | 13 ++++++------- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/Assets/Fungus/Legacy/PageCommands.cs b/Assets/Fungus/Legacy/PageCommands.cs index 764cfbfe..89d2e94e 100644 --- a/Assets/Fungus/Legacy/PageCommands.cs +++ b/Assets/Fungus/Legacy/PageCommands.cs @@ -149,18 +149,19 @@ namespace Fungus public override void Execute(CommandQueue commandQueue, Action onComplete) { + string subbedText = Game.stringTable.SubstituteStrings(chooseText); + IDialog dialog = Game.GetInstance().GetDialog(); - PageController pageController = dialog as PageController; if (pageController != null) { // Legacy support for old Pages system - pageController.Choose(chooseText); + pageController.Choose(subbedText); } else { // Support for modern IDialog interface - dialog.Say(chooseText, null); + dialog.Say(subbedText, null); } // Choose always clears the commandQueue, so there's no need to call onComplete() diff --git a/Assets/Fungus/Legacy/PageController.cs b/Assets/Fungus/Legacy/PageController.cs index 395f8522..4f880a58 100644 --- a/Assets/Fungus/Legacy/PageController.cs +++ b/Assets/Fungus/Legacy/PageController.cs @@ -273,9 +273,8 @@ namespace Fungus } mode = Mode.Say; - string subbedText = Game.stringTable.SubstituteStrings(sayText); continueAction = sayAction; - WriteStory(subbedText); + WriteStory(sayText); } public void ClearOptions() @@ -285,15 +284,13 @@ namespace Fungus public void AddOption(string optionText, Action optionAction) { - string subbedText = Game.stringTable.FormatLinkText(Game.stringTable.SubstituteStrings(optionText)); - options.Add(new Option(subbedText, optionAction)); + options.Add(new Option(optionText, optionAction)); } public void Choose(string _chooseText) { mode = Mode.Choose; - string subbedText = Game.stringTable.SubstituteStrings(_chooseText); - WriteStory(subbedText); + WriteStory(_chooseText); } public void SetTimeout(float _timeoutDuration, Action _timeoutAction) diff --git a/Assets/Fungus/Scripts/Commands/DialogCommands.cs b/Assets/Fungus/Scripts/Commands/DialogCommands.cs index 1904243e..675cf3e3 100644 --- a/Assets/Fungus/Scripts/Commands/DialogCommands.cs +++ b/Assets/Fungus/Scripts/Commands/DialogCommands.cs @@ -15,17 +15,19 @@ namespace Fungus */ public class Say : CommandQueue.Command { - string storyText; + string sayText; - public Say(string _storyText) + public Say(string _sayText) { - storyText = _storyText; + sayText = _sayText; } public override void Execute(CommandQueue commandQueue, Action onComplete) { + string subbedText = Game.stringTable.SubstituteStrings(sayText); + IDialog sayDialog = Game.GetInstance().GetDialog(); - sayDialog.Say(storyText, onComplete); + sayDialog.Say(subbedText, onComplete); } } @@ -47,7 +49,9 @@ namespace Fungus public override void Execute(CommandQueue commandQueue, Action onComplete) { IDialog characterDialog = Game.GetInstance().GetDialog(); - characterDialog.AddOption(optionText, optionAction); + + string subbedText = Game.stringTable.FormatLinkText(Game.stringTable.SubstituteStrings(optionText)); + characterDialog.AddOption(subbedText, optionAction); if (onComplete != null) { diff --git a/Assets/Fungus/Scripts/Dialog.cs b/Assets/Fungus/Scripts/Dialog.cs index f7d11803..28766af8 100644 --- a/Assets/Fungus/Scripts/Dialog.cs +++ b/Assets/Fungus/Scripts/Dialog.cs @@ -362,16 +362,16 @@ namespace Fungus public void Say(string _sayText, Action sayAction) { - string subbedText = Game.stringTable.SubstituteStrings(_sayText); + string copyText = _sayText; // Hack: Handle Say(""); by writing a single space character. - if (subbedText.Length == 0) + if (copyText.Length == 0) { - subbedText = " "; + copyText = " "; } continueAction = sayAction; - previousSayText = subbedText; + previousSayText = copyText; if (timeoutDuration > 0 && options.Count > 0) @@ -380,7 +380,7 @@ namespace Fungus timeoutTimer = timeoutDuration; } - WriteSayText(subbedText); + WriteSayText(copyText); } void WriteSayText(string _sayText) @@ -489,8 +489,7 @@ namespace Fungus public void AddOption(string optionText, Action optionAction) { - string subbedText = Game.stringTable.FormatLinkText(Game.stringTable.SubstituteStrings(optionText)); - options.Add(new Option(subbedText, optionAction)); + options.Add(new Option(optionText, optionAction)); } public void SetTimeout(float _timeoutDuration, Action _timeoutAction)