diff --git a/Parlance.Tests/ConformanceTests.cs b/Parlance.Tests/ConformanceTests.cs index e36a14c..d8ed949 100644 --- a/Parlance.Tests/ConformanceTests.cs +++ b/Parlance.Tests/ConformanceTests.cs @@ -123,12 +123,20 @@ public void StepDialogue() Assert.Fail($"unexpected error: {outDict["error"]} - {(string)v["description"]}"); } + var expected = (Dictionary)v["expected"]; var visibleChoices = (List)outDict["visibleChoices"]; var ids = new List(); + var tags = new List(); foreach (var choiceObj in visibleChoices) { var choice = (Dictionary)choiceObj; ids.Add(choice.ContainsKey("id") ? choice["id"] : null); + tags.Add(choice.TryGetValue("tags", out var t) ? t : null); + } + var lockedIds = new List(); + foreach (Dictionary choice in (List)outDict["lockedChoices"]) + { + lockedIds.Add(choice.ContainsKey("id") ? choice["id"] : null); } var onEnterEffects = (IEnumerable)outDict["onEnterEffects"]; @@ -139,12 +147,18 @@ public void StepDialogue() var got = new Dictionary { - { "nodeId", outNode.TryGetValue("id", out var idObj) ? idObj : null }, { "visibleChoiceIds", ids }, + { "lockedChoiceIds", lockedIds }, { "onEnterEffectCount", onEnterList.Count }, { "onEnterEffects", onEnterList } }; - AssertDeepEqual((Dictionary)v["expected"], got, (string)v["description"]); + // Optional fields are checked whenever the vector states them. + if (expected.ContainsKey("nodeId")) got["nodeId"] = outNode.TryGetValue("id", out var idObj) ? idObj : null; + if (expected.ContainsKey("textHidden")) got["textHidden"] = outDict["textHidden"]; + if (expected.ContainsKey("text")) got["text"] = outNode.TryGetValue("text", out var textObj) ? textObj : null; + if (expected.ContainsKey("nodeTags")) got["nodeTags"] = outNode.TryGetValue("tags", out var nodeTags) ? nodeTags : null; + if (expected.ContainsKey("visibleChoiceTags")) got["visibleChoiceTags"] = tags; + AssertDeepEqual(expected, got, (string)v["description"]); } } @@ -166,6 +180,13 @@ public void ChooseChoice() var rng = RngFrom(rngSpec); var outDict = Runtime.ChooseChoice(diag, nodeId, choiceId, state, project, rng); + + if (v.ContainsKey("expectedError")) + { + AssertExpectedError(v, outDict); + continue; + } + if (outDict.ContainsKey("error")) { Assert.Fail($"unexpected error: {outDict["error"]} - {(string)v["description"]}"); @@ -197,15 +218,13 @@ public void AdvanceNode() var nodeId = (string)v["nodeId"]; var state = State.FromDict((Dictionary)v["state"]); - var outDict = Runtime.AdvanceNode(diag, nodeId, state); + var project = v.ContainsKey("project") ? (Dictionary)v["project"] : new Dictionary(); + + var outDict = Runtime.AdvanceNode(diag, nodeId, state, project); if (v.ContainsKey("expectedError")) { - string expectedErr = (string)v["expectedError"]; - if (!outDict.ContainsKey("error")) - Assert.Fail($"expected error containing {expectedErr}, but succeeded - {(string)v["description"]}"); - string errStr = outDict["error"].ToString(); - Assert.IsTrue(errStr.Contains(expectedErr), $"error {errStr} does not contain {expectedErr}"); + AssertExpectedError(v, outDict); continue; } @@ -329,6 +348,17 @@ public void Progression() } } + // The reference throws; this port returns { error }. Either way the + // message must contain the vector's expectedError substring. + private void AssertExpectedError(Dictionary v, Dictionary outDict) + { + string expectedErr = (string)v["expectedError"]; + if (!outDict.ContainsKey("error")) + Assert.Fail($"expected error containing {expectedErr}, but succeeded - {(string)v["description"]}"); + string errStr = outDict["error"].ToString(); + Assert.IsTrue(errStr.Contains(expectedErr), $"error {errStr} does not contain {expectedErr} - {(string)v["description"]}"); + } + private Func RngFrom(object spec) { List values = spec is List l ? l : new List { spec }; diff --git a/README.md b/README.md index 7b6053e..a879927 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,15 @@ A C# runtime for [Parlance](https://github.com/Orbitope/parlance), a git-native **Parlance is the authoring tool; this is the Unity runtime for what it produces.** You write your story in Parlance's visual editor — dialogue and quest canvases, a searchable reference index, live playtest — and it saves as human-readable JSON directly in your repo. No database, no import/export step, git as the single source of truth. -This package reads that JSON and runs it in Unity: dialogues, conditions, effects, skill checks (with conditional modifiers), character dialogue offers, quests, endings. It is verified against Parlance's published conformance vectors rather than against its author's confidence. +This package reads that JSON and runs it in Unity: dialogues (conditional lines, fallback and locked choices, line and choice tags, engine commands), conditions, effects, skill checks (with conditional modifiers), character dialogue offers, quests, endings. It is verified against Parlance's published conformance vectors rather than against its author's confidence. ## Compatibility | parlance-unity | Parlance spec | Families | |---|---|---| -| `main` (unreleased) | v0.14.0 — pinned to [`f4a25b0`](conformance/PIN) | 11 of 11 | +| `main` (unreleased) | v0.15.0 — pinned to [`a3c6454`](conformance/PIN) | 11 of 11 — 207 / 207 vectors | -[`conformance/PIN`](conformance/PIN) is the authoritative record of which upstream ref the vectors came from. +[`conformance/PIN`](conformance/PIN) is the authoritative record of which upstream ref the vectors came from. The v0.15.0 pin names the release-prep commit the tag will be cut from; it moves to the tag commit once v0.15.0 is tagged. ## Install @@ -33,40 +33,68 @@ State is immutable: every entry point returns a new state and never mutates its ```csharp using Parlance; -// 1. Initialize your project JSON and Game State +// 1. Initialize your project JSON and Game State. The project is the whole +// data set (rules, factions, quests, …); a dialogue is one entry in it. var projectDict = ParseMyJson(myParlanceJsonTextAsset.text); +var dialogues = (Dictionary)projectDict["dialogues"]; +var dialogue = (Dictionary)dialogues["d_intro"]; var state = State.FromDict(mySavedGameStateJson); -// 2. Present a node: filters choices by showIf, interpolates {placeholders}. -var step = Runtime.StepDialogue(projectDict, "node_start", state); -Debug.Log(step["node"]["text"]); -foreach (var choice in (IEnumerable)step["visibleChoices"]) +// 2. Present a node: resolves conditional nodes, partitions the choices, +// interpolates {placeholders}. Every entry point returns { "error": … } +// instead of throwing when the call is invalid. +var step = Runtime.StepDialogue(dialogue, "node_start", state, projectDict); +var node = (Dictionary)step["node"]; +string nodeId = (string)node["id"]; // the RESOLVED node: may differ from the id you asked for +if (!(bool)step["textHidden"] && node.TryGetValue("text", out var line)) { - Debug.Log(choice["text"]); + Debug.Log(line); // no line when hidden, or on a text-less choice node +} +foreach (Dictionary choice in (List)step["visibleChoices"]) +{ + Debug.Log(choice["text"]); // selectable +} +foreach (Dictionary choice in (List)step["lockedChoices"]) +{ + // Opt-in: failing choices authored whenLocked: "show". Render greyed out, + // with lockedText in place of text when set. Never selectable. + Debug.Log(choice.TryGetValue("lockedText", out var lt) ? lt : choice["text"]); } // 3. onEnter effects are RETURNED, not applied. You decide when they fire — -// on first arrival, not on replay. -state = Runtime.ApplyEffects(step["onEnterEffects"], state, projectDict); +// on first arrival, not on replay. Walk them in order and dispatch any +// `engine` effect yourself: ApplyEffect leaves state unchanged for it. +var onEnter = (IEnumerable)step["onEnterEffects"]; +foreach (Dictionary effect in onEnter) +{ + if ((string)effect["type"] == "engine") MyEngine.Dispatch((string)effect["command"], effect.GetValueOrDefault("args")); +} +state = Runtime.ApplyEffects(onEnter, state, projectDict); // 4. Take a choice. Pass a seeded RNG so checks are reproducible. var outcome = Runtime.ChooseChoice( - projectDict, - "node_start", - "ch_ask", - state, + dialogue, + nodeId, + "ch_ask", + state, + projectDict, Rng.ForStep(mySeed, stepIndex) ); -state = outcome["newState"]; +if (outcome.ContainsKey("error")) throw new InvalidOperationException((string)outcome["error"]); +state = (State)outcome["newState"]; if (outcome.ContainsKey("checkResult")) { Debug.Log(outcome["checkResult"]); // passed, roll, total, skillValue, dice (+ bonus, appliedModifiers) } -var nextNodeId = outcome.GetValueOrDefault("nextNodeId"); // null on a terminal choice +var nextNodeId = outcome.GetValueOrDefault("nextNodeId"); // null on a terminal choice; resolve it with the next StepDialogue ``` ### Important Notes +- **A gated node with choices or `isEnd` is not skipped — only its line is hidden.** `StepDialogue` returns it with `textHidden: true` and `node.text == ""`; its choices are offered, an `isEnd` node still ends the dialogue, and its `onEnter` still fires. Only an interstitial gated node (no choices, not `isEnd`) is skipped, through `next`. `StepDialogue` and `AdvanceNode` share one `ResolveNode` walk. +- **Resolve once per arrival, on the arrival state.** If you apply `onEnter` before presenting, resolve with `ResolveNode` and present with `StepResolvedNode(node, postEffectState, project, arrivalState)` so `textHidden` is judged on arrival while choices filter on the post-effect state. Never re-resolve a node the player has already seen. +- **`ChooseChoice` only accepts a choice that was offered.** A hidden choice, a locked choice, or a `fallback` while a non-fallback choice is visible returns an `error` containing `not selectable`. A fallback is offered only when no other choice is visible. +- **Tags pass through untouched.** `node["tags"]` and each visible choice's `tags` come back exactly as authored; hang animation, audio or camera cues off them. - **`onEnter` effects are not applied for you.** `StepDialogue` returns them; firing them is the caller's job, on first arrival only. Applying them on every render double-counts on a rewind. - **A node with no choices is not necessarily over.** If it has `next`, call `AdvanceNode` — that's a listen-only beat. Treating it as the end silently truncates ambient chains. - **Passive checks never roll.** Show or hide a passive-check choice with `PassiveCheckPasses` (`skill + Σbonus >= difficulty`), so a check modifier means the same thing in both modes. diff --git a/Runtime/Runtime.cs b/Runtime/Runtime.cs index bd86317..f0f7e97 100644 --- a/Runtime/Runtime.cs +++ b/Runtime/Runtime.cs @@ -300,6 +300,11 @@ public static State ApplyEffect(object effectObj, State state, Dictionary StepDialogue(Dictionary dialogue, string nodeId, State state, Dictionary project = null) + // ------------------------------------------------------------ resolveNode -- + + // Whether a failed node showIf SKIPS this node (interstitial narration: no + // choices, not isEnd) or only hides its LINE (contract 0.15). One + // definition, read by ResolveNode and NodeTextHidden. + public static bool IsSkippableNode(Dictionary node) + { + bool hasChoices = node.TryGetValue("choices", out var cObj) && cObj is IEnumerable cList && cList.Any(); + bool isEnd = node.TryGetValue("isEnd", out var eObj) && eObj is bool e && e; + return !hasChoices && !isEnd; + } + + private static bool HasGate(Dictionary node, out object gate) + { + return node.TryGetValue("showIf", out gate) && gate != null; + } + + private static bool Holds(object condition, State state, Dictionary project) + { + return Evaluate(condition as Dictionary ?? new Dictionary(), state, project); + } + + private static string DialogueId(Dictionary dialogue) + { + return dialogue.TryGetValue("id", out var dId) && dId != null ? dId.ToString() : "?"; + } + + // The node the player actually reaches from `nodeId`: walks past + // INTERSTITIAL nodes whose showIf fails, following `next`. A gated node + // with choices or isEnd is never skipped — a failed gate there hides only + // its line (see StepResolvedNode's textHidden). This is the one skip walk; + // StepDialogue and AdvanceNode both use it, so a gated node behaves the + // same however it is reached. A skipped node is inert: no text, no onEnter. + // + // Judged ONCE, on arrival, against the arrival state — before onEnter. + // The reference throws on a missing node, a ring of conditional nodes, or + // a skipped node with no `next` (all COND-invalid data); this port returns + // the message as `error` instead, matching its other entry points. + public static (Dictionary node, string error) ResolveNode(Dictionary dialogue, string nodeId, State state, Dictionary project = null) { if (project == null) project = new Dictionary(); - - var node = FindNode(dialogue, nodeId); - if (node == null) + var seen = new HashSet(); + string currentId = nodeId; + while (true) { - string diagId = dialogue.TryGetValue("id", out var dId) ? dId.ToString() : "?"; - return new Dictionary { { "error", $"node '{nodeId}' does not exist in dialogue '{diagId}'" } }; + var node = FindNode(dialogue, currentId); + if (node == null) + return (null, $"node '{currentId}' does not exist in dialogue '{DialogueId(dialogue)}'"); + if (!HasGate(node, out var gate) || !IsSkippableNode(node) || Holds(gate, state, project)) + return (node, null); + if (!seen.Add(currentId)) + return (null, $"Cycle among conditional nodes in dialogue '{DialogueId(dialogue)}' at '{currentId}'"); + if (!node.TryGetValue("next", out var nextObj) || nextObj == null) + return (null, $"conditional node '{currentId}' in dialogue '{DialogueId(dialogue)}' has showIf but no 'next' to skip to"); + currentId = nextObj.ToString(); } + } + + // Whether a node's LINE is withheld at this state: a failed gate on a node + // that is not skippable (it has choices or isEnd). Judge it against the + // ARRIVAL state, the same moment as the skip gate. + public static bool NodeTextHidden(Dictionary node, State state, Dictionary project = null) + { + if (project == null) project = new Dictionary(); + return HasGate(node, out var gate) && !IsSkippableNode(node) && !Holds(gate, state, project); + } + + // How a choice whose showIf fails is presented: choice.whenLocked, else + // rules.choices.whenLockedDefault, else "hide". + public static string ResolveWhenLocked(Dictionary choice, Dictionary project = null) + { + if (choice.TryGetValue("whenLocked", out var wl) && wl is string wlStr) return wlStr; + if (project != null + && project.TryGetValue("rules", out var rObj) && rObj is Dictionary rules + && rules.TryGetValue("choices", out var cObj) && cObj is Dictionary choiceRules + && choiceRules.TryGetValue("whenLockedDefault", out var dObj) && dObj is string dStr) + return dStr; + return "hide"; + } - // 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. + // THE one place the fallback and whenLocked rules live; StepResolvedNode + // and ChooseChoice both read it, so a choice can never be offered by one + // and refused by the other. Returns the authored choice objects. + // visible — passing non-fallback choices; or, only when there are none, + // the passing fallback choices. Authored order. + // locked — failing choices whose whenLocked resolves to "show". + public static (List> visible, List> locked) PartitionChoices(Dictionary node, State state, Dictionary project = null) + { + if (project == null) project = new Dictionary(); + var all = new List>(); + if (node.TryGetValue("choices", out var choicesObj) && choicesObj is IEnumerable choicesList) { - var seen = new HashSet(); - while (node.TryGetValue("showIf", out var gateObj) - && !Evaluate(gateObj as Dictionary ?? new Dictionary(), state, project)) - { - string here = node.TryGetValue("id", out var hId) ? hId.ToString() : nodeId; - if (!seen.Add(here)) - { - return new Dictionary { { "error", "Cycle among conditional nodes: resolution cannot escape" } }; - } - if (!node.ContainsKey("next")) - { - return new Dictionary { { "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 { { "error", $"next target '{nextId}' does not exist in dialogue '{diagId}'" } }; - } - node = nextNode; - } + foreach (var cObj in choicesList) + if (cObj is Dictionary c) all.Add(c); } + var passes = all.Select(ch => !HasGate(ch, out var g) || Holds(g, state, project)).ToList(); + bool IsFallback(Dictionary ch) => ch.TryGetValue("fallback", out var f) && f is bool fb && fb; + bool anyPrimary = all.Where((ch, i) => passes[i] && !IsFallback(ch)).Any(); - var visible = new List(); - if (node.TryGetValue("choices", out var choicesObj) && choicesObj is IEnumerable choicesList) + var visible = new List>(); + var locked = new List>(); + for (int i = 0; i < all.Count; i++) { - foreach (var choiceObj in choicesList) + var ch = all[i]; + if (passes[i]) { - if (!(choiceObj is Dictionary choice)) continue; - if (choice.TryGetValue("showIf", out var showIfObj) && !Evaluate(showIfObj as Dictionary ?? new Dictionary(), state, project)) continue; - - string text = choice.TryGetValue("text", out var tObj) ? tObj.ToString() : ""; - string rendered = Interpolate.Process(text, state); - - if (rendered == text) - { - visible.Add(choice); - } - else - { - var c = new Dictionary(choice); - c["text"] = rendered; - visible.Add(c); - } + if (anyPrimary ? !IsFallback(ch) : IsFallback(ch)) visible.Add(ch); + } + else if (ResolveWhenLocked(ch, project) == "show") + { + locked.Add(ch); } } - + return (visible, locked); + } + + // A choice with `text` and `lockedText` interpolated; the same object when + // nothing changed, so callers comparing identity still see the original. + private static Dictionary InterpolateChoice(Dictionary choice, State state) + { + Dictionary copy = null; + foreach (var key in new[] { "text", "lockedText" }) + { + if (!choice.TryGetValue(key, out var tObj) || !(tObj is string text)) continue; + string rendered = Interpolate.Process(text, state); + if (rendered == text) continue; + copy ??= new Dictionary(choice); + copy[key] = rendered; + } + return copy ?? choice; + } + + // ----------------------------------------------------------- stepDialogue -- + + // Presentation of a node that has ALREADY been resolved (see ResolveNode). + // Resolution happens once per arrival; a caller that applies onEnter + // between resolving and presenting uses this, passing the post-effect + // state as `state` and the ARRIVAL state as `arrivalState`: textHidden is + // part of the arrival answer, only choice filtering and interpolation + // read the post-effect state. `arrivalState` defaults to `state`. + public static Dictionary StepResolvedNode(Dictionary node, State state, Dictionary project = null, State arrivalState = null) + { + if (project == null) project = new Dictionary(); + var (visibleRaw, lockedRaw) = PartitionChoices(node, state, project); + var visible = visibleRaw.Select(ch => (object)InterpolateChoice(ch, state)).ToList(); + var locked = lockedRaw.Select(ch => (object)InterpolateChoice(ch, state)).ToList(); + bool textHidden = NodeTextHidden(node, arrivalState ?? state, project); + + // Copies preserve every authored key (tags included) untouched. var outNode = node; - string nodeText = node.TryGetValue("text", out var nTextObj) ? nTextObj.ToString() : ""; - string renderedText = Interpolate.Process(nodeText, state); - if (renderedText != nodeText) + if (textHidden) { - outNode = new Dictionary(node); - outNode["text"] = renderedText; + outNode = new Dictionary(node) { ["text"] = "" }; + } + else if (node.TryGetValue("text", out var tObj) && tObj is string nodeText) + { + // A text-less node (0.15: allowed with choices) is left text-less. + string rendered = Interpolate.Process(nodeText, state); + if (rendered != nodeText) + { + outNode = new Dictionary(node) { ["text"] = rendered }; + } } + object onEnter = node.TryGetValue("onEnter", out var oe) && oe != null ? oe : new List(); return new Dictionary { { "node", outNode }, { "visibleChoices", visible }, - { "onEnterEffects", node.TryGetValue("onEnter", out var onEnter) ? onEnter : new List() } + { "lockedChoices", locked }, + { "textHidden", textHidden }, + { "onEnterEffects", onEnter } }; } + // Resolve (skip walk, once, against `state`) then present. The node + // returned may not be the one requested: read its id off the result. + public static Dictionary StepDialogue(Dictionary dialogue, string nodeId, State state, Dictionary project = null) + { + if (project == null) project = new Dictionary(); + var (node, error) = ResolveNode(dialogue, nodeId, state, project); + if (error != null) return new Dictionary { { "error", error } }; + return StepResolvedNode(node, state, project); + } + // ----------------------------------------------------------- chooseChoice -- - + + // Returns an `error` (message contains "not selectable") unless the choice + // is in PartitionChoices' visible set at `state`: a hidden choice, a locked + // one, and a fallback while a non-fallback choice is visible are refused. + // Its nextNodeId is the requested target, not yet resolved — the next + // StepDialogue resolves it. public static Dictionary ChooseChoice(Dictionary dialogue, string nodeId, string choiceId, State state, Dictionary project = null, Func rng = null) { if (project == null) project = new Dictionary(); - + var node = FindNode(dialogue, nodeId); if (node == null) { - string diagId = dialogue.TryGetValue("id", out var dId) ? dId.ToString() : "?"; - return new Dictionary { { "error", $"node '{nodeId}' does not exist in dialogue '{diagId}'" } }; + return new Dictionary { { "error", $"node '{nodeId}' does not exist in dialogue '{DialogueId(dialogue)}'" } }; } Dictionary choice = null; @@ -548,6 +658,10 @@ public static Dictionary ChooseChoice(Dictionary { return new Dictionary { { "error", $"choice '{choiceId}' does not exist on node '{nodeId}'" } }; } + if (!PartitionChoices(node, state, project).visible.Any(c => ReferenceEquals(c, choice))) + { + return new Dictionary { { "error", $"choice '{choiceId}' in node '{nodeId}' is not selectable at this state (hidden, locked, or an unoffered fallback)" } }; + } IEnumerable effects = choice.TryGetValue("effects", out var effObj) && effObj is IEnumerable effList ? effList : new List(); State nextState = ApplyEffects(effects, state, project); @@ -595,56 +709,38 @@ public static Dictionary ChooseChoice(Dictionary } // ------------------------------------------------------------ advanceNode -- - - public static Dictionary AdvanceNode(Dictionary dialogue, string nodeId, State state) + + // Resolves `node.next` for a listen-only beat. No effects are applied and + // the target's onEnter is NOT fired (caller's job, as for a goto arrival). + // The returned id is post-skip: the target goes through ResolveNode, the + // same walk StepDialogue uses, so a gated target with choices or isEnd is + // returned (line hidden), never skipped. + public static Dictionary AdvanceNode(Dictionary dialogue, string nodeId, State state, Dictionary project = null) { + if (project == null) project = new Dictionary(); var node = FindNode(dialogue, nodeId); if (node == null) { - string diagId = dialogue.TryGetValue("id", out var dId) ? dId.ToString() : "?"; - return new Dictionary { { "error", $"node '{nodeId}' does not exist in dialogue '{diagId}'" } }; + return new Dictionary { { "error", $"node '{nodeId}' does not exist in dialogue '{DialogueId(dialogue)}'" } }; } - if (!node.ContainsKey("next")) + if (!node.TryGetValue("next", out var targetIdObj) || targetIdObj == null) { return new Dictionary { { "error", $"node '{nodeId}' has no 'next' to advance from" } }; } - object targetIdObj = node["next"]; - string targetId = targetIdObj != null ? targetIdObj.ToString() : 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(); - var visited = new HashSet(); - while (true) + string targetId = targetIdObj.ToString(); + if (FindNode(dialogue, targetId) == null) { - var targetNode = FindNode(dialogue, targetId); - if (targetNode == null) - { - string diagId = dialogue.TryGetValue("id", out var dId) ? dId.ToString() : "?"; - return new Dictionary { { "error", $"next target '{targetId}' does not exist in dialogue '{diagId}'" } }; - } - if (!targetNode.TryGetValue("showIf", out var gateObj)) break; - if (Evaluate(gateObj as Dictionary ?? new Dictionary(), state, emptyProject)) break; - if (!visited.Add(targetId)) - { - return new Dictionary { { "error", "Cycle among conditional nodes: resolution cannot escape" } }; - } - if (!targetNode.ContainsKey("next")) - { - return new Dictionary { { "error", $"conditional node '{targetId}' has no 'next' to skip to" } }; - } - targetId = targetNode["next"]?.ToString(); + return new Dictionary { { "error", $"next target '{targetId}' does not exist in dialogue '{DialogueId(dialogue)}'" } }; } + var (resolved, error) = ResolveNode(dialogue, targetId, state, project); + if (error != null) return new Dictionary { { "error", error } }; + return new Dictionary { - { "nextNodeId", targetId }, + { "nextNodeId", resolved["id"] }, { "newState", state } }; } diff --git a/conformance/PIN b/conformance/PIN index e10143c..129d4df 100644 --- a/conformance/PIN +++ b/conformance/PIN @@ -3,7 +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.14.0 -parlanceCommit=f4a25b0d94ca8569a2897e8354a3f1317f826a82 +parlanceVersion=v0.15.0 +parlanceCommit=a3c6454772823579aa86fedc25fcefa10eea4288 parlanceRepo=git@github.com:Orbitope/parlance.git # diff --git a/conformance/README.md b/conformance/README.md index 596ef39..c840599 100644 --- a/conformance/README.md +++ b/conformance/README.md @@ -17,15 +17,15 @@ Counts below drift every time vectors are added, so treat them as indicative and | File | Function | Vectors | |---|---|---| | `evaluate.json` | `evaluate(condition, state, project)` | 53 | -| `apply_effect.json` | `applyEffect(effect, state, project)` | 27 | +| `apply_effect.json` | `applyEffect(effect, state, project)` | 29 | | `resolve_check.json` | `resolveCheck(check, state, rng, defaultDice?, criticals?, project?)` | 24 | -| `step_dialogue.json` | `stepDialogue(dialogue, nodeId, state, project)` | 11 | -| `choose_choice.json` | `chooseChoice(dialogue, nodeId, choiceId, state, project, rng)` | 10 | -| `advance.json` | `advanceNode(dialogue, nodeId, state, project)` | 12 | +| `step_dialogue.json` | `stepDialogue(dialogue, nodeId, state, project)` | 24 | +| `choose_choice.json` | `chooseChoice(dialogue, nodeId, choiceId, state, project, rng)` | 17 | +| `advance.json` | `advanceNode(dialogue, nodeId, state, project)` | 14 | | `resolveCharacterDialogue.json` | `resolveCharacterDialogue(state, character, project, visited?)` | 16 | | `nextContinuations.json` | `nextContinuations(state, project, visited, currentDialogueId)` — forced routing vs discovery | 4 | | `progression.json` | `levelForXp` / `pointsEarned` / `availablePoints` / `investSkillPoint` / `recomputeSkills` | 13 | -| `resolve_quests.json` | `resolveQuests(state, project)` | 6 | +| `resolve_quests.json` | `resolveQuests(state, project)` | 7 | | `rng.json` | mulberry32(seed) output stream — the seeded PRNG ports must reproduce exactly | 6 | ### `migrate_ladders/` — vectors for the 0.13 → 0.14 ladder migration @@ -53,9 +53,11 @@ agrees. See `validator/README.md` for the case format. Any runtime file may carry failure cases: a vector with `expectedError` (a substring the thrown error's message must contain) instead of `expected` means the call must -throw. `advance.json` carries them for a missing `next` and for a ring of conditional -nodes whose gates all fail — both validator-guaranteed impossibilities, thrown rather -than absorbed because reaching them means the data never passed validation. +throw. Two files carry them. `advance.json` has them for a missing `next` and for a +ring of conditional nodes whose gates all fail — both validator-guaranteed +impossibilities, thrown rather than absorbed because reaching them means the data never +passed validation. `choose_choice.json` (0.15) has them for a choice that is not +selectable: hidden, locked, or an unoffered fallback. ## Vector format @@ -86,7 +88,7 @@ Each file is a JSON array. Each element is a self-contained test vector with the // Expected output — exactly ONE of these two is present: "expected": varies by fn // see per-function sections below - "expectedError": string // advanceNode only — see Error cases below + "expectedError": string // advanceNode / chooseChoice only — see their sections } ``` @@ -194,10 +196,30 @@ below: without it, a runtime that never implements the skip walk still passes ev whose skipped node carries no `onEnter` — the *typical* gated narration line, since a conditional node is choiceless by construction. Older vectors omit the field. -`visibleChoiceIds` is the ordered list of choice ids that pass `showIf` filtering. +`visibleChoiceIds` is the ordered list of SELECTABLE choice ids: those that pass +`showIf`, with a `fallback` choice included only when no non-fallback choice passes. + +`lockedChoiceIds` (0.15, present on **every** vector — `[]` on the older ones) is the +ordered list of choices whose `showIf` failed and whose `whenLocked` resolves to `"show"` +(per-choice, else the vector's `project.rules.choices.whenLockedDefault`, else `"hide"`). +A port that ignores locked choices fails the vectors that expect a non-empty list, which +is the point: `lockedChoices` is opt-in for an ENGINE's presentation, not for conformance. + +`textHidden` (0.15, optional — absent means `false`) is true when the node's own `showIf` +failed on a node with `choices` or `isEnd`: the node is NOT skipped, its line is hidden. +`text`, when present, is the returned `node.text` — `""` for a hidden line, `null` for a +text-less node (whose `text` is absent). Check both: a port that still skips a gated +choice node fails on `nodeId`, and one that shows the hidden line fails on `text`. `onEnterEffects` is `node.onEnter` in order — the effects are returned but **not applied**, which is the caller's responsibility. +Since 0.15 a vector may also state `nodeTags` (the resolved node's `tags`, exactly as +authored) and `visibleChoiceTags` (per visible choice, its `tags` or `null`, in +`visibleChoiceIds` order). Tags are opaque pass-through, so check them when present: +a port that strips, sorts or dedupes them fails. The same vector puts an `engine` +effect among the `onEnterEffects`. It is returned in position like any effect, and +`apply_effect.json` pins that applying it changes nothing. + `onEnterEffectCount` is that list's length, kept for ports already checking it. **Check `onEnterEffects`, not the count.** The count alone is satisfied by returning the *choice's* effects instead of the node's, by returning them in @@ -217,6 +239,10 @@ wrong thing to the player's state while reporting conformance. `checkResult` is only present for active check vectors. `nextNodeId` is `null` for terminal choices (no `goto`, no `check`). +A vector with `expectedError` instead of `expected` (0.15) must THROW with a message +containing that string: choosing a hidden choice, a locked one, or a `fallback` while a +non-fallback choice is visible is not selectable. Same convention as `advance.json`. + ### advanceNode ```json { "expected": { "nextNodeId": "node_end", "newState": SerializedGameState } } @@ -232,8 +258,9 @@ returned `nextNodeId` is **post-skip**: the target is resolved through any faili exactly one *shown* beat — skipped nodes are inert, not beats. **Error cases.** A vector with `expectedError` instead of `expected` means the call must -throw; `expectedError` is a substring the thrown error's message must contain. This is the -one function in the suite with a failure contract — call it only on a node that declares +throw; `expectedError` is a substring the thrown error's message must contain. It is one +of two functions in the suite with a failure contract (the other is `chooseChoice`) — +call it only on a node that declares `next` (the validator's FLOW checks and the client both prevent constructing the call otherwise); reaching it anyway is a bug upstream, not a `Problem`/result-object case. @@ -290,7 +317,7 @@ order; `expected.state.questFired` is the sorted record. 2. For each vector, deserialize `state` by converting `inventory: string[]` to your language's equivalent of `Set`. 3. Call your implementation of the named function with the provided inputs. -4. If the vector carries `expectedError` (advanceNode only): assert the call throws / +4. If the vector carries `expectedError` (advanceNode and chooseChoice only): assert the call throws / returns an error whose message contains that substring, and stop — there is no output state to compare. 5. Otherwise, serialize the output state (if any) back to `{ ..., inventory: string[] }` diff --git a/conformance/advance.json b/conformance/advance.json index 75259c0..d2dc3fe 100644 --- a/conformance/advance.json +++ b/conformance/advance.json @@ -588,5 +588,339 @@ "skills": {}, "xp": 0 } + }, + { + "description": "line-only gate (0.15): advance into an isEnd node whose gate FAILS — it is the node the player lands on (never skipped, never a throw); its line is hidden by stepDialogue", + "dialogue": { + "entry": "node_open", + "id": "dlg_shapes", + "nodes": [ + { + "choices": [ + { + "goto": "node_options", + "id": "ch_ship", + "text": "Ask about the ship." + }, + { + "goto": "node_door", + "id": "ch_leave", + "text": "Leave." + } + ], + "id": "node_open", + "onEnter": [ + { + "flag": "visited_open", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "And you've seen the ledger. I can tell." + }, + { + "choices": [ + { + "goto": "node_door", + "id": "ch_door", + "text": "Try the door." + }, + { + "goto": "node_last", + "id": "ch_end", + "text": "Say goodbye." + } + ], + "id": "node_options" + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock", + "lockedText": "[Requires the key]", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock the door.", + "whenLocked": "show" + }, + { + "goto": "node_last", + "id": "ch_force", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Force it." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk", + "text": "Walk away." + } + ], + "id": "node_door", + "text": "The door." + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock2", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk2", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Shoulder past." + } + ], + "id": "node_gated_fallback", + "text": "A gated fallback proves nothing." + }, + { + "id": "node_last", + "isEnd": true, + "onEnter": [ + { + "flag": "reached_end", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "You think of the cup, still warm." + }, + { + "id": "node_hop", + "next": "node_last", + "text": "A beat." + }, + { + "id": "node_hop_open", + "next": "node_open", + "text": "Another beat." + } + ] + }, + "expected": { + "newState": { + "counters": {}, + "flags": {}, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + }, + "nextNodeId": "node_last" + }, + "fn": "advanceNode", + "nodeId": "node_hop", + "state": { + "counters": {}, + "flags": {}, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + } + }, + { + "description": "line-only gate: advance into a node with choices whose gate FAILS — same: reached, not skipped", + "dialogue": { + "entry": "node_open", + "id": "dlg_shapes", + "nodes": [ + { + "choices": [ + { + "goto": "node_options", + "id": "ch_ship", + "text": "Ask about the ship." + }, + { + "goto": "node_door", + "id": "ch_leave", + "text": "Leave." + } + ], + "id": "node_open", + "onEnter": [ + { + "flag": "visited_open", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "And you've seen the ledger. I can tell." + }, + { + "choices": [ + { + "goto": "node_door", + "id": "ch_door", + "text": "Try the door." + }, + { + "goto": "node_last", + "id": "ch_end", + "text": "Say goodbye." + } + ], + "id": "node_options" + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock", + "lockedText": "[Requires the key]", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock the door.", + "whenLocked": "show" + }, + { + "goto": "node_last", + "id": "ch_force", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Force it." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk", + "text": "Walk away." + } + ], + "id": "node_door", + "text": "The door." + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock2", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk2", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Shoulder past." + } + ], + "id": "node_gated_fallback", + "text": "A gated fallback proves nothing." + }, + { + "id": "node_last", + "isEnd": true, + "onEnter": [ + { + "flag": "reached_end", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "You think of the cup, still warm." + }, + { + "id": "node_hop", + "next": "node_last", + "text": "A beat." + }, + { + "id": "node_hop_open", + "next": "node_open", + "text": "Another beat." + } + ] + }, + "expected": { + "newState": { + "counters": {}, + "flags": {}, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + }, + "nextNodeId": "node_open" + }, + "fn": "advanceNode", + "nodeId": "node_hop_open", + "state": { + "counters": {}, + "flags": {}, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + } } ] diff --git a/conformance/apply_effect.json b/conformance/apply_effect.json index 739cb87..8507e00 100644 --- a/conformance/apply_effect.json +++ b/conformance/apply_effect.json @@ -981,5 +981,92 @@ "npc_a": -3 } } + }, + { + "fn": "applyEffect", + "description": "engine: an engine command changes NO state (the host dispatches on it; the runtime never interprets it)", + "state": { + "flags": { + "seen": true + }, + "reputation": {}, + "skills": {}, + "counters": { + "coins": 3 + }, + "inventory": [ + "key" + ], + "questStages": {}, + "xp": 40, + "skillPointsSpent": {}, + "texts": { + "player_name": "Wren" + }, + "pendingCutscene": "cs_intro" + }, + "effect": { + "type": "engine", + "command": "shake", + "args": [ + 0.5, + "camera_main", + true + ] + }, + "project": { + "factions": {} + }, + "expected": { + "flags": { + "seen": true + }, + "reputation": {}, + "skills": {}, + "counters": { + "coins": 3 + }, + "inventory": [ + "key" + ], + "questStages": {}, + "xp": 40, + "skillPointsSpent": {}, + "texts": { + "player_name": "Wren" + }, + "pendingCutscene": "cs_intro" + } + }, + { + "fn": "applyEffect", + "description": "engine: with no args the state is likewise untouched", + "state": { + "flags": {}, + "reputation": {}, + "skills": {}, + "counters": {}, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} + }, + "effect": { + "type": "engine", + "command": "fade_out" + }, + "project": { + "factions": {} + }, + "expected": { + "flags": {}, + "reputation": {}, + "skills": {}, + "counters": {}, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} + } } ] diff --git a/conformance/choose_choice.json b/conformance/choose_choice.json index 3d5199c..bb947d1 100644 --- a/conformance/choose_choice.json +++ b/conformance/choose_choice.json @@ -1,716 +1,1791 @@ [ - { - "fn": "chooseChoice", - "description": "goto: advances to target node, state unchanged", - "dialogue": { - "id": "dlg_conformance", - "entry": "node_start", - "nodes": [ - { - "id": "node_start", - "text": "Start.", - "choices": [ - { - "id": "ch_goto", - "text": "Proceed.", - "goto": "node_end" - } - ] - }, - { - "id": "node_end", - "isEnd": true, - "text": "End.", - "choices": [ - { - "id": "ch_terminal", - "text": "Done." + { + "fn": "chooseChoice", + "description": "goto: advances to target node, state unchanged", + "dialogue": { + "id": "dlg_conformance", + "entry": "node_start", + "nodes": [ + { + "id": "node_start", + "text": "Start.", + "choices": [ + { + "id": "ch_goto", + "text": "Proceed.", + "goto": "node_end" + } + ] + }, + { + "id": "node_end", + "isEnd": true, + "text": "End.", + "choices": [ + { + "id": "ch_terminal", + "text": "Done." + } + ] + } + ] + }, + "nodeId": "node_start", + "choiceId": "ch_goto", + "state": { + "flags": {}, + "reputation": {}, + "skills": {}, + "counters": {}, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} + }, + "project": { + "factions": {} + }, + "expected": { + "nextNodeId": "node_end", + "newState": { + "flags": {}, + "reputation": {}, + "skills": {}, + "counters": {}, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} } - ] } - ] }, - "nodeId": "node_start", - "choiceId": "ch_goto", - "state": { - "flags": {}, - "reputation": {}, - "skills": {}, - "counters": {}, - "inventory": [], - "questStages": {}, - "xp": 0, - "skillPointsSpent": {} - }, - "project": { - "factions": {} - }, - "expected": { - "nextNodeId": "node_end", - "newState": { - "flags": {}, - "reputation": {}, - "skills": {}, - "counters": {}, - "inventory": [], - "questStages": {}, - "xp": 0, - "skillPointsSpent": {} - } - } - }, - { - "fn": "chooseChoice", - "description": "goto with effects: effect applied before advancing", - "dialogue": { - "id": "dlg_conformance", - "entry": "node_start", - "nodes": [ - { - "id": "node_start", - "text": "Start.", - "choices": [ - { - "id": "ch_flag_goto", - "text": "Flag and go.", - "goto": "node_end", - "effects": [ - { - "type": "set_flag", - "flag": "took_path", - "value": true + { + "fn": "chooseChoice", + "description": "goto with effects: effect applied before advancing", + "dialogue": { + "id": "dlg_conformance", + "entry": "node_start", + "nodes": [ + { + "id": "node_start", + "text": "Start.", + "choices": [ + { + "id": "ch_flag_goto", + "text": "Flag and go.", + "goto": "node_end", + "effects": [ + { + "type": "set_flag", + "flag": "took_path", + "value": true + } + ] + } + ] + }, + { + "id": "node_end", + "isEnd": true, + "text": "End." } - ] - } - ] + ] + }, + "nodeId": "node_start", + "choiceId": "ch_flag_goto", + "state": { + "flags": {}, + "reputation": {}, + "skills": {}, + "counters": {}, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} }, - { - "id": "node_end", - "isEnd": true, - "text": "End." + "project": { + "factions": {} + }, + "expected": { + "nextNodeId": "node_end", + "newState": { + "flags": { + "took_path": true + }, + "reputation": {}, + "skills": {}, + "counters": {}, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} + } } - ] - }, - "nodeId": "node_start", - "choiceId": "ch_flag_goto", - "state": { - "flags": {}, - "reputation": {}, - "skills": {}, - "counters": {}, - "inventory": [], - "questStages": {}, - "xp": 0, - "skillPointsSpent": {} }, - "project": { - "factions": {} - }, - "expected": { - "nextNodeId": "node_end", - "newState": { - "flags": { - "took_path": true - }, - "reputation": {}, - "skills": {}, - "counters": {}, - "inventory": [], - "questStages": {}, - "xp": 0, - "skillPointsSpent": {} - } - } - }, - { - "fn": "chooseChoice", - "description": "active check pass: rng=0.2, roll=5, wit=5, total=10, DC=10 → success branch", - "dialogue": { - "id": "dlg_conformance", - "entry": "node_start", - "nodes": [ - { - "id": "node_start", - "text": "Start.", - "choices": [ - { - "id": "ch_check", - "text": "Roll.", - "check": { - "mode": "active", - "skill": "wit", - "difficulty": 10, - "onSuccess": "node_win", - "onFailure": "node_lose" - } - } - ] + { + "fn": "chooseChoice", + "description": "active check pass: rng=0.2, roll=5, wit=5, total=10, DC=10 → success branch", + "dialogue": { + "id": "dlg_conformance", + "entry": "node_start", + "nodes": [ + { + "id": "node_start", + "text": "Start.", + "choices": [ + { + "id": "ch_check", + "text": "Roll.", + "check": { + "mode": "active", + "skill": "wit", + "difficulty": 10, + "onSuccess": "node_win", + "onFailure": "node_lose" + } + } + ] + }, + { + "id": "node_win", + "isEnd": true, + "text": "Won." + }, + { + "id": "node_lose", + "isEnd": true, + "text": "Lost." + } + ] + }, + "nodeId": "node_start", + "choiceId": "ch_check", + "state": { + "flags": {}, + "reputation": {}, + "skills": { + "wit": 5 + }, + "counters": {}, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} }, - { - "id": "node_win", - "isEnd": true, - "text": "Won." + "project": { + "factions": {} }, - { - "id": "node_lose", - "isEnd": true, - "text": "Lost." + "rng": 0.2, + "expected": { + "nextNodeId": "node_win", + "newState": { + "flags": {}, + "reputation": {}, + "skills": { + "wit": 5 + }, + "counters": {}, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} + }, + "checkResult": { + "passed": true, + "roll": 5, + "total": 10, + "skillValue": 5, + "dice": "1d20" + } } - ] - }, - "nodeId": "node_start", - "choiceId": "ch_check", - "state": { - "flags": {}, - "reputation": {}, - "skills": { - "wit": 5 - }, - "counters": {}, - "inventory": [], - "questStages": {}, - "xp": 0, - "skillPointsSpent": {} }, - "project": { - "factions": {} - }, - "rng": 0.2, - "expected": { - "nextNodeId": "node_win", - "newState": { - "flags": {}, - "reputation": {}, - "skills": { - "wit": 5 - }, - "counters": {}, - "inventory": [], - "questStages": {}, - "xp": 0, - "skillPointsSpent": {} - }, - "checkResult": { - "passed": true, - "roll": 5, - "total": 10, - "skillValue": 5, - "dice": "1d20" - } - } - }, - { - "fn": "chooseChoice", - "description": "active check fail: rng=0.0, roll=1, wit=0, total=1, DC=10 → failure branch", - "dialogue": { - "id": "dlg_conformance", - "entry": "node_start", - "nodes": [ - { - "id": "node_start", - "text": "Start.", - "choices": [ - { - "id": "ch_check", - "text": "Roll.", - "check": { - "mode": "active", - "skill": "wit", - "difficulty": 10, - "onSuccess": "node_win", - "onFailure": "node_lose" - } - } - ] + { + "fn": "chooseChoice", + "description": "active check fail: rng=0.0, roll=1, wit=0, total=1, DC=10 → failure branch", + "dialogue": { + "id": "dlg_conformance", + "entry": "node_start", + "nodes": [ + { + "id": "node_start", + "text": "Start.", + "choices": [ + { + "id": "ch_check", + "text": "Roll.", + "check": { + "mode": "active", + "skill": "wit", + "difficulty": 10, + "onSuccess": "node_win", + "onFailure": "node_lose" + } + } + ] + }, + { + "id": "node_win", + "isEnd": true, + "text": "Won." + }, + { + "id": "node_lose", + "isEnd": true, + "text": "Lost." + } + ] + }, + "nodeId": "node_start", + "choiceId": "ch_check", + "state": { + "flags": {}, + "reputation": {}, + "skills": { + "wit": 0 + }, + "counters": {}, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} }, - { - "id": "node_win", - "isEnd": true, - "text": "Won." + "project": { + "factions": {} }, - { - "id": "node_lose", - "isEnd": true, - "text": "Lost." + "rng": 0, + "expected": { + "nextNodeId": "node_lose", + "newState": { + "flags": {}, + "reputation": {}, + "skills": { + "wit": 0 + }, + "counters": {}, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} + }, + "checkResult": { + "passed": false, + "roll": 1, + "total": 1, + "skillValue": 0, + "dice": "1d20" + } } - ] - }, - "nodeId": "node_start", - "choiceId": "ch_check", - "state": { - "flags": {}, - "reputation": {}, - "skills": { - "wit": 0 - }, - "counters": {}, - "inventory": [], - "questStages": {}, - "xp": 0, - "skillPointsSpent": {} }, - "project": { - "factions": {} - }, - "rng": 0, - "expected": { - "nextNodeId": "node_lose", - "newState": { - "flags": {}, - "reputation": {}, - "skills": { - "wit": 0 - }, - "counters": {}, - "inventory": [], - "questStages": {}, - "xp": 0, - "skillPointsSpent": {} - }, - "checkResult": { - "passed": false, - "roll": 1, - "total": 1, - "skillValue": 0, - "dice": "1d20" - } - } - }, - { - "fn": "chooseChoice", - "description": "active check with pre-choice effect: effect applied before roll, skill read from post-effect state", - "dialogue": { - "id": "dlg_conformance", - "entry": "node_start", - "nodes": [ - { - "id": "node_start", - "text": "Start.", - "choices": [ - { - "id": "ch_effect_then_check", - "text": "Buff and roll.", - "effects": [ - { - "type": "set_flag", - "flag": "prepared", - "value": true + { + "fn": "chooseChoice", + "description": "active check with pre-choice effect: effect applied before roll, skill read from post-effect state", + "dialogue": { + "id": "dlg_conformance", + "entry": "node_start", + "nodes": [ + { + "id": "node_start", + "text": "Start.", + "choices": [ + { + "id": "ch_effect_then_check", + "text": "Buff and roll.", + "effects": [ + { + "type": "set_flag", + "flag": "prepared", + "value": true + } + ], + "check": { + "mode": "active", + "skill": "wit", + "difficulty": 10, + "onSuccess": "node_win", + "onFailure": "node_lose" + } + } + ] + }, + { + "id": "node_win", + "isEnd": true, + "text": "Won." + }, + { + "id": "node_lose", + "isEnd": true, + "text": "Lost." } - ], - "check": { - "mode": "active", - "skill": "wit", - "difficulty": 10, - "onSuccess": "node_win", - "onFailure": "node_lose" - } - } - ] + ] }, - { - "id": "node_win", - "isEnd": true, - "text": "Won." + "nodeId": "node_start", + "choiceId": "ch_effect_then_check", + "state": { + "flags": {}, + "reputation": {}, + "skills": { + "wit": 5 + }, + "counters": {}, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} }, - { - "id": "node_lose", - "isEnd": true, - "text": "Lost." + "project": { + "factions": {} + }, + "rng": 0.2, + "expected": { + "nextNodeId": "node_win", + "newState": { + "flags": { + "prepared": true + }, + "reputation": {}, + "skills": { + "wit": 5 + }, + "counters": {}, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} + }, + "checkResult": { + "passed": true, + "roll": 5, + "total": 10, + "skillValue": 5, + "dice": "1d20" + } } - ] }, - "nodeId": "node_start", - "choiceId": "ch_effect_then_check", - "state": { - "flags": {}, - "reputation": {}, - "skills": { - "wit": 5 - }, - "counters": {}, - "inventory": [], - "questStages": {}, - "xp": 0, - "skillPointsSpent": {} + { + "fn": "chooseChoice", + "description": "passive check: treated as plain goto, no roll, no checkResult", + "dialogue": { + "id": "dlg_conformance", + "entry": "node_start", + "nodes": [ + { + "id": "node_start", + "text": "Start.", + "choices": [ + { + "id": "ch_passive", + "text": "Passive.", + "goto": "node_win", + "check": { + "mode": "passive", + "skill": "wit", + "difficulty": 5 + } + } + ] + }, + { + "id": "node_win", + "isEnd": true, + "text": "Won." + } + ] + }, + "nodeId": "node_start", + "choiceId": "ch_passive", + "state": { + "flags": {}, + "reputation": {}, + "skills": { + "wit": 0 + }, + "counters": {}, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} + }, + "project": { + "factions": {} + }, + "expected": { + "nextNodeId": "node_win", + "newState": { + "flags": {}, + "reputation": {}, + "skills": { + "wit": 0 + }, + "counters": {}, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} + } + } }, - "project": { - "factions": {} + { + "fn": "chooseChoice", + "description": "terminal choice (no goto, no check on isEnd node): nextNodeId is null", + "dialogue": { + "id": "dlg_conformance", + "entry": "node_end", + "nodes": [ + { + "id": "node_end", + "isEnd": true, + "text": "End.", + "choices": [ + { + "id": "ch_terminal", + "text": "Done." + } + ] + } + ] + }, + "nodeId": "node_end", + "choiceId": "ch_terminal", + "state": { + "flags": {}, + "reputation": {}, + "skills": {}, + "counters": {}, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} + }, + "project": { + "factions": {} + }, + "expected": { + "nextNodeId": null, + "newState": { + "flags": {}, + "reputation": {}, + "skills": {}, + "counters": {}, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} + } + } }, - "rng": 0.2, - "expected": { - "nextNodeId": "node_win", - "newState": { - "flags": { - "prepared": true - }, - "reputation": {}, - "skills": { - "wit": 5 - }, - "counters": {}, - "inventory": [], - "questStages": {}, - "xp": 0, - "skillPointsSpent": {} - }, - "checkResult": { - "passed": true, - "roll": 5, - "total": 10, - "skillValue": 5, - "dice": "1d20" - } - } - }, - { - "fn": "chooseChoice", - "description": "passive check: treated as plain goto, no roll, no checkResult", - "dialogue": { - "id": "dlg_conformance", - "entry": "node_start", - "nodes": [ - { - "id": "node_start", - "text": "Start.", - "choices": [ - { - "id": "ch_passive", - "text": "Passive.", - "goto": "node_win", - "check": { - "mode": "passive", - "skill": "wit", - "difficulty": 5 - } + { + "fn": "chooseChoice", + "description": "multiple effects threaded in order: flag then reputation", + "dialogue": { + "id": "dlg_conformance", + "entry": "node_start", + "nodes": [ + { + "id": "node_start", + "text": "Start.", + "choices": [ + { + "id": "ch_multi_effect", + "text": "Two effects.", + "goto": "node_end", + "effects": [ + { + "type": "set_flag", + "flag": "done", + "value": true + }, + { + "type": "adjust_reputation", + "faction": "guild", + "delta": 2 + } + ] + } + ] + }, + { + "id": "node_end", + "isEnd": true, + "text": "End." + } + ] + }, + "nodeId": "node_start", + "choiceId": "ch_multi_effect", + "state": { + "flags": {}, + "reputation": { + "guild": 0 + }, + "skills": {}, + "counters": {}, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} + }, + "project": { + "factions": { + "guild": { + "id": "guild", + "name": "Guild", + "summary": "s", + "reputationRange": { + "min": -10, + "max": 10 + } + } } - ] }, - { - "id": "node_win", - "isEnd": true, - "text": "Won." + "expected": { + "nextNodeId": "node_end", + "newState": { + "flags": { + "done": true + }, + "reputation": { + "guild": 2 + }, + "skills": {}, + "counters": {}, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} + } } - ] - }, - "nodeId": "node_start", - "choiceId": "ch_passive", - "state": { - "flags": {}, - "reputation": {}, - "skills": { - "wit": 0 - }, - "counters": {}, - "inventory": [], - "questStages": {}, - "xp": 0, - "skillPointsSpent": {} }, - "project": { - "factions": {} - }, - "expected": { - "nextNodeId": "node_win", - "newState": { - "flags": {}, - "reputation": {}, - "skills": { - "wit": 0 - }, - "counters": {}, - "inventory": [], - "questStages": {}, - "xp": 0, - "skillPointsSpent": {} - } - } - }, - { - "fn": "chooseChoice", - "description": "terminal choice (no goto, no check on isEnd node): nextNodeId is null", - "dialogue": { - "id": "dlg_conformance", - "entry": "node_end", - "nodes": [ - { - "id": "node_end", - "isEnd": true, - "text": "End.", - "choices": [ - { - "id": "ch_terminal", - "text": "Done." + { + "fn": "chooseChoice", + "description": "give_item effect: item appears in inventory after choice", + "dialogue": { + "id": "dlg_conformance", + "entry": "node_start", + "nodes": [ + { + "id": "node_start", + "text": "Start.", + "choices": [ + { + "id": "ch_loot", + "text": "Take the key.", + "goto": "node_end", + "effects": [ + { + "type": "give_item", + "item": "key_card" + } + ] + } + ] + }, + { + "id": "node_end", + "isEnd": true, + "text": "End." + } + ] + }, + "nodeId": "node_start", + "choiceId": "ch_loot", + "state": { + "flags": {}, + "reputation": {}, + "skills": {}, + "counters": {}, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} + }, + "project": { + "factions": {} + }, + "expected": { + "nextNodeId": "node_end", + "newState": { + "flags": {}, + "reputation": {}, + "skills": {}, + "counters": {}, + "inventory": [ + "key_card" + ], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} } - ] } - ] }, - "nodeId": "node_end", - "choiceId": "ch_terminal", - "state": { - "flags": {}, - "reputation": {}, - "skills": {}, - "counters": {}, - "inventory": [], - "questStages": {}, - "xp": 0, - "skillPointsSpent": {} + { + "fn": "chooseChoice", + "description": "a check modifier flips the branch: roll=5 wit=5 base 10 < DC 15, +6 primed -> 16 -> success", + "dialogue": { + "id": "dlg_conformance", + "entry": "node_start", + "nodes": [ + { + "id": "node_start", + "text": "Start.", + "choices": [ + { + "id": "ch_check", + "text": "Roll.", + "check": { + "mode": "active", + "skill": "wit", + "difficulty": 15, + "onSuccess": "node_win", + "onFailure": "node_lose", + "modifiers": [ + { + "when": { + "type": "flag", + "flag": "primed", + "value": true + }, + "bonus": 6 + } + ] + } + } + ] + }, + { + "id": "node_win", + "isEnd": true, + "text": "Won." + }, + { + "id": "node_lose", + "isEnd": true, + "text": "Lost." + } + ] + }, + "nodeId": "node_start", + "choiceId": "ch_check", + "state": { + "flags": { + "primed": true + }, + "reputation": {}, + "skills": { + "wit": 5 + }, + "counters": {}, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} + }, + "project": { + "factions": {} + }, + "rng": 0.2, + "expected": { + "nextNodeId": "node_win", + "newState": { + "flags": { + "primed": true + }, + "reputation": {}, + "skills": { + "wit": 5 + }, + "counters": {}, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} + }, + "checkResult": { + "passed": true, + "roll": 5, + "total": 16, + "skillValue": 5, + "dice": "1d20", + "bonus": 6, + "appliedModifiers": [ + 0 + ] + } + } }, - "project": { - "factions": {} + { + "fn": "chooseChoice", + "description": "locked (0.15): choosing a choice whose showIf fails throws — locked (whenLocked show) is never selectable", + "dialogue": { + "entry": "node_open", + "id": "dlg_shapes", + "nodes": [ + { + "id": "node_open", + "text": "And you've seen the ledger. I can tell.", + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "onEnter": [ + { + "flag": "visited_open", + "type": "set_flag", + "value": true + } + ], + "choices": [ + { + "goto": "node_options", + "id": "ch_ship", + "text": "Ask about the ship." + }, + { + "goto": "node_door", + "id": "ch_leave", + "text": "Leave." + } + ] + }, + { + "id": "node_options", + "choices": [ + { + "goto": "node_door", + "id": "ch_door", + "text": "Try the door." + }, + { + "goto": "node_last", + "id": "ch_end", + "text": "Say goodbye." + } + ] + }, + { + "id": "node_door", + "text": "The door.", + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock the door.", + "whenLocked": "show", + "lockedText": "[Requires the key]" + }, + { + "goto": "node_last", + "id": "ch_force", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Force it." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk", + "text": "Walk away." + } + ] + }, + { + "id": "node_gated_fallback", + "text": "A gated fallback proves nothing.", + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock2", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk2", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Shoulder past." + } + ] + }, + { + "id": "node_last", + "isEnd": true, + "text": "You think of the cup, still warm.", + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "onEnter": [ + { + "flag": "reached_end", + "type": "set_flag", + "value": true + } + ] + }, + { + "id": "node_hop", + "text": "A beat.", + "next": "node_last" + }, + { + "id": "node_hop_open", + "text": "Another beat.", + "next": "node_open" + } + ] + }, + "nodeId": "node_door", + "choiceId": "ch_unlock", + "state": { + "counters": {}, + "flags": {}, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + }, + "project": { + "factions": {} + }, + "expectedError": "not selectable" }, - "expected": { - "nextNodeId": null, - "newState": { - "flags": {}, - "reputation": {}, - "skills": {}, - "counters": {}, - "inventory": [], - "questStages": {}, - "xp": 0, - "skillPointsSpent": {} - } - } - }, - { - "fn": "chooseChoice", - "description": "multiple effects threaded in order: flag then reputation", - "dialogue": { - "id": "dlg_conformance", - "entry": "node_start", - "nodes": [ - { - "id": "node_start", - "text": "Start.", - "choices": [ - { - "id": "ch_multi_effect", - "text": "Two effects.", - "goto": "node_end", - "effects": [ - { - "type": "set_flag", - "flag": "done", - "value": true - }, - { - "type": "adjust_reputation", - "faction": "guild", - "delta": 2 + { + "fn": "chooseChoice", + "description": "hidden: choosing a choice whose showIf fails throws — same rule whether hidden or locked", + "dialogue": { + "entry": "node_open", + "id": "dlg_shapes", + "nodes": [ + { + "id": "node_open", + "text": "And you've seen the ledger. I can tell.", + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "onEnter": [ + { + "flag": "visited_open", + "type": "set_flag", + "value": true + } + ], + "choices": [ + { + "goto": "node_options", + "id": "ch_ship", + "text": "Ask about the ship." + }, + { + "goto": "node_door", + "id": "ch_leave", + "text": "Leave." + } + ] + }, + { + "id": "node_options", + "choices": [ + { + "goto": "node_door", + "id": "ch_door", + "text": "Try the door." + }, + { + "goto": "node_last", + "id": "ch_end", + "text": "Say goodbye." + } + ] + }, + { + "id": "node_door", + "text": "The door.", + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock the door.", + "whenLocked": "show", + "lockedText": "[Requires the key]" + }, + { + "goto": "node_last", + "id": "ch_force", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Force it." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk", + "text": "Walk away." + } + ] + }, + { + "id": "node_gated_fallback", + "text": "A gated fallback proves nothing.", + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock2", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk2", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Shoulder past." + } + ] + }, + { + "id": "node_last", + "isEnd": true, + "text": "You think of the cup, still warm.", + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "onEnter": [ + { + "flag": "reached_end", + "type": "set_flag", + "value": true + } + ] + }, + { + "id": "node_hop", + "text": "A beat.", + "next": "node_last" + }, + { + "id": "node_hop_open", + "text": "Another beat.", + "next": "node_open" + } + ] + }, + "nodeId": "node_door", + "choiceId": "ch_force", + "state": { + "counters": {}, + "flags": {}, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + }, + "project": { + "factions": {}, + "rules": { + "choices": { + "whenLockedDefault": "show" } - ] } - ] }, - { - "id": "node_end", - "isEnd": true, - "text": "End." - } - ] + "expectedError": "not selectable" }, - "nodeId": "node_start", - "choiceId": "ch_multi_effect", - "state": { - "flags": {}, - "reputation": { - "guild": 0 - }, - "skills": {}, - "counters": {}, - "inventory": [], - "questStages": {}, - "xp": 0, - "skillPointsSpent": {} + { + "fn": "chooseChoice", + "description": "fallback: choosing the fallback while a non-fallback choice is visible throws — it was not offered", + "dialogue": { + "entry": "node_open", + "id": "dlg_shapes", + "nodes": [ + { + "id": "node_open", + "text": "And you've seen the ledger. I can tell.", + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "onEnter": [ + { + "flag": "visited_open", + "type": "set_flag", + "value": true + } + ], + "choices": [ + { + "goto": "node_options", + "id": "ch_ship", + "text": "Ask about the ship." + }, + { + "goto": "node_door", + "id": "ch_leave", + "text": "Leave." + } + ] + }, + { + "id": "node_options", + "choices": [ + { + "goto": "node_door", + "id": "ch_door", + "text": "Try the door." + }, + { + "goto": "node_last", + "id": "ch_end", + "text": "Say goodbye." + } + ] + }, + { + "id": "node_door", + "text": "The door.", + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock the door.", + "whenLocked": "show", + "lockedText": "[Requires the key]" + }, + { + "goto": "node_last", + "id": "ch_force", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Force it." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk", + "text": "Walk away." + } + ] + }, + { + "id": "node_gated_fallback", + "text": "A gated fallback proves nothing.", + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock2", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk2", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Shoulder past." + } + ] + }, + { + "id": "node_last", + "isEnd": true, + "text": "You think of the cup, still warm.", + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "onEnter": [ + { + "flag": "reached_end", + "type": "set_flag", + "value": true + } + ] + }, + { + "id": "node_hop", + "text": "A beat.", + "next": "node_last" + }, + { + "id": "node_hop_open", + "text": "Another beat.", + "next": "node_open" + } + ] + }, + "nodeId": "node_door", + "choiceId": "ch_walk", + "state": { + "counters": {}, + "flags": { + "has_key": true + }, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + }, + "project": { + "factions": {} + }, + "expectedError": "not selectable" }, - "project": { - "factions": { - "guild": { - "id": "guild", - "name": "Guild", - "summary": "s", - "reputationRange": { - "min": -10, - "max": 10 - } + { + "fn": "chooseChoice", + "description": "fallback: choosing the fallback when nothing else is visible advances normally", + "dialogue": { + "entry": "node_open", + "id": "dlg_shapes", + "nodes": [ + { + "id": "node_open", + "text": "And you've seen the ledger. I can tell.", + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "onEnter": [ + { + "flag": "visited_open", + "type": "set_flag", + "value": true + } + ], + "choices": [ + { + "goto": "node_options", + "id": "ch_ship", + "text": "Ask about the ship." + }, + { + "goto": "node_door", + "id": "ch_leave", + "text": "Leave." + } + ] + }, + { + "id": "node_options", + "choices": [ + { + "goto": "node_door", + "id": "ch_door", + "text": "Try the door." + }, + { + "goto": "node_last", + "id": "ch_end", + "text": "Say goodbye." + } + ] + }, + { + "id": "node_door", + "text": "The door.", + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock the door.", + "whenLocked": "show", + "lockedText": "[Requires the key]" + }, + { + "goto": "node_last", + "id": "ch_force", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Force it." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk", + "text": "Walk away." + } + ] + }, + { + "id": "node_gated_fallback", + "text": "A gated fallback proves nothing.", + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock2", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk2", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Shoulder past." + } + ] + }, + { + "id": "node_last", + "isEnd": true, + "text": "You think of the cup, still warm.", + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "onEnter": [ + { + "flag": "reached_end", + "type": "set_flag", + "value": true + } + ] + }, + { + "id": "node_hop", + "text": "A beat.", + "next": "node_last" + }, + { + "id": "node_hop_open", + "text": "Another beat.", + "next": "node_open" + } + ] + }, + "nodeId": "node_door", + "choiceId": "ch_walk", + "state": { + "counters": {}, + "flags": {}, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + }, + "project": { + "factions": {} + }, + "expected": { + "nextNodeId": "node_last", + "newState": { + "counters": {}, + "flags": {}, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + } } - } }, - "expected": { - "nextNodeId": "node_end", - "newState": { - "flags": { - "done": true - }, - "reputation": { - "guild": 2 - }, - "skills": {}, - "counters": {}, - "inventory": [], - "questStages": {}, - "xp": 0, - "skillPointsSpent": {} - } - } - }, - { - "fn": "chooseChoice", - "description": "give_item effect: item appears in inventory after choice", - "dialogue": { - "id": "dlg_conformance", - "entry": "node_start", - "nodes": [ - { - "id": "node_start", - "text": "Start.", - "choices": [ - { - "id": "ch_loot", - "text": "Take the key.", - "goto": "node_end", - "effects": [ - { - "type": "give_item", - "item": "key_card" + { + "fn": "chooseChoice", + "description": "text-less node: choices on a node with no text are chosen like any other", + "dialogue": { + "entry": "node_open", + "id": "dlg_shapes", + "nodes": [ + { + "id": "node_open", + "text": "And you've seen the ledger. I can tell.", + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "onEnter": [ + { + "flag": "visited_open", + "type": "set_flag", + "value": true + } + ], + "choices": [ + { + "goto": "node_options", + "id": "ch_ship", + "text": "Ask about the ship." + }, + { + "goto": "node_door", + "id": "ch_leave", + "text": "Leave." + } + ] + }, + { + "id": "node_options", + "choices": [ + { + "goto": "node_door", + "id": "ch_door", + "text": "Try the door." + }, + { + "goto": "node_last", + "id": "ch_end", + "text": "Say goodbye." + } + ] + }, + { + "id": "node_door", + "text": "The door.", + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock the door.", + "whenLocked": "show", + "lockedText": "[Requires the key]" + }, + { + "goto": "node_last", + "id": "ch_force", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Force it." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk", + "text": "Walk away." + } + ] + }, + { + "id": "node_gated_fallback", + "text": "A gated fallback proves nothing.", + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock2", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk2", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Shoulder past." + } + ] + }, + { + "id": "node_last", + "isEnd": true, + "text": "You think of the cup, still warm.", + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "onEnter": [ + { + "flag": "reached_end", + "type": "set_flag", + "value": true + } + ] + }, + { + "id": "node_hop", + "text": "A beat.", + "next": "node_last" + }, + { + "id": "node_hop_open", + "text": "Another beat.", + "next": "node_open" } - ] - } - ] + ] + }, + "nodeId": "node_options", + "choiceId": "ch_door", + "state": { + "counters": {}, + "flags": {}, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 }, - { - "id": "node_end", - "isEnd": true, - "text": "End." + "project": { + "factions": {} + }, + "expected": { + "nextNodeId": "node_door", + "newState": { + "counters": {}, + "flags": {}, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + } } - ] - }, - "nodeId": "node_start", - "choiceId": "ch_loot", - "state": { - "flags": {}, - "reputation": {}, - "skills": {}, - "counters": {}, - "inventory": [], - "questStages": {}, - "xp": 0, - "skillPointsSpent": {} - }, - "project": { - "factions": {} }, - "expected": { - "nextNodeId": "node_end", - "newState": { - "flags": {}, - "reputation": {}, - "skills": {}, - "counters": {}, - "inventory": [ - "key_card" - ], - "questStages": {}, - "xp": 0, - "skillPointsSpent": {} - } - } - }, - { - "fn": "chooseChoice", - "description": "a check modifier flips the branch: roll=5 wit=5 base 10 < DC 15, +6 primed -> 16 -> success", - "dialogue": { - "id": "dlg_conformance", - "entry": "node_start", - "nodes": [ - { - "id": "node_start", - "text": "Start.", - "choices": [ - { - "id": "ch_check", - "text": "Roll.", - "check": { - "mode": "active", - "skill": "wit", - "difficulty": 15, - "onSuccess": "node_win", - "onFailure": "node_lose", - "modifiers": [ - { - "when": { - "type": "flag", - "flag": "primed", - "value": true + { + "fn": "chooseChoice", + "description": "hidden-line node: choices on a node whose line is hidden are chosen like any other (the node was reached, only its line was withheld)", + "dialogue": { + "entry": "node_open", + "id": "dlg_shapes", + "nodes": [ + { + "id": "node_open", + "text": "And you've seen the ledger. I can tell.", + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true }, - "bonus": 6 - } - ] - } - } - ] + "onEnter": [ + { + "flag": "visited_open", + "type": "set_flag", + "value": true + } + ], + "choices": [ + { + "goto": "node_options", + "id": "ch_ship", + "text": "Ask about the ship." + }, + { + "goto": "node_door", + "id": "ch_leave", + "text": "Leave." + } + ] + }, + { + "id": "node_options", + "choices": [ + { + "goto": "node_door", + "id": "ch_door", + "text": "Try the door." + }, + { + "goto": "node_last", + "id": "ch_end", + "text": "Say goodbye." + } + ] + }, + { + "id": "node_door", + "text": "The door.", + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock the door.", + "whenLocked": "show", + "lockedText": "[Requires the key]" + }, + { + "goto": "node_last", + "id": "ch_force", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Force it." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk", + "text": "Walk away." + } + ] + }, + { + "id": "node_gated_fallback", + "text": "A gated fallback proves nothing.", + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock2", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk2", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Shoulder past." + } + ] + }, + { + "id": "node_last", + "isEnd": true, + "text": "You think of the cup, still warm.", + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "onEnter": [ + { + "flag": "reached_end", + "type": "set_flag", + "value": true + } + ] + }, + { + "id": "node_hop", + "text": "A beat.", + "next": "node_last" + }, + { + "id": "node_hop_open", + "text": "Another beat.", + "next": "node_open" + } + ] }, - { - "id": "node_win", - "isEnd": true, - "text": "Won." + "nodeId": "node_open", + "choiceId": "ch_ship", + "state": { + "counters": {}, + "flags": {}, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 }, - { - "id": "node_lose", - "isEnd": true, - "text": "Lost." + "project": { + "factions": {} + }, + "expected": { + "nextNodeId": "node_options", + "newState": { + "counters": {}, + "flags": {}, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + } } - ] - }, - "nodeId": "node_start", - "choiceId": "ch_check", - "state": { - "flags": { - "primed": true - }, - "reputation": {}, - "skills": { - "wit": 5 - }, - "counters": {}, - "inventory": [], - "questStages": {}, - "xp": 0, - "skillPointsSpent": {} - }, - "project": { - "factions": {} }, - "rng": 0.2, - "expected": { - "nextNodeId": "node_win", - "newState": { - "flags": { - "primed": true - }, - "reputation": {}, - "skills": { - "wit": 5 - }, - "counters": {}, - "inventory": [], - "questStages": {}, - "xp": 0, - "skillPointsSpent": {} - }, - "checkResult": { - "passed": true, - "roll": 5, - "total": 16, - "skillValue": 5, - "dice": "1d20", - "bonus": 6, - "appliedModifiers": [ - 0 - ] - } + { + "fn": "chooseChoice", + "description": "engine: a choice's effects apply in order around an engine command, which itself changes nothing", + "dialogue": { + "id": "dlg_conformance", + "entry": "node_start", + "nodes": [ + { + "id": "node_start", + "text": "Start.", + "choices": [ + { + "id": "ch_engine", + "text": "Kick.", + "goto": "node_end", + "effects": [ + { + "type": "set_flag", + "flag": "kicked", + "value": true + }, + { + "type": "engine", + "command": "play_sfx", + "args": [ + "door_kick", + 0.8 + ] + }, + { + "type": "adjust_counter", + "counter": "noise", + "delta": 2 + } + ] + } + ] + }, + { + "id": "node_end", + "isEnd": true, + "text": "End." + } + ] + }, + "nodeId": "node_start", + "choiceId": "ch_engine", + "state": { + "flags": {}, + "reputation": {}, + "skills": {}, + "counters": {}, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} + }, + "project": { + "factions": {} + }, + "expected": { + "nextNodeId": "node_end", + "newState": { + "flags": { + "kicked": true + }, + "reputation": {}, + "skills": {}, + "counters": { + "noise": 2 + }, + "inventory": [], + "questStages": {}, + "xp": 0, + "skillPointsSpent": {} + } + } } - } ] diff --git a/conformance/resolve_quests.json b/conformance/resolve_quests.json index d2004d2..bfb6f7a 100644 --- a/conformance/resolve_quests.json +++ b/conformance/resolve_quests.json @@ -116,5 +116,29 @@ "state": { "flags": { "step_one": true, "step_two": true }, "reputation": {}, "skills": {}, "counters": {}, "inventory": [], "questStages": {}, "xp": 50, "skillPointsSpent": {}, "questFired": ["q_a/outcome/out_a", "q_b/outcome/out_b"] }, "firings": [{ "quest": "q_a", "kind": "outcome", "id": "out_a" }, { "quest": "q_b", "kind": "outcome", "id": "out_b" }] } + }, + { + "fn": "resolveQuests", + "description": "cascade needs a second pass: an earlier quest (by id) is satisfied only by a later quest's firing, so a single in-order pass stops short of the fixpoint", + "state": { "flags": { "step_one": true }, "reputation": {}, "skills": {}, "counters": {}, "inventory": [], "questStages": {}, "xp": 0, "skillPointsSpent": {} }, + "project": { + "factions": {}, + "quests": { + "q_a": { + "id": "q_a", "name": "A", "summary": "s", + "stages": [{ "id": "s1", "order": 1, "description": "d" }], + "outcomes": [{ "id": "out_a", "kind": "success", "description": "d", "reachedWhen": { "type": "flag", "flag": "step_two", "value": true }, "effects": [{ "type": "grant_xp", "amount": 50 }] }] + }, + "q_b": { + "id": "q_b", "name": "B", "summary": "s", + "stages": [{ "id": "s1", "order": 1, "description": "d" }], + "outcomes": [{ "id": "out_b", "kind": "success", "description": "d", "reachedWhen": { "type": "flag", "flag": "step_one", "value": true }, "effects": [{ "type": "set_flag", "flag": "step_two", "value": true }] }] + } + } + }, + "expected": { + "state": { "flags": { "step_one": true, "step_two": true }, "reputation": {}, "skills": {}, "counters": {}, "inventory": [], "questStages": {}, "xp": 50, "skillPointsSpent": {}, "questFired": ["q_a/outcome/out_a", "q_b/outcome/out_b"] }, + "firings": [{ "quest": "q_b", "kind": "outcome", "id": "out_b" }, { "quest": "q_a", "kind": "outcome", "id": "out_a" }] + } } ] diff --git a/conformance/step_dialogue.json b/conformance/step_dialogue.json index b7f376a..98b7ef9 100644 --- a/conformance/step_dialogue.json +++ b/conformance/step_dialogue.json @@ -89,6 +89,7 @@ ] }, "expected": { + "lockedChoiceIds": [], "nodeId": "node_start", "onEnterEffectCount": 1, "onEnterEffects": [ @@ -207,6 +208,7 @@ ] }, "expected": { + "lockedChoiceIds": [], "nodeId": "node_start", "onEnterEffectCount": 1, "onEnterEffects": [ @@ -328,6 +330,7 @@ ] }, "expected": { + "lockedChoiceIds": [], "nodeId": "node_start", "onEnterEffectCount": 1, "onEnterEffects": [ @@ -449,6 +452,7 @@ ] }, "expected": { + "lockedChoiceIds": [], "nodeId": "node_start", "onEnterEffectCount": 1, "onEnterEffects": [ @@ -514,6 +518,7 @@ ] }, "expected": { + "lockedChoiceIds": [], "nodeId": "node_end", "onEnterEffectCount": 0, "onEnterEffects": [], @@ -575,6 +580,7 @@ ] }, "expected": { + "lockedChoiceIds": [], "nodeId": "node_start", "onEnterEffectCount": 0, "onEnterEffects": [], @@ -609,6 +615,7 @@ ] }, "expected": { + "lockedChoiceIds": [], "nodeId": "node_only", "onEnterEffectCount": 0, "onEnterEffects": [], @@ -659,6 +666,7 @@ ] }, "expected": { + "lockedChoiceIds": [], "nodeId": "node_enter", "onEnterEffectCount": 2, "onEnterEffects": [ @@ -744,6 +752,7 @@ ] }, "expected": { + "lockedChoiceIds": [], "nodeId": "n_real", "onEnterEffectCount": 1, "onEnterEffects": [ @@ -824,6 +833,7 @@ ] }, "expected": { + "lockedChoiceIds": [], "nodeId": "n_hidden", "onEnterEffectCount": 1, "onEnterEffects": [ @@ -904,6 +914,7 @@ ] }, "expected": { + "lockedChoiceIds": [], "nodeId": "n_real", "onEnterEffectCount": 1, "onEnterEffects": [ @@ -929,5 +940,2056 @@ "skills": {}, "xp": 0 } + }, + { + "description": "line-only gate (0.15): showIf FAILS on a node with choices — node is NOT skipped, its line is hidden (textHidden, text \"\"), its choices are offered and its onEnter is returned", + "dialogue": { + "entry": "node_open", + "id": "dlg_shapes", + "nodes": [ + { + "choices": [ + { + "goto": "node_options", + "id": "ch_ship", + "text": "Ask about the ship." + }, + { + "goto": "node_door", + "id": "ch_leave", + "text": "Leave." + } + ], + "id": "node_open", + "onEnter": [ + { + "flag": "visited_open", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "And you've seen the ledger. I can tell." + }, + { + "choices": [ + { + "goto": "node_door", + "id": "ch_door", + "text": "Try the door." + }, + { + "goto": "node_last", + "id": "ch_end", + "text": "Say goodbye." + } + ], + "id": "node_options" + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock", + "lockedText": "[Requires the key]", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock the door.", + "whenLocked": "show" + }, + { + "goto": "node_last", + "id": "ch_force", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Force it." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk", + "text": "Walk away." + } + ], + "id": "node_door", + "text": "The door." + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock2", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk2", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Shoulder past." + } + ], + "id": "node_gated_fallback", + "text": "A gated fallback proves nothing." + }, + { + "id": "node_last", + "isEnd": true, + "onEnter": [ + { + "flag": "reached_end", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "You think of the cup, still warm." + }, + { + "id": "node_hop", + "next": "node_last", + "text": "A beat." + }, + { + "id": "node_hop_open", + "next": "node_open", + "text": "Another beat." + } + ] + }, + "expected": { + "lockedChoiceIds": [], + "nodeId": "node_open", + "onEnterEffectCount": 1, + "onEnterEffects": [ + { + "flag": "visited_open", + "type": "set_flag", + "value": true + } + ], + "text": "", + "textHidden": true, + "visibleChoiceIds": [ + "ch_ship", + "ch_leave" + ] + }, + "fn": "stepDialogue", + "nodeId": "node_open", + "state": { + "counters": {}, + "flags": {}, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + } + }, + { + "description": "line-only gate: showIf PASSES on a node with choices — the line shows as authored", + "dialogue": { + "entry": "node_open", + "id": "dlg_shapes", + "nodes": [ + { + "choices": [ + { + "goto": "node_options", + "id": "ch_ship", + "text": "Ask about the ship." + }, + { + "goto": "node_door", + "id": "ch_leave", + "text": "Leave." + } + ], + "id": "node_open", + "onEnter": [ + { + "flag": "visited_open", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "And you've seen the ledger. I can tell." + }, + { + "choices": [ + { + "goto": "node_door", + "id": "ch_door", + "text": "Try the door." + }, + { + "goto": "node_last", + "id": "ch_end", + "text": "Say goodbye." + } + ], + "id": "node_options" + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock", + "lockedText": "[Requires the key]", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock the door.", + "whenLocked": "show" + }, + { + "goto": "node_last", + "id": "ch_force", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Force it." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk", + "text": "Walk away." + } + ], + "id": "node_door", + "text": "The door." + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock2", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk2", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Shoulder past." + } + ], + "id": "node_gated_fallback", + "text": "A gated fallback proves nothing." + }, + { + "id": "node_last", + "isEnd": true, + "onEnter": [ + { + "flag": "reached_end", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "You think of the cup, still warm." + }, + { + "id": "node_hop", + "next": "node_last", + "text": "A beat." + }, + { + "id": "node_hop_open", + "next": "node_open", + "text": "Another beat." + } + ] + }, + "expected": { + "lockedChoiceIds": [], + "nodeId": "node_open", + "onEnterEffectCount": 1, + "onEnterEffects": [ + { + "flag": "visited_open", + "type": "set_flag", + "value": true + } + ], + "text": "And you've seen the ledger. I can tell.", + "textHidden": false, + "visibleChoiceIds": [ + "ch_ship", + "ch_leave" + ] + }, + "fn": "stepDialogue", + "nodeId": "node_open", + "state": { + "counters": {}, + "flags": { + "seen_ledger": true + }, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + } + }, + { + "description": "line-only gate: showIf FAILS on an isEnd node — reached (not skipped, not thrown), line hidden, dialogue ends, onEnter returned", + "dialogue": { + "entry": "node_open", + "id": "dlg_shapes", + "nodes": [ + { + "choices": [ + { + "goto": "node_options", + "id": "ch_ship", + "text": "Ask about the ship." + }, + { + "goto": "node_door", + "id": "ch_leave", + "text": "Leave." + } + ], + "id": "node_open", + "onEnter": [ + { + "flag": "visited_open", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "And you've seen the ledger. I can tell." + }, + { + "choices": [ + { + "goto": "node_door", + "id": "ch_door", + "text": "Try the door." + }, + { + "goto": "node_last", + "id": "ch_end", + "text": "Say goodbye." + } + ], + "id": "node_options" + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock", + "lockedText": "[Requires the key]", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock the door.", + "whenLocked": "show" + }, + { + "goto": "node_last", + "id": "ch_force", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Force it." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk", + "text": "Walk away." + } + ], + "id": "node_door", + "text": "The door." + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock2", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk2", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Shoulder past." + } + ], + "id": "node_gated_fallback", + "text": "A gated fallback proves nothing." + }, + { + "id": "node_last", + "isEnd": true, + "onEnter": [ + { + "flag": "reached_end", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "You think of the cup, still warm." + }, + { + "id": "node_hop", + "next": "node_last", + "text": "A beat." + }, + { + "id": "node_hop_open", + "next": "node_open", + "text": "Another beat." + } + ] + }, + "expected": { + "lockedChoiceIds": [], + "nodeId": "node_last", + "onEnterEffectCount": 1, + "onEnterEffects": [ + { + "flag": "reached_end", + "type": "set_flag", + "value": true + } + ], + "text": "", + "textHidden": true, + "visibleChoiceIds": [] + }, + "fn": "stepDialogue", + "nodeId": "node_last", + "state": { + "counters": {}, + "flags": {}, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + } + }, + { + "description": "text-less choice node (0.15): no `text` at all — presents only its options; textHidden is false (nothing was withheld) and text is absent (null here)", + "dialogue": { + "entry": "node_open", + "id": "dlg_shapes", + "nodes": [ + { + "choices": [ + { + "goto": "node_options", + "id": "ch_ship", + "text": "Ask about the ship." + }, + { + "goto": "node_door", + "id": "ch_leave", + "text": "Leave." + } + ], + "id": "node_open", + "onEnter": [ + { + "flag": "visited_open", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "And you've seen the ledger. I can tell." + }, + { + "choices": [ + { + "goto": "node_door", + "id": "ch_door", + "text": "Try the door." + }, + { + "goto": "node_last", + "id": "ch_end", + "text": "Say goodbye." + } + ], + "id": "node_options" + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock", + "lockedText": "[Requires the key]", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock the door.", + "whenLocked": "show" + }, + { + "goto": "node_last", + "id": "ch_force", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Force it." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk", + "text": "Walk away." + } + ], + "id": "node_door", + "text": "The door." + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock2", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk2", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Shoulder past." + } + ], + "id": "node_gated_fallback", + "text": "A gated fallback proves nothing." + }, + { + "id": "node_last", + "isEnd": true, + "onEnter": [ + { + "flag": "reached_end", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "You think of the cup, still warm." + }, + { + "id": "node_hop", + "next": "node_last", + "text": "A beat." + }, + { + "id": "node_hop_open", + "next": "node_open", + "text": "Another beat." + } + ] + }, + "expected": { + "lockedChoiceIds": [], + "nodeId": "node_options", + "onEnterEffectCount": 0, + "onEnterEffects": [], + "text": null, + "textHidden": false, + "visibleChoiceIds": [ + "ch_door", + "ch_end" + ] + }, + "fn": "stepDialogue", + "nodeId": "node_options", + "state": { + "counters": {}, + "flags": {}, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + } + }, + { + "description": "fallback (0.15): NOT offered while a non-fallback choice is visible (has_key set); ch_force fails its gate and is hidden (whenLocked defaults to hide)", + "dialogue": { + "entry": "node_open", + "id": "dlg_shapes", + "nodes": [ + { + "choices": [ + { + "goto": "node_options", + "id": "ch_ship", + "text": "Ask about the ship." + }, + { + "goto": "node_door", + "id": "ch_leave", + "text": "Leave." + } + ], + "id": "node_open", + "onEnter": [ + { + "flag": "visited_open", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "And you've seen the ledger. I can tell." + }, + { + "choices": [ + { + "goto": "node_door", + "id": "ch_door", + "text": "Try the door." + }, + { + "goto": "node_last", + "id": "ch_end", + "text": "Say goodbye." + } + ], + "id": "node_options" + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock", + "lockedText": "[Requires the key]", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock the door.", + "whenLocked": "show" + }, + { + "goto": "node_last", + "id": "ch_force", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Force it." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk", + "text": "Walk away." + } + ], + "id": "node_door", + "text": "The door." + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock2", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk2", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Shoulder past." + } + ], + "id": "node_gated_fallback", + "text": "A gated fallback proves nothing." + }, + { + "id": "node_last", + "isEnd": true, + "onEnter": [ + { + "flag": "reached_end", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "You think of the cup, still warm." + }, + { + "id": "node_hop", + "next": "node_last", + "text": "A beat." + }, + { + "id": "node_hop_open", + "next": "node_open", + "text": "Another beat." + } + ] + }, + "expected": { + "lockedChoiceIds": [], + "nodeId": "node_door", + "onEnterEffectCount": 0, + "onEnterEffects": [], + "text": "The door.", + "textHidden": false, + "visibleChoiceIds": [ + "ch_unlock" + ] + }, + "fn": "stepDialogue", + "nodeId": "node_door", + "state": { + "counters": {}, + "flags": { + "has_key": true + }, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + } + }, + { + "description": "fallback: offered ONLY when no non-fallback choice is visible; ch_unlock (whenLocked show) is returned locked, ch_force (default hide) is not", + "dialogue": { + "entry": "node_open", + "id": "dlg_shapes", + "nodes": [ + { + "choices": [ + { + "goto": "node_options", + "id": "ch_ship", + "text": "Ask about the ship." + }, + { + "goto": "node_door", + "id": "ch_leave", + "text": "Leave." + } + ], + "id": "node_open", + "onEnter": [ + { + "flag": "visited_open", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "And you've seen the ledger. I can tell." + }, + { + "choices": [ + { + "goto": "node_door", + "id": "ch_door", + "text": "Try the door." + }, + { + "goto": "node_last", + "id": "ch_end", + "text": "Say goodbye." + } + ], + "id": "node_options" + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock", + "lockedText": "[Requires the key]", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock the door.", + "whenLocked": "show" + }, + { + "goto": "node_last", + "id": "ch_force", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Force it." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk", + "text": "Walk away." + } + ], + "id": "node_door", + "text": "The door." + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock2", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk2", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Shoulder past." + } + ], + "id": "node_gated_fallback", + "text": "A gated fallback proves nothing." + }, + { + "id": "node_last", + "isEnd": true, + "onEnter": [ + { + "flag": "reached_end", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "You think of the cup, still warm." + }, + { + "id": "node_hop", + "next": "node_last", + "text": "A beat." + }, + { + "id": "node_hop_open", + "next": "node_open", + "text": "Another beat." + } + ] + }, + "expected": { + "lockedChoiceIds": [ + "ch_unlock" + ], + "nodeId": "node_door", + "onEnterEffectCount": 0, + "onEnterEffects": [], + "text": "The door.", + "textHidden": false, + "visibleChoiceIds": [ + "ch_walk" + ] + }, + "fn": "stepDialogue", + "nodeId": "node_door", + "state": { + "counters": {}, + "flags": {}, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + } + }, + { + "description": "locked (0.15): rules.choices.whenLockedDefault=show makes ch_force locked too; lockedChoices keep authored order", + "dialogue": { + "entry": "node_open", + "id": "dlg_shapes", + "nodes": [ + { + "choices": [ + { + "goto": "node_options", + "id": "ch_ship", + "text": "Ask about the ship." + }, + { + "goto": "node_door", + "id": "ch_leave", + "text": "Leave." + } + ], + "id": "node_open", + "onEnter": [ + { + "flag": "visited_open", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "And you've seen the ledger. I can tell." + }, + { + "choices": [ + { + "goto": "node_door", + "id": "ch_door", + "text": "Try the door." + }, + { + "goto": "node_last", + "id": "ch_end", + "text": "Say goodbye." + } + ], + "id": "node_options" + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock", + "lockedText": "[Requires the key]", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock the door.", + "whenLocked": "show" + }, + { + "goto": "node_last", + "id": "ch_force", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Force it." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk", + "text": "Walk away." + } + ], + "id": "node_door", + "text": "The door." + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock2", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk2", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Shoulder past." + } + ], + "id": "node_gated_fallback", + "text": "A gated fallback proves nothing." + }, + { + "id": "node_last", + "isEnd": true, + "onEnter": [ + { + "flag": "reached_end", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "You think of the cup, still warm." + }, + { + "id": "node_hop", + "next": "node_last", + "text": "A beat." + }, + { + "id": "node_hop_open", + "next": "node_open", + "text": "Another beat." + } + ] + }, + "expected": { + "lockedChoiceIds": [ + "ch_unlock", + "ch_force" + ], + "nodeId": "node_door", + "onEnterEffectCount": 0, + "onEnterEffects": [], + "text": "The door.", + "textHidden": false, + "visibleChoiceIds": [ + "ch_walk" + ] + }, + "fn": "stepDialogue", + "nodeId": "node_door", + "project": { + "factions": {}, + "rules": { + "choices": { + "whenLockedDefault": "show" + } + } + }, + "state": { + "counters": {}, + "flags": {}, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + } + }, + { + "description": "locked beside a visible choice: has_key set, whenLockedDefault=show — ch_unlock is selectable, ch_force is locked and must NOT appear in visibleChoices, and the fallback stays hidden", + "dialogue": { + "entry": "node_open", + "id": "dlg_shapes", + "nodes": [ + { + "choices": [ + { + "goto": "node_options", + "id": "ch_ship", + "text": "Ask about the ship." + }, + { + "goto": "node_door", + "id": "ch_leave", + "text": "Leave." + } + ], + "id": "node_open", + "onEnter": [ + { + "flag": "visited_open", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "And you've seen the ledger. I can tell." + }, + { + "choices": [ + { + "goto": "node_door", + "id": "ch_door", + "text": "Try the door." + }, + { + "goto": "node_last", + "id": "ch_end", + "text": "Say goodbye." + } + ], + "id": "node_options" + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock", + "lockedText": "[Requires the key]", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock the door.", + "whenLocked": "show" + }, + { + "goto": "node_last", + "id": "ch_force", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Force it." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk", + "text": "Walk away." + } + ], + "id": "node_door", + "text": "The door." + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock2", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk2", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Shoulder past." + } + ], + "id": "node_gated_fallback", + "text": "A gated fallback proves nothing." + }, + { + "id": "node_last", + "isEnd": true, + "onEnter": [ + { + "flag": "reached_end", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "You think of the cup, still warm." + }, + { + "id": "node_hop", + "next": "node_last", + "text": "A beat." + }, + { + "id": "node_hop_open", + "next": "node_open", + "text": "Another beat." + } + ] + }, + "expected": { + "lockedChoiceIds": [ + "ch_force" + ], + "nodeId": "node_door", + "onEnterEffectCount": 0, + "onEnterEffects": [], + "text": "The door.", + "textHidden": false, + "visibleChoiceIds": [ + "ch_unlock" + ] + }, + "fn": "stepDialogue", + "nodeId": "node_door", + "project": { + "factions": {}, + "rules": { + "choices": { + "whenLockedDefault": "show" + } + } + }, + "state": { + "counters": {}, + "flags": { + "has_key": true + }, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + } + }, + { + "description": "gated fallback: its own showIf must pass too — nothing visible when every gate fails (the validator warns on this node)", + "dialogue": { + "entry": "node_open", + "id": "dlg_shapes", + "nodes": [ + { + "choices": [ + { + "goto": "node_options", + "id": "ch_ship", + "text": "Ask about the ship." + }, + { + "goto": "node_door", + "id": "ch_leave", + "text": "Leave." + } + ], + "id": "node_open", + "onEnter": [ + { + "flag": "visited_open", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "And you've seen the ledger. I can tell." + }, + { + "choices": [ + { + "goto": "node_door", + "id": "ch_door", + "text": "Try the door." + }, + { + "goto": "node_last", + "id": "ch_end", + "text": "Say goodbye." + } + ], + "id": "node_options" + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock", + "lockedText": "[Requires the key]", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock the door.", + "whenLocked": "show" + }, + { + "goto": "node_last", + "id": "ch_force", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Force it." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk", + "text": "Walk away." + } + ], + "id": "node_door", + "text": "The door." + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock2", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk2", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Shoulder past." + } + ], + "id": "node_gated_fallback", + "text": "A gated fallback proves nothing." + }, + { + "id": "node_last", + "isEnd": true, + "onEnter": [ + { + "flag": "reached_end", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "You think of the cup, still warm." + }, + { + "id": "node_hop", + "next": "node_last", + "text": "A beat." + }, + { + "id": "node_hop_open", + "next": "node_open", + "text": "Another beat." + } + ] + }, + "expected": { + "lockedChoiceIds": [], + "nodeId": "node_gated_fallback", + "onEnterEffectCount": 0, + "onEnterEffects": [], + "text": "A gated fallback proves nothing.", + "textHidden": false, + "visibleChoiceIds": [] + }, + "fn": "stepDialogue", + "nodeId": "node_gated_fallback", + "state": { + "counters": {}, + "flags": {}, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + } + }, + { + "description": "gated fallback: shown when its gate passes and no non-fallback is visible", + "dialogue": { + "entry": "node_open", + "id": "dlg_shapes", + "nodes": [ + { + "choices": [ + { + "goto": "node_options", + "id": "ch_ship", + "text": "Ask about the ship." + }, + { + "goto": "node_door", + "id": "ch_leave", + "text": "Leave." + } + ], + "id": "node_open", + "onEnter": [ + { + "flag": "visited_open", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "And you've seen the ledger. I can tell." + }, + { + "choices": [ + { + "goto": "node_door", + "id": "ch_door", + "text": "Try the door." + }, + { + "goto": "node_last", + "id": "ch_end", + "text": "Say goodbye." + } + ], + "id": "node_options" + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock", + "lockedText": "[Requires the key]", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock the door.", + "whenLocked": "show" + }, + { + "goto": "node_last", + "id": "ch_force", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Force it." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk", + "text": "Walk away." + } + ], + "id": "node_door", + "text": "The door." + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock2", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk2", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Shoulder past." + } + ], + "id": "node_gated_fallback", + "text": "A gated fallback proves nothing." + }, + { + "id": "node_last", + "isEnd": true, + "onEnter": [ + { + "flag": "reached_end", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "You think of the cup, still warm." + }, + { + "id": "node_hop", + "next": "node_last", + "text": "A beat." + }, + { + "id": "node_hop_open", + "next": "node_open", + "text": "Another beat." + } + ] + }, + "expected": { + "lockedChoiceIds": [], + "nodeId": "node_gated_fallback", + "onEnterEffectCount": 0, + "onEnterEffects": [], + "text": "A gated fallback proves nothing.", + "textHidden": false, + "visibleChoiceIds": [ + "ch_walk2" + ] + }, + "fn": "stepDialogue", + "nodeId": "node_gated_fallback", + "state": { + "counters": {}, + "flags": {}, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": { + "might": 7 + }, + "xp": 0 + } + }, + { + "description": "interstitial skip is unchanged: requesting node_hop_open resolves through it? No — node_hop_open has no gate, so it is returned itself; only a GATED interstitial node is skipped", + "dialogue": { + "entry": "node_open", + "id": "dlg_shapes", + "nodes": [ + { + "choices": [ + { + "goto": "node_options", + "id": "ch_ship", + "text": "Ask about the ship." + }, + { + "goto": "node_door", + "id": "ch_leave", + "text": "Leave." + } + ], + "id": "node_open", + "onEnter": [ + { + "flag": "visited_open", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "And you've seen the ledger. I can tell." + }, + { + "choices": [ + { + "goto": "node_door", + "id": "ch_door", + "text": "Try the door." + }, + { + "goto": "node_last", + "id": "ch_end", + "text": "Say goodbye." + } + ], + "id": "node_options" + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock", + "lockedText": "[Requires the key]", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock the door.", + "whenLocked": "show" + }, + { + "goto": "node_last", + "id": "ch_force", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Force it." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk", + "text": "Walk away." + } + ], + "id": "node_door", + "text": "The door." + }, + { + "choices": [ + { + "goto": "node_last", + "id": "ch_unlock2", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "text": "Unlock." + }, + { + "fallback": true, + "goto": "node_last", + "id": "ch_walk2", + "showIf": { + "op": ">=", + "skill": "might", + "type": "skill", + "value": 5 + }, + "text": "Shoulder past." + } + ], + "id": "node_gated_fallback", + "text": "A gated fallback proves nothing." + }, + { + "id": "node_last", + "isEnd": true, + "onEnter": [ + { + "flag": "reached_end", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "seen_ledger", + "type": "flag", + "value": true + }, + "text": "You think of the cup, still warm." + }, + { + "id": "node_hop", + "next": "node_last", + "text": "A beat." + }, + { + "id": "node_hop_open", + "next": "node_open", + "text": "Another beat." + } + ] + }, + "expected": { + "lockedChoiceIds": [], + "nodeId": "node_hop_open", + "onEnterEffectCount": 0, + "onEnterEffects": [], + "text": "Another beat.", + "textHidden": false, + "visibleChoiceIds": [] + }, + "fn": "stepDialogue", + "nodeId": "node_hop_open", + "state": { + "counters": {}, + "flags": {}, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + } + }, + { + "description": "tags: node.tags and choice.tags are returned unchanged on the step (opaque pass-through), and an engine effect sits in onEnterEffects in authored order", + "dialogue": { + "entry": "node_tagged", + "id": "dlg_tags", + "nodes": [ + { + "choices": [ + { + "goto": "node_end", + "id": "ch_calm", + "tags": [ + "tone:calm" + ], + "text": "Easy." + }, + { + "goto": "node_end", + "id": "ch_plain", + "text": "Say nothing." + }, + { + "goto": "node_end", + "id": "ch_hidden", + "showIf": { + "flag": "has_key", + "type": "flag", + "value": true + }, + "tags": [ + "tone:sharp" + ], + "text": "Never." + } + ], + "id": "node_tagged", + "onEnter": [ + { + "flag": "visited", + "type": "set_flag", + "value": true + }, + { + "args": [ + 0.5 + ], + "command": "shake", + "type": "engine" + }, + { + "counter": "visits", + "delta": 1, + "type": "adjust_counter" + } + ], + "tags": [ + "mood:angry", + "sfx:door" + ], + "text": "The door slams." + }, + { + "id": "node_end", + "isEnd": true, + "text": "End." + } + ] + }, + "expected": { + "lockedChoiceIds": [], + "nodeId": "node_tagged", + "nodeTags": [ + "mood:angry", + "sfx:door" + ], + "onEnterEffectCount": 3, + "onEnterEffects": [ + { + "flag": "visited", + "type": "set_flag", + "value": true + }, + { + "args": [ + 0.5 + ], + "command": "shake", + "type": "engine" + }, + { + "counter": "visits", + "delta": 1, + "type": "adjust_counter" + } + ], + "visibleChoiceIds": [ + "ch_calm", + "ch_plain" + ], + "visibleChoiceTags": [ + [ + "tone:calm" + ], + null + ] + }, + "fn": "stepDialogue", + "nodeId": "node_tagged", + "project": { + "factions": {} + }, + "state": { + "counters": {}, + "flags": {}, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + } + }, + { + "description": "line-only gate (0.15), self-clearing: the gate is judged ONCE, on ARRIVAL, before onEnter — a node whose own onEnter would fail its own showIf still shows its line (a port that applies onEnter first and then evaluates hides it)", + "dialogue": { + "entry": "node_greet", + "id": "dlg_greet", + "nodes": [ + { + "choices": [ + { + "goto": "node_end", + "id": "ch_bye", + "text": "Bye." + } + ], + "id": "node_greet", + "onEnter": [ + { + "flag": "met_keeper", + "type": "set_flag", + "value": true + } + ], + "showIf": { + "flag": "met_keeper", + "type": "flag", + "value": false + }, + "text": "A stranger. Welcome." + }, + { + "id": "node_end", + "isEnd": true, + "text": "Go well." + } + ] + }, + "expected": { + "lockedChoiceIds": [], + "nodeId": "node_greet", + "onEnterEffectCount": 1, + "onEnterEffects": [ + { + "flag": "met_keeper", + "type": "set_flag", + "value": true + } + ], + "text": "A stranger. Welcome.", + "textHidden": false, + "visibleChoiceIds": [ + "ch_bye" + ] + }, + "fn": "stepDialogue", + "nodeId": "node_greet", + "state": { + "counters": {}, + "flags": { + "met_keeper": false + }, + "inventory": [], + "questStages": {}, + "reputation": {}, + "skillPointsSpent": {}, + "skills": {}, + "xp": 0 + } } ] diff --git a/schema/binding.schema.json b/schema/binding.schema.json new file mode 100644 index 0000000..2df92dc --- /dev/null +++ b/schema/binding.schema.json @@ -0,0 +1,36 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "binding.schema.json", + "title": "Asset Binding", + "description": "Mapping from asset ids (portraits, VO keys, cutscene assets) to locations per target/profile.", + "type": "object", + "properties": { + "profile": { + "type": "string", + "description": "Identifier for the target profile (e.g., 'godot', 'editor', 'web')." + }, + "portraits": { + "type": "object", + "additionalProperties": { + "type": "string" + }, + "description": "Mapping of portrait IDs to engine paths or URLs." + }, + "vo": { + "type": "object", + "additionalProperties": { + "type": "string" + }, + "description": "Mapping of VO keys to engine paths or URLs." + }, + "cutscenes": { + "type": "object", + "additionalProperties": { + "type": "string" + }, + "description": "Mapping of cutscene asset IDs to engine paths or URLs." + } + }, + "required": ["profile"], + "additionalProperties": false +} diff --git a/schema/common.schema.json b/schema/common.schema.json index 46b1daa..a0c14a3 100644 --- a/schema/common.schema.json +++ b/schema/common.schema.json @@ -473,6 +473,32 @@ "value" ], "additionalProperties": false + }, + { + "description": "An engine command: an opaque name plus literal arguments, handed to the host engine in order among the other effects (camera shake, a sound cue, an animation trigger). The runtime changes NO state for it — it is returned in the step's effect list and the engine decides what it means. 'command' must be lowercase snake_case (validator rule ENGINE); a project may declare its commands in rules.engine.commands so a typo is a warning rather than a silent no-op.", + "properties": { + "type": { + "const": "engine" + }, + "command": { + "type": "string" + }, + "args": { + "type": "array", + "items": { + "type": [ + "string", + "number", + "boolean" + ] + } + } + }, + "required": [ + "type", + "command" + ], + "additionalProperties": false } ] }, diff --git a/schema/dialogue.schema.json b/schema/dialogue.schema.json index c542815..3410e6f 100644 --- a/schema/dialogue.schema.json +++ b/schema/dialogue.schema.json @@ -56,7 +56,8 @@ "description": "overrides the dialogue's default speaker for this line — a character or skill id; omit for narration" }, "text": { - "type": "string" + "type": "string", + "description": "The line shown at this node. Optional ONLY on a node with non-empty 'choices' (a text-less choice node presents just its options); every other node must carry it — enforced by the validator (FLOW), since a schema-level conditional would reject valid nodes here." }, "onEnter": { "type": "array", @@ -67,7 +68,7 @@ }, "showIf": { "$ref": "common.schema.json#/definitions/condition", - "description": "Optional gate on this node's DISPLAY. When it fails the node is skipped and resolution continues at 'next': its text is not shown and its onEnter effects DO NOT fire. Requires 'next'; mutually exclusive with 'choices' and 'isEnd', which confines this to interstitial narration and makes skipping unambiguous. A 'next' chain must terminate at a node with no showIf." + "description": "Optional gate on this node's DISPLAY. On an interstitial node (one with 'next', no choices, not isEnd) a failed gate SKIPS the node: resolution continues at 'next', its text is not shown and its onEnter effects DO NOT fire; such a node requires 'next', and a 'next' chain must terminate at a node with no showIf. On a node with 'choices' or 'isEnd' a failed gate hides only the LINE: the node is still reached, its choices are still offered (or the dialogue still ends) and its onEnter effects still fire — the step reports textHidden. A showIf on a node with no text is an error either way (nothing to hide)." }, "isEnd": { "type": "boolean", @@ -104,6 +105,23 @@ "goto": { "$ref": "common.schema.json#/definitions/id", "description": "next node id (omit if check provides onSuccess/onFailure, or if choice ends convo)" + }, + "fallback": { + "type": "boolean", + "description": "true: this choice is offered ONLY when no non-fallback choice on the node is visible (its own showIf, if any, must still pass) — Ink's '* ->', Yarn's fallthrough. A node with an ungated fallback can never strand the player, so the validator drops its 'may be stuck' warning; more than one fallback, or a fallback beside no gated sibling, is a warning." + }, + "whenLocked": { + "type": "string", + "enum": ["hide", "show"], + "description": "What the player sees when this choice's showIf FAILS. 'hide' (the engine default, overridable by rules.choices.whenLockedDefault) drops it from the step entirely; 'show' returns it in stepDialogue's lockedChoices so the engine can present it greyed out. It is never selectable either way." + }, + "lockedText": { + "type": "string", + "description": "Optional replacement text for a choice presented locked (whenLocked 'show'), e.g. '[Requires Engineering 3]'. Localizable, never voiced. Omit to show the choice's own text." + }, + "tags": { + "$ref": "common.schema.json#/definitions/tags", + "description": "Opaque per-choice labels (e.g. 'mood:angry'). Pass-through: the runtime returns them on the visible choice and never reads them." } }, "required": [ @@ -120,11 +138,14 @@ "notes": { "type": "string", "description": "Author-only annotation. Never shown to the player; ignored by the runtime." + }, + "tags": { + "$ref": "common.schema.json#/definitions/tags", + "description": "Opaque per-line labels (e.g. 'mood:angry', 'sfx:door') an engine hangs animation, audio or camera work off. Pass-through: the runtime returns them on the step's node and never reads them; no validator rule reads them either." } }, "required": [ - "id", - "text" + "id" ], "additionalProperties": false } diff --git a/schema/rules.schema.json b/schema/rules.schema.json index db99ac1..030b85a 100644 --- a/schema/rules.schema.json +++ b/schema/rules.schema.json @@ -16,7 +16,7 @@ }, "criticals": { "type": "boolean", - "description": "Critical rolls (snake-eyes / boxcars). When true, every die showing its minimum ALWAYS fails and every die showing its maximum ALWAYS succeeds, regardless of skill or difficulty. Defaults to false \u2014 enabling it changes every check outcome, so it is an explicit per-project opt-in." + "description": "Critical rolls (snake-eyes / boxcars). When true, every die showing its minimum ALWAYS fails and every die showing its maximum ALWAYS succeeds, regardless of skill or difficulty. Defaults to false — enabling it changes every check outcome, so it is an explicit per-project opt-in." } }, "additionalProperties": false @@ -27,11 +27,81 @@ "properties": { "tagVocabulary": { "type": "array", - "items": { "type": "string" }, + "items": { + "type": "string" + }, "description": "Controlled vocabulary for Quest.tags. Journal UIs group and prioritise quests from these, so a typo'd tag silently drops out of the grouping — declaring the vocabulary here turns that into an OBJ warning. Omit the field and any tag is accepted." } }, "additionalProperties": false + }, + "choices": { + "type": "object", + "description": "Choice presentation rules.", + "properties": { + "whenLockedDefault": { + "type": "string", + "enum": [ + "hide", + "show" + ], + "description": "Project-wide default for a choice's 'whenLocked' when the choice does not set it. 'hide' (the engine default) keeps the classic behaviour — a choice whose showIf fails is dropped from the step; 'show' returns it in stepDialogue's lockedChoices for greyed-out presentation. A per-choice 'whenLocked' overrides this." + } + }, + "additionalProperties": false + }, + "engine": { + "type": "object", + "description": "Engine-command rules (the 'engine' effect).", + "properties": { + "commands": { + "type": "object", + "description": "Declared engine command names, keyed by command. Declaring the set turns an undeclared command in an 'engine' effect into an ENGINE warning (a typo is otherwise a silent no-op at runtime). Omit the field and any name is accepted.", + "propertyNames": { + "pattern": "^[a-z][a-z0-9_]*$" + }, + "additionalProperties": { + "type": "object", + "properties": { + "args": { + "description": "Expected argument count, or \"any\". When a number, an effect whose args length differs is an ENGINE warning.", + "oneOf": [ + { + "type": "integer", + "minimum": 0 + }, + { + "const": "any" + } + ] + }, + "description": { + "type": "string" + } + }, + "additionalProperties": false + } + } + }, + "additionalProperties": false + }, + "flag": { + "type": "object", + "description": "Flag authoring rules.", + "properties": { + "exclusiveGroups": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "string" + }, + "minItems": 2 + }, + "description": "Lists of flags that are mutually exclusive. A validator rule enforces that no single effect sequence sets more than one flag in a group to true." + } + }, + "additionalProperties": false } }, "additionalProperties": false