miaoda-game-scenario-cocos
v0.2.0
Published
Cocos Creator skin for miaoda-game-scenario-core: a thin @ccclass Component that runs a data-driven story / event script on a node, resolving blocking commands (a `wait` that awaits the scene scheduler, a `say` that awaits a click) and player choices. For
Maintainers
Readme
miaoda-game-scenario-cocos
Use this Cocos Creator component to play miaoda-game-scenario-core scripts with scene-backed commands, dialogue, choices, and waits.
Install
pnpm add miaoda-game-scenario-cocos miaoda-game-scenario-corecc is an optional peer dependency supplied by your Cocos project.
Minimal story
const story = node.addComponent(ScenarioComponent)
.on('say', (ctx) => dialogueBox.show(ctx.args[0], ctx.args[1]))
.on('show', (ctx) => stage.showActor(ctx.args[0]))
.onChoice((options) => choiceMenu.present(options));
story.load(scriptTextAsset.text);
story.memory.assign({ coin: 8 });
await story.play();wait is built in and uses seconds. Command handlers may return a promise to block until a dialogue, animation, or audio action completes. Use the supplied abort signal in long-running handlers so scene destruction can cancel their UI work.
For simple chapter saves, persist story.memory.toJSON() and call play(label). For exact continuation, save a quiescent story.snapshot, restore it with loadSnapshot, then call resume. Do not checkpoint while a command or choice is waiting.
Public API
ScenarioComponent, command registration, onChoice, load, play, resume, stop, memory, snapshot, and core scenario exports are available. The component does not render dialogue or choices automatically.
