Your own menus, and starting scenes yourself
The start screen, the campaign menu, the briefing and the debrief are the client's by default. Each can be drawn your own way while the client keeps doing the work: playing missions, keeping progress, loading saves. And you choose which scene opens first, or open one from your own code.
// in src/main.ts
const campaign = defineCampaign({
id: 'the-long-road',
name: 'The Long Road',
game,
missions,
menu: { component: (props) => <WarMap campaign={props.campaign} /> } // your campaign menu
})
const home = menuScene({
id: 'home',
name: 'Home',
title: 'The Long Road',
buttons: [
{ label: 'Campaign', scene: campaign.menu },
{ label: 'Skirmish', scene: 'play' },
{ label: 'Credits', scene: 'credits' }
],
mount: (element, { scene, goTo }) => drawMyHome(element, scene, goTo) // your start screen
})
const scenes = [home, ...appScenes({ game }).filter((scene) => scene.id !== 'home'), ...campaign.scenes]
startApp({ target: '#game', game, scenes, start: sceneAsked(scenes, 'home') })Your start screen draws three buttons, your war map is the campaign menu, and everything behind them is the client's.
Your own start screen
Keep the client's, change its buttons
appScenes({
game,
home: {
buttons: [{ label: 'Campaign', scene: campaign.menu }], // first
after: [exitButton(shell)], // last
behind: flyover // a game or cinematic playing behind it
},
scenes: { play: { name: 'Skirmish' } } // the client's Play, renamed
})Draw it yourself, keep its buttons
appScenes({
game,
home: {
component: (props) => (
<div class='my-home'>
<h1>{props.scene.title}</h1>
<For each={props.scene.buttons.filter((button) => button.shown?.() ?? true)}>
{(button) => <button onClick={() => (button.run ? button.run(props.goTo) : props.goTo(button.scene!, button.args))}>{button.label}</button>}
</For>
</div>
)
}
})The buttons are plain data (MenuChoice): a label, and either a scene to open (with args) or run(goTo). You only draw them. MenuScreen is the client's, to wrap instead.
Write the start screen from nothing
A menu is a scene like any other; leave appScenes out and list your own:
const play = gameScene({ id: 'play', name: 'Play', game, map: valley, exit: { label: 'Menu', scene: sceneRef('home') } })
const home = menuScene({ id: 'home', name: 'Home', title: 'My game', buttons: [{ label: 'Play', scene: play }], music: 'theme' })
startApp({ target: '#game', game, scenes: [home, play], start: 'home' })exit is where the game's Leave button goes. See Menus for music, a game behind and fetching ahead.
Your own campaign menu
A campaign's menu is given a CampaignController (props.campaign). Draw anything; call it to act.
import { defineCampaign, type CampaignMenuProps } from '@v12-engine/client/app'
function WarMap(props: CampaignMenuProps) {
const campaign = props.campaign
return (
<div class='war-map'>
<For each={campaign.missions}>
{(mission) => (
<button
class='pin'
classList={{ won: !!campaign.won(mission.id), locked: !campaign.reached(mission.id) }}
disabled={!campaign.reached(mission.id)}
onClick={() => campaign.play(mission.id)}
>
{mission.name}
</button>
)}
</For>
<button onClick={() => campaign.play(campaign.next().id)}>Continue</button>
<select value={campaign.difficulty()} onChange={(event) => campaign.setDifficulty(event.currentTarget.value)}>
<For each={campaign.difficulties}>{(difficulty) => <option value={difficulty}>{difficulty}</option>}</For>
</select>
<button onClick={() => campaign.leave()}>Back</button>
</div>
)
}
defineCampaign({ id, name, game, missions, menu: { title: 'The Long Road', component: WarMap } })play(id) goes to the mission's briefing (if it has one), then plays it. A mission is reached once the one before it is won, or as its unlock says. won(id) tells how it went (its time). difficulty() and setDifficulty() are the campaign's difficulty. startOver() forgets the progress; saves lists and loads the campaign's saves.
| Do it with | When |
|---|---|
menu: { title, subtitle, background } | the client's menu, your words and picture |
menu: { component: (props) => <MyFrame><CampaignMenu {...props} /></MyFrame> } | the client's menu in your frame |
menu: { component: WarMap } | your own, in Solid |
menu: { mount: (element, props) => … } | your own, in any HTML, React or Vue; return what takes it away |
Chapters and a difficulty
defineCampaign({
…,
difficulties: ['easy', 'normal', 'hard'],
chapters: [{ id: 'one', name: 'Chapter One', missions: ['homecoming', 'siege'] }, { id: 'two', name: 'Chapter Two', missions: ['warlord'] }]
})The chosen difficulty reaches each mission as MissionContext.difficulty; see AI for missions and campaigns.
Your own briefing and debrief
defineCampaign({
…,
screens: {
briefing: { component: (props) => <Parchment><BriefingScreen {...props} /></Parchment> },
debrief: { mount: (element, props) => drawScroll(element, props) }
}
})The briefing gets begin and back; the debrief gets goOn. A mission's words for both are in its briefing and debrief (or the campaign file). BriefingScreen and DebriefScreen are the client's, to wrap.
Start a scene yourself
Open the app on a scene other than the start screen
startApp({ target: '#game', game, scenes, start: 'play' })start is a scene's id. sceneAsked(scenes, 'home') reads it from the address: /?play opens Play, /?editor the editor, anything else the start screen.
Open a mission straight away
A campaign's missions are one scene that takes the mission as an argument. To open one directly (to test it, or for a "Continue" on your start screen), go to it with its id:
{ label: 'Continue', scene: campaign.mission, args: { mission: 'siege' } } // a menu button
context.goTo(campaign.mission, { mission: 'siege' }) // from a scene of your own
context.goTo(campaign.briefing, { mission: 'siege' }) // through its briefingFor a page that opens on a mission by its address (/?mission=siege), put a scene of your own first that only goes on:
const launcher: Scene = {
id: 'launcher',
name: 'Launcher',
names: [campaign.mission, 'home'],
open: (_element, context) => {
const mission = new URLSearchParams(location.search).get('mission')
if (mission) context.goTo(campaign.mission, { mission })
else context.goTo('home')
return () => {}
}
}
startApp({ target: '#game', game, scenes: [launcher, ...scenes], start: 'launcher' })names lists the scenes it leads to, checked as the app starts.
Start a game with your own map and start
const duel = gameScene({
id: 'duel',
name: 'Duel',
game,
map: (args) => mapsByName[args.map as string] ?? valley,
onStart: (world, { player }) => {
world.spawn('paladin', player, { x: 10, z: 10 })
world.computers.seat(2, { difficulty: 'hard' })
},
exit: { label: 'Menu', scene: sceneRef('home') }
})
context.goTo(duel, { map: 'arena' })onStart runs once the world is made, before the first frame. beforePlay runs on a loaded game too.
One game on a page, no scenes
import { launch } from '@v12-engine/client'
const game = launch({ target: '#game', game: loaded, map: valley, onStart: (world) => setUp(world), leave: { label: 'Quit', run: () => location.assign('/') } })
await game.ready // the GameClient
game.restart() // the same game again, from the startGo to another scene from inside a game
The HUD's Leave button goes to the scene's exit. To leave from your own part or the pause menu, call client.menu.leave(). To go elsewhere, give the scene a way: a game scene of your own receives goTo in its load context, and a menu button's run(goTo) gets it too.
Fetch a scene before the player clicks
menuScene({ id: 'home', name: 'Home', title: 'My game', buttons, warm: [campaign.menu] })
await app.warm(campaign.mission, { mission: 'siege' })Reference
| You want to… | Use |
|---|---|
| the usual scenes in one call | appScenes |
| a menu | menuScene (buttons, behind, music, component, mount) |
| a game | gameScene, mapPlayScene, cinematicScene |
| a campaign | defineCampaign: menu, briefing, debrief, mission, scenes |
| a scene of your own | a Scene: id, name, open(element, context), names |
| a scene's code fetched when it opens | lazyScene |
| the first scene | startApp({ start }), sceneAsked |
| go to a scene | context.goTo(scene, args), MenuChoice.scene, MenuChoice.run |
| scenes added or removed while running | app.scenes.register, app.scenes.remove |
More: Scenes, The start screen, Menus, The campaign menu, Add a scene.