BlueGit

timfa questward

Files

questward / shared / definitions / worldSettings.js

worldSettings.js

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