| 1 | export const WORLD_SETTING_CATEGORIES = [ |
| 2 | { |
| 3 | id: "simulation", |
| 4 | label: "Simulation", |
| 5 | fields: [ |
| 6 | { |
| 7 | key: "walkTilesPerSecond", |
| 8 | label: "Walk speed (tiles/s)", |
| 9 | hint: "Run is always double this value.", |
| 10 | type: "number", |
| 11 | min: 0.25, |
| 12 | max: 20, |
| 13 | step: 0.25 |
| 14 | }, |
| 15 | { |
| 16 | key: "simulationTickHz", |
| 17 | label: "Simulation tick (Hz)", |
| 18 | hint: "How often the server steps. Movement still uses the walk/run cadence.", |
| 19 | type: "number", |
| 20 | min: 5, |
| 21 | max: 60, |
| 22 | step: 1 |
| 23 | }, |
| 24 | { |
| 25 | key: "regionUnloadGracePeriodMs", |
| 26 | label: "Region unload grace (ms)", |
| 27 | hint: "How long a region stays resident after the last player leaves.", |
| 28 | type: "number", |
| 29 | min: 0, |
| 30 | step: 1000 |
| 31 | } |
| 32 | ] |
| 33 | }, |
| 34 | { |
| 35 | id: "graphics", |
| 36 | label: "Graphics", |
| 37 | fields: [ |
| 38 | { |
| 39 | key: "nightDarkness", |
| 40 | label: "Night darkness", |
| 41 | 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.", |
| 42 | type: "range", |
| 43 | min: 0, |
| 44 | max: 1, |
| 45 | step: 0.01, |
| 46 | previewNightHour: 23 |
| 47 | }, |
| 48 | { |
| 49 | key: "wetSandBand", |
| 50 | label: "Wet sand band", |
| 51 | hint: "How far into sand tiles the wet shoreline blends toward water (0 = off, 1 = full tile). Default 0.6. Winter ice (shallow water) does not wet sand — only deep water does.", |
| 52 | type: "range", |
| 53 | min: 0, |
| 54 | max: 1, |
| 55 | step: 0.01 |
| 56 | }, |
| 57 | { |
| 58 | key: "bloomThreshold", |
| 59 | label: "Bloom threshold", |
| 60 | hint: "Brightness above which bloom-layer pixels start glowing.", |
| 61 | type: "range", |
| 62 | min: 0, |
| 63 | max: 1, |
| 64 | step: 0.01 |
| 65 | }, |
| 66 | { |
| 67 | key: "bloomSoftKnee", |
| 68 | label: "Bloom soft knee", |
| 69 | hint: "Softens the threshold edge.", |
| 70 | type: "range", |
| 71 | min: 0, |
| 72 | max: 1, |
| 73 | step: 0.01 |
| 74 | }, |
| 75 | { |
| 76 | key: "bloomIntensity", |
| 77 | label: "Bloom intensity", |
| 78 | hint: "How strong the bloom glow is.", |
| 79 | type: "range", |
| 80 | min: 0, |
| 81 | max: 4, |
| 82 | step: 0.05 |
| 83 | }, |
| 84 | { |
| 85 | key: "bloomBlurSize", |
| 86 | label: "Bloom blur size", |
| 87 | hint: "Base blur kernel size for the bloom glow.", |
| 88 | type: "range", |
| 89 | min: 0.5, |
| 90 | max: 12, |
| 91 | step: 0.25 |
| 92 | }, |
| 93 | { |
| 94 | key: "bloomSaturation", |
| 95 | label: "Bloom saturation", |
| 96 | hint: "1 is neutral; higher values punch bloom chroma.", |
| 97 | type: "range", |
| 98 | min: 0, |
| 99 | max: 3, |
| 100 | step: 0.05 |
| 101 | }, |
| 102 | { |
| 103 | key: "bloomColorPreserve", |
| 104 | label: "Bloom colour preserve", |
| 105 | hint: "0–1 tint of bloom towards the source sprite hue.", |
| 106 | type: "range", |
| 107 | min: 0, |
| 108 | max: 1, |
| 109 | step: 0.01 |
| 110 | }, |
| 111 | { |
| 112 | key: "bloomDilate", |
| 113 | label: "Bloom dilate", |
| 114 | hint: "Expands tiny bright pixels before blur (texels). 0 disables.", |
| 115 | type: "range", |
| 116 | min: 0, |
| 117 | max: 12, |
| 118 | step: 0.25 |
| 119 | }, |
| 120 | { |
| 121 | key: "bloomScales", |
| 122 | label: "Bloom scales", |
| 123 | hint: "Number of horizontal/vertical blur scale pairs.", |
| 124 | type: "number", |
| 125 | min: 1, |
| 126 | max: 4, |
| 127 | step: 1 |
| 128 | }, |
| 129 | { |
| 130 | key: "bloomHalfRes", |
| 131 | label: "Bloom half-res", |
| 132 | hint: "1 runs dilate/blur at half resolution (cheaper). 0 keeps full resolution.", |
| 133 | type: "number", |
| 134 | min: 0, |
| 135 | max: 1, |
| 136 | step: 1 |
| 137 | } |
| 138 | ] |
| 139 | }, |
| 140 | { |
| 141 | id: "world", |
| 142 | label: "World", |
| 143 | fields: [ |
| 144 | { |
| 145 | key: "defaultGroundTypeId", |
| 146 | label: "Default ground type id", |
| 147 | hint: "Ground used for never-edited chunks (1 = grass).", |
| 148 | type: "number", |
| 149 | min: 1, |
| 150 | step: 1 |
| 151 | } |
| 152 | ] |
| 153 | }, |
| 154 | { |
| 155 | id: "characters", |
| 156 | label: "Characters", |
| 157 | fields: [ |
| 158 | { |
| 159 | key: "characterDeletionDelayMs", |
| 160 | label: "Character deletion delay (ms)", |
| 161 | hint: "Wait time after a character is marked for deletion.", |
| 162 | type: "number", |
| 163 | min: 0, |
| 164 | step: 1000 |
| 165 | } |
| 166 | ] |
| 167 | }, |
| 168 | { |
| 169 | id: "starterEquipment", |
| 170 | label: "Starter Equipment", |
| 171 | /** Custom panel: equipped + inventory for new characters only. */ |
| 172 | panel: "starterEquipment", |
| 173 | fields: [] |
| 174 | }, |
| 175 | { |
| 176 | id: "communication", |
| 177 | label: "Communication", |
| 178 | fields: [ |
| 179 | { |
| 180 | key: "chatMaxCharacters", |
| 181 | label: "Chat max characters", |
| 182 | hint: "Maximum length of a proximity chat line after trimming.", |
| 183 | type: "number", |
| 184 | min: 1, |
| 185 | max: 500, |
| 186 | step: 1 |
| 187 | } |
| 188 | ] |
| 189 | }, |
| 190 | { |
| 191 | id: "inventory", |
| 192 | label: "Inventory", |
| 193 | fields: [ |
| 194 | { |
| 195 | key: "groundItemDespawnDurationMs", |
| 196 | label: "Ground item despawn (ms)", |
| 197 | hint: "How long dropped items remain on the ground.", |
| 198 | type: "number", |
| 199 | min: 0, |
| 200 | step: 1000 |
| 201 | } |
| 202 | ] |
| 203 | }, |
| 204 | { |
| 205 | id: "economy", |
| 206 | label: "Economy", |
| 207 | fields: [ |
| 208 | { |
| 209 | key: "shopPriceLerpDurationMs", |
| 210 | label: "Shop price lerp (ms)", |
| 211 | hint: "How long shop prices take to move towards the last market sale.", |
| 212 | type: "number", |
| 213 | min: 0, |
| 214 | step: 1000 |
| 215 | } |
| 216 | ] |
| 217 | }, |
| 218 | { |
| 219 | id: "basePrices", |
| 220 | label: "Base prices", |
| 221 | /** Custom panel (item seed list); not scalar fields. */ |
| 222 | panel: "itemSeedPrices", |
| 223 | fields: [] |
| 224 | }, |
| 225 | { |
| 226 | id: "equipmentStats", |
| 227 | label: "Equipment Stats", |
| 228 | /** Custom panel: piece × tier bonus tables. */ |
| 229 | panel: "equipmentStats", |
| 230 | fields: [] |
| 231 | }, |
| 232 | { |
| 233 | id: "gameAdmins", |
| 234 | label: "Admins", |
| 235 | /** Game admin accounts (state.sqlite), not world scalar settings. */ |
| 236 | panel: "gameAdmins", |
| 237 | fields: [] |
| 238 | }, |
| 239 | { |
| 240 | id: "courier", |
| 241 | label: "Courier", |
| 242 | fields: [ |
| 243 | { |
| 244 | key: "pigeonTakeoffTilesPerSec", |
| 245 | label: "Pigeon takeoff speed (tiles/s)", |
| 246 | hint: "Speed for the first pigeonPhaseTiles of the flight.", |
| 247 | type: "number", |
| 248 | min: 0.25, |
| 249 | max: 40, |
| 250 | step: 0.25 |
| 251 | }, |
| 252 | { |
| 253 | key: "pigeonCruiseTilesPerSec", |
| 254 | label: "Pigeon cruise speed (tiles/s)", |
| 255 | hint: "Speed after takeoff and before landing. Default 8 overtakes a walking player.", |
| 256 | type: "number", |
| 257 | min: 0.25, |
| 258 | max: 40, |
| 259 | step: 0.25 |
| 260 | }, |
| 261 | { |
| 262 | key: "pigeonLandingTilesPerSec", |
| 263 | label: "Pigeon landing speed (tiles/s)", |
| 264 | hint: "Speed for the last pigeonPhaseTiles of the flight.", |
| 265 | type: "number", |
| 266 | min: 0.25, |
| 267 | max: 40, |
| 268 | step: 0.25 |
| 269 | }, |
| 270 | { |
| 271 | key: "pigeonPhaseTiles", |
| 272 | label: "Pigeon takeoff/landing distance (tiles)", |
| 273 | hint: "How many tiles of the route use takeoff at the start and landing at the end.", |
| 274 | type: "number", |
| 275 | min: 1, |
| 276 | max: 64, |
| 277 | step: 1 |
| 278 | } |
| 279 | ] |
| 280 | } |
| 281 | ]; |
| 282 | |
| 283 | export function allSettingFields () |
| 284 | { |
| 285 | return WORLD_SETTING_CATEGORIES.flatMap((category) => category.fields); |
| 286 | } |
| 287 | |
| 288 | export function formatSettingValue (value) |
| 289 | { |
| 290 | if (typeof value === "number" && !Number.isInteger(value)) |
| 291 | { return String(Math.round(value * 1000) / 1000); } |
| 292 | return String(value); |
| 293 | } |
| 294 | |
| 295 | export function coerceSettingValue (field, raw) |
| 296 | { |
| 297 | if (raw === "" || raw == null) |
| 298 | { return null; } |
| 299 | const value = Number(raw); |
| 300 | if (!Number.isFinite(value)) |
| 301 | { return null; } |
| 302 | let next = value; |
| 303 | if (field.min != null) |
| 304 | { next = Math.max(field.min, next); } |
| 305 | if (field.max != null) |
| 306 | { next = Math.min(field.max, next); } |
| 307 | return next; |
| 308 | } |
| 309 | |
| 310 | export function settingsValuesEqual (a, b) |
| 311 | { |
| 312 | if (typeof a === "number" && typeof b === "number") |
| 313 | { return Math.abs(a - b) < 1e-9; } |
| 314 | return a === b; |
| 315 | } |
| 316 | |
| 317 | export function itemSeedMapsEqual (a, b) |
| 318 | { |
| 319 | const left = a && typeof a === "object" ? a : {}; |
| 320 | const right = b && typeof b === "object" ? b : {}; |
| 321 | const keys = new Set([...Object.keys(left), ...Object.keys(right)]); |
| 322 | for (const key of keys) |
| 323 | { |
| 324 | const lv = left[key]; |
| 325 | const rv = right[key]; |
| 326 | if (lv == null && rv == null) |
| 327 | { continue; } |
| 328 | if (lv == null || rv == null) |
| 329 | { return false; } |
| 330 | if (!settingsValuesEqual(Number(lv), Number(rv))) |
| 331 | { return false; } |
| 332 | } |
| 333 | return true; |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * Diff sparse itemSeedValues maps. Bullets name the item when possible. |
| 338 | * @param {(itemId: number) => string|null} [displayNameFor] |
| 339 | */ |
| 340 | export function diffItemSeedValues (previous, next, displayNameFor = null) |
| 341 | { |
| 342 | const bullets = []; |
| 343 | const prev = previous && typeof previous === "object" ? previous : {}; |
| 344 | const upcoming = next && typeof next === "object" ? next : {}; |
| 345 | const keys = new Set([...Object.keys(prev), ...Object.keys(upcoming)]); |
| 346 | for (const key of [...keys].sort((a, b) => Number(a) - Number(b))) |
| 347 | { |
| 348 | const from = prev[key]; |
| 349 | const to = upcoming[key]; |
| 350 | if (settingsValuesEqual(Number(from), Number(to))) |
| 351 | { continue; } |
| 352 | const itemId = Number(key); |
| 353 | const name = displayNameFor?.(itemId) || `Item ${key}`; |
| 354 | const fromText = from == null ? "default" : formatSettingValue(from); |
| 355 | const toText = to == null ? "default" : formatSettingValue(to); |
| 356 | bullets.push(`${name} seed value changed from ${fromText} to ${toText}.`); |
| 357 | } |
| 358 | return bullets; |
| 359 | } |
| 360 | |
| 361 | export function diffSettings (previous, next, fields = allSettingFields()) |
| 362 | { |
| 363 | const bullets = []; |
| 364 | const changed = {}; |
| 365 | for (const field of fields) |
| 366 | { |
| 367 | if (!Object.prototype.hasOwnProperty.call(next, field.key)) |
| 368 | { continue; } |
| 369 | const from = previous[field.key]; |
| 370 | const to = next[field.key]; |
| 371 | if (settingsValuesEqual(from, to)) |
| 372 | { continue; } |
| 373 | changed[field.key] = to; |
| 374 | bullets.push(`${field.label} changed from ${formatSettingValue(from)} to ${formatSettingValue(to)}.`); |
| 375 | } |
| 376 | return { bullets, changed }; |
| 377 | } |