@doodle-engine/core 0.0.17 ā 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/assets/loader.d.ts +34 -0
- package/dist/assets/loader.d.ts.map +1 -0
- package/dist/assets/manifest.d.ts +20 -0
- package/dist/assets/manifest.d.ts.map +1 -0
- package/dist/core.cjs +2 -2
- package/dist/core.js +594 -492
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/assets.d.ts +45 -0
- package/dist/types/assets.d.ts.map +1 -0
- package/dist/types/conditions.d.ts +1 -1
- package/dist/types/effects.d.ts +4 -4
- package/dist/types/entities.d.ts +39 -1
- package/dist/types/entities.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/core.js
CHANGED
|
@@ -1,233 +1,332 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var T = (
|
|
4
|
-
function
|
|
5
|
-
|
|
1
|
+
var k = Object.defineProperty;
|
|
2
|
+
var O = (n, e, t) => e in n ? k(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
|
+
var T = (n, e, t) => O(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
function Fe(n) {
|
|
5
|
+
var t;
|
|
6
|
+
const e = ((t = n.split(".").pop()) == null ? void 0 : t.toLowerCase()) ?? "";
|
|
7
|
+
return ["jpg", "jpeg", "png", "gif", "webp", "svg", "avif"].includes(e) ? "image" : ["mp4", "webm", "ogv", "mov"].includes(e) ? "video" : "audio";
|
|
8
|
+
}
|
|
9
|
+
function qe(n, e) {
|
|
10
|
+
const t = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set();
|
|
11
|
+
if (e.shell) {
|
|
12
|
+
const { splash: o, loading: i, title: s, uiSounds: l } = e.shell;
|
|
13
|
+
o && (o.logo && t.add(o.logo), o.background && t.add(o.background), o.sound && t.add(o.sound)), i && (i.background && t.add(i.background), i.music && t.add(i.music)), s && (s.logo && t.add(s.logo), s.background && t.add(s.background), s.music && t.add(s.music)), l && (l.click && t.add(l.click), l.hover && t.add(l.hover), l.menuOpen && t.add(l.menuOpen), l.menuClose && t.add(l.menuClose));
|
|
14
|
+
}
|
|
15
|
+
const a = (o) => {
|
|
16
|
+
o && !t.has(o) && r.add(o);
|
|
17
|
+
};
|
|
18
|
+
for (const o of Object.values(n.locations))
|
|
19
|
+
a(o.banner), a(o.music), a(o.ambient);
|
|
20
|
+
for (const o of Object.values(n.characters))
|
|
21
|
+
a(o.portrait);
|
|
22
|
+
for (const o of Object.values(n.items))
|
|
23
|
+
a(o.icon), a(o.image);
|
|
24
|
+
for (const o of Object.values(n.maps))
|
|
25
|
+
a(o.image);
|
|
26
|
+
for (const o of Object.values(n.interludes))
|
|
27
|
+
if (a(o.background), a(o.banner), a(o.music), a(o.voice), o.sounds)
|
|
28
|
+
for (const i of o.sounds)
|
|
29
|
+
a(i);
|
|
30
|
+
for (const o of Object.values(n.dialogues))
|
|
31
|
+
for (const i of o.nodes)
|
|
32
|
+
a(i.voice), a(i.portrait);
|
|
33
|
+
return {
|
|
34
|
+
shell: Array.from(t).filter(Boolean),
|
|
35
|
+
game: Array.from(r).filter(Boolean)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const C = "doodle-engine-assets-";
|
|
39
|
+
function Pe(n = "1") {
|
|
40
|
+
const e = `${C}${n}`, t = /* @__PURE__ */ new Set(), r = typeof caches < "u";
|
|
41
|
+
async function a() {
|
|
42
|
+
if (!r) return null;
|
|
43
|
+
try {
|
|
44
|
+
return await caches.open(e);
|
|
45
|
+
} catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async function o(i) {
|
|
50
|
+
if (t.has(i)) return;
|
|
51
|
+
const s = await a();
|
|
52
|
+
if (s) {
|
|
53
|
+
if (await s.match(i)) {
|
|
54
|
+
t.add(i);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const c = await fetch(i);
|
|
58
|
+
if (!c.ok)
|
|
59
|
+
throw new Error(`Failed to load asset: ${i} (${c.status})`);
|
|
60
|
+
await s.put(i, c);
|
|
61
|
+
} else {
|
|
62
|
+
const l = await fetch(i);
|
|
63
|
+
if (!l.ok)
|
|
64
|
+
throw new Error(`Failed to load asset: ${i} (${l.status})`);
|
|
65
|
+
}
|
|
66
|
+
t.add(i);
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
async isAvailable(i) {
|
|
70
|
+
if (t.has(i)) return !0;
|
|
71
|
+
const s = await a();
|
|
72
|
+
return s ? await s.match(i) !== void 0 : !1;
|
|
73
|
+
},
|
|
74
|
+
async load(i) {
|
|
75
|
+
await o(i);
|
|
76
|
+
},
|
|
77
|
+
async loadMany(i, s) {
|
|
78
|
+
let l = 0;
|
|
79
|
+
const c = i.length;
|
|
80
|
+
for (const u of i)
|
|
81
|
+
s == null || s(l, c, u), await o(u), l++, s == null || s(l, c, u);
|
|
82
|
+
},
|
|
83
|
+
getUrl(i) {
|
|
84
|
+
return i;
|
|
85
|
+
},
|
|
86
|
+
prefetch(i) {
|
|
87
|
+
for (const s of i)
|
|
88
|
+
o(s).catch(() => {
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
async clear() {
|
|
92
|
+
if (t.clear(), !!r)
|
|
93
|
+
try {
|
|
94
|
+
const i = await caches.keys();
|
|
95
|
+
await Promise.all(
|
|
96
|
+
i.filter((s) => s.startsWith(C)).map((s) => caches.delete(s))
|
|
97
|
+
);
|
|
98
|
+
} catch {
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function R(n, e) {
|
|
104
|
+
switch (n.type) {
|
|
6
105
|
case "hasFlag":
|
|
7
|
-
return D(
|
|
106
|
+
return D(n.flag, e);
|
|
8
107
|
case "notFlag":
|
|
9
|
-
return
|
|
108
|
+
return V(n.flag, e);
|
|
10
109
|
case "hasItem":
|
|
11
|
-
return
|
|
110
|
+
return $(n.itemId, e);
|
|
12
111
|
case "variableEquals":
|
|
13
|
-
return
|
|
112
|
+
return F(n.variable, n.value, e);
|
|
14
113
|
case "variableGreaterThan":
|
|
15
|
-
return
|
|
114
|
+
return q(n.variable, n.value, e);
|
|
16
115
|
case "variableLessThan":
|
|
17
|
-
return
|
|
116
|
+
return P(n.variable, n.value, e);
|
|
18
117
|
case "atLocation":
|
|
19
|
-
return
|
|
118
|
+
return M(n.locationId, e);
|
|
20
119
|
case "questAtStage":
|
|
21
|
-
return W(
|
|
120
|
+
return W(n.questId, n.stageId, e);
|
|
22
121
|
case "characterAt":
|
|
23
|
-
return
|
|
122
|
+
return j(n.characterId, n.locationId, e);
|
|
24
123
|
case "characterInParty":
|
|
25
|
-
return G(
|
|
124
|
+
return G(n.characterId, e);
|
|
26
125
|
case "relationshipAbove":
|
|
27
|
-
return H(
|
|
126
|
+
return H(n.characterId, n.value, e);
|
|
28
127
|
case "relationshipBelow":
|
|
29
|
-
return
|
|
128
|
+
return Q(n.characterId, n.value, e);
|
|
30
129
|
case "timeIs":
|
|
31
|
-
return
|
|
130
|
+
return J(n.startHour, n.endHour, e);
|
|
32
131
|
case "itemAt":
|
|
33
|
-
return
|
|
132
|
+
return U(n.itemId, n.locationId, e);
|
|
34
133
|
case "roll":
|
|
35
|
-
return
|
|
134
|
+
return B(n.min, n.max, n.threshold);
|
|
36
135
|
default:
|
|
37
136
|
return !1;
|
|
38
137
|
}
|
|
39
138
|
}
|
|
40
|
-
function
|
|
41
|
-
return
|
|
139
|
+
function S(n, e) {
|
|
140
|
+
return n.every((t) => R(t, e));
|
|
42
141
|
}
|
|
43
|
-
function D(
|
|
44
|
-
return e.flags[
|
|
142
|
+
function D(n, e) {
|
|
143
|
+
return e.flags[n] === !0;
|
|
45
144
|
}
|
|
46
|
-
function
|
|
47
|
-
return e.flags[
|
|
145
|
+
function V(n, e) {
|
|
146
|
+
return e.flags[n] !== !0;
|
|
48
147
|
}
|
|
49
|
-
function
|
|
50
|
-
return e.inventory.includes(
|
|
148
|
+
function $(n, e) {
|
|
149
|
+
return e.inventory.includes(n);
|
|
51
150
|
}
|
|
52
|
-
function
|
|
53
|
-
return
|
|
151
|
+
function F(n, e, t) {
|
|
152
|
+
return t.variables[n] === e;
|
|
54
153
|
}
|
|
55
|
-
function
|
|
56
|
-
const r =
|
|
154
|
+
function q(n, e, t) {
|
|
155
|
+
const r = t.variables[n];
|
|
57
156
|
return typeof r == "number" && r > e;
|
|
58
157
|
}
|
|
59
|
-
function
|
|
60
|
-
const r =
|
|
158
|
+
function P(n, e, t) {
|
|
159
|
+
const r = t.variables[n];
|
|
61
160
|
return typeof r == "number" && r < e;
|
|
62
161
|
}
|
|
63
|
-
function
|
|
64
|
-
return e.currentLocation ===
|
|
162
|
+
function M(n, e) {
|
|
163
|
+
return e.currentLocation === n;
|
|
65
164
|
}
|
|
66
|
-
function W(
|
|
67
|
-
return
|
|
165
|
+
function W(n, e, t) {
|
|
166
|
+
return t.questProgress[n] === e;
|
|
68
167
|
}
|
|
69
|
-
function
|
|
70
|
-
const r =
|
|
168
|
+
function j(n, e, t) {
|
|
169
|
+
const r = t.characterState[n];
|
|
71
170
|
return (r == null ? void 0 : r.location) === e;
|
|
72
171
|
}
|
|
73
|
-
function G(
|
|
74
|
-
const
|
|
75
|
-
return (
|
|
172
|
+
function G(n, e) {
|
|
173
|
+
const t = e.characterState[n];
|
|
174
|
+
return (t == null ? void 0 : t.inParty) === !0;
|
|
76
175
|
}
|
|
77
|
-
function H(
|
|
78
|
-
const r =
|
|
176
|
+
function H(n, e, t) {
|
|
177
|
+
const r = t.characterState[n];
|
|
79
178
|
return r !== void 0 && r.relationship > e;
|
|
80
179
|
}
|
|
81
|
-
function
|
|
82
|
-
const r =
|
|
180
|
+
function Q(n, e, t) {
|
|
181
|
+
const r = t.characterState[n];
|
|
83
182
|
return r !== void 0 && r.relationship < e;
|
|
84
183
|
}
|
|
85
|
-
function
|
|
86
|
-
const r =
|
|
87
|
-
return
|
|
184
|
+
function J(n, e, t) {
|
|
185
|
+
const r = t.currentTime.hour;
|
|
186
|
+
return n < e ? r >= n && r < e : r >= n || r < e;
|
|
88
187
|
}
|
|
89
|
-
function
|
|
90
|
-
return
|
|
188
|
+
function U(n, e, t) {
|
|
189
|
+
return t.itemLocations[n] === e;
|
|
91
190
|
}
|
|
92
|
-
function
|
|
93
|
-
return Math.floor(Math.random() * (e -
|
|
191
|
+
function B(n, e, t) {
|
|
192
|
+
return Math.floor(Math.random() * (e - n + 1)) + n >= t;
|
|
94
193
|
}
|
|
95
|
-
function
|
|
96
|
-
switch (
|
|
194
|
+
function _(n, e) {
|
|
195
|
+
switch (n.type) {
|
|
97
196
|
case "setFlag":
|
|
98
|
-
return
|
|
197
|
+
return z(n.flag, e);
|
|
99
198
|
case "clearFlag":
|
|
100
|
-
return
|
|
199
|
+
return Y(n.flag, e);
|
|
101
200
|
case "setVariable":
|
|
102
|
-
return
|
|
201
|
+
return X(n.variable, n.value, e);
|
|
103
202
|
case "addVariable":
|
|
104
|
-
return K(
|
|
203
|
+
return K(n.variable, n.value, e);
|
|
105
204
|
case "addItem":
|
|
106
|
-
return
|
|
205
|
+
return Z(n.itemId, e);
|
|
107
206
|
case "removeItem":
|
|
108
|
-
return
|
|
207
|
+
return ee(n.itemId, e);
|
|
109
208
|
case "moveItem":
|
|
110
|
-
return
|
|
209
|
+
return te(n.itemId, n.locationId, e);
|
|
111
210
|
case "goToLocation":
|
|
112
|
-
return
|
|
211
|
+
return ne(n.locationId, e);
|
|
113
212
|
case "advanceTime":
|
|
114
|
-
return
|
|
213
|
+
return re(n.hours, e);
|
|
115
214
|
case "setQuestStage":
|
|
116
|
-
return
|
|
215
|
+
return ae(n.questId, n.stageId, e);
|
|
117
216
|
case "addJournalEntry":
|
|
118
|
-
return
|
|
217
|
+
return ie(n.entryId, e);
|
|
119
218
|
case "startDialogue":
|
|
120
|
-
return
|
|
219
|
+
return oe(n.dialogueId, e);
|
|
121
220
|
case "endDialogue":
|
|
122
221
|
return se(e);
|
|
123
222
|
case "setCharacterLocation":
|
|
124
|
-
return
|
|
223
|
+
return le(n.characterId, n.locationId, e);
|
|
125
224
|
case "addToParty":
|
|
126
|
-
return
|
|
225
|
+
return ce(n.characterId, e);
|
|
127
226
|
case "removeFromParty":
|
|
128
|
-
return
|
|
227
|
+
return ue(n.characterId, e);
|
|
129
228
|
case "setRelationship":
|
|
130
|
-
return
|
|
229
|
+
return de(n.characterId, n.value, e);
|
|
131
230
|
case "addRelationship":
|
|
132
|
-
return
|
|
231
|
+
return he(n.characterId, n.value, e);
|
|
133
232
|
case "setCharacterStat":
|
|
134
|
-
return
|
|
233
|
+
return pe(n.characterId, n.stat, n.value, e);
|
|
135
234
|
case "addCharacterStat":
|
|
136
|
-
return
|
|
235
|
+
return fe(n.characterId, n.stat, n.value, e);
|
|
137
236
|
case "setMapEnabled":
|
|
138
|
-
return ge(
|
|
237
|
+
return ge(n.enabled, e);
|
|
139
238
|
case "playMusic":
|
|
140
239
|
return e;
|
|
141
240
|
case "playSound":
|
|
142
|
-
return
|
|
241
|
+
return be(n.sound, e);
|
|
143
242
|
case "notify":
|
|
144
|
-
return
|
|
243
|
+
return me(n.message, e);
|
|
145
244
|
case "playVideo":
|
|
146
|
-
return
|
|
245
|
+
return ye(n.file, e);
|
|
147
246
|
case "showInterlude":
|
|
148
|
-
return
|
|
247
|
+
return ve(n.interludeId, e);
|
|
149
248
|
case "roll":
|
|
150
|
-
return Se(
|
|
249
|
+
return Se(n.variable, n.min, n.max, e);
|
|
151
250
|
default:
|
|
152
251
|
return e;
|
|
153
252
|
}
|
|
154
253
|
}
|
|
155
|
-
function
|
|
156
|
-
return
|
|
254
|
+
function v(n, e) {
|
|
255
|
+
return n.reduce((t, r) => _(r, t), e);
|
|
157
256
|
}
|
|
158
|
-
function
|
|
257
|
+
function z(n, e) {
|
|
159
258
|
return {
|
|
160
259
|
...e,
|
|
161
260
|
flags: {
|
|
162
261
|
...e.flags,
|
|
163
|
-
[
|
|
262
|
+
[n]: !0
|
|
164
263
|
}
|
|
165
264
|
};
|
|
166
265
|
}
|
|
167
|
-
function
|
|
266
|
+
function Y(n, e) {
|
|
168
267
|
return {
|
|
169
268
|
...e,
|
|
170
269
|
flags: {
|
|
171
270
|
...e.flags,
|
|
172
|
-
[
|
|
271
|
+
[n]: !1
|
|
173
272
|
}
|
|
174
273
|
};
|
|
175
274
|
}
|
|
176
|
-
function
|
|
275
|
+
function X(n, e, t) {
|
|
177
276
|
return {
|
|
178
|
-
...
|
|
277
|
+
...t,
|
|
179
278
|
variables: {
|
|
180
|
-
...
|
|
181
|
-
[
|
|
279
|
+
...t.variables,
|
|
280
|
+
[n]: e
|
|
182
281
|
}
|
|
183
282
|
};
|
|
184
283
|
}
|
|
185
|
-
function K(
|
|
186
|
-
const r =
|
|
284
|
+
function K(n, e, t) {
|
|
285
|
+
const r = t.variables[n], a = typeof r == "number" ? r + e : e;
|
|
187
286
|
return {
|
|
188
|
-
...
|
|
287
|
+
...t,
|
|
189
288
|
variables: {
|
|
190
|
-
...
|
|
191
|
-
[
|
|
289
|
+
...t.variables,
|
|
290
|
+
[n]: a
|
|
192
291
|
}
|
|
193
292
|
};
|
|
194
293
|
}
|
|
195
|
-
function
|
|
196
|
-
return e.inventory.includes(
|
|
294
|
+
function Z(n, e) {
|
|
295
|
+
return e.inventory.includes(n) ? e : {
|
|
197
296
|
...e,
|
|
198
|
-
inventory: [...e.inventory,
|
|
297
|
+
inventory: [...e.inventory, n],
|
|
199
298
|
itemLocations: {
|
|
200
299
|
...e.itemLocations,
|
|
201
|
-
[
|
|
300
|
+
[n]: "inventory"
|
|
202
301
|
}
|
|
203
302
|
};
|
|
204
303
|
}
|
|
205
|
-
function
|
|
304
|
+
function ee(n, e) {
|
|
206
305
|
return {
|
|
207
306
|
...e,
|
|
208
|
-
inventory: e.inventory.filter((
|
|
307
|
+
inventory: e.inventory.filter((t) => t !== n)
|
|
209
308
|
// Note: itemLocation is NOT updated here - the item stays at "inventory"
|
|
210
309
|
// or wherever it was. Use moveItem to relocate it.
|
|
211
310
|
};
|
|
212
311
|
}
|
|
213
|
-
function
|
|
312
|
+
function te(n, e, t) {
|
|
214
313
|
return {
|
|
215
|
-
...
|
|
216
|
-
inventory:
|
|
314
|
+
...t,
|
|
315
|
+
inventory: t.inventory.filter((r) => r !== n),
|
|
217
316
|
itemLocations: {
|
|
218
|
-
...
|
|
219
|
-
[
|
|
317
|
+
...t.itemLocations,
|
|
318
|
+
[n]: e
|
|
220
319
|
}
|
|
221
320
|
};
|
|
222
321
|
}
|
|
223
|
-
function
|
|
322
|
+
function ne(n, e) {
|
|
224
323
|
return {
|
|
225
324
|
...e,
|
|
226
|
-
currentLocation:
|
|
325
|
+
currentLocation: n
|
|
227
326
|
};
|
|
228
327
|
}
|
|
229
|
-
function
|
|
230
|
-
const
|
|
328
|
+
function re(n, e) {
|
|
329
|
+
const t = e.currentTime.hour + n, r = Math.floor(t / 24), a = t % 24;
|
|
231
330
|
return {
|
|
232
331
|
...e,
|
|
233
332
|
currentTime: {
|
|
@@ -236,128 +335,128 @@ function ne(t, e) {
|
|
|
236
335
|
}
|
|
237
336
|
};
|
|
238
337
|
}
|
|
239
|
-
function
|
|
338
|
+
function ae(n, e, t) {
|
|
240
339
|
return {
|
|
241
|
-
...
|
|
340
|
+
...t,
|
|
242
341
|
questProgress: {
|
|
243
|
-
...
|
|
244
|
-
[
|
|
342
|
+
...t.questProgress,
|
|
343
|
+
[n]: e
|
|
245
344
|
}
|
|
246
345
|
};
|
|
247
346
|
}
|
|
248
|
-
function
|
|
249
|
-
return e.unlockedJournalEntries.includes(
|
|
347
|
+
function ie(n, e) {
|
|
348
|
+
return e.unlockedJournalEntries.includes(n) ? e : {
|
|
250
349
|
...e,
|
|
251
|
-
unlockedJournalEntries: [...e.unlockedJournalEntries,
|
|
350
|
+
unlockedJournalEntries: [...e.unlockedJournalEntries, n]
|
|
252
351
|
};
|
|
253
352
|
}
|
|
254
|
-
function
|
|
353
|
+
function oe(n, e) {
|
|
255
354
|
return {
|
|
256
355
|
...e,
|
|
257
356
|
dialogueState: {
|
|
258
|
-
dialogueId:
|
|
357
|
+
dialogueId: n,
|
|
259
358
|
nodeId: ""
|
|
260
359
|
// Will be set by engine when it looks up the dialogue
|
|
261
360
|
}
|
|
262
361
|
};
|
|
263
362
|
}
|
|
264
|
-
function se(
|
|
363
|
+
function se(n) {
|
|
265
364
|
return {
|
|
266
|
-
...
|
|
365
|
+
...n,
|
|
267
366
|
dialogueState: null
|
|
268
367
|
};
|
|
269
368
|
}
|
|
270
|
-
function
|
|
271
|
-
const r =
|
|
369
|
+
function le(n, e, t) {
|
|
370
|
+
const r = t.characterState[n];
|
|
272
371
|
return r ? {
|
|
273
|
-
...
|
|
372
|
+
...t,
|
|
274
373
|
characterState: {
|
|
275
|
-
...
|
|
276
|
-
[
|
|
374
|
+
...t.characterState,
|
|
375
|
+
[n]: {
|
|
277
376
|
...r,
|
|
278
377
|
location: e
|
|
279
378
|
}
|
|
280
379
|
}
|
|
281
|
-
} :
|
|
380
|
+
} : t;
|
|
282
381
|
}
|
|
283
|
-
function
|
|
284
|
-
const
|
|
285
|
-
return
|
|
382
|
+
function ce(n, e) {
|
|
383
|
+
const t = e.characterState[n];
|
|
384
|
+
return t ? {
|
|
286
385
|
...e,
|
|
287
386
|
characterState: {
|
|
288
387
|
...e.characterState,
|
|
289
|
-
[
|
|
290
|
-
...
|
|
388
|
+
[n]: {
|
|
389
|
+
...t,
|
|
291
390
|
inParty: !0
|
|
292
391
|
}
|
|
293
392
|
}
|
|
294
393
|
} : e;
|
|
295
394
|
}
|
|
296
|
-
function
|
|
297
|
-
const
|
|
298
|
-
return
|
|
395
|
+
function ue(n, e) {
|
|
396
|
+
const t = e.characterState[n];
|
|
397
|
+
return t ? {
|
|
299
398
|
...e,
|
|
300
399
|
characterState: {
|
|
301
400
|
...e.characterState,
|
|
302
|
-
[
|
|
303
|
-
...
|
|
401
|
+
[n]: {
|
|
402
|
+
...t,
|
|
304
403
|
inParty: !1
|
|
305
404
|
}
|
|
306
405
|
}
|
|
307
406
|
} : e;
|
|
308
407
|
}
|
|
309
|
-
function
|
|
310
|
-
const r =
|
|
408
|
+
function de(n, e, t) {
|
|
409
|
+
const r = t.characterState[n];
|
|
311
410
|
return r ? {
|
|
312
|
-
...
|
|
411
|
+
...t,
|
|
313
412
|
characterState: {
|
|
314
|
-
...
|
|
315
|
-
[
|
|
413
|
+
...t.characterState,
|
|
414
|
+
[n]: {
|
|
316
415
|
...r,
|
|
317
416
|
relationship: e
|
|
318
417
|
}
|
|
319
418
|
}
|
|
320
|
-
} :
|
|
419
|
+
} : t;
|
|
321
420
|
}
|
|
322
|
-
function
|
|
323
|
-
const r =
|
|
421
|
+
function he(n, e, t) {
|
|
422
|
+
const r = t.characterState[n];
|
|
324
423
|
return r ? {
|
|
325
|
-
...
|
|
424
|
+
...t,
|
|
326
425
|
characterState: {
|
|
327
|
-
...
|
|
328
|
-
[
|
|
426
|
+
...t.characterState,
|
|
427
|
+
[n]: {
|
|
329
428
|
...r,
|
|
330
429
|
relationship: r.relationship + e
|
|
331
430
|
}
|
|
332
431
|
}
|
|
333
|
-
} :
|
|
432
|
+
} : t;
|
|
334
433
|
}
|
|
335
|
-
function
|
|
336
|
-
const a = r.characterState[
|
|
434
|
+
function pe(n, e, t, r) {
|
|
435
|
+
const a = r.characterState[n];
|
|
337
436
|
return a ? {
|
|
338
437
|
...r,
|
|
339
438
|
characterState: {
|
|
340
439
|
...r.characterState,
|
|
341
|
-
[
|
|
440
|
+
[n]: {
|
|
342
441
|
...a,
|
|
343
442
|
stats: {
|
|
344
443
|
...a.stats,
|
|
345
|
-
[e]:
|
|
444
|
+
[e]: t
|
|
346
445
|
}
|
|
347
446
|
}
|
|
348
447
|
}
|
|
349
448
|
} : r;
|
|
350
449
|
}
|
|
351
|
-
function
|
|
352
|
-
const a = r.characterState[
|
|
450
|
+
function fe(n, e, t, r) {
|
|
451
|
+
const a = r.characterState[n];
|
|
353
452
|
if (!a)
|
|
354
453
|
return r;
|
|
355
|
-
const
|
|
454
|
+
const o = a.stats[e], i = typeof o == "number" ? o + t : t;
|
|
356
455
|
return {
|
|
357
456
|
...r,
|
|
358
457
|
characterState: {
|
|
359
458
|
...r.characterState,
|
|
360
|
-
[
|
|
459
|
+
[n]: {
|
|
361
460
|
...a,
|
|
362
461
|
stats: {
|
|
363
462
|
...a.stats,
|
|
@@ -367,66 +466,66 @@ function pe(t, e, n, r) {
|
|
|
367
466
|
}
|
|
368
467
|
};
|
|
369
468
|
}
|
|
370
|
-
function ge(
|
|
469
|
+
function ge(n, e) {
|
|
371
470
|
return {
|
|
372
471
|
...e,
|
|
373
|
-
mapEnabled:
|
|
472
|
+
mapEnabled: n
|
|
374
473
|
};
|
|
375
474
|
}
|
|
376
|
-
function
|
|
475
|
+
function me(n, e) {
|
|
377
476
|
return {
|
|
378
477
|
...e,
|
|
379
|
-
notifications: [...e.notifications,
|
|
478
|
+
notifications: [...e.notifications, n]
|
|
380
479
|
};
|
|
381
480
|
}
|
|
382
|
-
function
|
|
481
|
+
function be(n, e) {
|
|
383
482
|
return {
|
|
384
483
|
...e,
|
|
385
|
-
pendingSounds: [...e.pendingSounds,
|
|
484
|
+
pendingSounds: [...e.pendingSounds, n]
|
|
386
485
|
};
|
|
387
486
|
}
|
|
388
|
-
function
|
|
487
|
+
function ye(n, e) {
|
|
389
488
|
return {
|
|
390
489
|
...e,
|
|
391
|
-
pendingVideo:
|
|
490
|
+
pendingVideo: n
|
|
392
491
|
};
|
|
393
492
|
}
|
|
394
|
-
function
|
|
493
|
+
function ve(n, e) {
|
|
395
494
|
return {
|
|
396
495
|
...e,
|
|
397
|
-
pendingInterlude:
|
|
496
|
+
pendingInterlude: n
|
|
398
497
|
};
|
|
399
498
|
}
|
|
400
|
-
function Se(
|
|
401
|
-
const a = Math.floor(Math.random() * (
|
|
499
|
+
function Se(n, e, t, r) {
|
|
500
|
+
const a = Math.floor(Math.random() * (t - e + 1)) + e;
|
|
402
501
|
return {
|
|
403
502
|
...r,
|
|
404
503
|
variables: {
|
|
405
504
|
...r.variables,
|
|
406
|
-
[
|
|
505
|
+
[n]: a
|
|
407
506
|
}
|
|
408
507
|
};
|
|
409
508
|
}
|
|
410
|
-
function L(
|
|
509
|
+
function L(n, e, t) {
|
|
411
510
|
let r;
|
|
412
|
-
if (
|
|
413
|
-
const a =
|
|
414
|
-
r = e[a] ??
|
|
511
|
+
if (n.startsWith("@")) {
|
|
512
|
+
const a = n.slice(1);
|
|
513
|
+
r = e[a] ?? n;
|
|
415
514
|
} else
|
|
416
|
-
r =
|
|
417
|
-
return
|
|
418
|
-
const i =
|
|
419
|
-
return i !== void 0 ? String(i) : `{${
|
|
515
|
+
r = n;
|
|
516
|
+
return t && r.includes("{") && (r = r.replace(/\{(\w+)\}/g, (a, o) => {
|
|
517
|
+
const i = t[o];
|
|
518
|
+
return i !== void 0 ? String(i) : `{${o}}`;
|
|
420
519
|
})), r;
|
|
421
520
|
}
|
|
422
|
-
function
|
|
423
|
-
return (
|
|
521
|
+
function Me(n, e) {
|
|
522
|
+
return (t) => L(t, n, e);
|
|
424
523
|
}
|
|
425
|
-
function
|
|
426
|
-
const
|
|
524
|
+
function Ie(n, e) {
|
|
525
|
+
const t = e.locales[n.currentLocale] ?? {}, r = (m) => L(m, t, n.variables), a = Te(n.currentLocation, e, r), o = we(n, e, r), i = Ne(n, e, r), { dialogue: s, choices: l } = Ee(n, e, r), c = Ae(n, e, r), u = Ce(n, e, r), g = Le(n, e, r), b = xe(n, e, r), d = n.mapEnabled ? ke(n, e, r) : null, f = e.locations[n.currentLocation], h = (f == null ? void 0 : f.music) ?? "", p = (f == null ? void 0 : f.ambient) ?? "", y = n.notifications.map(r), I = [...n.pendingSounds], x = n.pendingVideo;
|
|
427
526
|
let A = null;
|
|
428
|
-
if (
|
|
429
|
-
const m = e.interludes[
|
|
527
|
+
if (n.pendingInterlude) {
|
|
528
|
+
const m = e.interludes[n.pendingInterlude];
|
|
430
529
|
m && (A = {
|
|
431
530
|
id: m.id,
|
|
432
531
|
background: m.background,
|
|
@@ -441,66 +540,66 @@ function ve(t, e) {
|
|
|
441
540
|
}
|
|
442
541
|
return {
|
|
443
542
|
location: a,
|
|
444
|
-
charactersHere:
|
|
543
|
+
charactersHere: o,
|
|
445
544
|
itemsHere: i,
|
|
446
545
|
choices: l,
|
|
447
|
-
dialogue:
|
|
546
|
+
dialogue: s,
|
|
448
547
|
party: c,
|
|
449
|
-
inventory:
|
|
450
|
-
quests:
|
|
548
|
+
inventory: u,
|
|
549
|
+
quests: g,
|
|
451
550
|
journal: b,
|
|
452
|
-
variables: { ...
|
|
453
|
-
time:
|
|
454
|
-
map:
|
|
551
|
+
variables: { ...n.variables },
|
|
552
|
+
time: n.currentTime,
|
|
553
|
+
map: d,
|
|
455
554
|
music: h,
|
|
456
555
|
ambient: p,
|
|
457
556
|
notifications: y,
|
|
458
557
|
pendingSounds: I,
|
|
459
|
-
pendingVideo:
|
|
558
|
+
pendingVideo: x,
|
|
460
559
|
pendingInterlude: A
|
|
461
560
|
};
|
|
462
561
|
}
|
|
463
|
-
function
|
|
464
|
-
const r = e.locations[
|
|
562
|
+
function Te(n, e, t) {
|
|
563
|
+
const r = e.locations[n];
|
|
465
564
|
return r ? {
|
|
466
565
|
id: r.id,
|
|
467
|
-
name:
|
|
468
|
-
description:
|
|
566
|
+
name: t(r.name),
|
|
567
|
+
description: t(r.description),
|
|
469
568
|
banner: r.banner
|
|
470
569
|
} : {
|
|
471
|
-
id:
|
|
472
|
-
name:
|
|
473
|
-
description: `Location not found: ${
|
|
570
|
+
id: n,
|
|
571
|
+
name: n,
|
|
572
|
+
description: `Location not found: ${n}`,
|
|
474
573
|
banner: ""
|
|
475
574
|
};
|
|
476
575
|
}
|
|
477
|
-
function
|
|
576
|
+
function we(n, e, t) {
|
|
478
577
|
const r = [];
|
|
479
|
-
for (const [a,
|
|
480
|
-
if (
|
|
578
|
+
for (const [a, o] of Object.entries(n.characterState))
|
|
579
|
+
if (o.location === n.currentLocation) {
|
|
481
580
|
const i = e.characters[a];
|
|
482
581
|
i && r.push({
|
|
483
582
|
id: i.id,
|
|
484
|
-
name:
|
|
485
|
-
biography:
|
|
583
|
+
name: t(i.name),
|
|
584
|
+
biography: t(i.biography),
|
|
486
585
|
portrait: i.portrait,
|
|
487
|
-
location:
|
|
488
|
-
inParty:
|
|
489
|
-
relationship:
|
|
490
|
-
stats:
|
|
586
|
+
location: o.location,
|
|
587
|
+
inParty: o.inParty,
|
|
588
|
+
relationship: o.relationship,
|
|
589
|
+
stats: o.stats
|
|
491
590
|
});
|
|
492
591
|
}
|
|
493
592
|
return r;
|
|
494
593
|
}
|
|
495
|
-
function Ne(
|
|
594
|
+
function Ne(n, e, t) {
|
|
496
595
|
const r = [];
|
|
497
|
-
for (const [a,
|
|
498
|
-
if (
|
|
596
|
+
for (const [a, o] of Object.entries(n.itemLocations))
|
|
597
|
+
if (o === n.currentLocation) {
|
|
499
598
|
const i = e.items[a];
|
|
500
599
|
i && r.push({
|
|
501
600
|
id: i.id,
|
|
502
|
-
name:
|
|
503
|
-
description:
|
|
601
|
+
name: t(i.name),
|
|
602
|
+
description: t(i.description),
|
|
504
603
|
icon: i.icon,
|
|
505
604
|
image: i.image,
|
|
506
605
|
stats: i.stats
|
|
@@ -508,123 +607,123 @@ function Ne(t, e, n) {
|
|
|
508
607
|
}
|
|
509
608
|
return r;
|
|
510
609
|
}
|
|
511
|
-
function Ee(
|
|
610
|
+
function Ee(n, e, t) {
|
|
512
611
|
var l, c;
|
|
513
|
-
if (!
|
|
612
|
+
if (!n.dialogueState)
|
|
514
613
|
return { dialogue: null, choices: [] };
|
|
515
|
-
const r = e.dialogues[
|
|
614
|
+
const r = e.dialogues[n.dialogueState.dialogueId];
|
|
516
615
|
if (!r)
|
|
517
616
|
return { dialogue: null, choices: [] };
|
|
518
|
-
const a = r.nodes.find((
|
|
519
|
-
var
|
|
520
|
-
return
|
|
617
|
+
const a = r.nodes.find((u) => {
|
|
618
|
+
var g;
|
|
619
|
+
return u.id === ((g = n.dialogueState) == null ? void 0 : g.nodeId);
|
|
521
620
|
});
|
|
522
621
|
if (!a)
|
|
523
622
|
return { dialogue: null, choices: [] };
|
|
524
|
-
const
|
|
623
|
+
const o = a.speaker ? t(((l = e.characters[a.speaker]) == null ? void 0 : l.name) ?? a.speaker) : "Narrator", i = {
|
|
525
624
|
speaker: a.speaker,
|
|
526
|
-
speakerName:
|
|
527
|
-
text:
|
|
625
|
+
speakerName: o,
|
|
626
|
+
text: t(a.text),
|
|
528
627
|
portrait: a.portrait ?? ((c = e.characters[a.speaker ?? ""]) == null ? void 0 : c.portrait),
|
|
529
628
|
voice: a.voice
|
|
530
|
-
},
|
|
531
|
-
id:
|
|
532
|
-
text:
|
|
629
|
+
}, s = a.choices.filter((u) => !u.conditions || u.conditions.length === 0 ? !0 : S(u.conditions, n)).map((u) => ({
|
|
630
|
+
id: u.id,
|
|
631
|
+
text: t(u.text)
|
|
533
632
|
}));
|
|
534
|
-
return { dialogue: i, choices:
|
|
633
|
+
return { dialogue: i, choices: s };
|
|
535
634
|
}
|
|
536
|
-
function
|
|
635
|
+
function Ae(n, e, t) {
|
|
537
636
|
const r = [];
|
|
538
|
-
for (const [a,
|
|
539
|
-
if (
|
|
637
|
+
for (const [a, o] of Object.entries(n.characterState))
|
|
638
|
+
if (o.inParty) {
|
|
540
639
|
const i = e.characters[a];
|
|
541
640
|
i && r.push({
|
|
542
641
|
id: i.id,
|
|
543
|
-
name:
|
|
544
|
-
biography:
|
|
642
|
+
name: t(i.name),
|
|
643
|
+
biography: t(i.biography),
|
|
545
644
|
portrait: i.portrait,
|
|
546
|
-
location:
|
|
547
|
-
inParty:
|
|
548
|
-
relationship:
|
|
549
|
-
stats:
|
|
645
|
+
location: o.location,
|
|
646
|
+
inParty: o.inParty,
|
|
647
|
+
relationship: o.relationship,
|
|
648
|
+
stats: o.stats
|
|
550
649
|
});
|
|
551
650
|
}
|
|
552
651
|
return r;
|
|
553
652
|
}
|
|
554
|
-
function
|
|
555
|
-
return
|
|
653
|
+
function Ce(n, e, t) {
|
|
654
|
+
return n.inventory.map((r) => {
|
|
556
655
|
const a = e.items[r];
|
|
557
656
|
return a ? {
|
|
558
657
|
id: a.id,
|
|
559
|
-
name:
|
|
560
|
-
description:
|
|
658
|
+
name: t(a.name),
|
|
659
|
+
description: t(a.description),
|
|
561
660
|
icon: a.icon,
|
|
562
661
|
image: a.image,
|
|
563
662
|
stats: a.stats
|
|
564
663
|
} : null;
|
|
565
664
|
}).filter((r) => r !== null);
|
|
566
665
|
}
|
|
567
|
-
function Le(
|
|
666
|
+
function Le(n, e, t) {
|
|
568
667
|
const r = [];
|
|
569
|
-
for (const [a,
|
|
668
|
+
for (const [a, o] of Object.entries(n.questProgress)) {
|
|
570
669
|
const i = e.quests[a];
|
|
571
670
|
if (!i) continue;
|
|
572
|
-
const
|
|
573
|
-
|
|
671
|
+
const s = i.stages.find((l) => l.id === o);
|
|
672
|
+
s && r.push({
|
|
574
673
|
id: i.id,
|
|
575
|
-
name:
|
|
576
|
-
description:
|
|
577
|
-
currentStage:
|
|
578
|
-
currentStageDescription:
|
|
674
|
+
name: t(i.name),
|
|
675
|
+
description: t(i.description),
|
|
676
|
+
currentStage: s.id,
|
|
677
|
+
currentStageDescription: t(s.description)
|
|
579
678
|
});
|
|
580
679
|
}
|
|
581
680
|
return r;
|
|
582
681
|
}
|
|
583
|
-
function
|
|
584
|
-
return
|
|
682
|
+
function xe(n, e, t) {
|
|
683
|
+
return n.unlockedJournalEntries.map((r) => {
|
|
585
684
|
const a = e.journalEntries[r];
|
|
586
685
|
return a ? {
|
|
587
686
|
id: a.id,
|
|
588
|
-
title:
|
|
589
|
-
text:
|
|
687
|
+
title: t(a.title),
|
|
688
|
+
text: t(a.text),
|
|
590
689
|
category: a.category
|
|
591
690
|
} : null;
|
|
592
691
|
}).filter((r) => r !== null);
|
|
593
692
|
}
|
|
594
|
-
function
|
|
693
|
+
function ke(n, e, t) {
|
|
595
694
|
const r = Object.keys(e.maps);
|
|
596
695
|
if (r.length === 0) return null;
|
|
597
696
|
const a = e.maps[r[0]];
|
|
598
697
|
if (!a) return null;
|
|
599
|
-
const
|
|
600
|
-
const
|
|
698
|
+
const o = a.locations.map((i) => {
|
|
699
|
+
const s = e.locations[i.id];
|
|
601
700
|
return {
|
|
602
701
|
id: i.id,
|
|
603
|
-
name:
|
|
702
|
+
name: s ? t(s.name) : i.id,
|
|
604
703
|
x: i.x,
|
|
605
704
|
y: i.y,
|
|
606
|
-
isCurrent: i.id ===
|
|
705
|
+
isCurrent: i.id === n.currentLocation
|
|
607
706
|
};
|
|
608
707
|
});
|
|
609
708
|
return {
|
|
610
709
|
id: a.id,
|
|
611
|
-
name:
|
|
710
|
+
name: t(a.name),
|
|
612
711
|
image: a.image,
|
|
613
712
|
scale: a.scale,
|
|
614
|
-
locations:
|
|
713
|
+
locations: o
|
|
615
714
|
};
|
|
616
715
|
}
|
|
617
|
-
class
|
|
716
|
+
class We {
|
|
618
717
|
/**
|
|
619
718
|
* Create a new engine instance.
|
|
620
719
|
*
|
|
621
720
|
* @param registry - Content registry with all game entities
|
|
622
721
|
* @param state - Initial game state
|
|
623
722
|
*/
|
|
624
|
-
constructor(e,
|
|
723
|
+
constructor(e, t) {
|
|
625
724
|
T(this, "registry");
|
|
626
725
|
T(this, "state");
|
|
627
|
-
this.registry = e, this.state =
|
|
726
|
+
this.registry = e, this.state = t;
|
|
628
727
|
}
|
|
629
728
|
// ===========================================================================
|
|
630
729
|
// Core API Methods
|
|
@@ -638,18 +737,18 @@ class $e {
|
|
|
638
737
|
* @returns Initial snapshot
|
|
639
738
|
*/
|
|
640
739
|
newGame(e) {
|
|
641
|
-
const
|
|
642
|
-
for (const [a,
|
|
643
|
-
|
|
644
|
-
location:
|
|
740
|
+
const t = {};
|
|
741
|
+
for (const [a, o] of Object.entries(this.registry.characters))
|
|
742
|
+
t[a] = {
|
|
743
|
+
location: o.location,
|
|
645
744
|
inParty: !1,
|
|
646
745
|
relationship: 0,
|
|
647
|
-
stats: { ...
|
|
746
|
+
stats: { ...o.stats }
|
|
648
747
|
// Clone stats
|
|
649
748
|
};
|
|
650
749
|
const r = {};
|
|
651
|
-
for (const [a,
|
|
652
|
-
r[a] =
|
|
750
|
+
for (const [a, o] of Object.entries(this.registry.items))
|
|
751
|
+
r[a] = o.location;
|
|
653
752
|
return this.state = {
|
|
654
753
|
currentLocation: e.startLocation,
|
|
655
754
|
currentTime: { ...e.startTime },
|
|
@@ -660,7 +759,7 @@ class $e {
|
|
|
660
759
|
unlockedJournalEntries: [],
|
|
661
760
|
playerNotes: [],
|
|
662
761
|
dialogueState: null,
|
|
663
|
-
characterState:
|
|
762
|
+
characterState: t,
|
|
664
763
|
itemLocations: r,
|
|
665
764
|
mapEnabled: !0,
|
|
666
765
|
notifications: [],
|
|
@@ -708,22 +807,22 @@ class $e {
|
|
|
708
807
|
var i;
|
|
709
808
|
if (!this.state.dialogueState)
|
|
710
809
|
return this.buildSnapshotAndClearTransients();
|
|
711
|
-
const
|
|
712
|
-
if (!
|
|
810
|
+
const t = this.registry.dialogues[this.state.dialogueState.dialogueId];
|
|
811
|
+
if (!t)
|
|
713
812
|
return this.buildSnapshotAndClearTransients();
|
|
714
|
-
const r =
|
|
813
|
+
const r = t.nodes.find((s) => {
|
|
715
814
|
var l;
|
|
716
|
-
return
|
|
815
|
+
return s.id === ((l = this.state.dialogueState) == null ? void 0 : l.nodeId);
|
|
717
816
|
});
|
|
718
817
|
if (!r)
|
|
719
818
|
return this.buildSnapshotAndClearTransients();
|
|
720
|
-
const a = r.choices.find((
|
|
819
|
+
const a = r.choices.find((s) => s.id === e);
|
|
721
820
|
if (!a)
|
|
722
821
|
return this.buildSnapshotAndClearTransients();
|
|
723
|
-
if (a.effects && (this.state =
|
|
822
|
+
if (a.effects && (this.state = v(a.effects, this.state)), ((i = this.state.dialogueState) == null ? void 0 : i.nodeId) === "")
|
|
724
823
|
return this.initDialogue(this.state.dialogueState.dialogueId);
|
|
725
|
-
const
|
|
726
|
-
if (!
|
|
824
|
+
const o = t.nodes.find((s) => s.id === a.next);
|
|
825
|
+
if (!o)
|
|
727
826
|
return this.state = {
|
|
728
827
|
...this.state,
|
|
729
828
|
dialogueState: null
|
|
@@ -731,16 +830,16 @@ class $e {
|
|
|
731
830
|
if (this.state = {
|
|
732
831
|
...this.state,
|
|
733
832
|
dialogueState: {
|
|
734
|
-
dialogueId:
|
|
735
|
-
nodeId:
|
|
833
|
+
dialogueId: t.id,
|
|
834
|
+
nodeId: o.id
|
|
736
835
|
}
|
|
737
|
-
},
|
|
738
|
-
const
|
|
739
|
-
|
|
836
|
+
}, o.effects && (this.state = v(o.effects, this.state)), o.choices.length === 0) {
|
|
837
|
+
const s = this.resolveNextNode(o);
|
|
838
|
+
s ? this.state = {
|
|
740
839
|
...this.state,
|
|
741
840
|
dialogueState: {
|
|
742
|
-
dialogueId:
|
|
743
|
-
nodeId:
|
|
841
|
+
dialogueId: t.id,
|
|
842
|
+
nodeId: s
|
|
744
843
|
}
|
|
745
844
|
} : this.state = {
|
|
746
845
|
...this.state,
|
|
@@ -758,32 +857,32 @@ class $e {
|
|
|
758
857
|
* @returns New snapshot with dialogue started
|
|
759
858
|
*/
|
|
760
859
|
talkTo(e) {
|
|
761
|
-
const
|
|
762
|
-
return !
|
|
860
|
+
const t = this.registry.characters[e];
|
|
861
|
+
return !t || !t.dialogue ? this.buildSnapshotAndClearTransients() : this.initDialogue(t.dialogue);
|
|
763
862
|
}
|
|
764
863
|
/**
|
|
765
864
|
* Initialize a dialogue from its start node.
|
|
766
865
|
* Used by talkTo and when a startDialogue effect fires mid-conversation.
|
|
767
866
|
*/
|
|
768
867
|
initDialogue(e) {
|
|
769
|
-
const
|
|
770
|
-
if (!
|
|
868
|
+
const t = this.registry.dialogues[e];
|
|
869
|
+
if (!t)
|
|
771
870
|
return this.buildSnapshotAndClearTransients();
|
|
772
|
-
const r =
|
|
871
|
+
const r = t.nodes.find((a) => a.id === t.startNode);
|
|
773
872
|
if (!r)
|
|
774
873
|
return this.buildSnapshotAndClearTransients();
|
|
775
874
|
if (this.state = {
|
|
776
875
|
...this.state,
|
|
777
876
|
dialogueState: {
|
|
778
|
-
dialogueId:
|
|
877
|
+
dialogueId: t.id,
|
|
779
878
|
nodeId: r.id
|
|
780
879
|
}
|
|
781
|
-
}, r.effects && (this.state =
|
|
880
|
+
}, r.effects && (this.state = v(r.effects, this.state)), r.choices.length === 0) {
|
|
782
881
|
const a = this.resolveNextNode(r);
|
|
783
882
|
a ? this.state = {
|
|
784
883
|
...this.state,
|
|
785
884
|
dialogueState: {
|
|
786
|
-
dialogueId:
|
|
885
|
+
dialogueId: t.id,
|
|
787
886
|
nodeId: a
|
|
788
887
|
}
|
|
789
888
|
} : this.state = {
|
|
@@ -822,25 +921,25 @@ class $e {
|
|
|
822
921
|
travelTo(e) {
|
|
823
922
|
if (!this.state.mapEnabled)
|
|
824
923
|
return this.buildSnapshotAndClearTransients();
|
|
825
|
-
const
|
|
826
|
-
if (
|
|
924
|
+
const t = Object.keys(this.registry.maps);
|
|
925
|
+
if (t.length === 0)
|
|
827
926
|
return this.buildSnapshotAndClearTransients();
|
|
828
|
-
const r = this.registry.maps[
|
|
927
|
+
const r = this.registry.maps[t[0]];
|
|
829
928
|
if (!r)
|
|
830
929
|
return this.buildSnapshotAndClearTransients();
|
|
831
|
-
const a = r.locations.find((
|
|
832
|
-
if (!a || !
|
|
930
|
+
const a = r.locations.find((g) => g.id === this.state.currentLocation), o = r.locations.find((g) => g.id === e);
|
|
931
|
+
if (!a || !o)
|
|
833
932
|
return this.buildSnapshotAndClearTransients();
|
|
834
933
|
const i = Math.sqrt(
|
|
835
|
-
Math.pow(
|
|
836
|
-
),
|
|
934
|
+
Math.pow(o.x - a.x, 2) + Math.pow(o.y - a.y, 2)
|
|
935
|
+
), s = Math.round(i * r.scale), l = this.state.currentTime.hour + s, c = Math.floor(l / 24), u = l % 24;
|
|
837
936
|
return this.state = {
|
|
838
937
|
...this.state,
|
|
839
938
|
currentLocation: e,
|
|
840
939
|
dialogueState: null,
|
|
841
940
|
currentTime: {
|
|
842
941
|
day: this.state.currentTime.day + c,
|
|
843
|
-
hour:
|
|
942
|
+
hour: u
|
|
844
943
|
}
|
|
845
944
|
}, this.checkTriggeredDialogues(), this.checkTriggeredInterludes(), this.buildSnapshotAndClearTransients();
|
|
846
945
|
}
|
|
@@ -853,11 +952,11 @@ class $e {
|
|
|
853
952
|
* @param text - Note content
|
|
854
953
|
* @returns New snapshot with note added
|
|
855
954
|
*/
|
|
856
|
-
writeNote(e,
|
|
955
|
+
writeNote(e, t) {
|
|
857
956
|
const r = {
|
|
858
957
|
id: `note_${Date.now()}`,
|
|
859
958
|
title: e,
|
|
860
|
-
text:
|
|
959
|
+
text: t
|
|
861
960
|
};
|
|
862
961
|
return this.state = {
|
|
863
962
|
...this.state,
|
|
@@ -875,7 +974,7 @@ class $e {
|
|
|
875
974
|
deleteNote(e) {
|
|
876
975
|
return this.state = {
|
|
877
976
|
...this.state,
|
|
878
|
-
playerNotes: this.state.playerNotes.filter((
|
|
977
|
+
playerNotes: this.state.playerNotes.filter((t) => t.id !== e)
|
|
879
978
|
}, this.buildSnapshotAndClearTransients();
|
|
880
979
|
}
|
|
881
980
|
/**
|
|
@@ -910,7 +1009,7 @@ class $e {
|
|
|
910
1009
|
* Transient state is data that should only appear in one snapshot.
|
|
911
1010
|
*/
|
|
912
1011
|
buildSnapshotAndClearTransients() {
|
|
913
|
-
const e =
|
|
1012
|
+
const e = Ie(this.state, this.registry);
|
|
914
1013
|
return this.state = {
|
|
915
1014
|
...this.state,
|
|
916
1015
|
notifications: [],
|
|
@@ -931,9 +1030,9 @@ class $e {
|
|
|
931
1030
|
*/
|
|
932
1031
|
resolveNextNode(e) {
|
|
933
1032
|
if (e.conditionalNext && e.conditionalNext.length > 0) {
|
|
934
|
-
for (const
|
|
935
|
-
if (
|
|
936
|
-
return
|
|
1033
|
+
for (const t of e.conditionalNext)
|
|
1034
|
+
if (S([t.condition], this.state))
|
|
1035
|
+
return t.next;
|
|
937
1036
|
}
|
|
938
1037
|
return e.next ?? null;
|
|
939
1038
|
}
|
|
@@ -947,18 +1046,18 @@ class $e {
|
|
|
947
1046
|
*/
|
|
948
1047
|
checkTriggeredDialogues() {
|
|
949
1048
|
for (const e of Object.values(this.registry.dialogues)) {
|
|
950
|
-
if (e.triggerLocation !== this.state.currentLocation || e.conditions && !
|
|
1049
|
+
if (e.triggerLocation !== this.state.currentLocation || e.conditions && !S(e.conditions, this.state))
|
|
951
1050
|
continue;
|
|
952
|
-
const
|
|
953
|
-
if (
|
|
1051
|
+
const t = e.nodes.find((r) => r.id === e.startNode);
|
|
1052
|
+
if (t) {
|
|
954
1053
|
if (this.state = {
|
|
955
1054
|
...this.state,
|
|
956
1055
|
dialogueState: {
|
|
957
1056
|
dialogueId: e.id,
|
|
958
|
-
nodeId:
|
|
1057
|
+
nodeId: t.id
|
|
959
1058
|
}
|
|
960
|
-
},
|
|
961
|
-
const r = this.resolveNextNode(
|
|
1059
|
+
}, t.effects && (this.state = v(t.effects, this.state)), t.choices.length === 0) {
|
|
1060
|
+
const r = this.resolveNextNode(t);
|
|
962
1061
|
r ? this.state = {
|
|
963
1062
|
...this.state,
|
|
964
1063
|
dialogueState: {
|
|
@@ -984,44 +1083,44 @@ class $e {
|
|
|
984
1083
|
*/
|
|
985
1084
|
checkTriggeredInterludes() {
|
|
986
1085
|
for (const e of Object.values(this.registry.interludes))
|
|
987
|
-
if (e.triggerLocation === this.state.currentLocation && !(e.triggerConditions && !
|
|
1086
|
+
if (e.triggerLocation === this.state.currentLocation && !(e.triggerConditions && !S(e.triggerConditions, this.state))) {
|
|
988
1087
|
this.state = {
|
|
989
1088
|
...this.state,
|
|
990
1089
|
pendingInterlude: e.id
|
|
991
|
-
}, e.effects && (this.state =
|
|
1090
|
+
}, e.effects && (this.state = v(e.effects, this.state));
|
|
992
1091
|
break;
|
|
993
1092
|
}
|
|
994
1093
|
}
|
|
995
1094
|
}
|
|
996
|
-
function
|
|
997
|
-
return
|
|
998
|
-
`).map((e,
|
|
1095
|
+
function Oe(n) {
|
|
1096
|
+
return n.split(`
|
|
1097
|
+
`).map((e, t) => ({
|
|
999
1098
|
original: e,
|
|
1000
|
-
lineNumber:
|
|
1001
|
-
})).map(({ original: e, lineNumber:
|
|
1099
|
+
lineNumber: t + 1
|
|
1100
|
+
})).map(({ original: e, lineNumber: t }) => {
|
|
1002
1101
|
let r = e;
|
|
1003
1102
|
const a = e.indexOf("#");
|
|
1004
1103
|
if (a === -1)
|
|
1005
1104
|
r = e;
|
|
1006
1105
|
else {
|
|
1007
|
-
const
|
|
1008
|
-
if (
|
|
1009
|
-
const l = e.indexOf(
|
|
1106
|
+
const s = e.match(/"[^"]*"/);
|
|
1107
|
+
if (s) {
|
|
1108
|
+
const l = e.indexOf(s[0]), c = l + s[0].length;
|
|
1010
1109
|
a < l ? r = e.substring(0, a) : a >= l && a < c ? r = e.substring(0, c) + e.substring(c).split("#")[0] : r = e.substring(0, a);
|
|
1011
1110
|
} else
|
|
1012
1111
|
r = e.substring(0, a);
|
|
1013
1112
|
}
|
|
1014
|
-
const
|
|
1015
|
-
return { line: r.trim(), lineNumber:
|
|
1113
|
+
const o = r.length - r.trimStart().length;
|
|
1114
|
+
return { line: r.trim(), lineNumber: t, indent: o };
|
|
1016
1115
|
}).filter((e) => e.line.length > 0);
|
|
1017
1116
|
}
|
|
1018
|
-
function
|
|
1019
|
-
const e =
|
|
1117
|
+
function w(n) {
|
|
1118
|
+
const e = n.trim();
|
|
1020
1119
|
return e.startsWith("@") ? e : e.startsWith('"') && e.endsWith('"') ? e.substring(1, e.length - 1) : e;
|
|
1021
1120
|
}
|
|
1022
|
-
function
|
|
1023
|
-
const e =
|
|
1024
|
-
switch (
|
|
1121
|
+
function N(n) {
|
|
1122
|
+
const e = n.trim().split(/\s+/), t = e[0];
|
|
1123
|
+
switch (t) {
|
|
1025
1124
|
case "hasFlag":
|
|
1026
1125
|
return { type: "hasFlag", flag: e[1] };
|
|
1027
1126
|
case "notFlag":
|
|
@@ -1077,13 +1176,13 @@ function E(t) {
|
|
|
1077
1176
|
case "roll":
|
|
1078
1177
|
return { type: "roll", min: Number(e[1]), max: Number(e[2]), threshold: Number(e[3]) };
|
|
1079
1178
|
default:
|
|
1080
|
-
throw new Error(`Unknown condition type: ${
|
|
1179
|
+
throw new Error(`Unknown condition type: ${t}`);
|
|
1081
1180
|
}
|
|
1082
1181
|
}
|
|
1083
|
-
function
|
|
1084
|
-
const e =
|
|
1182
|
+
function E(n) {
|
|
1183
|
+
const e = n.trim();
|
|
1085
1184
|
if (e.startsWith("NOTIFY "))
|
|
1086
|
-
return { type: "notify", message:
|
|
1185
|
+
return { type: "notify", message: w(e.substring(7)) };
|
|
1087
1186
|
if (e.startsWith("MUSIC "))
|
|
1088
1187
|
return { type: "playMusic", track: e.substring(6).trim() };
|
|
1089
1188
|
if (e.startsWith("SOUND "))
|
|
@@ -1096,216 +1195,216 @@ function w(t) {
|
|
|
1096
1195
|
const a = e.split(/\s+/);
|
|
1097
1196
|
return { type: "roll", variable: a[1], min: Number(a[2]), max: Number(a[3]) };
|
|
1098
1197
|
}
|
|
1099
|
-
const
|
|
1198
|
+
const t = e.split(/\s+/), r = t[0];
|
|
1100
1199
|
switch (r) {
|
|
1101
1200
|
case "SET":
|
|
1102
|
-
if (
|
|
1103
|
-
return { type: "setFlag", flag:
|
|
1104
|
-
if (
|
|
1201
|
+
if (t[1] === "flag")
|
|
1202
|
+
return { type: "setFlag", flag: t[2] };
|
|
1203
|
+
if (t[1] === "variable")
|
|
1105
1204
|
return {
|
|
1106
1205
|
type: "setVariable",
|
|
1107
|
-
variable:
|
|
1108
|
-
value: isNaN(Number(
|
|
1206
|
+
variable: t[2],
|
|
1207
|
+
value: isNaN(Number(t[3])) ? t[3] : Number(t[3])
|
|
1109
1208
|
};
|
|
1110
|
-
if (
|
|
1111
|
-
return { type: "setQuestStage", questId:
|
|
1112
|
-
if (
|
|
1209
|
+
if (t[1] === "questStage")
|
|
1210
|
+
return { type: "setQuestStage", questId: t[2], stageId: t[3] };
|
|
1211
|
+
if (t[1] === "characterLocation")
|
|
1113
1212
|
return {
|
|
1114
1213
|
type: "setCharacterLocation",
|
|
1115
|
-
characterId:
|
|
1116
|
-
locationId:
|
|
1214
|
+
characterId: t[2],
|
|
1215
|
+
locationId: t[3]
|
|
1117
1216
|
};
|
|
1118
|
-
if (
|
|
1217
|
+
if (t[1] === "relationship")
|
|
1119
1218
|
return {
|
|
1120
1219
|
type: "setRelationship",
|
|
1121
|
-
characterId:
|
|
1122
|
-
value: Number(
|
|
1220
|
+
characterId: t[2],
|
|
1221
|
+
value: Number(t[3])
|
|
1123
1222
|
};
|
|
1124
|
-
if (
|
|
1223
|
+
if (t[1] === "characterStat")
|
|
1125
1224
|
return {
|
|
1126
1225
|
type: "setCharacterStat",
|
|
1127
|
-
characterId:
|
|
1128
|
-
stat:
|
|
1129
|
-
value: isNaN(Number(
|
|
1226
|
+
characterId: t[2],
|
|
1227
|
+
stat: t[3],
|
|
1228
|
+
value: isNaN(Number(t[4])) ? t[4] : Number(t[4])
|
|
1130
1229
|
};
|
|
1131
|
-
if (
|
|
1132
|
-
return { type: "setMapEnabled", enabled:
|
|
1133
|
-
throw new Error(`Unknown SET effect: ${
|
|
1230
|
+
if (t[1] === "mapEnabled")
|
|
1231
|
+
return { type: "setMapEnabled", enabled: t[2] === "true" };
|
|
1232
|
+
throw new Error(`Unknown SET effect: ${t[1]}`);
|
|
1134
1233
|
case "CLEAR":
|
|
1135
|
-
if (
|
|
1136
|
-
return { type: "clearFlag", flag:
|
|
1137
|
-
throw new Error(`Unknown CLEAR effect: ${
|
|
1234
|
+
if (t[1] === "flag")
|
|
1235
|
+
return { type: "clearFlag", flag: t[2] };
|
|
1236
|
+
throw new Error(`Unknown CLEAR effect: ${t[1]}`);
|
|
1138
1237
|
case "ADD":
|
|
1139
|
-
if (
|
|
1238
|
+
if (t[1] === "variable")
|
|
1140
1239
|
return {
|
|
1141
1240
|
type: "addVariable",
|
|
1142
|
-
variable:
|
|
1143
|
-
value: Number(
|
|
1241
|
+
variable: t[2],
|
|
1242
|
+
value: Number(t[3])
|
|
1144
1243
|
};
|
|
1145
|
-
if (
|
|
1146
|
-
return { type: "addItem", itemId:
|
|
1147
|
-
if (
|
|
1148
|
-
return { type: "addJournalEntry", entryId:
|
|
1149
|
-
if (
|
|
1150
|
-
return { type: "addToParty", characterId:
|
|
1151
|
-
if (
|
|
1244
|
+
if (t[1] === "item")
|
|
1245
|
+
return { type: "addItem", itemId: t[2] };
|
|
1246
|
+
if (t[1] === "journalEntry")
|
|
1247
|
+
return { type: "addJournalEntry", entryId: t[2] };
|
|
1248
|
+
if (t[1] === "toParty")
|
|
1249
|
+
return { type: "addToParty", characterId: t[2] };
|
|
1250
|
+
if (t[1] === "relationship")
|
|
1152
1251
|
return {
|
|
1153
1252
|
type: "addRelationship",
|
|
1154
|
-
characterId:
|
|
1155
|
-
value: Number(
|
|
1253
|
+
characterId: t[2],
|
|
1254
|
+
value: Number(t[3])
|
|
1156
1255
|
};
|
|
1157
|
-
if (
|
|
1256
|
+
if (t[1] === "characterStat")
|
|
1158
1257
|
return {
|
|
1159
1258
|
type: "addCharacterStat",
|
|
1160
|
-
characterId:
|
|
1161
|
-
stat:
|
|
1162
|
-
value: Number(
|
|
1259
|
+
characterId: t[2],
|
|
1260
|
+
stat: t[3],
|
|
1261
|
+
value: Number(t[4])
|
|
1163
1262
|
};
|
|
1164
|
-
throw new Error(`Unknown ADD effect: ${
|
|
1263
|
+
throw new Error(`Unknown ADD effect: ${t[1]}`);
|
|
1165
1264
|
case "REMOVE":
|
|
1166
|
-
if (
|
|
1167
|
-
return { type: "removeItem", itemId:
|
|
1168
|
-
if (
|
|
1169
|
-
return { type: "removeFromParty", characterId:
|
|
1170
|
-
throw new Error(`Unknown REMOVE effect: ${
|
|
1265
|
+
if (t[1] === "item")
|
|
1266
|
+
return { type: "removeItem", itemId: t[2] };
|
|
1267
|
+
if (t[1] === "fromParty")
|
|
1268
|
+
return { type: "removeFromParty", characterId: t[2] };
|
|
1269
|
+
throw new Error(`Unknown REMOVE effect: ${t[1]}`);
|
|
1171
1270
|
case "MOVE":
|
|
1172
|
-
if (
|
|
1173
|
-
return { type: "moveItem", itemId:
|
|
1174
|
-
throw new Error(`Unknown MOVE effect: ${
|
|
1271
|
+
if (t[1] === "item")
|
|
1272
|
+
return { type: "moveItem", itemId: t[2], locationId: t[3] };
|
|
1273
|
+
throw new Error(`Unknown MOVE effect: ${t[1]}`);
|
|
1175
1274
|
case "GOTO":
|
|
1176
|
-
if (
|
|
1177
|
-
return { type: "goToLocation", locationId:
|
|
1275
|
+
if (t[1] === "location")
|
|
1276
|
+
return { type: "goToLocation", locationId: t[2] };
|
|
1178
1277
|
throw new Error("GOTO should not be parsed as an effect");
|
|
1179
1278
|
case "ADVANCE":
|
|
1180
|
-
if (
|
|
1181
|
-
return { type: "advanceTime", hours: Number(
|
|
1182
|
-
throw new Error(`Unknown ADVANCE effect: ${
|
|
1279
|
+
if (t[1] === "time")
|
|
1280
|
+
return { type: "advanceTime", hours: Number(t[2]) };
|
|
1281
|
+
throw new Error(`Unknown ADVANCE effect: ${t[1]}`);
|
|
1183
1282
|
case "START":
|
|
1184
|
-
if (
|
|
1185
|
-
return { type: "startDialogue", dialogueId:
|
|
1186
|
-
throw new Error(`Unknown START effect: ${
|
|
1283
|
+
if (t[1] === "dialogue")
|
|
1284
|
+
return { type: "startDialogue", dialogueId: t[2] };
|
|
1285
|
+
throw new Error(`Unknown START effect: ${t[1]}`);
|
|
1187
1286
|
case "END":
|
|
1188
|
-
if (
|
|
1287
|
+
if (t[1] === "dialogue")
|
|
1189
1288
|
return { type: "endDialogue" };
|
|
1190
1289
|
throw new Error("END should not be parsed as an effect");
|
|
1191
1290
|
default:
|
|
1192
1291
|
throw new Error(`Unknown effect keyword: ${r}`);
|
|
1193
1292
|
}
|
|
1194
1293
|
}
|
|
1195
|
-
function
|
|
1196
|
-
const r =
|
|
1197
|
-
let
|
|
1294
|
+
function Re(n, e, t) {
|
|
1295
|
+
const r = n[e], a = w(r.line.substring(7)), o = [], i = [];
|
|
1296
|
+
let s = "", l = e + 1;
|
|
1198
1297
|
const c = r.indent;
|
|
1199
|
-
for (; l <
|
|
1200
|
-
const
|
|
1201
|
-
if (
|
|
1298
|
+
for (; l < n.length; ) {
|
|
1299
|
+
const d = n[l];
|
|
1300
|
+
if (d.line === "END" && d.indent === c) {
|
|
1202
1301
|
l++;
|
|
1203
1302
|
break;
|
|
1204
1303
|
}
|
|
1205
|
-
if (
|
|
1206
|
-
const
|
|
1207
|
-
|
|
1208
|
-
} else if (
|
|
1209
|
-
const
|
|
1210
|
-
if (
|
|
1211
|
-
const h =
|
|
1212
|
-
i.push({ type: "goToLocation", locationId: h }), i.push({ type: "endDialogue" }),
|
|
1304
|
+
if (d.line.startsWith("REQUIRE ")) {
|
|
1305
|
+
const f = d.line.substring(8).trim();
|
|
1306
|
+
o.push(N(f)), l++;
|
|
1307
|
+
} else if (d.line.startsWith("GOTO ")) {
|
|
1308
|
+
const f = d.line.substring(5).trim();
|
|
1309
|
+
if (f.startsWith("location ")) {
|
|
1310
|
+
const h = f.substring(9).trim();
|
|
1311
|
+
i.push({ type: "goToLocation", locationId: h }), i.push({ type: "endDialogue" }), s = "";
|
|
1213
1312
|
} else
|
|
1214
|
-
|
|
1313
|
+
s = f;
|
|
1215
1314
|
l++;
|
|
1216
|
-
} else
|
|
1315
|
+
} else d.line.includes(":") || i.push(E(d.line)), l++;
|
|
1217
1316
|
}
|
|
1218
|
-
const
|
|
1317
|
+
const u = a.replace(/[@"]/g, "").replace(/[^a-z0-9]/gi, "_");
|
|
1219
1318
|
return { choice: {
|
|
1220
|
-
id: `${
|
|
1319
|
+
id: `${t}_choice_${u.toLowerCase().substring(0, 30)}`,
|
|
1221
1320
|
text: a,
|
|
1222
|
-
conditions:
|
|
1321
|
+
conditions: o.length > 0 ? o : void 0,
|
|
1223
1322
|
effects: i.length > 0 ? i : void 0,
|
|
1224
|
-
next:
|
|
1323
|
+
next: s || ""
|
|
1225
1324
|
}, nextIndex: l };
|
|
1226
1325
|
}
|
|
1227
|
-
function De(
|
|
1228
|
-
const
|
|
1229
|
-
let
|
|
1326
|
+
function De(n, e) {
|
|
1327
|
+
const t = n[e], r = t.line.substring(3).trim(), a = N(r);
|
|
1328
|
+
let o;
|
|
1230
1329
|
const i = [];
|
|
1231
|
-
let
|
|
1232
|
-
const l =
|
|
1233
|
-
for (;
|
|
1234
|
-
const c =
|
|
1330
|
+
let s = e + 1;
|
|
1331
|
+
const l = t.indent;
|
|
1332
|
+
for (; s < n.length; ) {
|
|
1333
|
+
const c = n[s];
|
|
1235
1334
|
if (c.line === "END" && c.indent === l) {
|
|
1236
|
-
|
|
1335
|
+
s++;
|
|
1237
1336
|
break;
|
|
1238
1337
|
}
|
|
1239
|
-
c.line.startsWith("GOTO ") ? (
|
|
1338
|
+
c.line.startsWith("GOTO ") ? (o = c.line.substring(5).trim(), s++) : (i.push(E(c.line)), s++);
|
|
1240
1339
|
}
|
|
1241
|
-
return { condition: a, next:
|
|
1340
|
+
return { condition: a, next: o, effects: i, nextIndex: s };
|
|
1242
1341
|
}
|
|
1243
|
-
function
|
|
1244
|
-
const r =
|
|
1245
|
-
let a = null,
|
|
1246
|
-
const l = [], c = [],
|
|
1247
|
-
let
|
|
1342
|
+
function Ve(n, e) {
|
|
1343
|
+
const r = n[e].line.substring(5).trim();
|
|
1344
|
+
let a = null, o = "", i, s;
|
|
1345
|
+
const l = [], c = [], u = [];
|
|
1346
|
+
let g;
|
|
1248
1347
|
const b = [];
|
|
1249
|
-
let
|
|
1250
|
-
for (;
|
|
1251
|
-
const h =
|
|
1348
|
+
let d = e + 1;
|
|
1349
|
+
for (; d < n.length; ) {
|
|
1350
|
+
const h = n[d];
|
|
1252
1351
|
if (h.line.startsWith("NODE "))
|
|
1253
1352
|
break;
|
|
1254
1353
|
if (h.line.includes(":") && !h.line.startsWith("VOICE")) {
|
|
1255
1354
|
const p = h.line.indexOf(":"), y = h.line.substring(0, p).trim(), I = h.line.substring(p + 1).trim();
|
|
1256
|
-
y === "NARRATOR" ? a = null : a = y.toLowerCase(),
|
|
1355
|
+
y === "NARRATOR" ? a = null : a = y.toLowerCase(), o = w(I), d++;
|
|
1257
1356
|
} else if (h.line.startsWith("VOICE "))
|
|
1258
|
-
i = h.line.substring(6).trim(),
|
|
1357
|
+
i = h.line.substring(6).trim(), d++;
|
|
1259
1358
|
else if (h.line.startsWith("PORTRAIT "))
|
|
1260
|
-
|
|
1359
|
+
s = h.line.substring(9).trim(), d++;
|
|
1261
1360
|
else if (h.line.startsWith("CHOICE ")) {
|
|
1262
|
-
const p =
|
|
1263
|
-
c.push(p.choice),
|
|
1361
|
+
const p = Re(n, d, r);
|
|
1362
|
+
c.push(p.choice), d = p.nextIndex;
|
|
1264
1363
|
} else if (h.line.startsWith("IF ")) {
|
|
1265
|
-
const p = De(
|
|
1364
|
+
const p = De(n, d);
|
|
1266
1365
|
p.next && b.push({
|
|
1267
1366
|
condition: p.condition,
|
|
1268
1367
|
next: p.next
|
|
1269
|
-
}),
|
|
1368
|
+
}), u.push(...p.effects), d = p.nextIndex;
|
|
1270
1369
|
} else if (h.line.startsWith("GOTO ")) {
|
|
1271
1370
|
const p = h.line.substring(5).trim();
|
|
1272
1371
|
if (p.startsWith("location ")) {
|
|
1273
1372
|
const y = p.substring(9).trim();
|
|
1274
|
-
|
|
1373
|
+
u.push({ type: "goToLocation", locationId: y }), u.push({ type: "endDialogue" });
|
|
1275
1374
|
} else
|
|
1276
|
-
|
|
1277
|
-
|
|
1375
|
+
g = p;
|
|
1376
|
+
d++;
|
|
1278
1377
|
} else
|
|
1279
|
-
|
|
1378
|
+
u.push(E(h.line)), d++;
|
|
1280
1379
|
}
|
|
1281
|
-
const
|
|
1380
|
+
const f = {
|
|
1282
1381
|
id: r,
|
|
1283
1382
|
speaker: a,
|
|
1284
|
-
text:
|
|
1383
|
+
text: o,
|
|
1285
1384
|
voice: i,
|
|
1286
|
-
portrait:
|
|
1385
|
+
portrait: s,
|
|
1287
1386
|
conditions: l.length > 0 ? l : void 0,
|
|
1288
1387
|
choices: c,
|
|
1289
|
-
effects:
|
|
1290
|
-
next:
|
|
1388
|
+
effects: u.length > 0 ? u : void 0,
|
|
1389
|
+
next: g
|
|
1291
1390
|
};
|
|
1292
|
-
return b.length > 0 && (
|
|
1391
|
+
return b.length > 0 && (f.conditionalNext = b), { node: f, nextIndex: d };
|
|
1293
1392
|
}
|
|
1294
|
-
function
|
|
1295
|
-
const
|
|
1393
|
+
function je(n, e) {
|
|
1394
|
+
const t = Oe(n);
|
|
1296
1395
|
let r;
|
|
1297
|
-
const a = [],
|
|
1298
|
-
let i = "",
|
|
1299
|
-
for (;
|
|
1300
|
-
const l =
|
|
1396
|
+
const a = [], o = [];
|
|
1397
|
+
let i = "", s = 0;
|
|
1398
|
+
for (; s < t.length; ) {
|
|
1399
|
+
const l = t[s];
|
|
1301
1400
|
if (l.line.startsWith("TRIGGER "))
|
|
1302
|
-
r = l.line.substring(8).trim(),
|
|
1401
|
+
r = l.line.substring(8).trim(), s++;
|
|
1303
1402
|
else if (l.line.startsWith("REQUIRE ")) {
|
|
1304
1403
|
const c = l.line.substring(8).trim();
|
|
1305
|
-
a.push(
|
|
1404
|
+
a.push(N(c)), s++;
|
|
1306
1405
|
} else if (l.line.startsWith("NODE ")) {
|
|
1307
|
-
const c =
|
|
1308
|
-
|
|
1406
|
+
const c = Ve(t, s);
|
|
1407
|
+
o.push(c.node), i || (i = c.node.id), s = c.nextIndex;
|
|
1309
1408
|
} else
|
|
1310
1409
|
throw new Error(`Unexpected token at line ${l.lineNumber}: ${l.line}`);
|
|
1311
1410
|
}
|
|
@@ -1314,86 +1413,89 @@ function qe(t, e) {
|
|
|
1314
1413
|
triggerLocation: r,
|
|
1315
1414
|
conditions: a.length > 0 ? a : void 0,
|
|
1316
1415
|
startNode: i,
|
|
1317
|
-
nodes:
|
|
1416
|
+
nodes: o
|
|
1318
1417
|
};
|
|
1319
1418
|
}
|
|
1320
|
-
function
|
|
1321
|
-
const
|
|
1419
|
+
function Ge(n, e) {
|
|
1420
|
+
const t = n;
|
|
1322
1421
|
window.doodle = {
|
|
1323
1422
|
// Flag manipulation
|
|
1324
1423
|
setFlag(r) {
|
|
1325
|
-
|
|
1424
|
+
t.state.flags[r] = !0, e(), console.log(`š¾ Flag set: ${r}`);
|
|
1326
1425
|
},
|
|
1327
1426
|
clearFlag(r) {
|
|
1328
|
-
delete
|
|
1427
|
+
delete t.state.flags[r], e(), console.log(`š¾ Flag cleared: ${r}`);
|
|
1329
1428
|
},
|
|
1330
1429
|
// Variable manipulation
|
|
1331
1430
|
setVariable(r, a) {
|
|
1332
|
-
|
|
1431
|
+
t.state.variables[r] = a, e(), console.log(`š¾ Variable set: ${r} = ${a}`);
|
|
1333
1432
|
},
|
|
1334
1433
|
getVariable(r) {
|
|
1335
|
-
const a =
|
|
1434
|
+
const a = t.state.variables[r];
|
|
1336
1435
|
return console.log(`š¾ Variable: ${r} = ${a}`), a;
|
|
1337
1436
|
},
|
|
1338
1437
|
// Location control
|
|
1339
1438
|
teleport(r) {
|
|
1340
|
-
|
|
1439
|
+
n.travelTo(r), e(), console.log(`š¾ Teleported to: ${r}`);
|
|
1341
1440
|
},
|
|
1342
1441
|
// Dialogue control
|
|
1343
1442
|
triggerDialogue(r) {
|
|
1344
|
-
const a =
|
|
1443
|
+
const a = t.registry.dialogues[r];
|
|
1345
1444
|
if (!a) {
|
|
1346
1445
|
console.error(`š¾ Dialogue not found: ${r}`);
|
|
1347
1446
|
return;
|
|
1348
1447
|
}
|
|
1349
|
-
const
|
|
1350
|
-
if (!
|
|
1448
|
+
const o = a.nodes.find((i) => i.id === a.startNode);
|
|
1449
|
+
if (!o) {
|
|
1351
1450
|
console.error(`š¾ Start node not found for dialogue: ${r}`);
|
|
1352
1451
|
return;
|
|
1353
1452
|
}
|
|
1354
|
-
|
|
1453
|
+
t.state.dialogueState = {
|
|
1355
1454
|
dialogueId: a.id,
|
|
1356
|
-
nodeId:
|
|
1455
|
+
nodeId: o.id
|
|
1357
1456
|
}, e(), console.log(`š¾ Triggered dialogue: ${r}`);
|
|
1358
1457
|
},
|
|
1359
1458
|
// Quest control
|
|
1360
1459
|
setQuestStage(r, a) {
|
|
1361
|
-
|
|
1460
|
+
t.state.questProgress[r] = a, e(), console.log(`š¾ Quest stage set: ${r} -> ${a}`);
|
|
1362
1461
|
},
|
|
1363
1462
|
// Inventory control
|
|
1364
1463
|
addItem(r) {
|
|
1365
|
-
|
|
1464
|
+
t.state.inventory.includes(r) ? console.log(`š¾ Item already in inventory: ${r}`) : (t.state.inventory.push(r), t.state.itemLocations[r] = "inventory", e(), console.log(`š¾ Item added: ${r}`));
|
|
1366
1465
|
},
|
|
1367
1466
|
removeItem(r) {
|
|
1368
|
-
const a =
|
|
1369
|
-
a !== -1 ? (
|
|
1467
|
+
const a = t.state.inventory.indexOf(r);
|
|
1468
|
+
a !== -1 ? (t.state.inventory.splice(a, 1), delete t.state.itemLocations[r], e(), console.log(`š¾ Item removed: ${r}`)) : console.log(`š¾ Item not in inventory: ${r}`);
|
|
1370
1469
|
},
|
|
1371
1470
|
// Inspection
|
|
1372
1471
|
inspect() {
|
|
1373
|
-
const r =
|
|
1374
|
-
console.log("š¾ DOODLE ENGINE INSPECTOR š¾"), console.log(""), console.log("Current Location:", r.location.name), console.log("Current Time:", `Day ${r.time.day}, Hour ${r.time.hour}`), console.log("Flags:", Object.keys(
|
|
1472
|
+
const r = n.getSnapshot();
|
|
1473
|
+
console.log("š¾ DOODLE ENGINE INSPECTOR š¾"), console.log(""), console.log("Current Location:", r.location.name), console.log("Current Time:", `Day ${r.time.day}, Hour ${r.time.hour}`), console.log("Flags:", Object.keys(t.state.flags)), console.log("Variables:", t.state.variables), console.log("Inventory:", r.inventory.map((a) => a.name)), console.log("Quest Progress:", t.state.questProgress), console.log(""), console.log("Available commands:"), console.log(" doodle.setFlag(flag)"), console.log(" doodle.clearFlag(flag)"), console.log(" doodle.setVariable(variable, value)"), console.log(" doodle.getVariable(variable)"), console.log(" doodle.teleport(locationId)"), console.log(" doodle.triggerDialogue(dialogueId)"), console.log(" doodle.setQuestStage(questId, stageId)"), console.log(" doodle.addItem(itemId)"), console.log(" doodle.removeItem(itemId)"), console.log(" doodle.inspectState()"), console.log(" doodle.inspectRegistry()"), console.log(""), console.log("š Docs: https://katbella.com/doodle-engine/");
|
|
1375
1474
|
},
|
|
1376
1475
|
inspectState() {
|
|
1377
|
-
return console.log("š¾ GAME STATE:",
|
|
1476
|
+
return console.log("š¾ GAME STATE:", t.state), t.state;
|
|
1378
1477
|
},
|
|
1379
1478
|
inspectRegistry() {
|
|
1380
|
-
return console.log("š¾ CONTENT REGISTRY:",
|
|
1479
|
+
return console.log("š¾ CONTENT REGISTRY:", t.registry), t.registry;
|
|
1381
1480
|
}
|
|
1382
1481
|
}, console.log("š¾ Doodle Engine dev tools enabled! Type `doodle.inspect()` to see available commands.\nš You can also check out the docs: https://katbella.com/doodle-engine/");
|
|
1383
1482
|
}
|
|
1384
|
-
const
|
|
1483
|
+
const He = "0.0.1";
|
|
1385
1484
|
export {
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
Pe as
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
qe as
|
|
1397
|
-
|
|
1485
|
+
We as Engine,
|
|
1486
|
+
He as VERSION,
|
|
1487
|
+
_ as applyEffect,
|
|
1488
|
+
v as applyEffects,
|
|
1489
|
+
Ie as buildSnapshot,
|
|
1490
|
+
Pe as createAssetLoader,
|
|
1491
|
+
Me as createResolver,
|
|
1492
|
+
Ge as enableDevTools,
|
|
1493
|
+
R as evaluateCondition,
|
|
1494
|
+
S as evaluateConditions,
|
|
1495
|
+
qe as extractAssetPaths,
|
|
1496
|
+
Fe as getAssetType,
|
|
1497
|
+
N as parseCondition,
|
|
1498
|
+
je as parseDialogue,
|
|
1499
|
+
E as parseEffect,
|
|
1398
1500
|
L as resolveText
|
|
1399
1501
|
};
|