Make an editor panel
An editor panel is data (EditorPanelDef): id, name, icon, side, key, and what draws it (a Solid component, or mount for any HTML). List it in your editor scene's panels.
tsx
// in src/editor/waves.tsx
import type { EditorClient, EditorPanelDef, EditorPanelProps } from '@v12-engine/editor'
import { Button, Highlight } from '@v12-engine/client/kit'
import { createMemo, For } from 'solid-js'
/** The waves of the map, kept in the map's data under the game's key: the rules read them as `map.data` */
const KEY = 'mygame.waves'
const wavesOf = (editor: EditorClient): string[][] => (editor.map.data[KEY] as string[][] | undefined) ?? []
function WavesPanel(props: EditorPanelProps) {
const picked = props.panel.state('picked', 0) // kept in this browser with the panel
const filter = props.panel.filter({ placeholder: 'Find a wave: skeleton, 3' }) // Ctrl+F or / in the panel
// drawn again as the map changes (a wave added, undo), and for nothing else: `changes.of` is read as a signal
const waves = createMemo(() => (props.editor.changes.of('map'), wavesOf(props.editor)))
// the best first, a typo's nearest last (`skelton` finds the skeletons); `filterBy` where the list's order is to be kept
const shown = createMemo(() => filter.find(waves().map((wave, index) => ({ wave, index })), [{ name: 'units', get: (each) => each.wave }]))
const add = () => props.editor.edit((map) => map.info.setData(KEY, [...wavesOf(props.editor), ['skeleton', 'skeleton']]), 'Add a wave')
return (
<div class='grid gap-1 p-2'>
<filter.Field />
<For each={shown()}>
{({ item: { wave, index } }) => (
<Button size='sm' variant={index === picked() ? 'chosen' : 'ghost'} onClick={() => picked.set(index)}>
Wave {index + 1}: <Highlight text={wave.join(', ')} query={filter()} />
</Button>
)}
</For>
<Button size='sm' onClick={add}>
Add a wave
</Button>
</div>
)
}
export const wavesPanel: EditorPanelDef = {
id: 'mygame.waves',
name: 'Waves',
icon: 'mygame.wave',
side: 'right',
key: 'Shift+KeyW',
badge: (editor) => wavesOf(editor).length,
help: 'The waves of this map: which units come, in what order. Kept with the map.',
component: WavesPanel
}ts
// in src/main.ts
import { appScenes } from '@v12-engine/client/app'
import { editorScene } from '@v12-engine/editor'
const scenes = appScenes({ game, maps, editor: (scene) => editorScene({ ...scene, panels: [wavesPanel], icons: { 'mygame.wave': waveIcon } }) })Done: a Waves panel on the right rail (Shift+W) lists the map's waves, finds them with Ctrl+F (a typo finds too, and the letters found are marked), and Add a wave is one undo step saved with the map.
Reference
| Call | What it does |
|---|---|
editor.edit((map) => …, label) | Changes the map as one undoable step. |
map.info.setData(key, value) | Keeps data with the map; the rules read it as map.data. |
editor.changes.of('map') | A signal that changes with the map. |
panel.state(name, initial) | A value kept in this browser. |
panel.filter() | The panel's search field; filter.find(items, keys) matches, a typo's nearest last (fuzzy: false to take the words as typed). |
createSearch, fuzzyBy, filterBy, Highlight | The kit's search (@v12-engine/client/kit): a search over any list by weighted keys, with the letters that matched; the component that marks them (Search). |
panel.on(event, …) | Hears map.changed, selection, tool, undo. |
panel.provide(api) | Offers an API to other panels (editor.panels.api). |
editor.bus | Carries your game's own events. |
help, badge | The text behind the header's ?, and a count on the rail. |
For plain DOM, use mount(element, editor, panel) with the kit's pieces (kit.button…). The Code panel's New with code writes a panel stub. See Panels of the editor.