BlueGit

timfa questward

Files

questward / shared / definitions / worldSettings.js

worldSettings.js

worldSettings.js 6.2 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: "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 id: "courier",
204 label: "Courier",
205 fields: [
206 {
207 key: "pigeonTakeoffTilesPerSec",
208 label: "Pigeon takeoff speed (tiles/s)",
209 hint: "Speed for the first pigeonPhaseTiles of the flight.",
210 type: "number",
211 min: 0.25,
212 max: 40,
213 step: 0.25
214 },
215 {
216 key: "pigeonCruiseTilesPerSec",
217 label: "Pigeon cruise speed (tiles/s)",
218 hint: "Speed after takeoff and before landing. Default 8 overtakes a walking player.",
219 type: "number",
220 min: 0.25,
221 max: 40,
222 step: 0.25
223 },
224 {
225 key: "pigeonLandingTilesPerSec",
226 label: "Pigeon landing speed (tiles/s)",
227 hint: "Speed for the last pigeonPhaseTiles of the flight.",
228 type: "number",
229 min: 0.25,
230 max: 40,
231 step: 0.25
232 },
233 {
234 key: "pigeonPhaseTiles",
235 label: "Pigeon takeoff/landing distance (tiles)",
236 hint: "How many tiles of the route use takeoff at the start and landing at the end.",
237 type: "number",
238 min: 1,
239 max: 64,
240 step: 1
241 }
242 ]
243 }
244];
245
246export function allSettingFields ()
247{
248 return WORLD_SETTING_CATEGORIES.flatMap((category) => category.fields);
249}
250
251export function formatSettingValue (value)
252{
253 if (typeof value === "number" && !Number.isInteger(value))
254 { return String(Math.round(value * 1000) / 1000); }
255 return String(value);
256}
257
258export function coerceSettingValue (field, raw)
259{
260 if (raw === "" || raw == null)
261 { return null; }
262 const value = Number(raw);
263 if (!Number.isFinite(value))
264 { return null; }
265 let next = value;
266 if (field.min != null)
267 { next = Math.max(field.min, next); }
268 if (field.max != null)
269 { next = Math.min(field.max, next); }
270 return next;
271}
272
273export function settingsValuesEqual (a, b)
274{
275 if (typeof a === "number" && typeof b === "number")
276 { return Math.abs(a - b) < 1e-9; }
277 return a === b;
278}
279
280export function diffSettings (previous, next, fields = allSettingFields())
281{
282 const bullets = [];
283 const changed = {};
284 for (const field of fields)
285 {
286 if (!Object.prototype.hasOwnProperty.call(next, field.key))
287 { continue; }
288 const from = previous[field.key];
289 const to = next[field.key];
290 if (settingsValuesEqual(from, to))
291 { continue; }
292 changed[field.key] = to;
293 bullets.push(`${field.label} changed from ${formatSettingValue(from)} to ${formatSettingValue(to)}.`);
294 }
295 return { bullets, changed };
296}