Add functions for reading optional scene loading text and settings

This commit is contained in:
2026-04-11 04:14:05 +02:00
parent 4a9dea81cf
commit f439d2a873

View File

@@ -140,6 +140,38 @@ function expectString(value: unknown, label: string): string {
return value;
}
function readOptionalSceneLoadingText(value: unknown, label: string): string | null {
if (value === undefined || value === null) {
return null;
}
const normalizedValue = expectString(value, label).trim();
return normalizedValue.length === 0 ? null : normalizedValue;
}
function readSceneLoadingScreen(
value: unknown,
label: string,
options: { allowMissing: boolean }
): SceneLoadingScreenSettings {
if (value === undefined && options.allowMissing) {
return createDefaultSceneLoadingScreenSettings();
}
if (!isRecord(value)) {
throw new Error(`${label} must be an object.`);
}
return {
colorHex: expectString(value.colorHex, `${label}.colorHex`),
headline: readOptionalSceneLoadingText(value.headline, `${label}.headline`),
description: readOptionalSceneLoadingText(
value.description,
`${label}.description`
)
};
}
function expectBoolean(value: unknown, label: string): boolean {
if (typeof value !== "boolean") {
throw new Error(`${label} must be a boolean.`);