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