BlueGit

timfa questward

Files

questward / shared / definitions / worldSettings.js

worldSettings.js

worldSettings.js 8.0 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 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: "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 toward 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: "courier",
218 label: "Courier",
219 fields: [
220 {
221 key: "pigeonTakeoffTilesPerSec",
222 label: "Pigeon takeoff speed (tiles/s)",
223 hint: "Speed for the first pigeonPhaseTiles of the flight.",
224 type: "number",
225 min: 0.25,
226 max: 40,
227 step: 0.25
228 },
229 {
230 key: "pigeonCruiseTilesPerSec",
231 label: "Pigeon cruise speed (tiles/s)",
232 hint: "Speed after takeoff and before landing. Default 8 overtakes a walking player.",
233 type: "number",
234 min: 0.25,
235 max: 40,
236 step: 0.25
237 },
238 {
239 key: "pigeonLandingTilesPerSec",
240 label: "Pigeon landing speed (tiles/s)",
241 hint: "Speed for the last pigeonPhaseTiles of the flight.",
242 type: "number",
243 min: 0.25,
244 max: 40,
245 step: 0.25
246 },
247 {
248 key: "pigeonPhaseTiles",
249 label: "Pigeon takeoff/landing distance (tiles)",
250 hint: "How many tiles of the route use takeoff at the start and landing at the end.",
251 type: "number",
252 min: 1,
253 max: 64,
254 step: 1
255 }
256 ]
257 }
258];
259
260export function allSettingFields ()
261{
262 return WORLD_SETTING_CATEGORIES.flatMap((category) => category.fields);
263}
264
265export function formatSettingValue (value)
266{
267 if (typeof value === "number" && !Number.isInteger(value))
268 { return String(Math.round(value * 1000) / 1000); }
269 return String(value);
270}
271
272export function coerceSettingValue (field, raw)
273{
274 if (raw === "" || raw == null)
275 { return null; }
276 const value = Number(raw);
277 if (!Number.isFinite(value))
278 { return null; }
279 let next = value;
280 if (field.min != null)
281 { next = Math.max(field.min, next); }
282 if (field.max != null)
283 { next = Math.min(field.max, next); }
284 return next;
285}
286
287export function settingsValuesEqual (a, b)
288{
289 if (typeof a === "number" && typeof b === "number")
290 { return Math.abs(a - b) < 1e-9; }
291 return a === b;
292}
293
294export function itemSeedMapsEqual (a, b)
295{
296 const left = a && typeof a === "object" ? a : {};
297 const right = b && typeof b === "object" ? b : {};
298 const keys = new Set([...Object.keys(left), ...Object.keys(right)]);
299 for (const key of keys)
300 {
301 const lv = left[key];
302 const rv = right[key];
303 if (lv == null && rv == null)
304 { continue; }
305 if (lv == null || rv == null)
306 { return false; }
307 if (!settingsValuesEqual(Number(lv), Number(rv)))
308 { return false; }
309 }
310 return true;
311}
312
313/**
314 * Diff sparse itemSeedValues maps. Bullets name the item when possible.
315 * @param {(itemId: number) => string|null} [displayNameFor]
316 */
317export function diffItemSeedValues (previous, next, displayNameFor = null)
318{
319 const bullets = [];
320 const prev = previous && typeof previous === "object" ? previous : {};
321 const upcoming = next && typeof next === "object" ? next : {};
322 const keys = new Set([...Object.keys(prev), ...Object.keys(upcoming)]);
323 for (const key of [...keys].sort((a, b) => Number(a) - Number(b)))
324 {
325 const from = prev[key];
326 const to = upcoming[key];
327 if (settingsValuesEqual(Number(from), Number(to)))
328 { continue; }
329 const itemId = Number(key);
330 const name = displayNameFor?.(itemId) || `Item ${key}`;
331 const fromText = from == null ? "default" : formatSettingValue(from);
332 const toText = to == null ? "default" : formatSettingValue(to);
333 bullets.push(`${name} seed value changed from ${fromText} to ${toText}.`);
334 }
335 return bullets;
336}
337
338export function diffSettings (previous, next, fields = allSettingFields())
339{
340 const bullets = [];
341 const changed = {};
342 for (const field of fields)
343 {
344 if (!Object.prototype.hasOwnProperty.call(next, field.key))
345 { continue; }
346 const from = previous[field.key];
347 const to = next[field.key];
348 if (settingsValuesEqual(from, to))
349 { continue; }
350 changed[field.key] = to;
351 bullets.push(`${field.label} changed from ${formatSettingValue(from)} to ${formatSettingValue(to)}.`);
352 }
353 return { bullets, changed };
354}