| 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: "combat", |
| 170 | label: "Combat", |
| 171 | fields: [ |
| 172 | { |
| 173 | key: "skullBlackMax", |
| 174 | label: "Skull black max", |
| 175 | hint: "Skull score at pure black. Below this, tint lerps white→black. Above this, town guards treat the player as hostile and tint lerps toward red.", |
| 176 | type: "number", |
| 177 | min: 1, |
| 178 | step: 1 |
| 179 | }, |
| 180 | { |
| 181 | key: "skullRedMax", |
| 182 | label: "Skull red max", |
| 183 | hint: "Skull score at pure red. Between black max and this, tint lerps black→red; beyond it, toward dark red (clamped at 2× this value).", |
| 184 | type: "number", |
| 185 | min: 1, |
| 186 | step: 1 |
| 187 | } |
| 188 | ] |
| 189 | }, |
| 190 | { |
| 191 | id: "starterEquipment", |
| 192 | label: "Starter Equipment", |
| 193 | /** Custom panel: equipped + inventory for new characters only. */ |
| 194 | panel: "starterEquipment", |
| 195 | fields: [] |
| 196 | }, |
| 197 | { |
| 198 | id: "communication", |
| 199 | label: "Communication", |
| 200 | fields: [ |
| 201 | { |
| 202 | key: "chatMaxCharacters", |
| 203 | label: "Chat max characters", |
| 204 | hint: "Maximum length of a proximity chat line after trimming.", |
| 205 | type: "number", |
| 206 | min: 1, |
| 207 | max: 500, |
| 208 | step: 1 |
| 209 | } |
| 210 | ] |
| 211 | }, |
| 212 | { |
| 213 | id: "inventory", |
| 214 | label: "Inventory", |
| 215 | fields: [ |
| 216 | { |
| 217 | key: "groundItemDespawnDurationMs", |
| 218 | label: "Ground item despawn (ms)", |
| 219 | hint: "How long dropped items remain on the ground.", |
| 220 | type: "number", |
| 221 | min: 0, |
| 222 | step: 1000 |
| 223 | } |
| 224 | ] |
| 225 | }, |
| 226 | { |
| 227 | id: "economy", |
| 228 | label: "Economy", |
| 229 | fields: [ |
| 230 | { |
| 231 | key: "shopPriceLerpDurationMs", |
| 232 | label: "Shop price lerp (ms)", |
| 233 | hint: "How long shop prices take to move towards the last market sale.", |
| 234 | type: "number", |
| 235 | min: 0, |
| 236 | step: 1000 |
| 237 | } |
| 238 | ] |
| 239 | }, |
| 240 | { |
| 241 | id: "basePrices", |
| 242 | label: "Base prices", |
| 243 | /** Custom panel (item seed list); not scalar fields. */ |
| 244 | panel: "itemSeedPrices", |
| 245 | fields: [] |
| 246 | }, |
| 247 | { |
| 248 | id: "equipmentStats", |
| 249 | label: "Equipment Stats", |
| 250 | /** Custom panel: piece × tier bonus tables. */ |
| 251 | panel: "equipmentStats", |
| 252 | fields: [] |
| 253 | }, |
| 254 | { |
| 255 | id: "gameAdmins", |
| 256 | label: "Admins", |
| 257 | /** Game admin accounts (state.sqlite), not world scalar settings. */ |
| 258 | panel: "gameAdmins", |
| 259 | fields: [] |
| 260 | }, |
| 261 | { |
| 262 | id: "courier", |
| 263 | label: "Courier", |
| 264 | fields: [ |
| 265 | { |
| 266 | key: "pigeonTakeoffTilesPerSec", |
| 267 | label: "Pigeon takeoff speed (tiles/s)", |
| 268 | hint: "Speed for the first pigeonPhaseTiles of the flight.", |
| 269 | type: "number", |
| 270 | min: 0.25, |
| 271 | max: 40, |
| 272 | step: 0.25 |
| 273 | }, |
| 274 | { |
| 275 | key: "pigeonCruiseTilesPerSec", |
| 276 | label: "Pigeon cruise speed (tiles/s)", |
| 277 | hint: "Speed after takeoff and before landing. Default 8 overtakes a walking player.", |
| 278 | type: "number", |
| 279 | min: 0.25, |
| 280 | max: 40, |
| 281 | step: 0.25 |
| 282 | }, |
| 283 | { |
| 284 | key: "pigeonLandingTilesPerSec", |
| 285 | label: "Pigeon landing speed (tiles/s)", |
| 286 | hint: "Speed for the last pigeonPhaseTiles of the flight.", |
| 287 | type: "number", |
| 288 | min: 0.25, |
| 289 | max: 40, |
| 290 | step: 0.25 |
| 291 | }, |
| 292 | { |
| 293 | key: "pigeonPhaseTiles", |
| 294 | label: "Pigeon takeoff/landing distance (tiles)", |
| 295 | hint: "How many tiles of the route use takeoff at the start and landing at the end.", |
| 296 | type: "number", |
| 297 | min: 1, |
| 298 | max: 64, |
| 299 | step: 1 |
| 300 | } |
| 301 | ] |
| 302 | } |
| 303 | ]; |
| 304 | |
| 305 | export function allSettingFields () |
| 306 | { |
| 307 | return WORLD_SETTING_CATEGORIES.flatMap((category) => category.fields); |
| 308 | } |
| 309 | |
| 310 | export function formatSettingValue (value) |
| 311 | { |
| 312 | if (typeof value === "number" && !Number.isInteger(value)) |
| 313 | { return String(Math.round(value * 1000) / 1000); } |
| 314 | return String(value); |
| 315 | } |
| 316 | |
| 317 | export function coerceSettingValue (field, raw) |
| 318 | { |
| 319 | if (raw === "" || raw == null) |
| 320 | { return null; } |
| 321 | const value = Number(raw); |
| 322 | if (!Number.isFinite(value)) |
| 323 | { return null; } |
| 324 | let next = value; |
| 325 | if (field.min != null) |
| 326 | { next = Math.max(field.min, next); } |
| 327 | if (field.max != null) |
| 328 | { next = Math.min(field.max, next); } |
| 329 | return next; |
| 330 | } |
| 331 | |
| 332 | export function settingsValuesEqual (a, b) |
| 333 | { |
| 334 | if (typeof a === "number" && typeof b === "number") |
| 335 | { return Math.abs(a - b) < 1e-9; } |
| 336 | return a === b; |
| 337 | } |
| 338 | |
| 339 | export function itemSeedMapsEqual (a, b) |
| 340 | { |
| 341 | const left = a && typeof a === "object" ? a : {}; |
| 342 | const right = b && typeof b === "object" ? b : {}; |
| 343 | const keys = new Set([...Object.keys(left), ...Object.keys(right)]); |
| 344 | for (const key of keys) |
| 345 | { |
| 346 | const lv = left[key]; |
| 347 | const rv = right[key]; |
| 348 | if (lv == null && rv == null) |
| 349 | { continue; } |
| 350 | if (lv == null || rv == null) |
| 351 | { return false; } |
| 352 | if (!settingsValuesEqual(Number(lv), Number(rv))) |
| 353 | { return false; } |
| 354 | } |
| 355 | return true; |
| 356 | } |
| 357 | |
| 358 | /** |
| 359 | * Diff sparse itemSeedValues maps. Bullets name the item when possible. |
| 360 | * @param {(itemId: number) => string|null} [displayNameFor] |
| 361 | */ |
| 362 | export function diffItemSeedValues (previous, next, displayNameFor = null) |
| 363 | { |
| 364 | const bullets = []; |
| 365 | const prev = previous && typeof previous === "object" ? previous : {}; |
| 366 | const upcoming = next && typeof next === "object" ? next : {}; |
| 367 | const keys = new Set([...Object.keys(prev), ...Object.keys(upcoming)]); |
| 368 | for (const key of [...keys].sort((a, b) => Number(a) - Number(b))) |
| 369 | { |
| 370 | const from = prev[key]; |
| 371 | const to = upcoming[key]; |
| 372 | if (settingsValuesEqual(Number(from), Number(to))) |
| 373 | { continue; } |
| 374 | const itemId = Number(key); |
| 375 | const name = displayNameFor?.(itemId) || `Item ${key}`; |
| 376 | const fromText = from == null ? "default" : formatSettingValue(from); |
| 377 | const toText = to == null ? "default" : formatSettingValue(to); |
| 378 | bullets.push(`${name} seed value changed from ${fromText} to ${toText}.`); |
| 379 | } |
| 380 | return bullets; |
| 381 | } |
| 382 | |
| 383 | export function diffSettings (previous, next, fields = allSettingFields()) |
| 384 | { |
| 385 | const bullets = []; |
| 386 | const changed = {}; |
| 387 | for (const field of fields) |
| 388 | { |
| 389 | if (!Object.prototype.hasOwnProperty.call(next, field.key)) |
| 390 | { continue; } |
| 391 | const from = previous[field.key]; |
| 392 | const to = next[field.key]; |
| 393 | if (settingsValuesEqual(from, to)) |
| 394 | { continue; } |
| 395 | changed[field.key] = to; |
| 396 | bullets.push(`${field.label} changed from ${formatSettingValue(from)} to ${formatSettingValue(to)}.`); |
| 397 | } |
| 398 | return { bullets, changed }; |
| 399 | } |