@drincs/nqtr 0.0.1

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/dist/index.mjs ADDED
@@ -0,0 +1,1057 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+
18
+ // src/classes/Activity.ts
19
+ import { getFlag } from "@drincs/pixi-vn";
20
+
21
+ // src/managers/TimeManager.ts
22
+ import { GameStorageManager } from "@drincs/pixi-vn";
23
+ var TIME_SETTINGS_KEY = "___nqtr-time_manager_settings___";
24
+ var TIME_DATA_KEY = "___nqtr-time_manager_data___";
25
+ var TimeManager = class _TimeManager {
26
+ constructor() {
27
+ }
28
+ static set editSettings(value) {
29
+ let settings = {};
30
+ if (typeof value.minDayHour === "number") {
31
+ settings["minDayHour"] = value.minDayHour;
32
+ }
33
+ if (typeof value.maxDayHour === "number") {
34
+ settings["maxDayHour"] = value.maxDayHour;
35
+ }
36
+ if (typeof value.minDayHour === "number") {
37
+ settings["defaultTimeSpent"] = value.defaultTimeSpent;
38
+ }
39
+ if (Array.isArray(value.timeSlots)) {
40
+ settings["timeSlots"] = value.timeSlots;
41
+ }
42
+ if (typeof value.weekLength === "number") {
43
+ settings["weekLength"] = value.weekLength;
44
+ }
45
+ if (typeof value.newDayHour === "number") {
46
+ settings["newDayHour"] = value.newDayHour;
47
+ }
48
+ if (typeof value.weekendStartDay === "number") {
49
+ let weekLength = value.weekLength || _TimeManager.weekLength;
50
+ if (value.weekendStartDay >= weekLength) {
51
+ console.warn(`[NQTR] Weekend start day should be less than week length ${weekLength}`);
52
+ }
53
+ settings["weekendStartDay"] = value.weekendStartDay;
54
+ }
55
+ if (Array.isArray(value.weekDaysNames)) {
56
+ let weekLength = value.weekLength || _TimeManager.weekLength;
57
+ if (value.weekDaysNames.length !== weekLength) {
58
+ console.warn(`[NQTR] Week days names should be equal to week length ${weekLength}`);
59
+ }
60
+ settings["weekDaysNames"] = value.weekDaysNames;
61
+ }
62
+ GameStorageManager.setVariable(TIME_SETTINGS_KEY, settings);
63
+ }
64
+ static get minDayHour() {
65
+ let result = 0;
66
+ let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY);
67
+ if (settings && settings.hasOwnProperty("minDayHour")) {
68
+ result = settings.minDayHour || 0;
69
+ }
70
+ return result;
71
+ }
72
+ static get maxDayHour() {
73
+ let result = 24;
74
+ let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY);
75
+ if (settings && settings.hasOwnProperty("maxDayHour")) {
76
+ result = settings.maxDayHour || 24;
77
+ }
78
+ return result;
79
+ }
80
+ static get defaultTimeSpent() {
81
+ let result = 1;
82
+ let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY);
83
+ if (settings && settings.hasOwnProperty("defaultTimeSpent")) {
84
+ result = settings.defaultTimeSpent || 1;
85
+ }
86
+ return result;
87
+ }
88
+ static get newDayHour() {
89
+ let result = 0;
90
+ let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY);
91
+ if (settings && settings.hasOwnProperty("newDayHour")) {
92
+ result = settings.newDayHour || 0;
93
+ }
94
+ return result;
95
+ }
96
+ static get timeSlots() {
97
+ let result = [];
98
+ let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY);
99
+ if (settings && settings.hasOwnProperty("timeSlots")) {
100
+ result = settings.timeSlots || [];
101
+ }
102
+ return result;
103
+ }
104
+ static get weekLength() {
105
+ let result = 7;
106
+ let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY);
107
+ if (settings && settings.hasOwnProperty("weekLength")) {
108
+ result = settings.weekLength || 7;
109
+ }
110
+ return result;
111
+ }
112
+ static get weekendStartDay() {
113
+ let result = _TimeManager.weekLength - 1;
114
+ let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY);
115
+ if (settings && settings.hasOwnProperty("weekendStartDay")) {
116
+ result = settings.weekendStartDay || _TimeManager.weekLength - 1;
117
+ }
118
+ return result;
119
+ }
120
+ static get weekDaysNames() {
121
+ let result = [];
122
+ let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY);
123
+ if (settings && settings.hasOwnProperty("weekDaysNames")) {
124
+ result = settings.weekDaysNames || result;
125
+ }
126
+ return result;
127
+ }
128
+ static get currentHour() {
129
+ let data = GameStorageManager.getVariable(TIME_DATA_KEY) || {};
130
+ if (data.hasOwnProperty("currentHour") && typeof data.currentHour === "number") {
131
+ return data.currentHour;
132
+ }
133
+ return _TimeManager.minDayHour;
134
+ }
135
+ static set currentHour(value) {
136
+ let data = GameStorageManager.getVariable(TIME_DATA_KEY) || {};
137
+ if (typeof value === "number") {
138
+ data.currentHour = value;
139
+ } else {
140
+ delete data.currentHour;
141
+ }
142
+ GameStorageManager.setVariable(TIME_DATA_KEY, data);
143
+ }
144
+ static get currentDay() {
145
+ let data = GameStorageManager.getVariable(TIME_DATA_KEY) || {};
146
+ if (data.hasOwnProperty("currentDay") && typeof data.currentDay === "number") {
147
+ return data.currentDay;
148
+ }
149
+ return 0;
150
+ }
151
+ static set currentDay(value) {
152
+ let data = GameStorageManager.getVariable(TIME_DATA_KEY) || {};
153
+ if (typeof value === "number") {
154
+ data.currentDay = value;
155
+ } else {
156
+ delete data.currentDay;
157
+ }
158
+ GameStorageManager.setVariable(TIME_DATA_KEY, data);
159
+ }
160
+ static get isWeekend() {
161
+ return _TimeManager.weekDayNumber >= _TimeManager.weekendStartDay;
162
+ }
163
+ static get weekDayNumber() {
164
+ let result = _TimeManager.currentDay % _TimeManager.weekLength;
165
+ return result + 1;
166
+ }
167
+ static get weekDayName() {
168
+ let weekDayNumber = _TimeManager.weekDayNumber - 1;
169
+ if (weekDayNumber >= _TimeManager.weekDaysNames.length) {
170
+ console.warn(`[NQTR] Week day name is not defined for day ${weekDayNumber}`, _TimeManager.weekDaysNames);
171
+ return void 0;
172
+ }
173
+ return _TimeManager.weekDaysNames[weekDayNumber];
174
+ }
175
+ static newHour(timeSpent = _TimeManager.defaultTimeSpent) {
176
+ let newHour = _TimeManager.currentHour + timeSpent;
177
+ if (newHour >= _TimeManager.maxDayHour) {
178
+ _TimeManager.newDay();
179
+ newHour = _TimeManager.minDayHour + (newHour - _TimeManager.maxDayHour);
180
+ }
181
+ _TimeManager.currentHour = newHour;
182
+ return newHour;
183
+ }
184
+ static newDay(days = 1) {
185
+ let newDay = _TimeManager.currentDay + days;
186
+ _TimeManager.currentDay = newDay;
187
+ return newDay;
188
+ }
189
+ static nowIsBetween(fromHour, toHour) {
190
+ let currentHour = _TimeManager.currentHour;
191
+ if (fromHour < toHour) {
192
+ return currentHour >= fromHour && currentHour < toHour;
193
+ }
194
+ return currentHour >= fromHour || currentHour < toHour;
195
+ }
196
+ };
197
+
198
+ // src/classes/Activity.ts
199
+ var ActivityStoredAbstract = class {
200
+ constructor(onRun, props) {
201
+ this.defaultName = props.name;
202
+ this.defaultFromHour = props.fromHour;
203
+ this.defaultToHour = props.toHour;
204
+ this.defaultFromDay = props.fromDay;
205
+ this.defaultToDay = props.toDay;
206
+ this.defaultDisabled = props.disabled || false;
207
+ this.defaultHidden = props.hidden || false;
208
+ this._iconElement = props.iconElement;
209
+ this._onRun = onRun;
210
+ }
211
+ get name() {
212
+ return this.getStorageProperty("name") || this.defaultName || "";
213
+ }
214
+ set name(value) {
215
+ this.setStorageProperty("name", value);
216
+ }
217
+ get fromHour() {
218
+ return this.getStorageProperty("fromHour") || this.defaultFromHour || TimeManager.minDayHour;
219
+ }
220
+ set fromHour(value) {
221
+ this.setStorageProperty("fromHour", value);
222
+ }
223
+ get toHour() {
224
+ return this.getStorageProperty("toHour") || this.defaultToHour || TimeManager.maxDayHour + 1;
225
+ }
226
+ set toHour(value) {
227
+ this.setStorageProperty("toHour", value);
228
+ }
229
+ get fromDay() {
230
+ return this.getStorageProperty("fromDay") || this.defaultFromDay;
231
+ }
232
+ set fromDay(value) {
233
+ this.setStorageProperty("fromDay", value);
234
+ }
235
+ get toDay() {
236
+ return this.getStorageProperty("toDay") || this.defaultToDay;
237
+ }
238
+ set toDay(value) {
239
+ this.setStorageProperty("toDay", value);
240
+ }
241
+ get disabled() {
242
+ let value = this.getStorageProperty("disabled") || this.defaultDisabled;
243
+ if (typeof value === "string") {
244
+ return getFlag(value);
245
+ }
246
+ return value;
247
+ }
248
+ set disabled(value) {
249
+ this.setStorageProperty("disabled", value);
250
+ }
251
+ get hidden() {
252
+ if (this.fromDay && this.fromDay > TimeManager.currentDay) {
253
+ return true;
254
+ }
255
+ if (!TimeManager.nowIsBetween(this.fromHour, this.toHour)) {
256
+ return true;
257
+ }
258
+ if (!this.isExpired) {
259
+ return true;
260
+ }
261
+ let value = this.getStorageProperty("hidden") || this.defaultHidden;
262
+ if (typeof value === "string") {
263
+ return getFlag(value);
264
+ }
265
+ return value;
266
+ }
267
+ set hidden(value) {
268
+ this.setStorageProperty("hidden", value);
269
+ }
270
+ get iconElement() {
271
+ return this._iconElement;
272
+ }
273
+ get onRun() {
274
+ return this._onRun;
275
+ }
276
+ isExpired() {
277
+ if (this.toDay && this.toDay <= TimeManager.currentDay) {
278
+ return true;
279
+ }
280
+ return false;
281
+ }
282
+ export() {
283
+ return {
284
+ name: this.getStorageProperty("name") || this.defaultName,
285
+ fromHour: this.getStorageProperty("fromHour") || this.defaultFromHour,
286
+ toHour: this.getStorageProperty("toHour") || this.defaultToHour,
287
+ fromDay: this.getStorageProperty("fromDay") || this.defaultFromDay,
288
+ toDay: this.getStorageProperty("toDay") || this.defaultToDay,
289
+ disabled: this.getStorageProperty("disabled") || this.defaultDisabled,
290
+ hidden: this.getStorageProperty("hidden") || this.defaultHidden,
291
+ iconElement: this._iconElement
292
+ };
293
+ }
294
+ };
295
+ var ActivityModel = class {
296
+ constructor(id, onRun, props) {
297
+ this._id = id;
298
+ this._name = props.name;
299
+ this._fromHour = props.fromHour;
300
+ this._toHour = props.toHour;
301
+ this._fromDay = props.fromDay;
302
+ this._toDay = props.toDay;
303
+ this._disabled = props.disabled || false;
304
+ this._hidden = props.hidden || false;
305
+ this._iconElement = props.iconElement;
306
+ this._onRun = onRun;
307
+ }
308
+ get id() {
309
+ return this._id;
310
+ }
311
+ get name() {
312
+ return this._name;
313
+ }
314
+ get fromHour() {
315
+ return this._fromHour;
316
+ }
317
+ get toHour() {
318
+ return this._toHour;
319
+ }
320
+ get fromDay() {
321
+ return this._fromDay;
322
+ }
323
+ get toDay() {
324
+ return this._toDay;
325
+ }
326
+ get disabled() {
327
+ if (typeof this._disabled === "string") {
328
+ return getFlag(this._disabled);
329
+ }
330
+ return this._disabled;
331
+ }
332
+ get hidden() {
333
+ if (this.fromDay && this.fromDay > TimeManager.currentDay) {
334
+ return true;
335
+ }
336
+ if (!this.isDeadline) {
337
+ return true;
338
+ }
339
+ if (typeof this._hidden === "string") {
340
+ return getFlag(this._hidden);
341
+ }
342
+ return this._hidden;
343
+ }
344
+ get iconElement() {
345
+ return this._iconElement;
346
+ }
347
+ get onRun() {
348
+ return this._onRun;
349
+ }
350
+ isDeadline() {
351
+ if (this.toDay && this.toDay <= TimeManager.currentDay) {
352
+ return true;
353
+ }
354
+ return false;
355
+ }
356
+ export() {
357
+ return {
358
+ name: this._name,
359
+ fromHour: this._fromHour,
360
+ toHour: this._toHour,
361
+ fromDay: this._fromDay,
362
+ toDay: this._toDay,
363
+ disabled: this._disabled,
364
+ hidden: this._hidden,
365
+ iconElement: this._iconElement
366
+ };
367
+ }
368
+ };
369
+
370
+ // src/classes/navigation/Location.ts
371
+ import { getFlag as getFlag2, StoredClassModel } from "@drincs/pixi-vn";
372
+ var LOCATION_CATEGORY = "__nqtr-location__";
373
+ var LocationBaseModel = class extends StoredClassModel {
374
+ constructor(id, map, entrance, props) {
375
+ super(LOCATION_CATEGORY, id);
376
+ if (entrance.location.id !== id) {
377
+ throw new Error(`[NQTR] Entrance room ${entrance.id} is not in location ${id}`);
378
+ }
379
+ this._entrance = entrance;
380
+ this.defaultName = props.name || "";
381
+ this.defaultDisabled = props.disabled || false;
382
+ this.defaultHidden = props.hidden || false;
383
+ this._iconElement = props.iconElement;
384
+ this._map = map;
385
+ }
386
+ get entrance() {
387
+ return this._entrance;
388
+ }
389
+ get name() {
390
+ return this.getStorageProperty("name") || this.defaultName;
391
+ }
392
+ set name(value) {
393
+ this.setStorageProperty("name", value);
394
+ }
395
+ get disabled() {
396
+ let value = this.getStorageProperty("disabled") || this.defaultDisabled;
397
+ if (typeof value === "string") {
398
+ return getFlag2(value);
399
+ }
400
+ return value;
401
+ }
402
+ set disabled(value) {
403
+ this.setStorageProperty("disabled", value);
404
+ }
405
+ get hidden() {
406
+ let value = this.getStorageProperty("hidden") || this.defaultHidden;
407
+ if (typeof value === "string") {
408
+ return getFlag2(value);
409
+ }
410
+ return value;
411
+ }
412
+ set hidden(value) {
413
+ this.setStorageProperty("hidden", value);
414
+ }
415
+ get iconElement() {
416
+ return this._iconElement;
417
+ }
418
+ get map() {
419
+ return this._map;
420
+ }
421
+ };
422
+
423
+ // src/classes/navigation/Map.ts
424
+ import { getFlag as getFlag3, StoredClassModel as StoredClassModel2 } from "@drincs/pixi-vn";
425
+ var MAP_CATEGORY = "__nqtr-map__";
426
+ var MapBaseModel = class extends StoredClassModel2 {
427
+ constructor(id, props) {
428
+ super(MAP_CATEGORY, id);
429
+ this.defaultName = props.name || "";
430
+ this.defaultImage = props.image;
431
+ this.defaultDisabled = props.disabled || false;
432
+ this.defaultHidden = props.hidden || false;
433
+ }
434
+ get name() {
435
+ return this.getStorageProperty("name") || this.defaultName;
436
+ }
437
+ set name(value) {
438
+ this.setStorageProperty("name", value);
439
+ }
440
+ get image() {
441
+ return this.getStorageProperty("image") || this.defaultImage;
442
+ }
443
+ set image(value) {
444
+ this.setStorageProperty("image", value);
445
+ }
446
+ get disabled() {
447
+ let value = this.getStorageProperty("disabled") || this.defaultDisabled;
448
+ if (typeof value === "string") {
449
+ return getFlag3(value);
450
+ }
451
+ return value;
452
+ }
453
+ set disabled(value) {
454
+ this.setStorageProperty("disabled", value);
455
+ }
456
+ get hidden() {
457
+ let value = this.getStorageProperty("hidden") || this.defaultHidden;
458
+ if (typeof value === "string") {
459
+ return getFlag3(value);
460
+ }
461
+ return value;
462
+ }
463
+ set hidden(value) {
464
+ this.setStorageProperty("hidden", value);
465
+ }
466
+ };
467
+
468
+ // src/classes/navigation/Room.ts
469
+ import { getFlag as getFlag4, StoredClassModel as StoredClassModel3 } from "@drincs/pixi-vn";
470
+
471
+ // src/decorators/ActivityDecorator.ts
472
+ var registeredActivities = {};
473
+ function saveActivity(activity) {
474
+ if (Array.isArray(activity)) {
475
+ activity.forEach((c) => saveActivity(c));
476
+ return;
477
+ }
478
+ if (registeredActivities[activity.id]) {
479
+ console.warn(`[NQTR] Activity id ${activity.id} already exists, it will be overwritten`);
480
+ }
481
+ registeredActivities[activity.id] = activity;
482
+ }
483
+ function getActivityById(id) {
484
+ try {
485
+ let activity = registeredActivities[id];
486
+ if (!activity) {
487
+ console.error(`[NQTR] Activity ${id} not found`);
488
+ return;
489
+ }
490
+ return activity;
491
+ } catch (e) {
492
+ console.error(`[NQTR] Error while getting Activity ${id}`, e);
493
+ return;
494
+ }
495
+ }
496
+
497
+ // src/decorators/CommitmentDecorator.ts
498
+ import { GameStorageManager as GameStorageManager2 } from "@drincs/pixi-vn";
499
+ var TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY = "___nqtr-temporary_commitment___";
500
+ var registeredCommitments = {};
501
+ var fixedCommitments = {};
502
+ function saveCommitment(commitment) {
503
+ if (Array.isArray(commitment)) {
504
+ commitment.forEach((c) => saveCommitment(c));
505
+ return;
506
+ }
507
+ if (registeredCommitments[commitment.id]) {
508
+ console.warn(`[NQTR] Commitment id ${commitment.id} already exists, it will be overwritten`);
509
+ }
510
+ registeredCommitments[commitment.id] = commitment;
511
+ }
512
+ function getCommitmentById(id) {
513
+ try {
514
+ let commitment = registeredCommitments[id];
515
+ if (!commitment) {
516
+ console.error(`[NQTR] Commitment ${id} not found`);
517
+ return;
518
+ }
519
+ return commitment;
520
+ } catch (e) {
521
+ console.error(`[NQTR] Error while getting Commitment ${id}`, e);
522
+ return;
523
+ }
524
+ }
525
+ function setFixedCommitments(commitments) {
526
+ if (Array.isArray(commitments)) {
527
+ commitments.forEach((c) => saveCommitment(c));
528
+ return;
529
+ }
530
+ if (registeredCommitments[commitments.id]) {
531
+ console.warn(`[NQTR] Commitment id ${commitments.id} already exists, it will be overwritten`);
532
+ }
533
+ registeredCommitments[commitments.id] = commitments;
534
+ }
535
+ function addTemporaryCommitment(commitment) {
536
+ if (!Array.isArray(commitment)) {
537
+ commitment = [commitment];
538
+ }
539
+ let commitmentsIds = commitment.map((commitment2) => {
540
+ let commitmentTest = getCommitmentById(commitment2.id);
541
+ if (!commitmentTest) {
542
+ console.warn(`[NQTR] Commitment ${commitment2.id} not found, it will be ignored`);
543
+ return void 0;
544
+ }
545
+ return commitment2.id;
546
+ }).filter((id) => id !== void 0);
547
+ GameStorageManager2.setVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY, [commitmentsIds]);
548
+ }
549
+ function getFixedCommitments() {
550
+ return Object.values(fixedCommitments);
551
+ }
552
+ function getTemporaryCommitments() {
553
+ let commitmentsIds = GameStorageManager2.getVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY);
554
+ if (!commitmentsIds) {
555
+ return [];
556
+ }
557
+ let commitments = commitmentsIds.map((id) => getCommitmentById(id)).filter((commitment) => commitment !== void 0);
558
+ return commitments;
559
+ }
560
+
561
+ // src/decorators/RoomDecorator.ts
562
+ var registeredRooms = {};
563
+ function saveRoom(room) {
564
+ if (Array.isArray(room)) {
565
+ room.forEach((c) => saveRoom(c));
566
+ return;
567
+ }
568
+ if (registeredRooms[room.id]) {
569
+ console.warn(`[NQTR] Room id ${room.id} already exists, it will be overwritten`);
570
+ }
571
+ registeredRooms[room.id] = room;
572
+ }
573
+ function getRoomById(id) {
574
+ try {
575
+ let room = registeredRooms[id];
576
+ if (!room) {
577
+ console.error(`[NQTR] Room ${id} not found`);
578
+ return;
579
+ }
580
+ return room;
581
+ } catch (e) {
582
+ console.error(`[NQTR] Error while getting Room ${id}`, e);
583
+ return;
584
+ }
585
+ }
586
+
587
+ // src/functions/RoutineFunctions.ts
588
+ function clearExpiredRoutine() {
589
+ Object.entries(registeredCommitments).forEach(([_, commitment]) => {
590
+ if (commitment.isExpired()) {
591
+ delete registeredCommitments[commitment.id];
592
+ }
593
+ });
594
+ }
595
+ function getCurrentCommitments() {
596
+ let character_commitments = {};
597
+ let oltherCommitments = [];
598
+ getTemporaryCommitments().reverse().forEach((c) => {
599
+ if (!c.hidden) {
600
+ if (c.characters.length > 1) {
601
+ let allAvailable = c.characters.every((ch) => !character_commitments[ch.id]);
602
+ if (allAvailable) {
603
+ c.characters.forEach((ch) => {
604
+ character_commitments[ch.id] = c;
605
+ });
606
+ }
607
+ } else {
608
+ oltherCommitments.push(c);
609
+ }
610
+ }
611
+ });
612
+ getFixedCommitments().reverse().forEach((c) => {
613
+ if (!c.hidden) {
614
+ if (c.characters.length > 1) {
615
+ c.characters.forEach((ch) => {
616
+ if (!character_commitments[ch.id]) {
617
+ character_commitments[ch.id] = c;
618
+ }
619
+ });
620
+ } else {
621
+ oltherCommitments.push(c);
622
+ }
623
+ }
624
+ });
625
+ return Object.values(character_commitments).concat(oltherCommitments);
626
+ }
627
+ function getCommitmentByCharacter(character) {
628
+ getCurrentCommitments().forEach((c) => {
629
+ if (c.characters.map((ch) => ch.id).includes(character.id)) {
630
+ return c;
631
+ }
632
+ });
633
+ return void 0;
634
+ }
635
+
636
+ // src/classes/navigation/ActivityRoom.ts
637
+ var ActivityRoom = class extends ActivityStoredAbstract {
638
+ constructor(id, room, onRun, props) {
639
+ super(onRun, props);
640
+ this._id = id;
641
+ this._room = room;
642
+ }
643
+ setStorageProperty(_, __) {
644
+ this._room.setActivity(this);
645
+ }
646
+ getStorageProperty(propertyName) {
647
+ let activity = this._room.getActivityMemory(this.id);
648
+ if (!activity || !activity.hasOwnProperty(propertyName)) {
649
+ return void 0;
650
+ }
651
+ return activity[propertyName];
652
+ }
653
+ get id() {
654
+ return this._id;
655
+ }
656
+ get room() {
657
+ return this._room;
658
+ }
659
+ export() {
660
+ let result = {};
661
+ if (this.name !== void 0) {
662
+ result["name"] = this.name;
663
+ }
664
+ if (this.fromHour !== void 0) {
665
+ result["fromHour"] = this.fromHour;
666
+ }
667
+ if (this.toHour !== void 0) {
668
+ result["toHour"] = this.toHour;
669
+ }
670
+ if (this.fromDay !== void 0) {
671
+ result["fromDay"] = this.fromDay;
672
+ }
673
+ if (this.toDay !== void 0) {
674
+ result["toDay"] = this.toDay;
675
+ }
676
+ if (this.disabled !== void 0) {
677
+ result["disabled"] = this.disabled;
678
+ }
679
+ return result;
680
+ }
681
+ };
682
+
683
+ // src/classes/navigation/Room.ts
684
+ var ROOM_CATEGORY = "__nqtr-room__";
685
+ var RoomBaseModel = class extends StoredClassModel3 {
686
+ constructor(id, location, props) {
687
+ var _a;
688
+ super(ROOM_CATEGORY, id);
689
+ this._location = location;
690
+ this.defaultName = props.name || "";
691
+ this.defaultImage = props.image;
692
+ this.defaultActivityIds = ((_a = props.defaultActivities) == null ? void 0 : _a.map((activity) => activity.id)) || [];
693
+ this.defaultDisabled = props.disabled || false;
694
+ this.defaultHidden = props.hidden || false;
695
+ this._iconElement = props.iconElement;
696
+ }
697
+ get location() {
698
+ return this._location;
699
+ }
700
+ get name() {
701
+ return this.getStorageProperty("name") || this.defaultName;
702
+ }
703
+ set name(value) {
704
+ this.setStorageProperty("name", value);
705
+ }
706
+ get image() {
707
+ return this.getStorageProperty("image") || this.defaultImage;
708
+ }
709
+ set image(value) {
710
+ this.setStorageProperty("image", value);
711
+ }
712
+ get defaultActivities() {
713
+ let roomMemories = this.getStorageProperty("activities_memory") || {};
714
+ let activities = this.defaultActivityIds.map((id) => {
715
+ let activity = getActivityById(id);
716
+ if (!activity) {
717
+ console.warn(`[NQTR] Activity with id ${id} not found, so it will be ignored.`);
718
+ return void 0;
719
+ }
720
+ let memory = activity.export();
721
+ if (roomMemories && roomMemories[id]) {
722
+ memory = __spreadValues(__spreadValues({}, memory), roomMemories[id]);
723
+ }
724
+ return new ActivityRoom(id, this, activity.onRun, memory);
725
+ }).filter((activity) => activity !== void 0);
726
+ return activities;
727
+ }
728
+ get activityIds() {
729
+ let addedActivityIds = this.getStorageProperty(`addedActivityIds`) || [];
730
+ return this.defaultActivityIds.concat(addedActivityIds);
731
+ }
732
+ get activities() {
733
+ let activities = this.activityIds.map((id) => {
734
+ return this.getActivity(id);
735
+ }).filter((activity) => activity !== void 0);
736
+ return activities;
737
+ }
738
+ getActivityMemory(id) {
739
+ let roomMemories = this.getStorageProperty("activities_memory") || {};
740
+ let roomMemory = roomMemories[id] || {};
741
+ return roomMemory;
742
+ }
743
+ getActivity(id) {
744
+ if (!this.activityIds.includes(id)) {
745
+ console.error(`[NQTR] Activity with id ${id} not found in room ${this.id}`);
746
+ return void 0;
747
+ }
748
+ let activity = getActivityById(id);
749
+ if (!activity) {
750
+ console.error(`[NQTR] Activity with id ${id} not found`);
751
+ return void 0;
752
+ }
753
+ let roomMemories = this.getStorageProperty("activities_memory") || {};
754
+ let roomMemory = roomMemories[id] || {};
755
+ roomMemory = __spreadValues(__spreadValues({}, activity.export()), roomMemory);
756
+ return new ActivityRoom(id, this, activity.onRun, roomMemory);
757
+ }
758
+ setActivity(activity) {
759
+ let roomMemories = this.getStorageProperty("activities_memory") || {};
760
+ roomMemories[activity.id] = activity.export();
761
+ this.setStorageProperty("activities_memory", roomMemories);
762
+ }
763
+ addActivity(activity) {
764
+ if (this.activityIds.includes(activity.id)) {
765
+ let currentActivity = this.getActivity(activity.id);
766
+ if (currentActivity && currentActivity.isExpired()) {
767
+ this.removeActivity(activity.id);
768
+ return;
769
+ } else {
770
+ console.error(`[NQTR] Activity with id ${activity.id} already exists in room ${this.id}, so it will be ignored.`);
771
+ return;
772
+ }
773
+ }
774
+ let addedActivityIds = this.getStorageProperty(`addedActivityIds`) || [];
775
+ addedActivityIds.push(activity.id);
776
+ this.setStorageProperty("addedActivityIds", addedActivityIds);
777
+ }
778
+ removeActivity(activity) {
779
+ let activityId = typeof activity === "string" ? activity : activity.id;
780
+ if (this.defaultActivityIds.includes(activityId)) {
781
+ console.warn(`[NQTR] Activity with id ${activityId} is a default activity, so it can't be removed. It will be hidden instead.`);
782
+ let activityToEdit = this.getActivity(activityId);
783
+ if (!activityToEdit) {
784
+ console.error(`[NQTR] Activity with id ${activityId} not found, so it can't be hidden.`);
785
+ return;
786
+ }
787
+ activityToEdit.hidden = true;
788
+ return;
789
+ }
790
+ let addedActivityIds = this.getStorageProperty(`addedActivityIds`) || [];
791
+ let index = addedActivityIds.indexOf(activityId);
792
+ if (index === -1) {
793
+ console.error(`[NQTR] Activity with id ${activityId} not found, so it can't be removed.`);
794
+ return;
795
+ }
796
+ addedActivityIds.splice(index, 1);
797
+ this.setStorageProperty("addedActivityIds", addedActivityIds);
798
+ let roomMemories = this.getStorageProperty("activities_memory") || {};
799
+ delete roomMemories[activityId];
800
+ this.setStorageProperty("activities_memory", roomMemories);
801
+ }
802
+ clearExpiredActivities() {
803
+ this.activities.forEach((activity) => {
804
+ if (activity.isExpired()) {
805
+ this.removeActivity(activity.id);
806
+ }
807
+ });
808
+ }
809
+ get disabled() {
810
+ let value = this.getStorageProperty("disabled") || this.defaultDisabled;
811
+ if (typeof value === "string") {
812
+ return getFlag4(value);
813
+ }
814
+ return value;
815
+ }
816
+ set disabled(value) {
817
+ this.setStorageProperty("disabled", value);
818
+ }
819
+ get hidden() {
820
+ let value = this.getStorageProperty("hidden") || this.defaultHidden;
821
+ if (typeof value === "string") {
822
+ return getFlag4(value);
823
+ }
824
+ return value;
825
+ }
826
+ set hidden(value) {
827
+ this.setStorageProperty("hidden", value);
828
+ }
829
+ get iconElement() {
830
+ return this._iconElement;
831
+ }
832
+ getRoutine() {
833
+ let commitments = getCurrentCommitments();
834
+ return commitments.filter((c) => c.room.id === this.id);
835
+ }
836
+ };
837
+
838
+ // src/classes/quest/Goal.ts
839
+ var Goal = class {
840
+ constructor(props) {
841
+ this._description = props.description;
842
+ this.need = props.need || 1;
843
+ this.have = props.have || 0;
844
+ }
845
+ get description() {
846
+ return this._description;
847
+ }
848
+ get isComplete() {
849
+ return this.have >= this.need;
850
+ }
851
+ setComplete() {
852
+ this.have = this.need;
853
+ }
854
+ find() {
855
+ this.have++;
856
+ }
857
+ get export() {
858
+ return {
859
+ description: this.description,
860
+ need: this.need,
861
+ have: this.have
862
+ };
863
+ }
864
+ };
865
+
866
+ // src/classes/quest/Quest.ts
867
+ import { StoredClassModel as StoredClassModel4 } from "@drincs/pixi-vn";
868
+ var QUEST_CATEGORY = "__nqtr-quest__";
869
+ var QuestBaseModel = class extends StoredClassModel4 {
870
+ constructor(id, stages, props) {
871
+ super(QUEST_CATEGORY, id);
872
+ this._stages = stages;
873
+ this._name = props.name || "";
874
+ this._description = props.description || "";
875
+ this._icon = props.icon || "";
876
+ this._image = props.image || "";
877
+ this._isInDevelopment = props.isInDevelopment || false;
878
+ }
879
+ get stages() {
880
+ return this._stages;
881
+ }
882
+ get name() {
883
+ return this._name;
884
+ }
885
+ get description() {
886
+ return this._description;
887
+ }
888
+ get icon() {
889
+ return this._icon;
890
+ }
891
+ get image() {
892
+ return this._image;
893
+ }
894
+ get isInDevelopment() {
895
+ return this._isInDevelopment;
896
+ }
897
+ };
898
+
899
+ // src/classes/quest/Stage.ts
900
+ import { StoredClassModel as StoredClassModel5 } from "@drincs/pixi-vn";
901
+ var STAGE_CATEGORY = "__nqtr-stage__";
902
+ var StageBaseModel = class extends StoredClassModel5 {
903
+ constructor(id, props) {
904
+ super(STAGE_CATEGORY, id);
905
+ this._completed = false;
906
+ this._active = false;
907
+ this.defaultGoals = [];
908
+ this._name = props.name || "";
909
+ this._description = props.description || "";
910
+ this._adviceDescription = props.adviceDescription || "";
911
+ this._image = props.image || "";
912
+ this._daysRequiredToStart = props.daysRequiredToStart;
913
+ this._flagsRequired = props.flagsRequired;
914
+ this._questsRequired = props.questsRequired;
915
+ this._requestDescription = props.requestDescription || "";
916
+ this._onStart = props.onStart;
917
+ this._onEnd = props.onEnd;
918
+ }
919
+ get completed() {
920
+ return this._completed;
921
+ }
922
+ get active() {
923
+ return this._active;
924
+ }
925
+ get goals() {
926
+ let list = this.getStorageProperty("goals");
927
+ if (!list) {
928
+ return this.defaultGoals;
929
+ }
930
+ return list.map((goal) => new Goal(goal));
931
+ }
932
+ set goals(value) {
933
+ let list = value.map((goal) => goal.export);
934
+ this.setStorageProperty("goals", list);
935
+ }
936
+ get name() {
937
+ return this._name;
938
+ }
939
+ get description() {
940
+ return this._description;
941
+ }
942
+ get adviceDescription() {
943
+ return this._adviceDescription;
944
+ }
945
+ get image() {
946
+ return this._image;
947
+ }
948
+ get daysRequiredToStart() {
949
+ return this._daysRequiredToStart;
950
+ }
951
+ get flagsRequired() {
952
+ return this._flagsRequired;
953
+ }
954
+ get questsRequired() {
955
+ return this._questsRequired;
956
+ }
957
+ get requestDescription() {
958
+ return this._requestDescription;
959
+ }
960
+ get onStart() {
961
+ return this._onStart;
962
+ }
963
+ get onEnd() {
964
+ return this._onEnd;
965
+ }
966
+ };
967
+
968
+ // src/enums/ExecutionTypeEnum.ts
969
+ var ExecutionTypeEnum = /* @__PURE__ */ ((ExecutionTypeEnum2) => {
970
+ ExecutionTypeEnum2["AUTOMATIC"] = "automatic";
971
+ ExecutionTypeEnum2["INTERACTION"] = "interaction";
972
+ return ExecutionTypeEnum2;
973
+ })(ExecutionTypeEnum || {});
974
+
975
+ // src/functions/NavigationFunctions.ts
976
+ import { GameStorageManager as GameStorageManager3 } from "@drincs/pixi-vn";
977
+ var CURRENT_ROOM_MEMORY_KEY = "___nqtr-current_room_memory___";
978
+ function setCurrentRoom(room) {
979
+ let roomRegistrated = getRoomById(room.id);
980
+ if (!roomRegistrated) {
981
+ console.error(`[NQTR] The room ${room.id} is not registered, so it can't be set as current room`);
982
+ return;
983
+ }
984
+ localStorage.setItem(CURRENT_ROOM_MEMORY_KEY, room.id);
985
+ }
986
+ function getCurrentRoom() {
987
+ let roomId = GameStorageManager3.getVariable(CURRENT_ROOM_MEMORY_KEY);
988
+ if (!roomId) {
989
+ console.error(`[NQTR] The current room has not yet been set`);
990
+ return;
991
+ }
992
+ let room = getRoomById(roomId);
993
+ if (!room) {
994
+ console.error(`[NQTR] Current room ${roomId} not found`);
995
+ return;
996
+ }
997
+ return room;
998
+ }
999
+ function getCurrenrLocation() {
1000
+ let room = getCurrentRoom();
1001
+ if (!room) {
1002
+ return;
1003
+ }
1004
+ return room.location;
1005
+ }
1006
+ function getCueerntMap() {
1007
+ let location = getCurrenrLocation();
1008
+ if (!location) {
1009
+ return;
1010
+ }
1011
+ return location.map;
1012
+ }
1013
+
1014
+ // src/functions/ActivityFunctions.ts
1015
+ function clearExpiredActivities() {
1016
+ Object.entries(registeredRooms).forEach(([_, room]) => {
1017
+ room.clearExpiredActivities();
1018
+ });
1019
+ }
1020
+ function currentActivities() {
1021
+ let currentRoom = getCurrentRoom();
1022
+ if (!currentRoom) {
1023
+ return [];
1024
+ }
1025
+ return currentRoom.activities.filter((activity) => !activity.hidden);
1026
+ }
1027
+ export {
1028
+ ActivityModel,
1029
+ ExecutionTypeEnum,
1030
+ TimeManager as GameStepManager,
1031
+ Goal,
1032
+ LocationBaseModel,
1033
+ MapBaseModel,
1034
+ QuestBaseModel,
1035
+ RoomBaseModel,
1036
+ StageBaseModel,
1037
+ addTemporaryCommitment,
1038
+ clearExpiredActivities,
1039
+ clearExpiredRoutine,
1040
+ currentActivities,
1041
+ getActivityById,
1042
+ getCommitmentByCharacter,
1043
+ getCommitmentById,
1044
+ getCueerntMap,
1045
+ getCurrenrLocation,
1046
+ getCurrentCommitments,
1047
+ getCurrentRoom,
1048
+ getFixedCommitments,
1049
+ getRoomById,
1050
+ getTemporaryCommitments,
1051
+ saveActivity,
1052
+ saveCommitment,
1053
+ saveRoom,
1054
+ setCurrentRoom,
1055
+ setFixedCommitments
1056
+ };
1057
+ //# sourceMappingURL=index.mjs.map