Reduce client item property formatting to metadata-driven rules
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
// Maintainer-controlled web client version.
|
// Maintainer-controlled web client version.
|
||||||
// Format: YYYY.MM.DD Rn (example: 2026.02.20 R2)
|
// Format: YYYY.MM.DD Rn (example: 2026.02.20 R2)
|
||||||
window.CHGRID_WEB_VERSION = "2026.02.25 R273";
|
window.CHGRID_WEB_VERSION = "2026.02.25 R274";
|
||||||
// Optional display timezone for timestamps. Falls back to America/Detroit if unset/invalid.
|
// Optional display timezone for timestamps. Falls back to America/Detroit if unset/invalid.
|
||||||
window.CHGRID_TIME_ZONE = "America/Detroit";
|
window.CHGRID_TIME_ZONE = "America/Detroit";
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import { normalizeDegrees } from '../audio/spatial';
|
|
||||||
import { normalizeRadioChannel, normalizeRadioEffect, normalizeRadioEffectValue } from '../audio/radioStationRuntime';
|
|
||||||
import { type WorldItem } from '../state/gameState';
|
import { type WorldItem } from '../state/gameState';
|
||||||
import {
|
import {
|
||||||
getDefaultClockTimeZone,
|
|
||||||
getEditableItemPropertyKeys,
|
getEditableItemPropertyKeys,
|
||||||
getItemPropertyMetadata,
|
getItemPropertyMetadata,
|
||||||
getItemPropertyOptionValues,
|
getItemPropertyOptionValues,
|
||||||
@@ -48,22 +45,6 @@ export function createItemPropertyPresentation(deps: PresentationDeps): {
|
|||||||
if (key === 'capabilities') return item.capabilities.join(', ') || 'none';
|
if (key === 'capabilities') return item.capabilities.join(', ') || 'none';
|
||||||
if (key === 'useSound') return toSoundDisplayName(item.params.useSound ?? item.useSound);
|
if (key === 'useSound') return toSoundDisplayName(item.params.useSound ?? item.useSound);
|
||||||
if (key === 'emitSound') return toSoundDisplayName(item.params.emitSound ?? item.emitSound);
|
if (key === 'emitSound') return toSoundDisplayName(item.params.emitSound ?? item.emitSound);
|
||||||
if (key === 'timeZone') return String(item.params.timeZone ?? getDefaultClockTimeZone());
|
|
||||||
if (key === 'mediaChannel') return normalizeRadioChannel(item.params.mediaChannel);
|
|
||||||
if (key === 'mediaEffect') return normalizeRadioEffect(item.params.mediaEffect);
|
|
||||||
if (key === 'mediaEffectValue') return String(normalizeRadioEffectValue(item.params.mediaEffectValue));
|
|
||||||
if (key === 'emitEffect') return normalizeRadioEffect(item.params.emitEffect);
|
|
||||||
if (key === 'emitEffectValue') return String(normalizeRadioEffectValue(item.params.emitEffectValue));
|
|
||||||
if (key === 'facing') {
|
|
||||||
const parsed = Number(item.params.facing ?? 0);
|
|
||||||
if (!Number.isFinite(parsed)) return '0';
|
|
||||||
return String(Math.round(normalizeDegrees(parsed) * 10) / 10);
|
|
||||||
}
|
|
||||||
if (key === 'emitRange') {
|
|
||||||
const parsed = Number(item.params.emitRange ?? getItemTypeGlobalProperties(item.type)?.emitRange ?? 15);
|
|
||||||
if (!Number.isFinite(parsed)) return '15';
|
|
||||||
return String(Math.round(parsed));
|
|
||||||
}
|
|
||||||
const metadata = getItemPropertyMetadata(item.type, key);
|
const metadata = getItemPropertyMetadata(item.type, key);
|
||||||
const globalValue = getItemTypeGlobalProperties(item.type)?.[key];
|
const globalValue = getItemTypeGlobalProperties(item.type)?.[key];
|
||||||
const paramValue = item.params[key];
|
const paramValue = item.params[key];
|
||||||
@@ -75,6 +56,19 @@ export function createItemPropertyPresentation(deps: PresentationDeps): {
|
|||||||
if (metadata?.valueType === 'sound') {
|
if (metadata?.valueType === 'sound') {
|
||||||
return toSoundDisplayName(rawValue);
|
return toSoundDisplayName(rawValue);
|
||||||
}
|
}
|
||||||
|
if (metadata?.valueType === 'number') {
|
||||||
|
const parsed = Number(rawValue);
|
||||||
|
if (!Number.isFinite(parsed)) return '';
|
||||||
|
const step = metadata.range?.step;
|
||||||
|
if (step && step > 0 && Number.isFinite(step)) {
|
||||||
|
const precision = String(step).includes('.') ? String(step).split('.')[1]?.length ?? 0 : 0;
|
||||||
|
return String(Number(parsed.toFixed(precision)));
|
||||||
|
}
|
||||||
|
return String(parsed);
|
||||||
|
}
|
||||||
|
if (metadata?.valueType === 'list' || metadata?.valueType === 'text') {
|
||||||
|
return rawValue === undefined || rawValue === null ? '' : String(rawValue);
|
||||||
|
}
|
||||||
if (paramValue !== undefined) return String(paramValue);
|
if (paramValue !== undefined) return String(paramValue);
|
||||||
if (globalValue !== undefined) return String(globalValue);
|
if (globalValue !== undefined) return String(globalValue);
|
||||||
return '';
|
return '';
|
||||||
|
|||||||
Reference in New Issue
Block a user