| 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: "bloomThreshold", |
| 50 | label: "Bloom threshold", |
| 51 | hint: "Brightness above which bloom-layer pixels start glowing.", |
| 52 | type: "range", |
| 53 | min: 0, |
| 54 | max: 1, |
| 55 | step: 0.01 |
| 56 | }, |
| 57 | { |
| 58 | key: "bloomSoftKnee", |
| 59 | label: "Bloom soft knee", |
| 60 | hint: "Softens the threshold edge.", |
| 61 | type: "range", |
| 62 | min: 0, |
| 63 | max: 1, |
| 64 | step: 0.01 |
| 65 | }, |
| 66 | { |
| 67 | key: "bloomIntensity", |
| 68 | label: "Bloom intensity", |
| 69 | hint: "How strong the bloom glow is.", |
| 70 | type: "range", |
| 71 | min: 0, |
| 72 | max: 4, |
| 73 | step: 0.05 |
| 74 | }, |
| 75 | { |
| 76 | key: "bloomBlurSize", |
| 77 | label: "Bloom blur size", |
| 78 | hint: "Base blur kernel size for the bloom glow.", |
| 79 | type: "range", |
| 80 | min: 0.5, |
| 81 | max: 12, |
| 82 | step: 0.25 |
| 83 | }, |
| 84 | { |
| 85 | key: "bloomSaturation", |
| 86 | label: "Bloom saturation", |
| 87 | hint: "1 is neutral; higher values punch bloom chroma.", |
| 88 | type: "range", |
| 89 | min: 0, |
| 90 | max: 3, |
| 91 | step: 0.05 |
| 92 | }, |
| 93 | { |
| 94 | key: "bloomColorPreserve", |
| 95 | label: "Bloom colour preserve", |
| 96 | hint: "0–1 tint of bloom toward the source sprite hue.", |
| 97 | type: "range", |
| 98 | min: 0, |
| 99 | max: 1, |
| 100 | step: 0.01 |
| 101 | }, |
| 102 | { |
| 103 | key: "bloomDilate", |
| 104 | label: "Bloom dilate", |
| 105 | hint: "Expands tiny bright pixels before blur (texels). 0 disables.", |
| 106 | type: "range", |
| 107 | min: 0, |
| 108 | max: 12, |
| 109 | step: 0.25 |
| 110 | }, |
| 111 | { |
| 112 | key: "bloomScales", |
| 113 | label: "Bloom scales", |
| 114 | hint: "Number of horizontal/vertical blur scale pairs.", |
| 115 | type: "number", |
| 116 | min: 1, |
| 117 | max: 4, |
| 118 | step: 1 |
| 119 | }, |
| 120 | { |
| 121 | key: "bloomHalfRes", |
| 122 | label: "Bloom half-res", |
| 123 | hint: "1 runs dilate/blur at half resolution (cheaper). 0 keeps full resolution.", |
| 124 | type: "number", |
| 125 | min: 0, |
| 126 | max: 1, |
| 127 | step: 1 |
| 128 | } |
| 129 | ] |
| 130 | }, |
| 131 | { |
| 132 | id: "world", |
| 133 | label: "World", |
| 134 | fields: [ |
| 135 | { |
| 136 | key: "defaultGroundTypeId", |
| 137 | label: "Default ground type id", |
| 138 | hint: "Ground used for never-edited chunks (1 = grass).", |
| 139 | type: "number", |
| 140 | min: 1, |
| 141 | step: 1 |
| 142 | } |
| 143 | ] |
| 144 | }, |
| 145 | { |
| 146 | id: "characters", |
| 147 | label: "Characters", |
| 148 | fields: [ |
| 149 | { |
| 150 | key: "characterDeletionDelayMs", |
| 151 | label: "Character deletion delay (ms)", |
| 152 | hint: "Wait time after a character is marked for deletion.", |
| 153 | type: "number", |
| 154 | min: 0, |
| 155 | step: 1000 |
| 156 | } |
| 157 | ] |
| 158 | }, |
| 159 | { |
| 160 | id: "communication", |
| 161 | label: "Communication", |
| 162 | fields: [ |
| 163 | { |
| 164 | key: "chatMaxCharacters", |
| 165 | label: "Chat max characters", |
| 166 | hint: "Maximum length of a proximity chat line after trimming.", |
| 167 | type: "number", |
| 168 | min: 1, |
| 169 | max: 500, |
| 170 | step: 1 |
| 171 | } |
| 172 | ] |
| 173 | }, |
| 174 | { |
| 175 | id: "inventory", |
| 176 | label: "Inventory", |
| 177 | fields: [ |
| 178 | { |
| 179 | key: "groundItemDespawnDurationMs", |
| 180 | label: "Ground item despawn (ms)", |
| 181 | hint: "How long dropped items remain on the ground.", |
| 182 | type: "number", |
| 183 | min: 0, |
| 184 | step: 1000 |
| 185 | } |
| 186 | ] |
| 187 | }, |
| 188 | { |
| 189 | id: "economy", |
| 190 | label: "Economy", |
| 191 | fields: [ |
| 192 | { |
| 193 | key: "shopPriceLerpDurationMs", |
| 194 | label: "Shop price lerp (ms)", |
| 195 | hint: "How long shop prices take to move toward the last market sale.", |
| 196 | type: "number", |
| 197 | min: 0, |
| 198 | step: 1000 |
| 199 | } |
| 200 | ] |
| 201 | } |
| 202 | ]; |
| 203 | |
| 204 | export function allSettingFields () |
| 205 | { |
| 206 | return WORLD_SETTING_CATEGORIES.flatMap((category) => category.fields); |
| 207 | } |
| 208 | |
| 209 | export function formatSettingValue (value) |
| 210 | { |
| 211 | if (typeof value === "number" && !Number.isInteger(value)) |
| 212 | { return String(Math.round(value * 1000) / 1000); } |
| 213 | return String(value); |
| 214 | } |
| 215 | |
| 216 | export function coerceSettingValue (field, raw) |
| 217 | { |
| 218 | if (raw === "" || raw == null) |
| 219 | { return null; } |
| 220 | const value = Number(raw); |
| 221 | if (!Number.isFinite(value)) |
| 222 | { return null; } |
| 223 | let next = value; |
| 224 | if (field.min != null) |
| 225 | { next = Math.max(field.min, next); } |
| 226 | if (field.max != null) |
| 227 | { next = Math.min(field.max, next); } |
| 228 | return next; |
| 229 | } |
| 230 | |
| 231 | export function settingsValuesEqual (a, b) |
| 232 | { |
| 233 | if (typeof a === "number" && typeof b === "number") |
| 234 | { return Math.abs(a - b) < 1e-9; } |
| 235 | return a === b; |
| 236 | } |
| 237 | |
| 238 | export function diffSettings (previous, next, fields = allSettingFields()) |
| 239 | { |
| 240 | const bullets = []; |
| 241 | const changed = {}; |
| 242 | for (const field of fields) |
| 243 | { |
| 244 | if (!Object.prototype.hasOwnProperty.call(next, field.key)) |
| 245 | { continue; } |
| 246 | const from = previous[field.key]; |
| 247 | const to = next[field.key]; |
| 248 | if (settingsValuesEqual(from, to)) |
| 249 | { continue; } |
| 250 | changed[field.key] = to; |
| 251 | bullets.push(`${field.label} changed from ${formatSettingValue(from)} to ${formatSettingValue(to)}.`); |
| 252 | } |
| 253 | return { bullets, changed }; |
| 254 | } |