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 towards 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: "starterEquipment", label: "Starter Equipment", /** Custom panel: equipped + inventory for new characters only. */ panel: "starterEquipment", fields: [] }, { 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 towards the last market sale.", type: "number", min: 0, step: 1000 } ] }, { id: "basePrices", label: "Base prices", /** Custom panel (item seed list); not scalar fields. */ panel: "itemSeedPrices", fields: [] }, { id: "equipmentStats", label: "Equipment Stats", /** Custom panel: piece × tier bonus tables. */ panel: "equipmentStats", fields: [] }, { id: "gameAdmins", label: "Admins", /** Game admin accounts (state.sqlite), not world scalar settings. */ panel: "gameAdmins", fields: [] }, { id: "courier", label: "Courier", fields: [ { key: "pigeonTakeoffTilesPerSec", label: "Pigeon takeoff speed (tiles/s)", hint: "Speed for the first pigeonPhaseTiles of the flight.", type: "number", min: 0.25, max: 40, step: 0.25 }, { key: "pigeonCruiseTilesPerSec", label: "Pigeon cruise speed (tiles/s)", hint: "Speed after takeoff and before landing. Default 8 overtakes a walking player.", type: "number", min: 0.25, max: 40, step: 0.25 }, { key: "pigeonLandingTilesPerSec", label: "Pigeon landing speed (tiles/s)", hint: "Speed for the last pigeonPhaseTiles of the flight.", type: "number", min: 0.25, max: 40, step: 0.25 }, { key: "pigeonPhaseTiles", label: "Pigeon takeoff/landing distance (tiles)", hint: "How many tiles of the route use takeoff at the start and landing at the end.", type: "number", min: 1, max: 64, step: 1 } ] } ]; 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 itemSeedMapsEqual (a, b) { const left = a && typeof a === "object" ? a : {}; const right = b && typeof b === "object" ? b : {}; const keys = new Set([...Object.keys(left), ...Object.keys(right)]); for (const key of keys) { const lv = left[key]; const rv = right[key]; if (lv == null && rv == null) { continue; } if (lv == null || rv == null) { return false; } if (!settingsValuesEqual(Number(lv), Number(rv))) { return false; } } return true; } /** * Diff sparse itemSeedValues maps. Bullets name the item when possible. * @param {(itemId: number) => string|null} [displayNameFor] */ export function diffItemSeedValues (previous, next, displayNameFor = null) { const bullets = []; const prev = previous && typeof previous === "object" ? previous : {}; const upcoming = next && typeof next === "object" ? next : {}; const keys = new Set([...Object.keys(prev), ...Object.keys(upcoming)]); for (const key of [...keys].sort((a, b) => Number(a) - Number(b))) { const from = prev[key]; const to = upcoming[key]; if (settingsValuesEqual(Number(from), Number(to))) { continue; } const itemId = Number(key); const name = displayNameFor?.(itemId) || `Item ${key}`; const fromText = from == null ? "default" : formatSettingValue(from); const toText = to == null ? "default" : formatSettingValue(to); bullets.push(`${name} seed value changed from ${fromText} to ${toText}.`); } return bullets; } 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 }; }