From 78ce8810a241b735015ab08b78cc222093acacc0 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Sun, 12 Apr 2026 04:31:52 +0200 Subject: [PATCH] Add validateProjectTimeSettings function and update validation logic --- src/document/scene-document-validation.ts | 47 +++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/document/scene-document-validation.ts b/src/document/scene-document-validation.ts index 2d357ca4..4c5ea525 100644 --- a/src/document/scene-document-validation.ts +++ b/src/document/scene-document-validation.ts @@ -41,6 +41,10 @@ import { type ProjectDocument, type SceneDocument } from "./scene-document"; +import { + HOURS_PER_DAY, + type ProjectTimeSettings +} from "./project-time-settings"; import { isAdvancedRenderingWaterReflectionMode, isAdvancedRenderingShadowMapSize, @@ -572,6 +576,46 @@ function validateWorldSettings( } } +function validateProjectTimeSettings( + time: ProjectTimeSettings, + diagnostics: SceneDiagnostic[], + path = "time" +) { + if (!isFiniteNumber(time.startTimeOfDayHours)) { + diagnostics.push( + createDiagnostic( + "error", + "invalid-project-time-start-hours", + "Project time start-of-day must be a finite hour value.", + `${path}.startTimeOfDayHours` + ) + ); + } else if ( + time.startTimeOfDayHours < 0 || + time.startTimeOfDayHours >= HOURS_PER_DAY + ) { + diagnostics.push( + createDiagnostic( + "error", + "invalid-project-time-start-range", + "Project time start-of-day must stay within the 0..24 hour range.", + `${path}.startTimeOfDayHours` + ) + ); + } + + if (!isPositiveFiniteNumber(time.dayLengthMinutes)) { + diagnostics.push( + createDiagnostic( + "error", + "invalid-project-time-day-length", + "Project time day length must be a positive finite number of real minutes.", + `${path}.dayLengthMinutes` + ) + ); + } +} + function validatePointLightEntity( entity: PointLightEntity, path: string, @@ -2452,6 +2496,7 @@ function filterProjectSceneDiagnostics( (diagnostic) => diagnostic.path === undefined || (!diagnostic.path.startsWith("materials.") && + !diagnostic.path.startsWith("time.") && !diagnostic.path.startsWith("assets.")) ); } @@ -2647,6 +2692,7 @@ export function validateSceneDocument( const diagnostics: SceneDiagnostic[] = []; const seenIds = new Map(); + validateProjectTimeSettings(document.time, diagnostics); validateWorldSettings(document.world, document, diagnostics); for (const [materialKey, material] of Object.entries(document.materials)) { @@ -3091,6 +3137,7 @@ export function validateProjectDocument( ); } + validateProjectTimeSettings(document.time, diagnostics); validateProjectResources(document, diagnostics); for (const [sceneKey, scene] of Object.entries(document.scenes)) {