Repository navigation
feat(screenmap): add v2 parser + dispatcher with auto-detection - #93
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.tsparseScreenmapV2(raw)— parses the v2 shape into a fully-typedScreenmapV2with 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 existingMultiStripParseResultso the shape editor and moviemaker keep working with no changes. OneParsedStripper v2 segment, keyed by the segment'sid.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=Npositions before the tip.Existing files
src/common.ts—parseScreenmapMultiStripnow routes throughdetectScreenmapVersion. v1 documents take the legacy path; v2 documents are adapted viav2ToMultiStripResult. No signature changes; public surface identical.src/types/domain.ts— newScreenmapV2,ScreenmapV2Group,ScreenmapV2Segmentinterfaces.ScreenmapJson(v1) gains optionalversionfield for explicit tagging.Tests
tests/unit/screenmap-v2.test.ts— 27 new tests:zarray round-trip.MultiStripParseResultfor downstream consumers.parseScreenmapMultiStrip.Verification
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.