Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions Parlance.Tests/ConformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,18 @@ public void StepDialogue()
ids.Add(choice.ContainsKey("id") ? choice["id"] : null);
}
var onEnterEffects = (IEnumerable<object>)outDict["onEnterEffects"];

int count = 0;
foreach (var _ in onEnterEffects) count++;


var onEnterList = new List<object>();
foreach (var e in onEnterEffects) onEnterList.Add(e);

var outNode = (Dictionary<string, object>)outDict["node"];

var got = new Dictionary<string, object>
{
{ "nodeId", outNode.TryGetValue("id", out var idObj) ? idObj : null },
{ "visibleChoiceIds", ids },
{ "onEnterEffectCount", count }
{ "onEnterEffectCount", onEnterList.Count },
{ "onEnterEffects", onEnterList }
};
AssertDeepEqual((Dictionary<string, object>)v["expected"], got, (string)v["description"]);
}
Expand Down
60 changes: 57 additions & 3 deletions Runtime/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public static class Runtime
{
// ---------------------------------------------------------------- evaluate --
public static bool Evaluate(Dictionary<string, object> condition, State state, Dictionary<string, object> project = null)

Check warning on line 10 in Runtime/Runtime.cs

View workflow job for this annotation

GitHub Actions / test

Cannot convert null literal to non-nullable reference type.
{
if (project == null) project = new Dictionary<string, object>();
return _Evaluate(condition, state, project, new Dictionary<string, bool>());
Expand Down Expand Up @@ -184,7 +184,7 @@

// ------------------------------------------------------------- applyEffect --

public static State ApplyEffect(object effectObj, State state, Dictionary<string, object> project = null)

Check warning on line 187 in Runtime/Runtime.cs

View workflow job for this annotation

GitHub Actions / test

Cannot convert null literal to non-nullable reference type.
{
if (project == null) project = new Dictionary<string, object>();
State next = state.Copy();
Expand Down Expand Up @@ -284,7 +284,7 @@
return next;
}

public static State ApplyEffects(IEnumerable<object> effects, State state, Dictionary<string, object> project = null)

Check warning on line 287 in Runtime/Runtime.cs

View workflow job for this annotation

GitHub Actions / test

Cannot convert null literal to non-nullable reference type.
{
if (project == null) project = new Dictionary<string, object>();
State next = state;
Expand All @@ -300,7 +300,7 @@

// ------------------------------------------------------------ resolveCheck --

public static Dictionary<string, object> ResolveCheck(Dictionary<string, object> check, State state, Func<float> rng, object defaultDice = null, bool criticals = false)

Check warning on line 303 in Runtime/Runtime.cs

View workflow job for this annotation

GitHub Actions / test

Cannot convert null literal to non-nullable reference type.
{
object diceObj = check.TryGetValue("dice", out var dObj) ? dObj : defaultDice;
string notation = diceObj != null ? diceObj.ToString() : "1d20";
Expand Down Expand Up @@ -367,7 +367,7 @@

// ----------------------------------------------------------- stepDialogue --

public static Dictionary<string, object> StepDialogue(Dictionary<string, object> dialogue, string nodeId, State state, Dictionary<string, object> project = null)

Check warning on line 370 in Runtime/Runtime.cs

View workflow job for this annotation

GitHub Actions / test

Cannot convert null literal to non-nullable reference type.
{
if (project == null) project = new Dictionary<string, object>();

Expand All @@ -378,6 +378,36 @@
return new Dictionary<string, object> { { "error", $"node '{nodeId}' does not exist in dialogue '{diagId}'" } };
}

// Node-level showIf skip walk (contract 0.11.0): stepping onto a gated
// node whose gate fails resolves to the node the player actually sees —
// the same skip AdvanceNode performs, so a caller landing here by any path
// renders the shown node, not the hidden one. A ring of failing gates is
// COND-invalid and reported rather than looped.
{
var seen = new HashSet<string>();
while (node.TryGetValue("showIf", out var gateObj)
&& !Evaluate(gateObj as Dictionary<string, object> ?? new Dictionary<string, object>(), state, project))
{
string here = node.TryGetValue("id", out var hId) ? hId.ToString() : nodeId;
if (!seen.Add(here))
{
return new Dictionary<string, object> { { "error", "Cycle among conditional nodes: resolution cannot escape" } };
}
if (!node.ContainsKey("next"))
{
return new Dictionary<string, object> { { "error", $"conditional node '{here}' has no 'next' to skip to" } };
}
string nextId = node["next"]?.ToString();
var nextNode = FindNode(dialogue, nextId);
if (nextNode == null)
{
string diagId = dialogue.TryGetValue("id", out var dId) ? dId.ToString() : "?";
return new Dictionary<string, object> { { "error", $"next target '{nextId}' does not exist in dialogue '{diagId}'" } };
}
node = nextNode;
}
}

var visible = new List<object>();
if (node.TryGetValue("choices", out var choicesObj) && choicesObj is IEnumerable<object> choicesList)
{
Expand Down Expand Up @@ -421,7 +451,7 @@

// ----------------------------------------------------------- chooseChoice --

public static Dictionary<string, object> ChooseChoice(Dictionary<string, object> dialogue, string nodeId, string choiceId, State state, Dictionary<string, object> project = null, Func<float> rng = null)

Check warning on line 454 in Runtime/Runtime.cs

View workflow job for this annotation

GitHub Actions / test

Cannot convert null literal to non-nullable reference type.

Check warning on line 454 in Runtime/Runtime.cs

View workflow job for this annotation

GitHub Actions / test

Cannot convert null literal to non-nullable reference type.
{
if (project == null) project = new Dictionary<string, object>();

Expand Down Expand Up @@ -511,10 +541,34 @@

object targetIdObj = node["next"];
string targetId = targetIdObj != null ? targetIdObj.ToString() : null;
if (FindNode(dialogue, targetId) == null)

// Node-level showIf skip walk (contract 0.11.0). If the target node is
// gated and its gate fails, cross it to its own `next` and keep walking
// until a node with no gate — or a passing gate — is reached; that is the
// node the player sees. A ring of all-failing gates cannot escape (it is
// COND-invalid data) and is reported rather than looped forever. onEnter
// is NOT fired here: advance is navigation, exactly as the ungated path is.
var emptyProject = new Dictionary<string, object>();
var visited = new HashSet<string>();
while (true)
{
string diagId = dialogue.TryGetValue("id", out var dId) ? dId.ToString() : "?";
return new Dictionary<string, object> { { "error", $"next target '{targetId}' does not exist in dialogue '{diagId}'" } };
var targetNode = FindNode(dialogue, targetId);
if (targetNode == null)
{
string diagId = dialogue.TryGetValue("id", out var dId) ? dId.ToString() : "?";
return new Dictionary<string, object> { { "error", $"next target '{targetId}' does not exist in dialogue '{diagId}'" } };
}
if (!targetNode.TryGetValue("showIf", out var gateObj)) break;
if (Evaluate(gateObj as Dictionary<string, object> ?? new Dictionary<string, object>(), state, emptyProject)) break;
if (!visited.Add(targetId))
{
return new Dictionary<string, object> { { "error", "Cycle among conditional nodes: resolution cannot escape" } };
}
if (!targetNode.ContainsKey("next"))
{
return new Dictionary<string, object> { { "error", $"conditional node '{targetId}' has no 'next' to skip to" } };
}
targetId = targetNode["next"]?.ToString();
}

return new Dictionary<string, object>
Expand All @@ -526,7 +580,7 @@

// ------------------------------------------- resolveCharacterDialogue (feed) --

public static object ResolveCharacterDialogue(State state, Dictionary<string, object> character, Dictionary<string, object> project = null)

Check warning on line 583 in Runtime/Runtime.cs

View workflow job for this annotation

GitHub Actions / test

Cannot convert null literal to non-nullable reference type.
{
if (project == null) project = new Dictionary<string, object>();

Expand Down
8 changes: 2 additions & 6 deletions conformance/PIN
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
# These vectors are a PINNED COPY, not a fork. Never hand-edit them: they are
# generated from and asserted against the reference implementation, so an edit
# here makes this port chase a ghost. Re-copy from the named ref instead.
parlanceVersion=v0.9.0-unreleased
parlanceCommit=1a4e6572e68064b3b6def073413660ef27648ae2
parlanceVersion=v0.12.0
parlanceCommit=a45908cf66b87c5dd1e6db68be88d90a734ea117
parlanceRepo=git@github.com:Orbitope/parlance.git
#
# v0.9.0 is prepared but NOT YET TAGGED upstream (blocked on Actions billing).
# INTEGRATION.md requires pinning an exact tag, so this pin is provisional and
# MUST be moved to v0.9.0 once that tag exists. Recorded rather than silently
# pinned to a moving branch.
Loading
Loading