@drincs/nqtr 0.2.1 → 0.2.2

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.
Files changed (105) hide show
  1. package/dist/{StageProps-CkXejAbn.d.mts → StageProps-D002cyay.d.mts} +30 -2
  2. package/dist/{StageProps-BFsiCaZT.d.ts → StageProps-DleWO-vf.d.ts} +30 -2
  3. package/dist/classes/Commitment.d.mts +2 -2
  4. package/dist/classes/Commitment.d.ts +2 -2
  5. package/dist/classes/index.d.mts +4 -4
  6. package/dist/classes/index.d.ts +4 -4
  7. package/dist/classes/index.js +1 -131
  8. package/dist/classes/index.js.map +1 -1
  9. package/dist/classes/index.mjs +3 -132
  10. package/dist/classes/index.mjs.map +1 -1
  11. package/dist/classes/navigation/ActivityRoom.d.mts +2 -2
  12. package/dist/classes/navigation/ActivityRoom.d.ts +2 -2
  13. package/dist/classes/navigation/Location.d.mts +3 -3
  14. package/dist/classes/navigation/Location.d.ts +3 -3
  15. package/dist/classes/navigation/Map.d.mts +3 -3
  16. package/dist/classes/navigation/Map.d.ts +3 -3
  17. package/dist/classes/navigation/Room.d.mts +1 -1
  18. package/dist/classes/navigation/Room.d.ts +1 -1
  19. package/dist/classes/navigation/Room.js +43 -43
  20. package/dist/classes/navigation/Room.js.map +1 -1
  21. package/dist/classes/navigation/Room.mjs +43 -43
  22. package/dist/classes/navigation/Room.mjs.map +1 -1
  23. package/dist/classes/quest/Quest.d.mts +1 -1
  24. package/dist/classes/quest/Quest.d.ts +1 -1
  25. package/dist/classes/quest/Quest.js +107 -25
  26. package/dist/classes/quest/Quest.js.map +1 -1
  27. package/dist/classes/quest/Quest.mjs +107 -25
  28. package/dist/classes/quest/Quest.mjs.map +1 -1
  29. package/dist/classes/quest/Stage.d.mts +1 -1
  30. package/dist/classes/quest/Stage.d.ts +1 -1
  31. package/dist/classes/quest/Stage.js +34 -9
  32. package/dist/classes/quest/Stage.js.map +1 -1
  33. package/dist/classes/quest/Stage.mjs +34 -9
  34. package/dist/classes/quest/Stage.mjs.map +1 -1
  35. package/dist/decorators/ActivityDecorator.d.mts +10 -11
  36. package/dist/decorators/ActivityDecorator.d.ts +10 -11
  37. package/dist/decorators/ActivityDecorator.js +384 -9
  38. package/dist/decorators/ActivityDecorator.js.map +1 -1
  39. package/dist/decorators/ActivityDecorator.mjs +384 -9
  40. package/dist/decorators/ActivityDecorator.mjs.map +1 -1
  41. package/dist/decorators/CommitmentDecorator.d.mts +3 -3
  42. package/dist/decorators/CommitmentDecorator.d.ts +3 -3
  43. package/dist/decorators/QuestDecorator.d.mts +4 -3
  44. package/dist/decorators/QuestDecorator.d.ts +4 -3
  45. package/dist/decorators/QuestDecorator.js +107 -25
  46. package/dist/decorators/QuestDecorator.js.map +1 -1
  47. package/dist/decorators/QuestDecorator.mjs +107 -25
  48. package/dist/decorators/QuestDecorator.mjs.map +1 -1
  49. package/dist/decorators/RoomDecorator.d.mts +3 -3
  50. package/dist/decorators/RoomDecorator.d.ts +3 -3
  51. package/dist/decorators/index.d.mts +3 -3
  52. package/dist/decorators/index.d.ts +3 -3
  53. package/dist/decorators/index.js +328 -115
  54. package/dist/decorators/index.js.map +1 -1
  55. package/dist/decorators/index.mjs +329 -116
  56. package/dist/decorators/index.mjs.map +1 -1
  57. package/dist/functions/ActivityFunctions.d.mts +3 -3
  58. package/dist/functions/ActivityFunctions.d.ts +3 -3
  59. package/dist/functions/ActivityFunctions.js.map +1 -1
  60. package/dist/functions/ActivityFunctions.mjs.map +1 -1
  61. package/dist/functions/NavigationFunctions.d.mts +3 -3
  62. package/dist/functions/NavigationFunctions.d.ts +3 -3
  63. package/dist/functions/NavigationFunctions.js.map +1 -1
  64. package/dist/functions/NavigationFunctions.mjs.map +1 -1
  65. package/dist/functions/QuestFunctions.d.mts +8 -0
  66. package/dist/functions/QuestFunctions.d.ts +8 -0
  67. package/dist/functions/QuestFunctions.js +21 -0
  68. package/dist/functions/QuestFunctions.js.map +1 -0
  69. package/dist/functions/QuestFunctions.mjs +19 -0
  70. package/dist/functions/QuestFunctions.mjs.map +1 -0
  71. package/dist/functions/RoutineFunctions.d.mts +3 -3
  72. package/dist/functions/RoutineFunctions.d.ts +3 -3
  73. package/dist/functions/index.d.mts +4 -3
  74. package/dist/functions/index.d.ts +4 -3
  75. package/dist/functions/index.js +13 -0
  76. package/dist/functions/index.js.map +1 -1
  77. package/dist/functions/index.mjs +13 -1
  78. package/dist/functions/index.mjs.map +1 -1
  79. package/dist/index.d.mts +6 -5
  80. package/dist/index.d.ts +6 -5
  81. package/dist/index.js +254 -165
  82. package/dist/index.js.map +1 -1
  83. package/dist/index.mjs +254 -165
  84. package/dist/index.mjs.map +1 -1
  85. package/dist/interface/CommitmentProps.d.mts +2 -2
  86. package/dist/interface/CommitmentProps.d.ts +2 -2
  87. package/dist/interface/RoomProps.d.mts +2 -2
  88. package/dist/interface/RoomProps.d.ts +2 -2
  89. package/dist/interface/index.d.mts +3 -3
  90. package/dist/interface/index.d.ts +3 -3
  91. package/dist/interface/navigation/LocationProps.d.mts +3 -3
  92. package/dist/interface/navigation/LocationProps.d.ts +3 -3
  93. package/dist/interface/navigation/MapProps.d.mts +3 -3
  94. package/dist/interface/navigation/MapProps.d.ts +3 -3
  95. package/dist/interface/quest/QuestProps.d.mts +1 -1
  96. package/dist/interface/quest/QuestProps.d.ts +1 -1
  97. package/dist/interface/quest/StageProps.d.mts +1 -1
  98. package/dist/interface/quest/StageProps.d.ts +1 -1
  99. package/dist/types/QuestsRequired.d.mts +1 -1
  100. package/dist/types/QuestsRequired.d.ts +1 -1
  101. package/dist/types/index.d.mts +1 -1
  102. package/dist/types/index.d.ts +1 -1
  103. package/package.json +1 -1
  104. package/dist/{Commitment-BJTIpBQ5.d.ts → Commitment-D3LPSbFX.d.ts} +2 -2
  105. package/dist/{Commitment-CtNWnNQX.d.mts → Commitment-Eox2652k.d.mts} +2 -2
@@ -1,94 +1,6 @@
1
- import { GameStorageManager, StoredClassModel, getFlag } from '@drincs/pixi-vn';
1
+ import { GameStorageManager, getFlag, StoredClassModel } from '@drincs/pixi-vn';
2
2
 
3
- // src/decorators/ActivityDecorator.ts
4
- var registeredActivities = {};
5
- function saveActivity(activity) {
6
- if (Array.isArray(activity)) {
7
- activity.forEach((c) => saveActivity(c));
8
- return;
9
- }
10
- if (registeredActivities[activity.id]) {
11
- console.warn(`[NQTR] Activity id ${activity.id} already exists, it will be overwritten`);
12
- }
13
- registeredActivities[activity.id] = activity;
14
- }
15
- function getActivityById(id) {
16
- try {
17
- let activity = registeredActivities[id];
18
- if (!activity) {
19
- console.error(`[NQTR] Activity ${id} not found`);
20
- return;
21
- }
22
- return activity;
23
- } catch (e) {
24
- console.error(`[NQTR] Error while getting Activity ${id}`, e);
25
- return;
26
- }
27
- }
28
- var TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY = "___nqtr-temporary_commitment___";
29
- var registeredCommitments = {};
30
- var fixedCommitments = {};
31
- function saveCommitment(commitment) {
32
- if (Array.isArray(commitment)) {
33
- commitment.forEach((c) => saveCommitment(c));
34
- return;
35
- }
36
- if (registeredCommitments[commitment.id]) {
37
- console.warn(`[NQTR] Commitment id ${commitment.id} already exists, it will be overwritten`);
38
- }
39
- registeredCommitments[commitment.id] = commitment;
40
- }
41
- function getCommitmentById(id) {
42
- try {
43
- let commitment = registeredCommitments[id];
44
- if (!commitment) {
45
- console.error(`[NQTR] Commitment ${id} not found`);
46
- return;
47
- }
48
- return commitment;
49
- } catch (e) {
50
- console.error(`[NQTR] Error while getting Commitment ${id}`, e);
51
- return;
52
- }
53
- }
54
- function setFixedRoutine(commitments) {
55
- if (Array.isArray(commitments)) {
56
- commitments.forEach((c) => setFixedRoutine(c));
57
- return;
58
- }
59
- if (fixedCommitments[commitments.id]) {
60
- console.warn(`[NQTR] Commitment id ${commitments.id} already exists, it will be overwritten`);
61
- }
62
- fixedCommitments[commitments.id] = commitments;
63
- }
64
- function addCommitment(commitment) {
65
- if (!Array.isArray(commitment)) {
66
- commitment = [commitment];
67
- }
68
- let commitmentsIds = commitment.map((commitment2) => {
69
- let commitmentTest = getCommitmentById(commitment2.id);
70
- if (!commitmentTest) {
71
- console.warn(`[NQTR] Commitment ${commitment2.id} not found, it will be ignored`);
72
- return void 0;
73
- }
74
- return commitment2.id;
75
- }).filter((id) => id !== void 0);
76
- GameStorageManager.setVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY, commitmentsIds);
77
- }
78
- function removeCommitment(commitment) {
79
- if (!Array.isArray(commitment)) {
80
- commitment = [commitment];
81
- }
82
- let commitmentsIds = commitment.map((commitment2) => {
83
- return commitment2.id;
84
- });
85
- let currentCommitments = GameStorageManager.getVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY);
86
- if (!currentCommitments) {
87
- return;
88
- }
89
- currentCommitments = currentCommitments.filter((id) => !commitmentsIds.includes(id));
90
- GameStorageManager.setVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY, currentCommitments);
91
- }
3
+ // src/classes/Activity.ts
92
4
  var TIME_SETTINGS_KEY = "___nqtr-time_manager_settings___";
93
5
  var TIME_DATA_KEY = "___nqtr-time_manager_data___";
94
6
  var TimeManager = class _TimeManager {
@@ -331,6 +243,225 @@ var TimeManager = class _TimeManager {
331
243
  return currentHour >= fromHour || currentHour < toHour;
332
244
  }
333
245
  };
246
+
247
+ // src/classes/Activity.ts
248
+ var ActivityModel = class {
249
+ /**
250
+ * @param id The activity id, that must be unique.
251
+ * @param onRun The function that is called when the activity is runned. Have 2 parameters: the runned activity and the yourParams object, that is an object with the parameters that you want to pass to the onRun function.
252
+ * @param props The activity properties.
253
+ */
254
+ constructor(id, onRun, props) {
255
+ this._id = id;
256
+ this._name = props.name;
257
+ this._fromHour = props.fromHour;
258
+ this._toHour = props.toHour;
259
+ this._fromDay = props.fromDay;
260
+ this._toDay = props.toDay;
261
+ this._disabled = props.disabled || false;
262
+ this._hidden = props.hidden || false;
263
+ this._renderIcon = props.renderIcon;
264
+ this._onRun = onRun;
265
+ }
266
+ /**
267
+ * The activity id, that is unique.
268
+ */
269
+ get id() {
270
+ return this._id;
271
+ }
272
+ /**
273
+ * The name
274
+ */
275
+ get name() {
276
+ return this._name;
277
+ }
278
+ /**
279
+ * The hour when the activity starts. If the activity is not started yet, it will be hidden.
280
+ */
281
+ get fromHour() {
282
+ return this._fromHour;
283
+ }
284
+ /**
285
+ * The hour when the activity ends. If the activity is ended yet, it will be hidden.
286
+ */
287
+ get toHour() {
288
+ return this._toHour;
289
+ }
290
+ /**
291
+ * The day when the activity starts. If the activity is not started yet, it will be hidden.
292
+ */
293
+ get fromDay() {
294
+ return this._fromDay;
295
+ }
296
+ /**
297
+ * The day when the activity ends. If the activity is ended yet, it will be deleted or hidden.
298
+ */
299
+ get toDay() {
300
+ return this._toDay;
301
+ }
302
+ /**
303
+ * Whether is disabled.
304
+ */
305
+ get disabled() {
306
+ if (typeof this._disabled === "string") {
307
+ return getFlag(this._disabled);
308
+ }
309
+ return this._disabled;
310
+ }
311
+ /**
312
+ * Whether is hidden. If the activity is not started yet, it will be hidden.
313
+ */
314
+ get hidden() {
315
+ if (this.fromDay && this.fromDay > TimeManager.currentDay) {
316
+ return true;
317
+ }
318
+ if (!this.isDeadline) {
319
+ return true;
320
+ }
321
+ if (typeof this._hidden === "string") {
322
+ return getFlag(this._hidden);
323
+ }
324
+ return this._hidden;
325
+ }
326
+ /**
327
+ * The function for rendering the icon of the activity.
328
+ */
329
+ get renderIcon() {
330
+ let render = this._renderIcon;
331
+ if (render === void 0) {
332
+ return void 0;
333
+ }
334
+ if (typeof render === "function") {
335
+ return (props) => {
336
+ return render(this, props);
337
+ };
338
+ }
339
+ return (props) => render;
340
+ }
341
+ get _initialOnRun() {
342
+ return this._onRun;
343
+ }
344
+ /**
345
+ * The function that is called when the activity is runned.
346
+ */
347
+ get run() {
348
+ return (props) => this._onRun(this, props);
349
+ }
350
+ /**
351
+ * Whether the activity is a deadline.
352
+ * @returns Whether the activity is a deadline.
353
+ */
354
+ isDeadline() {
355
+ if (this.toDay && this.toDay <= TimeManager.currentDay) {
356
+ return true;
357
+ }
358
+ return false;
359
+ }
360
+ /**
361
+ * Export the activity properties.
362
+ * @returns The activity properties.
363
+ */
364
+ export() {
365
+ return {
366
+ name: this._name,
367
+ fromHour: this._fromHour,
368
+ toHour: this._toHour,
369
+ fromDay: this._fromDay,
370
+ toDay: this._toDay,
371
+ disabled: this._disabled,
372
+ hidden: this._hidden,
373
+ renderIcon: this._renderIcon
374
+ };
375
+ }
376
+ };
377
+
378
+ // src/decorators/ActivityDecorator.ts
379
+ var registeredActivities = {};
380
+ function newActivity(id, onRun, props) {
381
+ if (registeredActivities[id]) {
382
+ console.warn(`[NQTR] Activity ${id} already exists, it will be overwritten`);
383
+ }
384
+ let activity = new ActivityModel(id, onRun, props);
385
+ registeredActivities[id] = activity;
386
+ return activity;
387
+ }
388
+ function getActivityById(id) {
389
+ try {
390
+ let activity = registeredActivities[id];
391
+ if (!activity) {
392
+ console.error(`[NQTR] Activity ${id} not found`);
393
+ return;
394
+ }
395
+ return activity;
396
+ } catch (e) {
397
+ console.error(`[NQTR] Error while getting Activity ${id}`, e);
398
+ return;
399
+ }
400
+ }
401
+ var TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY = "___nqtr-temporary_commitment___";
402
+ var registeredCommitments = {};
403
+ var fixedCommitments = {};
404
+ function saveCommitment(commitment) {
405
+ if (Array.isArray(commitment)) {
406
+ commitment.forEach((c) => saveCommitment(c));
407
+ return;
408
+ }
409
+ if (registeredCommitments[commitment.id]) {
410
+ console.warn(`[NQTR] Commitment id ${commitment.id} already exists, it will be overwritten`);
411
+ }
412
+ registeredCommitments[commitment.id] = commitment;
413
+ }
414
+ function getCommitmentById(id) {
415
+ try {
416
+ let commitment = registeredCommitments[id];
417
+ if (!commitment) {
418
+ console.error(`[NQTR] Commitment ${id} not found`);
419
+ return;
420
+ }
421
+ return commitment;
422
+ } catch (e) {
423
+ console.error(`[NQTR] Error while getting Commitment ${id}`, e);
424
+ return;
425
+ }
426
+ }
427
+ function setFixedRoutine(commitments) {
428
+ if (Array.isArray(commitments)) {
429
+ commitments.forEach((c) => setFixedRoutine(c));
430
+ return;
431
+ }
432
+ if (fixedCommitments[commitments.id]) {
433
+ console.warn(`[NQTR] Commitment id ${commitments.id} already exists, it will be overwritten`);
434
+ }
435
+ fixedCommitments[commitments.id] = commitments;
436
+ }
437
+ function addCommitment(commitment) {
438
+ if (!Array.isArray(commitment)) {
439
+ commitment = [commitment];
440
+ }
441
+ let commitmentsIds = commitment.map((commitment2) => {
442
+ let commitmentTest = getCommitmentById(commitment2.id);
443
+ if (!commitmentTest) {
444
+ console.warn(`[NQTR] Commitment ${commitment2.id} not found, it will be ignored`);
445
+ return void 0;
446
+ }
447
+ return commitment2.id;
448
+ }).filter((id) => id !== void 0);
449
+ GameStorageManager.setVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY, commitmentsIds);
450
+ }
451
+ function removeCommitment(commitment) {
452
+ if (!Array.isArray(commitment)) {
453
+ commitment = [commitment];
454
+ }
455
+ let commitmentsIds = commitment.map((commitment2) => {
456
+ return commitment2.id;
457
+ });
458
+ let currentCommitments = GameStorageManager.getVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY);
459
+ if (!currentCommitments) {
460
+ return;
461
+ }
462
+ currentCommitments = currentCommitments.filter((id) => !commitmentsIds.includes(id));
463
+ GameStorageManager.setVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY, currentCommitments);
464
+ }
334
465
  var GOAL_CATEGORY = "__nqtr-goal__";
335
466
  var Goal = class extends StoredClassModel {
336
467
  constructor(id, props) {
@@ -520,17 +651,29 @@ var StageQuest = class extends Stage {
520
651
  if (storedCompleted) {
521
652
  return storedCompleted;
522
653
  }
523
- if (!this.flags.every((flag) => getFlag(flag.flag))) {
524
- return false;
525
- }
526
- if (!this.goals.every((goal) => goal.completed)) {
527
- return false;
654
+ if (this.flags.length > 0 && this.goals.length > 0) {
655
+ if (!this.flags.every((flag) => getFlag(flag.flag))) {
656
+ return false;
657
+ }
658
+ if (!this.goals.every((goal) => goal.completed)) {
659
+ return false;
660
+ }
661
+ return true;
528
662
  }
529
- return true;
663
+ return false;
530
664
  }
531
665
  set completed(value) {
532
666
  this.setStorageProperty("completed", value);
533
667
  }
668
+ /**
669
+ * If the stage is started.
670
+ */
671
+ get started() {
672
+ return this.getStorageProperty("started") || false;
673
+ }
674
+ set started(value) {
675
+ this.setStorageProperty("started", value);
676
+ }
534
677
  /**
535
678
  * The list of goals that the player needs to complete to finish the stage.
536
679
  */
@@ -580,13 +723,26 @@ var StageQuest = class extends Stage {
580
723
  return true;
581
724
  }
582
725
  /**
583
- * The function that will be called when the stage starts.
726
+ * Inizialize the stage. **This function should be called only by the Quest class.**
584
727
  */
585
- get onStart() {
728
+ inizialize() {
586
729
  if (this.daysRequiredToStart > 0) {
587
730
  this.prevStageEndDay = TimeManager.currentDay;
731
+ console.log(`[NQTR] Stage ${this.id} will start on day ${this.startDay}`);
732
+ }
733
+ }
734
+ /**
735
+ * The function that will be called when the stage starts.
736
+ */
737
+ start(props) {
738
+ if (this.canStart) {
739
+ this.started = true;
740
+ if (this.onStart) {
741
+ this.onStart(props);
742
+ }
743
+ } else {
744
+ console.warn(`[NQTR] Stage ${this.id} can't start`);
588
745
  }
589
- return super.onStart;
590
746
  }
591
747
  };
592
748
 
@@ -687,7 +843,10 @@ var Quest = class extends StoredClassModel {
687
843
  * If the quest is completed.
688
844
  */
689
845
  get completed() {
690
- return this.currentStageIndex === this.stages.length;
846
+ if (this.currentStageIndex === void 0) {
847
+ return false;
848
+ }
849
+ return this.currentStageIndex > this.stages.length - 1;
691
850
  }
692
851
  /**
693
852
  * Start the quest.
@@ -705,14 +864,15 @@ var Quest = class extends StoredClassModel {
705
864
  }
706
865
  this.currentStageIndex = 0;
707
866
  let currentStage = this.currentStage;
708
- if (currentStage && currentStage.onStart) {
709
- return currentStage.onStart(props);
867
+ if (currentStage && currentStage.start) {
868
+ return currentStage.start(props);
710
869
  } else {
711
870
  console.error(`[NQTR] Quest ${this.id} has no start stage`);
712
871
  }
713
872
  }
714
873
  /**
715
- * Try to go to the next stage.
874
+ * Go to the next stage if the current stage is completed.
875
+ * If you want to force the change of stage, use goNextStage.
716
876
  * @param startProps The properties for the start stage. If you not want to pass any property, you can pass an {}.
717
877
  * @param endProps The properties for the end stage. If you not want to pass any property, you can pass an {}.
718
878
  * @returns true if the stage was changed, false otherwise.
@@ -725,25 +885,78 @@ var Quest = class extends StoredClassModel {
725
885
  return false;
726
886
  }
727
887
  let currentStage = this.currentStage;
728
- let currentStageIndex = this.currentStageIndex;
729
- if (!currentStage || currentStageIndex === void 0) {
888
+ if (!currentStage) {
730
889
  console.error(`[NQTR] Quest ${this.id} has no current stage`);
731
890
  return false;
732
891
  }
733
892
  if (currentStage.completed) {
734
- let nextStageIndex = currentStageIndex + 1;
735
- currentStageIndex = nextStageIndex;
736
- let nextStage = this.currentStage;
737
- if (currentStage && currentStage.onEnd) {
738
- currentStage.onEnd(endProps);
739
- }
740
- if (nextStage && nextStage.onStart) {
741
- nextStage.onStart(startProps);
742
- }
743
- return true;
893
+ return this.goNextStage(startProps, endProps);
744
894
  }
745
895
  return false;
746
896
  }
897
+ /**
898
+ * Complete the current stage and go to the next stage.
899
+ * If you want to go to the next stage only if the current stage is completed, use tryToGoNextStage.
900
+ * @param startProps The properties for the start stage. If you not want to pass any property, you can pass an {}.
901
+ * @param endProps The properties for the end stage. If you not want to pass any property, you can pass an {}.
902
+ * @returns true if the stage was changed, false otherwise.
903
+ */
904
+ completeCurrentStageAndGoNext(startProps, endProps) {
905
+ let currentStage = this.currentStage;
906
+ if (!currentStage) {
907
+ console.error(`[NQTR] Quest ${this.id} has no current stage`);
908
+ return false;
909
+ }
910
+ currentStage.completed = true;
911
+ return this.goNextStage(startProps, endProps);
912
+ }
913
+ /**
914
+ * Go to the next stage without checking if the current stage is completed.
915
+ * If you want to go to the next stage only if the current stage is completed, use tryToGoNextStage.
916
+ * @param startProps
917
+ * @param endProps
918
+ * @returns returns true if the stage was changed, false otherwise.
919
+ */
920
+ goNextStage(startProps, endProps) {
921
+ if (!this.started) {
922
+ console.warn(`[NQTR] Quest ${this.id} is not started`);
923
+ return false;
924
+ }
925
+ if (this.completed) {
926
+ console.warn(`[NQTR] Quest ${this.id} is already completed`);
927
+ return false;
928
+ }
929
+ let prevStage = this.currentStage;
930
+ let currentStageIndex = this.currentStageIndex;
931
+ if (!prevStage || currentStageIndex === void 0) {
932
+ console.error(`[NQTR] Quest ${this.id} has no current stage`);
933
+ return false;
934
+ }
935
+ this.currentStageIndex = currentStageIndex + 1;
936
+ if (prevStage && prevStage.onEnd) {
937
+ prevStage.onEnd(endProps);
938
+ }
939
+ let nextCurrentStage = this.currentStage;
940
+ if (nextCurrentStage) {
941
+ nextCurrentStage.inizialize();
942
+ }
943
+ return true;
944
+ }
945
+ get currentStageMustStart() {
946
+ let currentStage = this.currentStage;
947
+ if (!currentStage) {
948
+ return false;
949
+ }
950
+ return !currentStage.started && currentStage.canStart && !currentStage.completed;
951
+ }
952
+ startCurrentStage(props) {
953
+ let newCurrentStage = this.currentStage;
954
+ if (newCurrentStage && this.currentStageMustStart) {
955
+ newCurrentStage.start(props);
956
+ } else {
957
+ console.warn(`[NQTR] Quest ${this.id} can't start the current stage`);
958
+ }
959
+ }
747
960
  };
748
961
 
749
962
  // src/decorators/QuestDecorator.ts
@@ -810,6 +1023,6 @@ function getAllMaps() {
810
1023
  return Object.values(result);
811
1024
  }
812
1025
 
813
- export { addCommitment, getActivityById, getAllLocations, getAllMaps, getCommitmentById, getQuestById, getRoomById, newQuest, removeCommitment, saveActivity, saveCommitment, saveRoom, setFixedRoutine };
1026
+ export { addCommitment, getActivityById, getAllLocations, getAllMaps, getCommitmentById, getQuestById, getRoomById, newActivity, newQuest, removeCommitment, saveCommitment, saveRoom, setFixedRoutine };
814
1027
  //# sourceMappingURL=out.js.map
815
1028
  //# sourceMappingURL=index.mjs.map