export const WORLD_SETTING_CATEGORIES = [ { id: "movement", label: "Movement", fields: [ { key: "walkTilesPerSecond", label: "Walk speed (tiles/s)", hint: "Run is always double this value.", type: "number", min: 0.25, max: 20, step: 0.25 } ] }, { id: "simulation", label: "Simulation", fields: [ { key: "simulationTickHz", label: "Simulation tick (Hz)", hint: "How often the server steps. Movement still uses the walk/run cadence.", type: "number", min: 5, max: 60, step: 1 }, { key: "regionUnloadGracePeriodMs", label: "Region unload grace (ms)", hint: "How long a region stays resident after the last player leaves.", type: "number", min: 0, step: 1000 } ] }, { id: "lighting", label: "Lighting", fields: [ { key: "nightDarkness", label: "Night darkness", hint: "How dark unlit tiles become at night. 0 is no extra darkening, 1 is fully black.", type: "range", min: 0, max: 1, step: 0.01 } ] }, { id: "world", label: "World", fields: [ { key: "defaultGroundTypeId", label: "Default ground type id", hint: "Ground used for never-edited chunks (1 = grass).", type: "number", min: 1, step: 1 } ] }, { id: "characters", label: "Characters", fields: [ { key: "characterDeletionDelayMs", label: "Character deletion delay (ms)", hint: "Wait time after a character is marked for deletion.", type: "number", min: 0, step: 1000 } ] }, { id: "economy", label: "Economy & items", fields: [ { key: "shopPriceLerpDurationMs", label: "Shop price lerp (ms)", hint: "How long shop prices take to move toward the last market sale.", type: "number", min: 0, step: 1000 }, { key: "groundItemDespawnDurationMs", label: "Ground item despawn (ms)", hint: "How long dropped items remain on the ground.", type: "number", min: 0, step: 1000 } ] } ]; export function allSettingFields () { return WORLD_SETTING_CATEGORIES.flatMap((category) => category.fields); } export function formatSettingValue (value) { if (typeof value === "number" && !Number.isInteger(value)) { return String(Math.round(value * 1000) / 1000); } return String(value); } export function coerceSettingValue (field, raw) { if (raw === "" || raw == null) { return null; } const value = Number(raw); if (!Number.isFinite(value)) { return null; } let next = value; if (field.min != null) { next = Math.max(field.min, next); } if (field.max != null) { next = Math.min(field.max, next); } return next; } export function diffSettings (previous, next, fields = allSettingFields()) { const bullets = []; const changed = {}; for (const field of fields) { if (!Object.prototype.hasOwnProperty.call(next, field.key)) { continue; } const from = previous[field.key]; const to = next[field.key]; if (from === to) { continue; } changed[field.key] = to; bullets.push(`${field.label} changed from ${formatSettingValue(from)} to ${formatSettingValue(to)}.`); } return { bullets, changed }; }