Skip to content

feat(screenmap): add v2 parser + dispatcher with auto-detection - #93

Merged
zackees merged 1 commit into
mainfrom
feat/screenmap-v2-parser
Jun 15, 2026
Merged

zackees merged 1 commit into
mainfrom
feat/screenmap-v2-parser

Conversation

@zackees

@zackees zackees commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Closes #92.

Implements the screenmap v2 schema designed in #88/#90/#91. v1 (FastLED ScreenMap) stays the legacy default; v2 documents are accepted alongside it without changes to downstream tools.

New module: src/screenmap-v2.ts

  • parseScreenmapV2(raw) — parses the v2 shape into a fully-typed ScreenmapV2 with structural + semantic validation: groups resolve, fork parents resolve, offset in range, x/y/z lengths match.
  • detectScreenmapVersion(obj) — auto-detects v1 vs v2 by shape, with explicit \"version\": 1|2\" taking priority.
  • v2ToMultiStripResult(v2) — adapts v2 onto the existing MultiStripParseResult so the shape editor and moviemaker keep working with no changes. One ParsedStrip per v2 segment, keyed by the segment's id.
  • resolveForkOffset(offset, parentLength) — codifies the offset rule from Design loop v3: ideal JSON screenmap (20+ rounds, dual adversary) #91: null/omitted = tip; non-negative = forward index; negative -N = N positions before the tip.

Existing files

  • src/common.ts — parseScreenmapMultiStrip now routes through detectScreenmapVersion. v1 documents take the legacy path; v2 documents are adapted via v2ToMultiStripResult. No signature changes; public surface identical.
  • src/types/domain.ts — new ScreenmapV2, ScreenmapV2Group, ScreenmapV2Segment interfaces. ScreenmapJson (v1) gains optional version field for explicit tagging.

Tests

tests/unit/screenmap-v2.test.ts — 27 new tests:

  • Version detection priority (explicit > shape).
  • Canonical v2 parsing (object + string input).
  • Optional z array round-trip.
  • Fork offset rules (null, positive, negative, range bounds).
  • Validation errors: missing segments, unknown group/parent, length mismatches, wrong explicit version.
  • Adaptation onto MultiStripParseResult for downstream consumers.
  • Dispatcher routing both v1 and v2 through parseScreenmapMultiStrip.

Verification

  • `npm test` — 367/367 pass (was 340)
  • `npm run lint` — clean
  • `npx tsc --noEmit` — clean
  • `npm run build` — succeeds

FastLED-side companion

FastLED parser support landed in FastLED/FastLED#3051 (merged). Together these two PRs close out the design pipeline from #88 → #91 → #92.

Implements the screenmap v2 schema designed in #88/#90/#91 and specified
in #92. v1 (FastLED ScreenMap shape) stays the legacy default; new v2
documents are accepted alongside it without changes to downstream tools.

* `src/screenmap-v2.ts` — new module:
  - `parseScreenmapV2(raw)` parses the v2 shape into a fully-typed
    `ScreenmapV2` with full structural + semantic validation (groups
    resolve, fork parents resolve, offset in range, x/y/z lengths match).
  - `detectScreenmapVersion(obj)` auto-detects v1 vs v2 by shape, with
    explicit `"version": 1|2` taking priority.
  - `v2ToMultiStripResult(v2)` adapts v2 onto the existing
    `MultiStripParseResult` so the shape editor and moviemaker keep
    working with no changes — one ParsedStrip per v2 segment, keyed by
    the segment's `id`.
  - `resolveForkOffset(offset, parentLength)` codifies the offset rule:
    null/omitted = tip; non-negative = forward index; negative `-N` =
    `N` positions before the tip (#91).

* `src/types/domain.ts` — new `ScreenmapV2`, `ScreenmapV2Group`,
  `ScreenmapV2Segment` interfaces. `ScreenmapJson` (v1) gains an
  optional `version` field for explicit tagging; otherwise unchanged.

* `src/common.ts` — `parseScreenmapMultiStrip` now routes through
  `detectScreenmapVersion`. v1 documents take the existing legacy
  path; v2 documents are adapted via `v2ToMultiStripResult`. No
  signature changes; public surface identical.

* `tests/unit/screenmap-v2.test.ts` — 27 new tests cover:
  - Version detection priority (explicit > shape).
  - Canonical v2 parsing (object + string input).
  - Optional `z` array round-trip.
  - Fork offset rules (null, positive, negative, range bounds).
  - Validation errors: missing segments, unknown group/parent, length
    mismatches, wrong explicit version.
  - Adaptation onto `MultiStripParseResult` for downstream consumers.
  - Dispatcher correctly routes v1 and v2 files through
    `parseScreenmapMultiStrip`.

Unit test suite: 367 / 367 pass (was 340). Lint, tsc --noEmit, and
`npm run build` all clean.

Closes #92.
@zackees
zackees merged commit 8edf6b5 into main Jun 15, 2026
4 checks 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.

Implement screenmap v2 schema parser + version dispatch (v1 kept for backward compat)

1 participant