このページはまだ日本語訳がないため、英語の原文を表示しています。
2D システムcues
github.com/nsgo-dev/game/pkg/cues keeps gameplay presentation mappings in a versioned YAML file, so gameplay code names a cue tag and never an asset. The package owns deterministic parsing and cue lifecycle bookkeeping. A game supplies cues.Hooks to connect the mapping to its particle, audio, camera and sprite systems.
version: 1
cues:
- tag: cue.hit.fire
once: true
particles:
file: fx/hit.yaml
attach: chest
offset:
x: 0.5
"y": -1
sound:
file: sfx/hit.yaml
shake:
amplitude: 0.5
duration: 100ms
flash:
color: '#ff8800'
duration: 50ms
- tag: cue.status.burning
whileActive: true
particles:
file: fx/burning.yaml
sound:
file: sfx/burning.yaml
loop: true
animation: burning
Each cue has a unique dotted tag, sets once, whileActive or both, and names at least one handler: particles (an effect file, an optional attach point and offset), sound (a file, optionally looping), shake (a non-negative amplitude and a duration), flash (a color and a duration on the target sprite) or animation (an animation state). cues.Parse refuses unknown fields, duplicate keys, trailing documents and invalid handlers with a *loaderr.Error naming the field, and cues.Encode writes the set back unchanged. The format is listed on File Formats.
Playing cues
NewPlayer validates the set and builds a client-side dispatcher. Dispatch takes an Event:
EventExecutedfires aoncecue. A one-shot is keyed by tag, target, instance and simulation step, so dispatching the same event again while re-simulating after a rollback does not play it twice.Forgetdrops the records of steps a rollback can no longer return to.EventAddedstarts awhileActivecue on a target, and is ignored while the cue is already active there.EventRemovedstops it, callingHooks.Stoponce.
After a rollback, keep dispatching the re-simulated events, then call Reconcile with the while-active cues of the corrected present state. Cues missing from that state stop, ordered by tag and then target, and newly present cues start in input order; a cue active before and after the rollback keeps playing without a restart. Reset stops every active cue and clears the one-shot records.
Hooks callbacks receive the parsed handler and the original event. Resource loading, pooling and target attachment stay in the game layer. The package imports no sound, rendering or scene code, so a headless server can parse cue files without constructing a player.