Skip to content

Commit

Permalink
don't change ResetNextIf to ResetIf when attached to a Trigger condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamiras committed Jun 26, 2023
1 parent 04fe66d commit caac96d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Source/Parser/AchievementBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,15 @@ private static void NormalizeResetNextIfs(List<List<RequirementEx>> groups)
continue;
}

if (lastRequirement.Type == RequirementType.Trigger)
{
// if the ResetNextIf is attached to a Trigger clause, assume there are other conditions
// that would also be reset if the ResetNextIf were changed to a ResetIf and that would
// cause the challenge indicator to be hidden.
canExtract = false;
continue;
}

resetNextIfClauses.Add(requirementEx);

resetNextIsForPause |= (lastRequirement.Type == RequirementType.PauseIf);
Expand Down
4 changes: 4 additions & 0 deletions Tests/Parser/AchievementBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ public void TestOptimizeNormalizeComparisons(string input, string expected)
[TestCase("never(byte(0x001234) != 5) && (byte(0x002345) == 6 || once(byte(0x002345) == 7))", "never(byte(0x001234) != 5) && (byte(0x002345) == 6 || once(byte(0x002345) == 7))")] // if there's a HitCount anywhere, leave the ResetIf alone
[TestCase("(measured(byte(0x1234) < 100) && unless(byte(0x1235) == 1)) || (measured(byte(0x1236) < 100) && unless(byte(0x1235) == 2))",
"(measured(byte(0x001234) < 100) && unless(byte(0x001235) == 1)) || (measured(byte(0x001236) < 100) && unless(byte(0x001235) == 2))")] // measured should prevent unless from being inverted
[TestCase("trigger_when(repeated(3, byte(0x1234) == 1) && never(byte(0x2345) == 2)", // don't convert ResetNextIf to ResetIf when attached to a challenge indicator
"trigger_when(repeated(3, byte(0x001234) == 1 && never(byte(0x002345) == 2)))")]
[TestCase("trigger_when(repeated(3, byte(0x1234) == 1) && never(byte(0x2345) == 2)) && byte(0x3456) == 3", // don't convert ResetNextIf to ResetIf when attached to a challenge indicator
"trigger_when(repeated(3, byte(0x001234) == 1 && never(byte(0x002345) == 2))) && byte(0x003456) == 3")]
public void TestOptimizeNormalizeResetIfsAndPauseIfs(string input, string expected)
{
var achievement = CreateAchievement(input);
Expand Down

0 comments on commit caac96d

Please sign in to comment.