BlueGit

timfa questward

Files

questward / shared / definitions / worldSettings.js

worldSettings.js

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