System·phaserthree·v1.0.0·MIT
Dialogue System
Branching JSON-driven dialogue runner with choices and variables. Engine-agnostic — bring your own UI renderer.
#dialogue#narrative#rpg
Install
npx gamecn add dialogue-systemSource preview
Compatibility
| Engines | phaser >=3.80.0 <4.0.0three >=0.160.0 |
| Frameworks | vanilla, react |
| Languages | typescript |
| Bundlers | vite |
Files installed
- {systems}/DialogueSystem.ts
- docs/gamecn/dialogue-system.md(docs)
Notes
Authoring a script
import type { DialogueScript } from "@/systems/DialogueSystem";
const script: DialogueScript = {
start: "intro",
nodes: {
intro: {
id: "intro",
speaker: "Old Man",
text: "Have we met before, traveler?",
choices: [
{ text: "We have.", next: "remember", set: { metBefore: true } },
{ text: "I don't think so.", next: "forget" },
],
},
remember: {
id: "remember",
speaker: "Old Man",
text: "Then you know what I want.",
next: "end",
},
forget: {
id: "forget",
speaker: "Old Man",
text: "Hmph. Then begone.",
next: "end",
},
end: {
id: "end",
text: "(end)",
// no `next` → finishes
},
},
};Running it
import { DialogueSystem } from "@/systems/DialogueSystem";
const dialogue = new DialogueSystem(script);
dialogue.onChange(({ current, finished }) => {
if (finished) {
ui.hide();
return;
}
ui.show(current!.speaker, current!.text, dialogue.visibleChoices());
});
dialogue.start({ playerName: "Max" });
// On UI events:
dialogue.next(); // advance linear node
dialogue.choose(0); // pick visible choice 0Conditional choices
{
text: "Show the king's seal.",
next: "kingResponse",
if: (vars) => vars.hasSeal === true,
}Notes
- The runner is pure logic — ship any UI you like (DOM, Phaser containers, R3F components).
- Variables are an opaque
Record<string, unknown>; structure them however you want. - Pair with
@main/save-loadto persist progress (vars+ current node id).
Related
- Audio ManagerSystem
Web Audio-based SFX and music manager with named buses, volume control, and pluggable buffer loading. Engine-agnostic.
- Input ManagerUtility
Engine-agnostic input action mapper. Map logical actions ('jump', 'left') to keyboard bindings and query state without coupling gameplay code to the DOM keyboard API.
- Mobile JoystickComponent
On-screen virtual joystick for touch input. Renders to a DOM element; exposes a 2D vector for gameplay. Engine-agnostic.
- Save LoadUtility
Type-safe localStorage-backed save system with versioning and migrations. Engine-agnostic.