export const WORLD_SETTING_CATEGORIES = [ { id: "simulation", label: "Simulation", 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 }, { 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: "graphics", label: "Graphics", fields: [ { key: "nightDarkness", label: "Night darkness", hint: "Peak ambient darkening for unlit tiles at night (22–5). Daytime (8–16) stays 0 — use the editor Night preview slider (or save while editing this) to see the effect.", type: "range", min: 0, max: 1, step: 0.01, previewNightHour: 23 }, { key: "bloomThreshold", label: "Bloom threshold", hint: "Brightness above which bloom-layer pixels start glowing.", type: "range", min: 0, max: 1, step: 0.01 }, { key: "bloomSoftKnee", label: "Bloom soft knee", hint: "Softens the threshold edge.", type: "range", min: 0, max: 1, step: 0.01 }, { key: "bloomIntensity", label: "Bloom intensity", hint: "How strong the bloom glow is.", type: "range", min: 0, max: 4, step: 0.05 }, { key: "bloomBlurSize", label: "Bloom blur size", hint: "Base blur kernel size for the bloom glow.", type: "range", min: 0.5, max: 12, step: 0.25 }, { key: "bloomSaturation", label: "Bloom saturation", hint: "1 is neutral; higher values punch bloom chroma.", type: "range", min: 0, max: 3, step: 0.05 }, { key: "bloomColorPreserve", label: "Bloom colour preserve", hint: "0–1 tint of bloom toward the source sprite hue.", type: "range", min: 0, max: 1, step: 0.01 }, { key: "bloomDilate", label: "Bloom dilate", hint: "Expands tiny bright pixels before blur (texels). 0 disables.", type: "range", min: 0, max: 12, step: 0.25 }, { key: "bloomScales", label: "Bloom scales", hint: "Number of horizontal/vertical blur scale pairs.", type: "number", min: 1, max: 4, step: 1 }, { key: "bloomHalfRes", label: "Bloom half-res", hint: "1 runs dilate/blur at half resolution (cheaper). 0 keeps full resolution.", type: "number", min: 0, max: 1, step: 1 } ] }, { 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: "communication", label: "Communication", fields: [ { key: "chatMaxCharacters", label: "Chat max characters", hint: "Maximum length of a proximity chat line after trimming.", type: "number", min: 1, max: 500, step: 1 } ] }, { id: "inventory", label: "Inventory", fields: [ { key: "groundItemDespawnDurationMs", label: "Ground item despawn (ms)", hint: "How long dropped items remain on the ground.", type: "number", min: 0, step: 1000 } ] }, { id: "economy", label: "Economy", 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 } ] } ]; 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 settingsValuesEqual (a, b) { if (typeof a === "number" && typeof b === "number") { return Math.abs(a - b) < 1e-9; } return a === b; } 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 (settingsValuesEqual(from, to)) { continue; } changed[field.key] = to; bullets.push(`${field.label} changed from ${formatSettingValue(from)} to ${formatSettingValue(to)}.`); } return { bullets, changed }; }