Skip to content

Commit

Permalink
bugfix: Fixed bug where multiple tunnels could not contain choices
Browse files Browse the repository at this point in the history
  • Loading branch information
PhoebeMitchell committed Nov 18, 2024
1 parent 707433f commit e344ba4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
9 changes: 7 additions & 2 deletions unity-ggjj/Assets/Scripts/NarrativeScript/NarrativeScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Linq;
using TextDecoder.Parser;
using Unity.Plastic.Newtonsoft.Json.Linq;
using UnityEngine;

[Serializable]
Expand Down Expand Up @@ -97,7 +98,7 @@ void ExploreNode()
{
while (story.canContinue)
{
var line = story.Continue();
var line = story.Continue().Trim();

if (line.Length == 0 ||
line[0] != '&')
Expand Down Expand Up @@ -127,10 +128,14 @@ void ExploreNode()
moveTags.Add(choice.GetTagValue(InvestigationState.BACKGROUND_TAG_KEY));
}

if (visitedPaths.Add(story.state.currentPathString))
if (visitedPaths.Add(story.state.currentPathString + story.state.callStack.elements.First().currentPointer.index))
{
ExploreNode();
}
else
{
Console.WriteLine();
}

story.state.LoadJson(savedState);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ public void ScriptReadingExploresMultipleChoicePaths(string script, IEnumerable<
{
new TestCaseData(EXPLORE_CHOICES_SCRIPT, CreateTestActions(6)).SetName("Explores multiple choices"),
new TestCaseData(DEAD_END_CHOICE_SCRIPT, CreateTestActions(5)).SetName("Handles dead end choices"),
new TestCaseData(TUNNEL_SCRIPT, CreateTestActions(2)).SetName("Handle tunnels")
new TestCaseData(TUNNEL_SCRIPT, CreateTestActions(2)).SetName("Handle tunnels"),
new TestCaseData(MULTIPLE_TUNNEL_SCRIPT, CreateTestActions(4)).SetName("Handle multiple tunnels"),
new TestCaseData(MULTIPLE_TUNNELS_WITH_CHOICES_SCRIPT, CreateTestActions(6)).SetName("Handle multiple tunnels with choices")
};

private const string EXPLORE_CHOICES_SCRIPT =
Expand Down Expand Up @@ -145,10 +147,38 @@ public void ScriptReadingExploresMultipleChoicePaths(string script, IEnumerable<
private const string TUNNEL_SCRIPT =
"-> TestTunnel ->\n" +
"&TESTACTION2\n" +
"-> END\n" +
"=== TestTunnel\n" +
"&TESTACTION1\n" +
"->->";

private const string MULTIPLE_TUNNEL_SCRIPT =
"-> TestTunnel1 ->\n" +
"&TESTACTION2\n" +
"-> TestTunnel2 ->\n" +
"&TESTACTION4\n" +
"-> END\n" +
"=== TestTunnel1\n" +
"&TESTACTION1\n" +
"->->\n" +
"=== TestTunnel2\n" +
"&TESTACTION3\n" +
"->->";

private const string MULTIPLE_TUNNELS_WITH_CHOICES_SCRIPT =
"-> TunnelWithChoice(0) ->\n" +
"&TESTACTION3\n" +
"-> TunnelWithChoice(3) ->\n" +
"&TESTACTION6\n" +
"-> END\n" +
"=== TunnelWithChoice(testActionIndex)\n" +
"+ [Choice1]\n" +
"&TESTACTION{1 + testActionIndex}\n" +
"-> TunnelWithChoice(testActionIndex)\n" +
"+ [Choice2]\n" +
"&TESTACTION{2 + testActionIndex}\n" +
"->->";

private static IEnumerable<string> CreateTestActions(int numberOfActions) =>
Enumerable.Range(1, numberOfActions).Select(i => $"&TESTACTION{i}");

Expand Down

0 comments on commit e344ba4

Please sign in to comment.