From 744ba85644062614330a09a2f0e4b8ddf8046710 Mon Sep 17 00:00:00 2001 From: Steve Halliwell Date: Sat, 12 Jun 2021 10:42:38 +1000 Subject: [PATCH] Add special case for text variation making no change Now when the textvariation is given an empty block, a vary sequence with no elements, correctly return that there is no variation found. closes #963 # Conflicts: # Assets/Fungus/Docs/CHANGELOG.txt --- Assets/Fungus/Docs/CHANGELOG.txt | 1 + .../Fungus/Scripts/Utils/TextVariationHandler.cs | 9 +++++++++ .../Editor/FungusTextVariationSelectionTests.cs | 15 +++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/Assets/Fungus/Docs/CHANGELOG.txt b/Assets/Fungus/Docs/CHANGELOG.txt index 7470c41e..37530ca3 100644 --- a/Assets/Fungus/Docs/CHANGELOG.txt +++ b/Assets/Fungus/Docs/CHANGELOG.txt @@ -12,6 +12,7 @@ Unreleased ## Changed - Block will LogError when an exception is caught from a Command being Executed. - WriterAudio.GetSecondsRemaining reports 0 if not playing. Thanks to KVinS. + - Add special case that skips variation logic for sequences that contains no elements, making no change. v3.13.6 ====== diff --git a/Assets/Fungus/Scripts/Utils/TextVariationHandler.cs b/Assets/Fungus/Scripts/Utils/TextVariationHandler.cs index 5c2111f8..15b341b9 100644 --- a/Assets/Fungus/Scripts/Utils/TextVariationHandler.cs +++ b/Assets/Fungus/Scripts/Utils/TextVariationHandler.cs @@ -168,6 +168,15 @@ namespace Fungus } } + // As per issue #963 this should just return as if no variation + if(varyingSections.Count == 1) + { + if (varyingSections[0].type == Section.VaryType.Sequence && + varyingSections[0].elements.Count == 0) + return false; + } + + return varyingSections.Count > 0; } diff --git a/Assets/Tests/Editor/FungusTextVariationSelectionTests.cs b/Assets/Tests/Editor/FungusTextVariationSelectionTests.cs index 64d2937f..28e15616 100644 --- a/Assets/Tests/Editor/FungusTextVariationSelectionTests.cs +++ b/Assets/Tests/Editor/FungusTextVariationSelectionTests.cs @@ -114,5 +114,20 @@ namespace Fungus.Tests Assert.Fail(); } } + + [Test] + public void SquareBracketsWithoutTypeNoImpact() + { + Fungus.TextVariationHandler.ClearHistory(); + + string startingText = @"This is test a [of changing nothing]"; + const string expected = @"This is test a [of changing nothing]"; + + string res = string.Empty; + + res = Fungus.TextVariationHandler.SelectVariations(startingText); + + Assert.AreEqual(expected, res); + } } } \ No newline at end of file