fix(viewer): normalize legacy door nodes against the schema before render (#303)
Legacy/unparsed door nodes can miss schema-defaulted fields (segments, columnRatios, dividerThickness, panelInset/panelDepth …) and crash the door geometry build (EDITOR-AM). `updateDoorMesh` re-applies the Zod defaults once at entry via `DoorNodeSchema.safeParse` (with a drop-bad-segments retry and a full-defaults fallback), so every downstream read sees populated data — including the shaped-top divider path #334 added. Also normalizes schema-valid legacy doors at load in `migrateNodes`, mirroring the existing stair normalizer, so the door panel and window system see defaulted data too. Reimplemented against main: the original used `segments ?? []` (wrong — legacy doors rendered an empty frame) and missed the #334 `dividerThickness` sites. Verified: `bun run check-types` clean, biome clean on touched files.
This commit is contained in:
@@ -6,6 +6,7 @@ import { create, type StoreApi, type UseBoundStore } from 'zustand'
|
||||
import { BuildingNode } from '../schema'
|
||||
import type { Collection, CollectionId } from '../schema/collections'
|
||||
import { generateCollectionId } from '../schema/collections'
|
||||
import { DoorNode as DoorNodeSchema } from '../schema/nodes/door'
|
||||
import { LevelNode } from '../schema/nodes/level'
|
||||
import {
|
||||
getPitchFromActiveRoofHeight,
|
||||
@@ -106,6 +107,11 @@ function normalizeStairSegmentNode(node: Record<string, unknown>) {
|
||||
return parsed.success ? parsed.data : null
|
||||
}
|
||||
|
||||
function normalizeDoorNode(node: Record<string, unknown>) {
|
||||
const parsed = DoorNodeSchema.safeParse(node)
|
||||
return parsed.success ? { ...node, ...parsed.data } : null
|
||||
}
|
||||
|
||||
function migrateWallSurfaceMaterials(node: Record<string, any>) {
|
||||
const hasInterior =
|
||||
node.interiorMaterial !== undefined || typeof node.interiorMaterialPreset === 'string'
|
||||
@@ -365,6 +371,13 @@ function migrateNodes(nodes: Record<string, any>): Record<string, AnyNode> {
|
||||
}
|
||||
}
|
||||
|
||||
if (node.type === 'door') {
|
||||
const normalized = normalizeDoorNode(node)
|
||||
if (normalized) {
|
||||
patchedNodes[id] = normalized
|
||||
}
|
||||
}
|
||||
|
||||
if (node.type === 'stair') {
|
||||
const normalized = normalizeStairNode(migrateStairSurfaceMaterials(node))
|
||||
if (normalized) {
|
||||
|
||||
Reference in New Issue
Block a user