Repository navigation
EN Create Custom Minigame
Français · Type: how-to · Audience: author · Context: engine repository, created project · Status: ready · Applies from: 4.2.5
When none of the built-in minigames fits, a game writes its own in TypeScript and plays it with
the same minigame command. This page walks through one, from the contract to the checks.
The engine ships pipes, cables, pick, hide, runner, stroke, scratch and the code wheel. A game adds its own in the
minigames its module exports (index.ts): an object { run(ctx): Promise<void>; required?: string[] }, where ctx
gives the overlay element, the scale, images, sounds, the params of the command and an abort signal; required
names the params the validator checks. { minigame: 'sword_fight', params: { … }, then: [ … ] } then plays it like a
built-in one. That is the plugin format: the same contract as the built-in ones.
The public module quest-n-click/minigames gives what a plugin needs:
| Name | What |
|---|---|
Minigame |
the contract: run(ctx), and what the validator reads (required, textParams, bindings) |
MinigameCtx |
what a minigame is given: its zone, images, sounds, parameters, labels, an abort signal |
minigames |
the built-in ones (pipes, stroke, pick, hide, runner, scratch, cables, code-wheel), each loaded when it starts |
MINIGAME_CSS |
their shared style |
The full signatures are in the Public API and in
src/engine/minigames/types.ts.
A minigame of your own, registered under an id, that a script or a rule starts with
{ minigame: '<id>', params: { … }, then: [ … ] }; the validator checks its parameters, images and sounds like a
built-in one's, and the player shows it over the scene with the hint voice's frame.
A created project (the module is game/index.ts) or a game of the engine repository (games/<id>/index.ts). The
contract has been public since 4.0; the module is named quest-n-click/minigames since 4.2.5 (web-scumm/minigames
before, removed in 4.3.0: quest-n-click migrate renames it). MinigameCtx.random exists since 4.1.15, the
result a minigame can report since 4.1.16.
- A game that runs: Your first game.
- Basic TypeScript and DOM: the minigame draws itself with the browser's DOM (or a canvas).
- The images and sounds it uses, prepared like the others (Images, Sound effects).
On your machine, in the created project's folder (npx quest-n-click …) or in the engine repository
(GAME=<id> npm run …). The code goes in the game module: game/index.ts in a created project,
games/<id>/index.ts in the engine repository.
-
Write
run(ctx). It fillsctx.root(an element over the scene, 16:10;ctx.uis pixels per logical unit, the root's width / 640), and returns a promise that resolves when the player won or skipped. A minigame never fails by itself: the promise resolves, andthenruns. Clean up whenctx.signalis aborted (the host closes the minigame). Images come fromparamsthroughctx.img(id)andctx.size(id); sounds throughctx.sfx(id);ctx.instruct(text)shows a line in the hint voice's frame;ctx.labels.skipis the game's "Skip" label.// game/index.ts in a created project (games/<id>/index.ts in the engine repository) import type { Minigame } from 'quest-n-click/minigames'; const swordFight: Minigame = { required: ['foe'], textParams: ['intro', 'win'], bindings: { images: ['foe'], sfx: ['hit'] }, run(ctx) { return new Promise<void>((resolve) => { const box = document.createElement('div'); ctx.root.append(box); const done = () => { box.remove(); resolve(); }; ctx.signal.addEventListener('abort', done, { once: true }); if (typeof ctx.params.intro === 'string') ctx.instruct(ctx.params.intro); const foe = document.createElement('img'); foe.src = ctx.img(String(ctx.params.foe)); foe.style.height = `${120 * ctx.u}px`; let hits = 0; foe.addEventListener('click', () => { if (typeof ctx.params.hit === 'string') ctx.sfx(ctx.params.hit); hits += 1; if (hits === 3) { if (typeof ctx.params.win === 'string') ctx.instruct(ctx.params.win); setTimeout(done, 1200); } }); const skip = document.createElement('button'); skip.textContent = ctx.labels.skip; skip.addEventListener('click', () => { box.dispatchEvent(new CustomEvent('mg-skip', { bubbles: true })); done(); }); box.append(foe, skip); }); }, };
-
Declare what the tools read.
required: the params a{ minigame }must give, or the validator refuses it.textParams: dot paths of the player-visible strings inparams(*visits every item of an array or value of an object, as inrounds.*.prompt).bindings: the params that name an image (images) or a sound ofaudio.sfx(sfx), which the validator checks exist. Any string param shaped like an image id (folder/name) is checked as an image too.
-
Register it in the module's
minigames, which the template already exports empty:export const minigames: Record<string, Minigame> = { sword_fight: swordFight };
The player, the Studio and the validator all read this export, merged over the built-in ones. An id that is already a built-in one replaces it for this game.
-
Play it from a rule, a topic or a script:
{ minigame: 'sword_fight', params: { foe: 'pirate/r1c1', hit: 'clang', intro: 'Three hits!', win: 'Touché.' }, then: [{ set: 'pirate_beaten' }] }
-
Say how it ended (optional). The player writes the result in the reserved flag
minigame.<id>:skippedwhen a bubblingmg-skipevent left the minigame's zone (as the Skip button above sends),wonotherwise. To give another result (passed,failed,disabled), dispatch from insidectx.roota bubblingnew CustomEvent('mg-record', { bubbles: true, detail: { result: 'failed' } })before resolving. The story reads it with{ flag: 'minigame.sword_fight', eq: 'failed' }.
-
Check it.
# in the created project npx quest-n-click validate npx quest-n-click dev# in the engine repository GAME=mygame npm run validate GAME=mygame npm run dev
Limit ·
custom-minigame-solverThe solver does not runrun: it counts the minigame as won and runsthen, and records nominigame.<id>flag. Put the minigame's effect on the game inthen(or in the commands after it), never insiderun: the save, the solver and the replay only know the commands.
Limit ·
custom-minigame-i18n-extractnpm run i18n -- extract(npx quest-n-click i18n extract) writes the texts of the built-in minigames' params, not those of a game's own minigame: as of 4.4.0 it reads the game without its module'sminigames. ItstextParamsare applied when the player loads a translation, but you add their paths to the locale file yourself, and a later extract may park them as_stale.
Limit ·
custom-minigame-randomctx.random(a draw from the run'sminigame:<id>stream, the same for the same seed) is given by the engine's player and may be absent under another host. Use it rather thanMath.randomwhen a layout or a timing should replay the same.
validate reports nothing about the command. In the game, the rule opens the minigame over the scene, the hint voice
shows intro, three taps show win and close it, and pirate_beaten is set; Skip closes it at once and then runs
too. The dev journal (?dev) shows the minigame.sword_fight flag change.
| Symptom | Cause | Fix |
|---|---|---|
unknown minigame: "sword_fight" (known: …) |
Not in the module's minigames, or a typo in the id |
Register it under that exact id |
minigame "sword_fight": missing required param "foe" |
The command does not give a param listed in required
|
Add the param, or drop it from required
|
minigame "sword_fight": "foe" must be an image id |
A param of bindings.images is not a string |
Give an image id, folder/name
|
minigame "sword_fight": unknown sound "clang" (audio.sfx) |
A param of bindings.sfx names no sound of audio.sfx
|
Declare the sound (Sound effects) |
… image not found: "pirate/r1c1" |
The image is not cut or not prepared |
npm run assets (npx quest-n-click assets) |
| The minigame never closes |
run's promise never resolves |
Resolve on win, on skip and on ctx.signal abort |
The game module (game/index.ts, or games/<id>/index.ts) and the content that plays it. A player's saves gain the
flag minigame.<id> once the minigame was played.
Remove the command, then the entry in minigames: the validator refuses a command whose minigame is no longer
registered, so it shows every place left. A minigame.<id> flag in older saves stays there and is harmless unless the
story reads it.
-
src/engine/minigames/types.ts: the contract; the built-in minigames beside it are working examples (src/engine/minigames/util.tsholds their helpers, not part of the public API). -
src/engine/dom/presenter.ts: how the player runs a minigame and reads its result. - Built-in minigames, Public API, Custom code for custom commands.
Generated publication · publication générée — current documentation · documentation courante: quest'n'click 4.4.0 r1, documentation revision · révision de la documentation 8dc717c69acb62c4742b69c54a7e7dfb620f75d8.
Earlier versions and permalinks · versions précédentes et liens permanents: https://wanoo.github.io/quest-n-click/docs/
An edit made in this wiki is overwritten at the next publication · une modification faite dans ce wiki est écrasée à la publication suivante.
Edit the source · Modifier la source · Report an error · Signaler une erreur
Index (6)
Start (6)
Play (9)
Install (17)
- Requirements
- Install from the release archive
- Install from npm, once published
- Install from the repository to work on the engine
- doctor: checking your machine
- Image toolchain
- Audio toolchain: ffmpeg, fluidsynth, Furnace, uv
- Upgrade
- Upgrade notes: 4.4
- Upgrade notes: 4.3
- Upgrade notes: 4.2
- Upgrade notes: 4.1
- Upgrade notes: v3
- Upgrade notes: v2 to v3
- Coming from web-scumm
- Package reference
- Install troubleshooting
Create a game (55)
- Your first game
- Layout of a created project and of the engine repository
- The working loop
- Content principles and the identity contract
- Rooms
- Geometry: placement, walk zones, masks, layers, camera
- Something is visible but unreachable
- Reactions
- Game commands
- Conditions
- Flags, variables and events: which to use
- Custom code
- Characters
- Items and inventory
- World map
- Dialogues
- Scripts and events
- Moving characters: patrols and walks
- Exits
- Chapters and objectives
- State and saves: persistent or temporary, renaming an id, migrations
- Staging: wide rooms and animations
- The stage: lights, particles, floors
- Skin and fonts
- Title and credits
- Heroes: several characters and hero choice
- Built-in minigames
- A custom minigame
- Translations
- Music in stems
- Sound effects
- Voices: per language and per hero
- Images: prompts, cutting sheets, transparency, scale
- Asset provenance
- The storyboard, source of truth
- Puzzle design
- Classic mechanics
- Review pages
- DSL reference
- Checking your game
- What the solver proves
- Solver options
- Playtests
- Remix
- Speedrun for authors
- The sealed ending
- Production template
- Example games
- Working with an AI
- Build and release a game
- Publish on GitHub Pages
- The static game on Clever Cloud
- Other static hosts
- Sub-path, cache and service worker, incomplete deploys, going back
- Testing on a phone over the LAN
Local Studio (24)
- The local Studio: overview and launch
- Edit a room
- Placement and stage
- Preview, apply, undo
- Storyboard
- Assets and cutting
- Check: validator, solver, critical path, heat, health, coverage
- Before and after captures
- Semantic diff
- Play and replay a session
- Rule explainer
- Language and objectives
- Voices and the heroes × languages matrix
- Map
- Notes
- Remix in the Studio
- Music
- The Assistant: bring your own key
- Demo mode and studio-apply
- Local and LAN security
- Studio API
- Local MCP: setting up each client
- MCP tools
- Studio troubleshooting
Team Studio (21)
- What runs where
- Concepts: revision, transaction, span, lease, preview, build
- Starting as an invited dev
- Working together day to day
- Roles and actions: the full matrix
- Invitations
- Managing members
- Write refused on the hosted Studio: stale base revision (409)
- Write refused on the hosted Studio: span locked (423)
- Recovering after a lost lease, a disconnection or a stale preview
- Comments
- Map and semantic diff
- Publishing builds
- Remote MCP
- The game in Git
- Upgrading the engine of a hosted game
- Hosted assets
- The server's command line
- Health and metrics routes
- Trying it locally with compose.yml
- Known limits
Clever Cloud (23)
- Clever Cloud: overview, cost and prerequisites
- Apps and add-ons
- Domains and TLS
- Keycloak
- Generic OIDC and GitLab
- Configuration
- First deployment
- Backups
- RPO and RTO
- Restore the Studio on a fresh installation
- Redeploys
- Upgrading the server and checking state after a migration
- Limits of going back
- Monitoring
- Security
- Rotating keys
- Recovering admin access
- Changing domain or OIDC provider
- Worker, PostgreSQL or Cellar down
- Exporting the game and leaving the installation
- Retention
- Clever Cloud troubleshooting
- Costs and teardown
Reality Bridge and connectors (16)
- The Reality Bridge: what it is
- Quick start
- Guarantees
- Install and run the Bridge
- Backup and restore
- Several tenants
- Signals and the manifest
- The Bridge's command line
- Connectors overview
- Email connector
- Telnet connector
- SSH connector
- Open Badges connector
- The connector SDK
- Security: Biscuit and signatures
- Bridge and connector troubleshooting
Contribute (25)
- Welcome
- Developer setup
- The dev loop
- Before a pull request
- Conventions
- Writing documentation
- Architecture
- Code tour
- Import boundaries
- Which tests run when
- Mutation testing
- The coverage ratchet
- The quality baseline
- CI explained
- Field passes
- Benchmarks
- Releasing
- npm packages
- Decisions and ADRs
- Governance
- Bot pull requests
- Contributing with AI agents
- Security policy
- Code of conduct
- Licences and credits