Skip to content

Declare the scratch-vm surface scratch-gui uses - #1

Merged
Mistium merged 3 commits into
mainfrom
vm-surface
Nov 1, 2026
Merged

Mistium merged 3 commits into
mainfrom
vm-surface

Conversation

@Mistium

@Mistium Mistium commented Nov 1, 2026

Copy link
Copy Markdown
Member

Exact TypeScript declarations for everything scratch-gui uses from scratch-vm, each written by reading the implementation on MistWarp/scratch-vm#37's branch.

What's declared

  • Classes and interfaces: VirtualMachine, Runtime, Target, RenderedTarget, Blocks, Thread, monitors, editing commands, ExtensionManager, SecurityManager, font and asset managers, storage assets, and a minimal renderer interface covering only what the GUI calls. Underscore members the GUI reads today (_blockInfo, _step, _cloneCounter and others) are kept apart in *Internals interfaces.
  • Events: 65 runtime events with their payloads, plus the VM's own map, which lists only the events the VM actually forwards. Unknown event names and wrong listener signatures are type errors.
  • Consumer events: consumers can declare events of their own by augmenting scratch-vm/events, as the GUI does for restore points and pausing.
  • Internal modules the GUI imports directly: argument-type, block-type, fractch-context, rotur/core and the opcode table.
  • Return types follow the VM's real behaviour. While a collaboration editing handler is set, reorder*, rename*, update* and postSpriteInfo can return a Promise, and saveProjectSb3 and exportSprite return types follow the zip type passed in.

Checks

  • npm run check type-checks the declarations and compile tests in test/, with @ts-expect-error negatives for every rejected case.
  • A strict consumer, installed from the packed tarball, type-checks with import VM from 'scratch-vm', import = require and checked JS.
  • 40 real GUI call sites type-check under scratch-gui's strict config.
  • An independent review compared about 70 declarations against the source and found no inaccuracies. The gaps it found are filled.

Bugs found while reading the VM. These are fixed or tracked separately:

There is no visible change.

Type the VM, runtime, targets, blocks, threads, monitors, extension
manager, security manager, editing commands, font and asset managers,
and the renderer calls the GUI makes, all read from scratch-vm
vm-structure. The VM event map now lists only the runtime events the VM
forwards, plus its own events, so vm.on('PROJECT_LOADED') is rejected.
Underscore members the GUI reads live in separate *Internals interfaces.
Also declare the internal modules the GUI imports: argument-type,
block-type, fractch-context, rotur/core and opcodes.generated.json.
Consumers add their own VM and runtime events by augmenting the
VirtualMachineCustomEvents and RuntimeCustomEvents interfaces in
scratch-vm/events; undeclared names are still rejected. Declare the
storage asset fields the GUI reads, type vm.assets, MonitorRecord.get,
FontManager fonts, EditingCommands.extensions and the zip output types
of saveProjectSb3 and exportSprite. Methods the editing handler wraps
now return void or a promise. Drop declarations scratch-gui does not use.
scratch-gui's src/packager calls convertToPackagedRuntime and reads
runtime.peripheralExtensions and runtime.v2BitmapAdapter.
@Mistium
Mistium merged commit 1f60334 into main Nov 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant