BlueGit

timfa questward

Files

questward / shared / definitions / worldSettings.js

worldSettings.js

worldSettings.js 9.7 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: "enclosedDarknessBonus",
50 label: "Enclosed darkness bonus",
51 hint: "Extra ambient darkness inside baked enclosed rooms (interior + enclosing walls/doors). Clamped so ambient never exceeds Night darkness. Build a small walled room, save the chunk, then use Night preview to check.",
52 type: "range",
53 min: 0,
54 max: 1,
55 step: 0.01,
56 previewNightHour: 23
57 },
58 {
59 key: "wetSandBand",
60 label: "Wet sand band",
61 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.",
62 type: "range",
63 min: 0,
64 max: 1,
65 step: 0.01
66 },
67 {
68 key: "bloomThreshold",
69 label: "Bloom threshold",
70 hint: "Brightness above which bloom-layer pixels start glowing.",
71 type: "range",
72 min: 0,
73 max: 1,
74 step: 0.01
75 },
76 {
77 key: "bloomSoftKnee",
78 label: "Bloom soft knee",
79 hint: "Softens the threshold edge.",
80 type: "range",
81 min: 0,
82 max: 1,
83 step: 0.01
84 },
85 {
86 key: "bloomIntensity",
87 label: "Bloom intensity",
88 hint: "How strong the bloom glow is.",
89 type: "range",
90 min: 0,
91 max: 4,
92 step: 0.05
93 },
94 {
95 key: "bloomBlurSize",
96 label: "Bloom blur size",
97 hint: "Base blur kernel size for the bloom glow.",
98 type: "range",
99 min: 0.5,
100 max: 12,
101 step: 0.25
102 },
103 {
104 key: "bloomSaturation",
105 label: "Bloom saturation",
106 hint: "1 is neutral; higher values punch bloom chroma.",
107 type: "range",
108 min: 0,
109 max: 3,
110 step: 0.05
111 },
112 {
113 key: "bloomColorPreserve",
114 label: "Bloom colour preserve",
115 hint: "0–1 tint of bloom towards the source sprite hue.",
116 type: "range",
117 min: 0,
118 max: 1,
119 step: 0.01
120 },
121 {
122 key: "bloomDilate",
123 label: "Bloom dilate",
124 hint: "Expands tiny bright pixels before blur (texels). 0 disables.",
125 type: "range",
126 min: 0,
127 max: 12,
128 step: 0.25
129 },
130 {
131 key: "bloomScales",
132 label: "Bloom scales",
133 hint: "Number of horizontal/vertical blur scale pairs.",
134 type: "number",
135 min: 1,
136 max: 4,
137 step: 1
138 },
139 {
140 key: "bloomHalfRes",
141 label: "Bloom half-res",
142 hint: "1 runs dilate/blur at half resolution (cheaper). 0 keeps full resolution.",
143 type: "number",
144 min: 0,
145 max: 1,
146 step: 1
147 }
148 ]
149 },
150 {
151 id: "world",
152 label: "World",
153 fields: [
154 {
155 key: "defaultGroundTypeId",
156 label: "Default ground type id",
157 hint: "Ground used for never-edited chunks (1 = grass).",
158 type: "number",
159 min: 1,
160 step: 1
161 }
162 ]
163 },
164 {
165 id: "characters",
166 label: "Characters",
167 fields: [
168 {
169 key: "characterDeletionDelayMs",
170 label: "Character deletion delay (ms)",
171 hint: "Wait time after a character is marked for deletion.",
172 type: "number",
173 min: 0,
174 step: 1000
175 }
176 ]
177 },
178 {
179 id: "combat",
180 label: "Combat",
181 fields: [
182 {
183 key: "skullBlackMax",
184 label: "Skull black max",
185 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.",
186 type: "number",
187 min: 1,
188 step: 1
189 },
190 {
191 key: "skullRedMax",
192 label: "Skull red max",
193 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).",
194 type: "number",
195 min: 1,
196 step: 1
197 }
198 ]
199 },
200 {
201 id: "starterEquipment",
202 label: "Starter Equipment",
203 /** Custom panel: equipped + inventory for new characters only. */
204 panel: "starterEquipment",
205 fields: []
206 },
207 {
208 id: "initialQuests",
209 label: "Quests",
210 /** Custom panel: quests granted to new characters (and existing if not started/completed). */
211 panel: "initialQuests",
212 fields: []
213 },
214 {
215 id: "communication",
216 label: "Communication",
217 fields: [
218 {
219 key: "chatMaxCharacters",
220 label: "Chat max characters",
221 hint: "Maximum length of a proximity chat line after trimming.",
222 type: "number",
223 min: 1,
224 max: 500,
225 step: 1
226 }
227 ]
228 },
229 {
230 id: "inventory",
231 label: "Inventory",
232 fields: [
233 {
234 key: "groundItemDespawnDurationMs",
235 label: "Ground item despawn (ms)",
236 hint: "How long dropped items remain on the ground.",
237 type: "number",
238 min: 0,
239 step: 1000
240 }
241 ]
242 },
243 {
244 id: "economy",
245 label: "Economy",
246 fields: [
247 {
248 key: "shopPriceLerpDurationMs",
249 label: "Shop price lerp (ms)",
250 hint: "How long shop prices take to move towards the last market sale.",
251 type: "number",
252 min: 0,
253 step: 1000
254 }
255 ]
256 },
257 {
258 id: "basePrices",
259 label: "Base prices",
260 /** Custom panel (item seed list); not scalar fields. */
261 panel: "itemSeedPrices",
262 fields: []
263 },
264 {
265 id: "equipmentStats",
266 label: "Equipment Stats",
267 /** Custom panel: piece × tier bonus tables. */
268 panel: "equipmentStats",
269 fields: []
270 },
271 {
272 id: "gameAdmins",
273 label: "Admins",
274 /** Game admin accounts (state.sqlite), not world scalar settings. */
275 panel: "gameAdmins",
276 fields: []
277 },
278 {
279 id: "courier",
280 label: "Courier",
281 fields: [
282 {
283 key: "pigeonTakeoffTilesPerSec",
284 label: "Pigeon takeoff speed (tiles/s)",
285 hint: "Speed for the first pigeonPhaseTiles of the flight.",
286 type: "number",
287 min: 0.25,
288 max: 40,
289 step: 0.25
290 },
291 {
292 key: "pigeonCruiseTilesPerSec",
293 label: "Pigeon cruise speed (tiles/s)",
294 hint: "Speed after takeoff and before landing. Default 8 overtakes a walking player.",
295 type: "number",
296 min: 0.25,
297 max: 40,
298 step: 0.25
299 },
300 {
301 key: "pigeonLandingTilesPerSec",
302 label: "Pigeon landing speed (tiles/s)",
303 hint: "Speed for the last pigeonPhaseTiles of the flight.",
304 type: "number",
305 min: 0.25,
306 max: 40,
307 step: 0.25
308 },
309 {
310 key: "pigeonPhaseTiles",
311 label: "Pigeon takeoff/landing distance (tiles)",
312 hint: "How many tiles of the route use takeoff at the start and landing at the end.",
313 type: "number",
314 min: 1,
315 max: 64,
316 step: 1
317 }
318 ]
319 }
320];
321
322export function allSettingFields ()
323{
324 return WORLD_SETTING_CATEGORIES.flatMap((category) => category.fields);
325}
326
327export function formatSettingValue (value)
328{
329 if (typeof value === "number" && !Number.isInteger(value))
330 { return String(Math.round(value * 1000) / 1000); }
331 return String(value);
332}
333
334export function coerceSettingValue (field, raw)
335{
336 if (raw === "" || raw == null)
337 { return null; }
338 const value = Number(raw);
339 if (!Number.isFinite(value))
340 { return null; }
341 let next = value;
342 if (field.min != null)
343 { next = Math.max(field.min, next); }
344 if (field.max != null)
345 { next = Math.min(field.max, next); }
346 return next;
347}
348
349export function settingsValuesEqual (a, b)
350{
351 if (typeof a === "number" && typeof b === "number")
352 { return Math.abs(a - b) < 1e-9; }
353 return a === b;
354}
355
356export function itemSeedMapsEqual (a, b)
357{
358 const left = a && typeof a === "object" ? a : {};
359 const right = b && typeof b === "object" ? b : {};
360 const keys = new Set([...Object.keys(left), ...Object.keys(right)]);
361 for (const key of keys)
362 {
363 const lv = left[key];
364 const rv = right[key];
365 if (lv == null && rv == null)
366 { continue; }
367 if (lv == null || rv == null)
368 { return false; }
369 if (!settingsValuesEqual(Number(lv), Number(rv)))
370 { return false; }
371 }
372 return true;
373}
374
375/**
376 * Diff sparse itemSeedValues maps. Bullets name the item when possible.
377 * @param {(itemId: number) => string|null} [displayNameFor]
378 */
379export function diffItemSeedValues (previous, next, displayNameFor = null)
380{
381 const bullets = [];
382 const prev = previous && typeof previous === "object" ? previous : {};
383 const upcoming = next && typeof next === "object" ? next : {};
384 const keys = new Set([...Object.keys(prev), ...Object.keys(upcoming)]);
385 for (const key of [...keys].sort((a, b) => Number(a) - Number(b)))
386 {
387 const from = prev[key];
388 const to = upcoming[key];
389 if (settingsValuesEqual(Number(from), Number(to)))
390 { continue; }
391 const itemId = Number(key);
392 const name = displayNameFor?.(itemId) || `Item ${key}`;
393 const fromText = from == null ? "default" : formatSettingValue(from);
394 const toText = to == null ? "default" : formatSettingValue(to);
395 bullets.push(`${name} seed value changed from ${fromText} to ${toText}.`);
396 }
397 return bullets;
398}
399
400export function diffSettings (previous, next, fields = allSettingFields())
401{
402 const bullets = [];
403 const changed = {};
404 for (const field of fields)
405 {
406 if (!Object.prototype.hasOwnProperty.call(next, field.key))
407 { continue; }
408 const from = previous[field.key];
409 const to = next[field.key];
410 if (settingsValuesEqual(from, to))
411 { continue; }
412 changed[field.key] = to;
413 bullets.push(`${field.label} changed from ${formatSettingValue(from)} to ${formatSettingValue(to)}.`);
414 }
415 return { bullets, changed };
416}