A game that is more than one scene needs a way from one to the next, so the graph can load one (#39)
game-maker / suite (push) Failing after 11m6s

Load scene sets a flag on the World like Stop and Restart do; the swap
happens after the tick, and the last wish of a tick wins. Exactly one
thing crosses over: the SharedState, so global variables and global
machines keep what they know while everything local is built anew.
Loading the scene that is already running rebuilds it, which is what
"reset the level" means when the score must survive.

A run starts either from the start scene (a new project field, set from
the asset panel and marked with an arrow in the list) or from whatever
scene is open. The toggle next to Play says which question is asked and
remembers the answer in localStorage: it is a way of working, not part
of the game.

Sounds no longer end because a scene ends. A voice belongs to the
behavior that started it and stops right after On destroy, so the scene
swap is no longer a special case at all. For the enemy that plays its
explosion and destroys itself in the same breath there is now a
detached input on Play sound.

The scene selector stays usable while a run plays, because a double
click in the asset panel already did the same thing unguarded. It moves
what the editor looks at, not what the run plays.
This commit is contained in:
admin committed 2026-09-15 13:24:26 +02:00
1 parent 30090fc48e
commit 1e9d21cd5d
30 files changed
+976 -57

No files matched your search

+22 -3
View File
@@ -1,5 +1,9 @@
import { AddAnimationFramesCommand } from '../../core/commands/animationCommands';
import { CreateAssetCommand, SetActiveSceneCommand } from '../../core/commands/assetCommands';
import {
CreateAssetCommand,
SetActiveSceneCommand,
SetStartSceneCommand,
} from '../../core/commands/assetCommands';
import { oneStep } from '../../core/commands/CompoundCommand';
import { nextAssetName } from '../../core/commands/naming';
import {
@@ -85,13 +89,23 @@ export class AssetPanel extends Panel {
);
}
/**
* What a scene row says about itself: `●` the one the editor shows, `▶` the one a run begins
* with. Two marks rather than one, because they are two different questions and often two
* different scenes – the level you are editing versus the title screen.
*/
private sceneHint(id: string): string {
const { activeSceneId, startSceneId } = this.state.project;
const marks = `${id === startSceneId ? '▶' : ''}${id === activeSceneId ? '●' : ''}`;
return marks ? `scene ${marks}` : 'scene';
}
private refresh(): void {
const active = this.state.project.activeSceneId;
this.list.setItems(
this.state.project.assets.map((asset) => ({
id: asset.id,
label: asset.name,
hint: asset.type === 'scene' && asset.id === active ? 'scene ●' : asset.type,
hint: asset.type === 'scene' ? this.sceneHint(asset.id) : asset.type,
swatch: hasColorSwatch(asset.type) ? Number(asset.props.color ?? 0) : undefined,
overridden: assetDeviates(this.state.project, asset),
})),
@@ -187,6 +201,11 @@ export class AssetPanel extends Panel {
onSelect: () => this.state.execute(new SetActiveSceneCommand(id)),
disabled: this.state.project.activeSceneId === id,
});
const isStart = this.state.project.startSceneId === id;
items.push({
label: isStart ? 'Clear start scene' : 'Set as start scene',
onSelect: () => this.state.execute(new SetStartSceneCommand(isStart ? '' : id)),
});
}
if (asset.type === 'texture') {
items.push({
+51 -8
View File
@@ -1,7 +1,8 @@
import { Graphics } from 'pixi.js';
import { RenameProjectCommand } from '../../core/commands/projectCommands';
import { listScenes } from '../../core/model/Project';
import { Button, Dropdown, HStack, Label, Spacer, TextField, Theme, type Widget } from '../../ui';
import { Button, Dropdown, HStack, Label, Menu, Spacer, TextField, Theme, type Widget } from '../../ui';
import type { PlayFrom } from '../settings';
import type { EditorState, SaveStatus } from '../state';
/** What the toolbar buttons trigger; the editor supplies the implementations. */
@@ -27,9 +28,10 @@ const SAVE_LABELS: Record<SaveStatus, string> = {
export class Toolbar extends HStack {
private readonly bg = new Graphics();
private readonly projectName: TextField;
private readonly sceneButton: Dropdown;
private readonly sceneSelect: Dropdown;
private readonly undoButton: Button;
private readonly redoButton: Button;
private readonly playFrom: Dropdown;
private readonly playButton: Button;
private readonly pauseButton: Button;
private readonly status: Label;
@@ -58,11 +60,11 @@ export class Toolbar extends HStack {
this.add(new Spacer(Theme.padding));
this.add(new Label('Scene', { style: 'muted' }));
this.sceneButton = new Dropdown('—', {
this.sceneSelect = new Dropdown('—', {
width: 160,
onClick: () => actions.openSceneMenu(this.sceneButton),
onClick: () => actions.openSceneMenu(this.sceneSelect),
});
this.add(this.sceneButton);
this.add(this.sceneSelect);
this.add(new Spacer(Theme.padding));
this.undoButton = new Button('Undo', { onClick: () => state.undo() });
@@ -71,6 +73,12 @@ export class Toolbar extends HStack {
this.add(this.redoButton);
this.add(new Spacer(), 1);
// Next to Play, because it answers a question about Play: which scene does this start?
this.playFrom = new Dropdown('—', {
width: 130,
onClick: () => this.openPlayFromMenu(),
});
this.add(this.playFrom);
this.playButton = new Button('▶ Play', {
variant: 'primary',
width: 110,
@@ -102,6 +110,33 @@ export class Toolbar extends HStack {
this.refresh();
}
/** The start-scene switch for the check scripts: what it says, and where to click it. */
playFromInfo(): { mode: PlayFrom; label: string; scene: string } {
return {
mode: this.state.playFrom,
label: this.playFrom.text,
scene: this.state.sceneToPlay()?.name ?? '',
};
}
/** The switch itself, so a check can open it without hunting for its (elided) caption. */
get playFromButton(): Dropdown {
return this.playFrom;
}
/** The scene selector, for the check scripts – its caption is a scene name, not a fixed label. */
get sceneButton(): Dropdown {
return this.sceneSelect;
}
private openPlayFromMenu(): void {
const mark = (from: PlayFrom, text: string) => (this.state.playFrom === from ? `● ${text}` : text);
new Menu([
{ label: mark('start', 'Start scene'), onSelect: () => this.state.setPlayFrom('start') },
{ label: mark('active', 'Active scene'), onSelect: () => this.state.setPlayFrom('active') },
]).openBelow(this.playFrom);
}
/** Frame rate readout; `null` while no measurement is available yet. */
setFps(fps: number | null): void {
this.fps.setText(fps === null ? '– fps' : `${fps} fps`);
@@ -112,20 +147,28 @@ export class Toolbar extends HStack {
this.projectName.setValue(state.project.name);
const scene = state.activeScene;
const scenes = listScenes(state.project);
this.sceneButton.setText(scene ? scene.name : scenes.length ? 'Select scene' : 'No scene');
this.sceneSelect.setText(scene ? scene.name : scenes.length ? 'Select scene' : 'No scene');
const editing = state.mode === 'edit';
const from = state.sceneToPlay();
// The mode, worded exactly like the menu entry it came from – a caption that reads differently
// from the thing you picked makes you check twice whether you picked the right one.
this.playFrom.setText(state.playFrom === 'active' ? 'Active scene' : 'Start scene');
this.playFrom.setEnabled(editing);
// Undo/redo work in play mode too – on the runtime copy's own history.
this.undoButton.setEnabled(state.commands.canUndo);
this.redoButton.setEnabled(state.commands.canRedo);
this.playButton.setText(editing ? '▶ Play' : '■ Stop');
this.playButton.variant = editing ? 'primary' : 'danger';
this.playButton.setEnabled(scene !== undefined);
this.playButton.setEnabled(from !== undefined);
this.playButton.invalidate();
this.pauseButton.setText(state.paused ? '▶ Resume' : '❚❚ Pause');
this.pauseButton.setEnabled(!editing);
this.pauseButton.invalidate();
this.projectName.setEnabled(editing);
this.sceneButton.setEnabled(editing);
// Stays usable in play mode: it only says which scene the editor looks at, which is the same
// thing a double-click in the Assets panel does – and that one was never blocked. The run is
// not touched by it; a running scene is swapped by `Load scene`, not from here.
this.sceneSelect.setEnabled(true);
this.status.setText(SAVE_LABELS[state.saveStatus]);
this.status.setStyle(state.saveStatus === 'error' || state.saveStatus === 'conflict' ? 'body' : 'small');
}