Add profile views to the studio

- Add Cave, Tree, Formation and Fluid profile views beside the scene viewer
- Add a settings form panel that changes the preview only
- Pass typed values with scene requests
- Add view icons in the studio's icon style
This commit is contained in:
piexel committed 2026-11-15 11:17:34 +01:00
1 parent 05984cf64a
commit 8afbff4b42
14 files changed
+256 -5

No files matched your search

@@ -18,6 +18,7 @@ import type {
PatternEntry,
PatternTile,
PickInspection,
ProfileFormState,
SavedStart,
SavedTile,
SavedWorldInfo,
@@ -45,6 +46,8 @@ export interface ScenePlace {
key: string
variant: number
size: number | null
/** Settings typed into a profile form, by name, which only change the preview. */
overrides?: Record<string, string>
}
export interface TileRequest {
@@ -211,6 +214,13 @@ export class BridgeClient {
return this.json(`suggestions?${new URLSearchParams(of)}`)
}
/** A profile entry's settings as a form, with the typed values applied. */
profileForm(viewId: string, key: string, overrides: Record<string, string>, signal?: AbortSignal): Promise<ProfileFormState> {
const query = sceneQuery(viewId, { key, variant: 0, size: null, overrides })
query.delete('variant')
return this.json(`profile-form?${query}`, { signal })
}
sceneEntries(viewId: string): Promise<SceneEntry[]> {
return this.json(`scene-entries?${new URLSearchParams({ view: viewId })}`)
}
@@ -357,6 +367,9 @@ function sceneQuery(viewId: string, place: ScenePlace): URLSearchParams {
if (place.size !== null) {
query.set('size', String(place.size))
}
for (const [name, value] of Object.entries(place.overrides ?? {})) {
query.set(`set.${name}`, value)
}
return query
}
+24
View File
@@ -45,6 +45,30 @@ export interface SceneViewInfo extends ModuleViewInfo {
parts: boolean
/** The sizes the scenes can be built at, or null when each entry has its own. */
sizes: SceneSizes | null
/** Whether each entry has a settings form (a config profile view); absent for the module views. */
form?: boolean
}
/** One setting of a profile form: its value as the preview uses it, and what it is when nothing is typed. */
export interface ProfileField {
name: string
description: string
kind: 'boolean' | 'integer' | 'decimal' | 'enum'
value: string | number | boolean
defaultValue: string | number | boolean
minimum: number | null
maximum: number | null
/** An enum's constants. */
choices: string[]
/** Whether the value was typed into the form. */
changed: boolean
}
/** The settings of a profile as a form, with short lines about it. */
export interface ProfileFormState {
title: string
fields: ProfileField[]
notes: string[]
}
/** The sizes a scene view builds its scenes at, as blocks across, smallest first, and the one shown first (IrisApi SceneSizes). */
@@ -36,6 +36,10 @@ export type IdeIconName =
| 'undo'
| 'web'
| 'views/biomes'
| 'views/cave-profiles'
| 'views/fluid-profiles'
| 'views/formation-profiles'
| 'views/tree-profiles'
| 'views/noise'
| 'views/objects'
| 'views/palettes'
@@ -0,0 +1,4 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M1.5 14.5V9C1.5 5 4.5 2 8 2C11.5 2 14.5 5 14.5 9V14.5" stroke="#6C707E" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M5 14.5V10C5 8.2 6.3 7 8 7C9.7 7 11 8.2 11 10V14.5" stroke="#6C707E" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 360 B

@@ -0,0 +1,4 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M1.5 14.5V9C1.5 5 4.5 2 8 2C11.5 2 14.5 5 14.5 9V14.5" stroke="#CED0D6" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M5 14.5V10C5 8.2 6.3 7 8 7C9.7 7 11 8.2 11 10V14.5" stroke="#CED0D6" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 360 B

@@ -0,0 +1,3 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M8 1.5C8 1.5 3.5 6.5 3.5 9.5C3.5 12 5.5 14.5 8 14.5C10.5 14.5 12.5 12 12.5 9.5C12.5 6.5 8 1.5 8 1.5Z" stroke="#6C707E" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 257 B

@@ -0,0 +1,3 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M8 1.5C8 1.5 3.5 6.5 3.5 9.5C3.5 12 5.5 14.5 8 14.5C10.5 14.5 12.5 12 12.5 9.5C12.5 6.5 8 1.5 8 1.5Z" stroke="#CED0D6" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 257 B

@@ -0,0 +1,4 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M5 14.5C5.5 11 6 8 6.5 5.5C7 3 7.5 1.5 8 1.5C8.5 1.5 9 3 9.5 5.5C10 8 10.5 11 11 14.5" stroke="#6C707E" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M2 14.5H14" stroke="#6C707E" stroke-linecap="round"/>
</svg>

After

Width:  |  Height:  |  Size: 328 B

@@ -0,0 +1,4 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M5 14.5C5.5 11 6 8 6.5 5.5C7 3 7.5 1.5 8 1.5C8.5 1.5 9 3 9.5 5.5C10 8 10.5 11 11 14.5" stroke="#CED0D6" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M2 14.5H14" stroke="#CED0D6" stroke-linecap="round"/>
</svg>

After

Width:  |  Height:  |  Size: 328 B

@@ -0,0 +1,4 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M8 1.5L12.5 8H10.5L13.5 12H2.5L5.5 8H3.5L8 1.5Z" stroke="#6C707E" stroke-linejoin="round"/>
<path d="M8 12V14.5" stroke="#6C707E" stroke-linecap="round"/>
</svg>

After

Width:  |  Height:  |  Size: 267 B

@@ -0,0 +1,4 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M8 1.5L12.5 8H10.5L13.5 12H2.5L5.5 8H3.5L8 1.5Z" stroke="#CED0D6" stroke-linejoin="round"/>
<path d="M8 12V14.5" stroke="#CED0D6" stroke-linecap="round"/>
</svg>

After

Width:  |  Height:  |  Size: 267 B

@@ -0,0 +1,129 @@
import { useState } from 'react'
import { IdeIcon } from '@/components/IdeIcon'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { ScrollArea } from '@/components/ui/scroll-area'
import { cn } from '@/lib/utils'
import type { ProfileField, ProfileFormState } from '../bridge/types'
interface ProfileFormPanelProps {
state: ProfileFormState | null
/** Called with the typed text, or null to go back to what the pack has. */
onChange(name: string, value: string | null): void
onResetAll(): void
className?: string
}
/**
* The settings of the chosen profile as a form beside its scene. What is typed here only changes the preview, so the
* pack's files stay as they are; the header offers to put every value back.
*/
export function ProfileFormPanel({ state, onChange, onResetAll, className }: ProfileFormPanelProps): React.JSX.Element {
const changes = state?.fields.filter((field) => field.changed).length ?? 0
return (
<section className={cn('flex min-h-0 flex-col', className)}>
<div className="flex h-[30px] shrink-0 items-center px-4 pt-1">
<h2 className="min-w-0 flex-1 truncate text-[11px] font-semibold text-muted-foreground">{state?.title ?? 'Settings'}</h2>
{changes > 0 && (
<Button variant="link" size="xs" className="h-auto p-0 text-[11.5px]" title="Put every value back to what the pack has" onClick={onResetAll}>
Reset {changes}
</Button>
)}
</div>
<ScrollArea className="min-h-0 flex-1">
<div className="px-4 pb-2">
{state?.notes.map((note) => (
<p key={note} className="pb-1 text-[11.5px] text-secondary-text">
{note}
</p>
))}
{state?.fields.map((field) => (
<FieldEditor key={`${field.name}:${String(field.value)}`} field={field} onChange={onChange} />
))}
</div>
</ScrollArea>
</section>
)
}
function FieldEditor({ field, onChange }: { field: ProfileField; onChange(name: string, value: string | null): void }): React.JSX.Element {
return (
<div className="py-0.5">
<div className="flex h-7 items-center gap-2">
<label className="min-w-0 flex-[4] truncate text-[12px]" title={field.description}>
{field.name}
</label>
<div className="flex min-w-0 flex-[6] items-center gap-1">
{field.kind === 'boolean' || field.kind === 'enum' ? <ChoiceInput field={field} onChange={onChange} /> : <NumberInput field={field} onChange={onChange} />}
<Button variant="ghost" size="icon-sm" title="Back to the pack's value" className={cn('size-6 shrink-0', !field.changed && 'invisible')} onClick={() => onChange(field.name, null)}>
<IdeIcon name="reset" className="size-3.5" />
</Button>
</div>
</div>
</div>
)
}
function ChoiceInput({ field, onChange }: { field: ProfileField; onChange(name: string, value: string | null): void }): React.JSX.Element {
const choices = field.kind === 'boolean' ? ['true', 'false'] : field.choices
return (
<select
className="h-7 w-full min-w-0 rounded-md border border-input bg-transparent px-1.5 text-[12px] outline-none focus-visible:border-ring dark:bg-input/30"
value={String(field.value)}
title={field.description}
onChange={(event) => onChange(field.name, event.target.value)}
>
{choices.map((choice) => (
<option key={choice} value={choice}>
{choice}
</option>
))}
</select>
)
}
function NumberInput({ field, onChange }: { field: ProfileField; onChange(name: string, value: string | null): void }): React.JSX.Element {
const shown = String(field.value)
const [draft, setDraft] = useState(shown)
const problem = problemWith(field, draft)
const commit = (): void => {
if (draft !== shown && problem === null) {
onChange(field.name, draft.trim())
}
}
return (
<Input
value={draft}
inputMode="decimal"
aria-invalid={problem !== null}
title={problem ?? field.description}
className="h-7 px-2 text-[12px] tabular-nums md:text-[12px]"
onChange={(event) => setDraft(event.target.value)}
onBlur={commit}
onKeyDown={(event) => {
if (event.key === 'Enter') {
commit()
} else if (event.key === 'Escape') {
setDraft(shown)
}
}}
/>
)
}
function problemWith(field: ProfileField, draft: string): string | null {
const number = Number(draft)
if (draft.trim() === '' || !Number.isFinite(number)) {
return 'Not a number'
}
if (field.kind === 'integer' && !Number.isInteger(number)) {
return 'Not a whole number'
}
if (field.minimum !== null && number < field.minimum) {
return `At least ${field.minimum}`
}
if (field.maximum !== null && number > field.maximum) {
return `At most ${field.maximum}`
}
return null
}
+52 -5
View File
@@ -2,7 +2,7 @@ import { useEffect, useMemo, useRef, useState } from 'react'
import { Button } from '@/components/ui/button'
import { ScrollArea } from '@/components/ui/scroll-area'
import type { BridgeClient } from '../bridge/BridgeClient'
import { NO_PART, type JsonPath, type SceneEntry, type SceneViewInfo } from '../bridge/types'
import { NO_PART, type JsonPath, type ProfileFormState, type SceneEntry, type SceneViewInfo } from '../bridge/types'
import { parsedText } from '../editor/jsonValues'
import { nodeDrawingPart, nodeWithPath } from '../editor/nodeLayout'
import { SuggestionStore } from '../editor/suggestionStore'
@@ -21,6 +21,7 @@ import { EntryBrowser } from './EntryBrowser'
import { useEntryFiles } from './EntryFileDialogs'
import { NodeInspector } from './NodeInspector'
import { NodePane } from './NodePane'
import { ProfileFormPanel } from './ProfileFormPanel'
import { Panel, SidebarPanel, SizeChoice, Stepper, ViewIsland } from './Sidebar'
import { SceneViewport, type PickedSurface } from './SceneViewport'
@@ -72,7 +73,21 @@ export function SceneStudio({ client, view, packRevision, onSummary, tell }: Sce
const [pickedPart, setPickedPart] = useState(NO_PART)
const highlightedPart = view.parts ? (selected?.partId ?? pickedPart) : NO_PART
const { scene, shown, sceneParts, building } = useSceneMesh(client, view, entry, variant, size, packRevision, models, images, farLeavesOnly, highlightedPart, tell)
const [typed, setTyped] = useState<{ owner: string; values: Record<string, string> }>({ owner: '', values: NO_OVERRIDES })
const typedOwner = `${view.id}:${entry?.key ?? ''}`
const overrides = typed.owner === typedOwner ? typed.values : NO_OVERRIDES
const changeSetting = (name: string, value: string | null): void =>
setTyped((current) => {
const next = { ...(current.owner === typedOwner ? current.values : NO_OVERRIDES) }
if (value === null) {
delete next[name]
} else {
next[name] = value
}
return { owner: typedOwner, values: next }
})
const profileForm = useProfileForm(client, view, entry?.key ?? null, overrides, packRevision, tell)
const { scene, shown, sceneParts, building } = useSceneMesh(client, view, entry, variant, size, overrides, packRevision, models, images, farLeavesOnly, highlightedPart, tell)
const shownScene = shown?.scene ?? null
const blockIndex = useMemo(() => (shownScene === null ? null : new BlockIndex(shownScene)), [shownScene])
const shownParts = partsOf(sceneParts, shownScene)
@@ -143,7 +158,8 @@ export function SceneStudio({ client, view, packRevision, onSummary, tell }: Sce
/>
)}
</div>
<Panel className={view.editable ? 'w-[300px]' : 'w-[250px]'}>
<Panel className={view.editable || view.form ? 'w-[300px]' : 'w-[250px]'}>
{view.form === true && <ProfileFormPanel className="flex-[5]" state={profileForm} onChange={changeSetting} onResetAll={() => setTyped({ owner: typedOwner, values: NO_OVERRIDES })} />}
{view.baked && entry !== null && <BakeMeter timing={bakeTiming} />}
{selected !== null && editor.state !== null ? (
<NodeInspector key={JSON.stringify(selected.path)} node={selected} state={editor.state} values={values} suggestions={suggestions} onEdit={editor.edit} />
@@ -217,6 +233,35 @@ function partNote(parts: Int32Array, part: number): string {
return blocks === 0 ? ' · part has no blocks here' : ` · part has ${NUMBER.format(blocks)}`
}
const NO_OVERRIDES: Record<string, string> = {}
/** The settings form of the chosen profile with the typed values applied, for a view that has one; read again after the pack reloads. */
function useProfileForm(
client: BridgeClient,
view: SceneViewInfo,
key: string | null,
overrides: Record<string, string>,
packRevision: number,
tell: (message: string) => void
): ProfileFormState | null {
const [form, setForm] = useState<ProfileFormState | null>(null)
const overridesKey = JSON.stringify(overrides)
const hasForm = view.form === true
useEffect(() => {
if (!hasForm || key === null) {
setForm(null)
return
}
const stop = new AbortController()
client
.profileForm(view.id, key, JSON.parse(overridesKey) as Record<string, string>, stop.signal)
.then((found) => !stop.signal.aborted && setForm(found))
.catch((failure: Error) => !stop.signal.aborted && tell(failure.message))
return () => stop.abort()
}, [client, view.id, hasForm, key, overridesKey, packRevision, tell])
return form
}
function useSceneEntries(client: BridgeClient, viewId: string, packRevision: number, tell: (message: string) => void): SceneEntry[] {
const [entries, setEntries] = useState<SceneEntry[]>([])
useEffect(() => {
@@ -259,6 +304,7 @@ function useSceneMesh(
entry: SceneEntry | null,
variant: number,
size: number | null,
overrides: Record<string, string>,
packRevision: number,
models: BlockModels,
images: BridgeAssets,
@@ -274,13 +320,14 @@ function useSceneMesh(
const key = entry?.key ?? null
const viewId = view.id
const hasParts = view.parts
const overridesKey = JSON.stringify(overrides)
useEffect(() => {
if (key === null) {
return
}
const stop = new AbortController()
const place = { key, variant, size }
const place = { key, variant, size, overrides: JSON.parse(overridesKey) as Record<string, string> }
setBuilding(true)
client
.scene(viewId, place, stop.signal)
@@ -304,7 +351,7 @@ function useSceneMesh(
setBuilding(false)
})
return () => stop.abort()
}, [client, viewId, hasParts, key, variant, size, packRevision, tell])
}, [client, viewId, hasParts, key, variant, size, overridesKey, packRevision, tell])
const faint = useMemo(() => {
const parts = partsOf(sceneParts, scene)
@@ -12,6 +12,10 @@ const VIEW_ICONS: Record<string, IdeIconName> = {
biomes: 'views/biomes',
regions: 'views/regions',
rivers: 'views/rivers',
caveProfiles: 'views/cave-profiles',
treeProfiles: 'views/tree-profiles',
formationProfiles: 'views/formation-profiles',
fluidProfiles: 'views/fluid-profiles',
world3d: 'views/world-3d',
savedWorld: 'views/saved-world',
'iris:terrain/palettes': 'views/palettes',