Section Explorer
scm-js/plugin-section-explorer,
installed from Plugins ▸ Browse Plugins…, is the worked example for api.document.sections and
api.names: Tools ▸ Section Explorer… (Ctrl+Shift+H) is a hex editor that knows the map
file. The left pane is sections.list() with badges for what the registry and the buffer
say (raw, unknown, unsaved, edited, repeated, wrong size, cut short); the middle is a hex
view of sections.bytes(index) drawn only for the rows on screen, coloured by the field
each byte belongs to; the right is the inspector — the section's description, find and
go-to, the field under the cursor with its path, value, meaning and an editing control,
the raw readings in every width, and a structure tree that pages long arrays and follows
the cursor.
layout.ts there is the node model: a schema (a struct of fields, an array of records,
a primitive) is instantiated at an offset into a Node tree whose children are built on
demand, so a terrain section of 32,768 tiles costs nothing until a row of it is looked
at; pathAt / leafAt descend by arithmetic through fixed-stride arrays, leavesIn
walks a byte range for the hex view's colours, and a leaf's Semantic says how its value
is shown (describe, with the record's sibling values, so an action's target reads as
a location, an amount or an AI script depending on the type byte) and edited (a number,
a drop-down from api.names, flag ticks, text). layouts.ts is every section: the
record shapes of UNIT / THG2 / DD2 / MRGN / TRIG / MBRF with one-line summaries, the
fixed tables (VCOD, the settings and restriction tables per revision, PUNI, FORC, CRGB,
…), the per-cell terrain and fog sections, and the string table, whose layout is read
off its own offsets (one leaf per distinct blob, however many indices share it). A
section longer than its layout gets a trailing-bytes leaf; a name with no layout is
shown as plain bytes. buffer.ts is the edit buffer — overwrite, insert, remove, resize,
with its own undo that merges a run of typing into one step — and Apply writes every
changed buffer through sections.write, which is what makes the editor parse the file
again. Both pure modules have tests in that repository.