BlueGit

timfa questward

Files

questward / shared / definitions / worldSettings.js

worldSettings.js

worldSettings.js 3.1 KiB Download Raw
1export const WORLD_SETTING_CATEGORIES = [
2 {
3 id: "movement",
4 label: "Movement",
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 },
17 {
18 id: "simulation",
19 label: "Simulation",
20 fields: [
21 {
22 key: "simulationTickHz",
23 label: "Simulation tick (Hz)",
24 hint: "How often the server steps. Movement still uses the walk/run cadence.",
25 type: "number",
26 min: 5,
27 max: 60,
28 step: 1
29 },
30 {
31 key: "regionUnloadGracePeriodMs",
32 label: "Region unload grace (ms)",
33 hint: "How long a region stays resident after the last player leaves.",
34 type: "number",
35 min: 0,
36 step: 1000
37 }
38 ]
39 },
40 {
41 id: "lighting",
42 label: "Lighting",
43 fields: [
44 {
45 key: "nightDarkness",
46 label: "Night darkness",
47 hint: "How dark unlit tiles become at night. 0 is no extra darkening, 1 is fully black.",
48 type: "range",
49 min: 0,
50 max: 1,
51 step: 0.01
52 }
53 ]
54 },
55 {
56 id: "world",
57 label: "World",
58 fields: [
59 {
60 key: "defaultGroundTypeId",
61 label: "Default ground type id",
62 hint: "Ground used for never-edited chunks (1 = grass).",
63 type: "number",
64 min: 1,
65 step: 1
66 }
67 ]
68 },
69 {
70 id: "characters",
71 label: "Characters",
72 fields: [
73 {
74 key: "characterDeletionDelayMs",
75 label: "Character deletion delay (ms)",
76 hint: "Wait time after a character is marked for deletion.",
77 type: "number",
78 min: 0,
79 step: 1000
80 }
81 ]
82 },
83 {
84 id: "economy",
85 label: "Economy & items",
86 fields: [
87 {
88 key: "shopPriceLerpDurationMs",
89 label: "Shop price lerp (ms)",
90 hint: "How long shop prices take to move toward the last market sale.",
91 type: "number",
92 min: 0,
93 step: 1000
94 },
95 {
96 key: "groundItemDespawnDurationMs",
97 label: "Ground item despawn (ms)",
98 hint: "How long dropped items remain on the ground.",
99 type: "number",
100 min: 0,
101 step: 1000
102 }
103 ]
104 }
105];
106
107export function allSettingFields ()
108{
109 return WORLD_SETTING_CATEGORIES.flatMap((category) => category.fields);
110}
111
112export function formatSettingValue (value)
113{
114 if (typeof value === "number" && !Number.isInteger(value))
115 { return String(Math.round(value * 1000) / 1000); }
116 return String(value);
117}
118
119export function coerceSettingValue (field, raw)
120{
121 if (raw === "" || raw == null)
122 { return null; }
123 const value = Number(raw);
124 if (!Number.isFinite(value))
125 { return null; }
126 let next = value;
127 if (field.min != null)
128 { next = Math.max(field.min, next); }
129 if (field.max != null)
130 { next = Math.min(field.max, next); }
131 return next;
132}
133
134export function diffSettings (previous, next, fields = allSettingFields())
135{
136 const bullets = [];
137 const changed = {};
138 for (const field of fields)
139 {
140 if (!Object.prototype.hasOwnProperty.call(next, field.key))
141 { continue; }
142 const from = previous[field.key];
143 const to = next[field.key];
144 if (from === to)
145 { continue; }
146 changed[field.key] = to;
147 bullets.push(`${field.label} changed from ${formatSettingValue(from)} to ${formatSettingValue(to)}.`);
148 }
149 return { bullets, changed };
150}