Quests, timers & journal
Quests with steps, relationship points, timers and countdowns, achievements and the journal.
Quests
// src/content/quests/jacks_letter/index.ts
export default defineQuest({
title: "Jack's letter",
description: 'Something is waiting in the mailbox.',
steps: { // in order
mailbox: 'Check the mailbox',
read: 'Read the letter',
talk: { // listed from the start, reads "???" until `when` is true
text: 'Talk with Jack',
when: ({ game }) => game.flags.get('took_jacks_letter'),
// hiddenText: '???',
},
},
onStart: ({ game }) => {},
onComplete: ({ game }) => game.items.add('apple', 3, { notify: true }),
})
game.quests.start('jacks_letter') // toast "New quest: …"
game.quests.setStep('jacks_letter', 'read') // typed step ids
game.quests.advance('jacks_letter') // the next step, or done after the last
game.quests.complete('jacks_letter'); game.quests.fail('jacks_letter'); game.quests.reset('jacks_letter')
game.quests.status('jacks_letter') // 'inactive' | 'active' | 'done' | 'failed'
game.quests.step('jacks_letter'); game.quests.isStepDone('jacks_letter', 'mailbox')
const quests = useQuests() // React
The quest log shows finished steps and the current one. Later steps stay out of the list, except steps with a when: those take a line from the start and read hiddenText (default ???) until when returns true or the step is done. useQuests() gives each quest's steps as ready lines (text, masked, done, current).
The quest log is windows/quests, opened from the pause menu. Steps not reached yet stay hidden.
Relationships
Points per character, see Characters.
Timers and countdowns
game.timers.start('bomb', { seconds: 60, label: 'Bomb', event: 'cave/boom' }) // counts down, then starts the event
game.timers.start('race') // no seconds = a stopwatch that counts up
if (await game.timers.wait('bomb')) { … } // true = it ran out, false = stopped first
const took = game.timers.stop('race') // seconds it ran; no event
game.timers.add('bomb', 10) // more time (negative = less)
game.timers.pause('bomb'); game.timers.resume() // one, or all without an id
game.timers.left('bomb'); game.timers.elapsed('race'); game.timers.has('bomb'); game.timers.list()
const timer = useTimer('bomb') // React: { left, elapsed, paused, label } once per second
| Option | |
|---|---|
seconds | Length of a countdown. Without it the timer counts up until stop(). |
label, show | Text in front of the time; show: false keeps it off the screen. |
event | An event started when the countdown runs out. Use this (not wait()) for anything that must still happen after a save is loaded: timers are saved, waiting code is not. |
during | Where it keeps running besides the map: { event: true, minigame: true, window: false }. Missing keys come from content/config/timers.ts. |
// src/content/config/timers.ts
export default defineTimers({
runsDuring: { event: false, minigame: true, window: false }, // battles count as minigames
place: { top: 56, left: 16 }, // CSS position on the screen (used by src/content/ui/Timers.tsx: their layout)
warnSeconds: 10, // the last seconds get the `timerWarning` look
tenthsUnder: 10, // 0:09.4
sounds: { /* tick: 'sfx/tick', end: 'sfx/alarm' */ },
})
Timers never run on the title screen, during a map change or while the game is in the background. Their look is timer and timerWarning in content/look/parts.ts.
Achievements & journal
// src/content/achievements/builder/index.ts
export default defineAchievement({ title: 'Home sweet home', description: 'Help Jack build his house.', secret: false /*, icon */ })
game.achievements.unlock('builder') // once; toast "Achievement: …" ({ notify: false } to skip)
game.achievements.has('builder'); game.achievements.list()
// src/content/codex/anna/index.ts
export default defineCodex({
title: 'Anna', category: 'People', text: 'Runs a small stall…', // image?
// Optional: other versions by game state. The first whose `when` is true is shown.
versions: [
{ when: (game) => game.relationships.get('anna') >= 30, text: 'A close friend…' },
{ when: (game) => game.flags.get('met_anna'), title: 'Anna?', image: strangeAnna },
],
})
game.codex.unlock('anna') // toast "New journal entry: Anna"
game.codex.has('anna'); game.codex.get('anna').entry.text; game.codex.byCategory()
- Achievements are per device (all saves). Secret ones show "???" until earned.
- Achievements, journal entries, endings and title screens unlock the same way:
unlock()istruethe first time, an unknown id only warns in the console and unlocks nothing, and watching a locked scene from Extras (Show all) earns nothing. - Journal entries belong to the playthrough. Only found entries are listed, grouped by
category. - A version replaces only the fields it sets (
title,text,image). Put the strongest condition first. The journal updates by itself when the state changes. - Window
journal(pause menu): Journal and Achievements tabs.