@drincs/nqtr 0.1.18 → 0.1.20

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 (167) hide show
  1. package/dist/{Commitment-DNn_TEgV.d.mts → Commitment-C3Nc2RJH.d.mts} +17 -4
  2. package/dist/{Commitment-GIA4EK_q.d.ts → Commitment-Cc2kZEy0.d.ts} +17 -4
  3. package/dist/Quest-BQ1pwvQ_.d.ts +197 -0
  4. package/dist/Quest-DaNlPBHb.d.mts +197 -0
  5. package/dist/classes/Commitment.d.mts +2 -2
  6. package/dist/classes/Commitment.d.ts +2 -2
  7. package/dist/classes/Commitment.js +12 -1
  8. package/dist/classes/Commitment.js.map +1 -1
  9. package/dist/classes/Commitment.mjs +12 -1
  10. package/dist/classes/Commitment.mjs.map +1 -1
  11. package/dist/classes/index.d.mts +4 -4
  12. package/dist/classes/index.d.ts +4 -4
  13. package/dist/classes/index.js +514 -313
  14. package/dist/classes/index.js.map +1 -1
  15. package/dist/classes/index.mjs +512 -312
  16. package/dist/classes/index.mjs.map +1 -1
  17. package/dist/classes/navigation/ActivityRoom.d.mts +2 -2
  18. package/dist/classes/navigation/ActivityRoom.d.ts +2 -2
  19. package/dist/classes/navigation/ActivityRoom.js +1 -1
  20. package/dist/classes/navigation/ActivityRoom.js.map +1 -1
  21. package/dist/classes/navigation/ActivityRoom.mjs +1 -1
  22. package/dist/classes/navigation/ActivityRoom.mjs.map +1 -1
  23. package/dist/classes/navigation/Location.d.mts +2 -2
  24. package/dist/classes/navigation/Location.d.ts +2 -2
  25. package/dist/classes/navigation/Location.js.map +1 -1
  26. package/dist/classes/navigation/Location.mjs.map +1 -1
  27. package/dist/classes/navigation/Map.d.mts +2 -2
  28. package/dist/classes/navigation/Map.d.ts +2 -2
  29. package/dist/classes/navigation/Map.js.map +1 -1
  30. package/dist/classes/navigation/Map.mjs.map +1 -1
  31. package/dist/classes/navigation/Room.d.mts +2 -2
  32. package/dist/classes/navigation/Room.d.ts +2 -2
  33. package/dist/classes/navigation/Room.js +15 -15
  34. package/dist/classes/navigation/Room.js.map +1 -1
  35. package/dist/classes/navigation/Room.mjs +15 -15
  36. package/dist/classes/navigation/Room.mjs.map +1 -1
  37. package/dist/classes/quest/Goal.d.mts +21 -13
  38. package/dist/classes/quest/Goal.d.ts +21 -13
  39. package/dist/classes/quest/Goal.js +50 -15
  40. package/dist/classes/quest/Goal.js.map +1 -1
  41. package/dist/classes/quest/Goal.mjs +47 -15
  42. package/dist/classes/quest/Goal.mjs.map +1 -1
  43. package/dist/classes/quest/Quest.d.mts +3 -2
  44. package/dist/classes/quest/Quest.d.ts +3 -2
  45. package/dist/classes/quest/Quest.js +536 -9
  46. package/dist/classes/quest/Quest.js.map +1 -1
  47. package/dist/classes/quest/Quest.mjs +537 -10
  48. package/dist/classes/quest/Quest.mjs.map +1 -1
  49. package/dist/classes/quest/Stage.d.mts +3 -2
  50. package/dist/classes/quest/Stage.d.ts +3 -2
  51. package/dist/classes/quest/Stage.js +396 -51
  52. package/dist/classes/quest/Stage.js.map +1 -1
  53. package/dist/classes/quest/Stage.mjs +394 -52
  54. package/dist/classes/quest/Stage.mjs.map +1 -1
  55. package/dist/decorators/ActivityDecorator.d.mts +1 -1
  56. package/dist/decorators/ActivityDecorator.d.ts +1 -1
  57. package/dist/decorators/ActivityDecorator.js.map +1 -1
  58. package/dist/decorators/ActivityDecorator.mjs.map +1 -1
  59. package/dist/decorators/CommitmentDecorator.d.mts +32 -6
  60. package/dist/decorators/CommitmentDecorator.d.ts +32 -6
  61. package/dist/decorators/CommitmentDecorator.js +7 -7
  62. package/dist/decorators/CommitmentDecorator.js.map +1 -1
  63. package/dist/decorators/CommitmentDecorator.mjs +5 -5
  64. package/dist/decorators/CommitmentDecorator.mjs.map +1 -1
  65. package/dist/decorators/QuestDecorator.d.mts +28 -0
  66. package/dist/decorators/QuestDecorator.d.ts +28 -0
  67. package/dist/decorators/QuestDecorator.js +33 -0
  68. package/dist/decorators/QuestDecorator.js.map +1 -0
  69. package/dist/decorators/QuestDecorator.mjs +29 -0
  70. package/dist/decorators/QuestDecorator.mjs.map +1 -0
  71. package/dist/decorators/RoomDecorator.d.mts +3 -3
  72. package/dist/decorators/RoomDecorator.d.ts +3 -3
  73. package/dist/decorators/RoomDecorator.js.map +1 -1
  74. package/dist/decorators/RoomDecorator.mjs.map +1 -1
  75. package/dist/decorators/index.d.mts +8 -3
  76. package/dist/decorators/index.d.ts +8 -3
  77. package/dist/decorators/index.js +30 -15
  78. package/dist/decorators/index.js.map +1 -1
  79. package/dist/decorators/index.mjs +27 -12
  80. package/dist/decorators/index.mjs.map +1 -1
  81. package/dist/functions/ActivityFunctions.d.mts +2 -2
  82. package/dist/functions/ActivityFunctions.d.ts +2 -2
  83. package/dist/functions/ActivityFunctions.js.map +1 -1
  84. package/dist/functions/ActivityFunctions.mjs.map +1 -1
  85. package/dist/functions/NavigationFunctions.d.mts +2 -2
  86. package/dist/functions/NavigationFunctions.d.ts +2 -2
  87. package/dist/functions/NavigationFunctions.js.map +1 -1
  88. package/dist/functions/NavigationFunctions.mjs.map +1 -1
  89. package/dist/functions/RoutineFunctions.d.mts +21 -4
  90. package/dist/functions/RoutineFunctions.d.ts +21 -4
  91. package/dist/functions/RoutineFunctions.js +16 -16
  92. package/dist/functions/RoutineFunctions.js.map +1 -1
  93. package/dist/functions/RoutineFunctions.mjs +16 -16
  94. package/dist/functions/RoutineFunctions.mjs.map +1 -1
  95. package/dist/functions/index.d.mts +3 -3
  96. package/dist/functions/index.d.ts +3 -3
  97. package/dist/functions/index.js +16 -16
  98. package/dist/functions/index.js.map +1 -1
  99. package/dist/functions/index.mjs +16 -16
  100. package/dist/functions/index.mjs.map +1 -1
  101. package/dist/index.d.mts +7 -6
  102. package/dist/index.d.ts +7 -6
  103. package/dist/index.js +543 -326
  104. package/dist/index.js.map +1 -1
  105. package/dist/index.mjs +536 -319
  106. package/dist/index.mjs.map +1 -1
  107. package/dist/interface/CommitmentProps.d.mts +2 -2
  108. package/dist/interface/CommitmentProps.d.ts +2 -2
  109. package/dist/interface/RoomProps.d.mts +2 -2
  110. package/dist/interface/RoomProps.d.ts +2 -2
  111. package/dist/interface/index.d.mts +4 -4
  112. package/dist/interface/index.d.ts +4 -4
  113. package/dist/interface/navigation/LocationProps.d.mts +2 -2
  114. package/dist/interface/navigation/LocationProps.d.ts +2 -2
  115. package/dist/interface/navigation/MapProps.d.mts +2 -2
  116. package/dist/interface/navigation/MapProps.d.ts +2 -2
  117. package/dist/interface/quest/GoalProps.d.mts +12 -0
  118. package/dist/interface/quest/GoalProps.d.ts +12 -0
  119. package/dist/interface/quest/QuestProps.d.mts +6 -9
  120. package/dist/interface/quest/QuestProps.d.ts +6 -9
  121. package/dist/interface/quest/StageFlags.d.mts +12 -0
  122. package/dist/interface/quest/StageFlags.d.ts +12 -0
  123. package/dist/interface/quest/StageFlags.js +4 -0
  124. package/dist/interface/quest/StageFlags.js.map +1 -0
  125. package/dist/interface/quest/StageFlags.mjs +3 -0
  126. package/dist/interface/quest/StageFlags.mjs.map +1 -0
  127. package/dist/interface/quest/StageProps.d.mts +3 -2
  128. package/dist/interface/quest/StageProps.d.ts +3 -2
  129. package/dist/override/OnEndStage.d.mts +19 -0
  130. package/dist/override/OnEndStage.d.ts +19 -0
  131. package/dist/override/OnEndStage.js +4 -0
  132. package/dist/override/OnEndStage.js.map +1 -0
  133. package/dist/override/OnEndStage.mjs +3 -0
  134. package/dist/override/OnEndStage.mjs.map +1 -0
  135. package/dist/override/OnStartStage.d.mts +19 -0
  136. package/dist/override/OnStartStage.d.ts +19 -0
  137. package/dist/override/OnStartStage.js +4 -0
  138. package/dist/override/OnStartStage.js.map +1 -0
  139. package/dist/override/OnStartStage.mjs +3 -0
  140. package/dist/override/OnStartStage.mjs.map +1 -0
  141. package/dist/override/index.d.mts +2 -0
  142. package/dist/override/index.d.ts +2 -0
  143. package/dist/types/ExecutionType.d.mts +3 -0
  144. package/dist/types/ExecutionType.d.ts +3 -0
  145. package/dist/types/ExecutionType.js +4 -0
  146. package/dist/types/ExecutionType.js.map +1 -0
  147. package/dist/types/ExecutionType.mjs +3 -0
  148. package/dist/types/ExecutionType.mjs.map +1 -0
  149. package/dist/types/QuestsRequired.d.mts +3 -2
  150. package/dist/types/QuestsRequired.d.ts +3 -2
  151. package/dist/types/index.d.mts +4 -2
  152. package/dist/types/index.d.ts +4 -2
  153. package/package.json +1 -1
  154. package/dist/Quest-Bdm0R9LA.d.mts +0 -71
  155. package/dist/Quest-CxJcXETG.d.ts +0 -71
  156. package/dist/enums/ExecutionTypeEnum.d.mts +0 -6
  157. package/dist/enums/ExecutionTypeEnum.d.ts +0 -6
  158. package/dist/enums/ExecutionTypeEnum.js +0 -12
  159. package/dist/enums/ExecutionTypeEnum.js.map +0 -1
  160. package/dist/enums/ExecutionTypeEnum.mjs +0 -10
  161. package/dist/enums/ExecutionTypeEnum.mjs.map +0 -1
  162. package/dist/enums/index.d.mts +0 -1
  163. package/dist/enums/index.d.ts +0 -1
  164. package/dist/enums/index.js +0 -12
  165. package/dist/enums/index.js.map +0 -1
  166. package/dist/enums/index.mjs +0 -10
  167. package/dist/enums/index.mjs.map +0 -1
@@ -407,11 +407,12 @@ var CommitmentBaseModel = class extends StoredClassModel {
407
407
  this.defaultFromDay = props.fromDay;
408
408
  this.defaultToDay = props.toDay;
409
409
  this._renderImage = props.renderImage;
410
- this._executionType = props.executionType || "interaction" /* INTERACTION */;
410
+ this._executionType = props.executionType || "interaction";
411
411
  this._onRun = props.onRun;
412
412
  this.defaultDisabled = props.disabled || false;
413
413
  this.defaultHidden = props.hidden || false;
414
414
  this._renderIcon = props.renderIcon;
415
+ this.defaultPriority = props.priority || 0;
415
416
  }
416
417
  /**
417
418
  * The character or characters that are in the commitment and so in the room.
@@ -553,6 +554,16 @@ var CommitmentBaseModel = class extends StoredClassModel {
553
554
  set hidden(value) {
554
555
  this.setStorageProperty("hidden", value);
555
556
  }
557
+ /**
558
+ * The priority. The higher the number, the higher the priority.
559
+ * To ensure that a character is not in 2 places at the same time, if there are 2 or more valid commits at the same time and with the same character, the one with the highest priority will be chosen.
560
+ */
561
+ get priority() {
562
+ return this.getStorageProperty("priority") || this.defaultPriority || 0;
563
+ }
564
+ set priority(value) {
565
+ this.setStorageProperty("priority", value);
566
+ }
556
567
  /**
557
568
  * Whether the commitment is expired.
558
569
  * @returns Whether the commitment is expired.
@@ -564,6 +575,199 @@ var CommitmentBaseModel = class extends StoredClassModel {
564
575
  return false;
565
576
  }
566
577
  };
578
+ var ActivityStoredAbstract = class {
579
+ /**
580
+ * @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.
581
+ * @param props The activity properties.
582
+ */
583
+ constructor(onRun, props) {
584
+ this.defaultName = props.name;
585
+ this.defaultFromHour = props.fromHour;
586
+ this.defaultToHour = props.toHour;
587
+ this.defaultFromDay = props.fromDay;
588
+ this.defaultToDay = props.toDay;
589
+ this.defaultDisabled = props.disabled || false;
590
+ this.defaultHidden = props.hidden || false;
591
+ this._renderIcon = props.renderIcon;
592
+ this._onRun = onRun;
593
+ }
594
+ /**
595
+ * The name
596
+ */
597
+ get name() {
598
+ return this.getStorageProperty("name") || this.defaultName || "";
599
+ }
600
+ set name(value) {
601
+ this.setStorageProperty("name", value);
602
+ }
603
+ /**
604
+ * The hour when the activity starts. If the activity is not started yet, it will be hidden.
605
+ */
606
+ get fromHour() {
607
+ return this.getStorageProperty("fromHour") || this.defaultFromHour || TimeManager.minDayHours;
608
+ }
609
+ set fromHour(value) {
610
+ this.setStorageProperty("fromHour", value);
611
+ }
612
+ /**
613
+ * The hour when the activity ends. If the activity is ended yet, it will be hidden.
614
+ */
615
+ get toHour() {
616
+ return this.getStorageProperty("toHour") || this.defaultToHour || TimeManager.maxDayHours + 1;
617
+ }
618
+ set toHour(value) {
619
+ this.setStorageProperty("toHour", value);
620
+ }
621
+ /**
622
+ * The day when the activity starts. If the activity is not started yet, it will be hidden.
623
+ */
624
+ get fromDay() {
625
+ return this.getStorageProperty("fromDay") || this.defaultFromDay;
626
+ }
627
+ set fromDay(value) {
628
+ this.setStorageProperty("fromDay", value);
629
+ }
630
+ /**
631
+ * The day when the activity ends. If the activity is ended yet, it will be deleted or hidden.
632
+ */
633
+ get toDay() {
634
+ return this.getStorageProperty("toDay") || this.defaultToDay;
635
+ }
636
+ set toDay(value) {
637
+ this.setStorageProperty("toDay", value);
638
+ }
639
+ /**
640
+ * Whether is disabled.
641
+ */
642
+ get disabled() {
643
+ let value = this.getStorageProperty("disabled") || this.defaultDisabled;
644
+ if (typeof value === "string") {
645
+ return getFlag(value);
646
+ }
647
+ return value;
648
+ }
649
+ set disabled(value) {
650
+ this.setStorageProperty("disabled", value);
651
+ }
652
+ /**
653
+ * Whether is hidden. If the activity is not started yet, it will be hidden.
654
+ */
655
+ get hidden() {
656
+ if (this.fromDay && this.fromDay > TimeManager.currentDay) {
657
+ return true;
658
+ }
659
+ if (!TimeManager.nowIsBetween(this.fromHour, this.toHour)) {
660
+ return true;
661
+ }
662
+ if (!this.isExpired) {
663
+ return true;
664
+ }
665
+ let value = this.getStorageProperty("hidden") || this.defaultHidden;
666
+ if (typeof value === "string") {
667
+ return getFlag(value);
668
+ }
669
+ return value;
670
+ }
671
+ set hidden(value) {
672
+ this.setStorageProperty("hidden", value);
673
+ }
674
+ /**
675
+ * The function for rendering the icon of the activity.
676
+ */
677
+ get renderIcon() {
678
+ let render = this._renderIcon;
679
+ if (render === void 0) {
680
+ return void 0;
681
+ }
682
+ if (typeof render === "function") {
683
+ return (props) => {
684
+ return render(this, props);
685
+ };
686
+ }
687
+ return (props) => render;
688
+ }
689
+ /**
690
+ * The function that is called when the activity is runned.
691
+ */
692
+ get onRun() {
693
+ return (props) => {
694
+ return this._onRun(this, props);
695
+ };
696
+ }
697
+ /**
698
+ * Whether the activity is a deadline.
699
+ * @returns Whether the activity is a deadline.
700
+ */
701
+ isExpired() {
702
+ if (this.toDay && this.toDay <= TimeManager.currentDay) {
703
+ return true;
704
+ }
705
+ return false;
706
+ }
707
+ /**
708
+ * Export the activity properties.
709
+ * @returns The activity properties.
710
+ */
711
+ export() {
712
+ return {
713
+ name: this.getStorageProperty("name") || this.defaultName,
714
+ fromHour: this.getStorageProperty("fromHour") || this.defaultFromHour,
715
+ toHour: this.getStorageProperty("toHour") || this.defaultToHour,
716
+ fromDay: this.getStorageProperty("fromDay") || this.defaultFromDay,
717
+ toDay: this.getStorageProperty("toDay") || this.defaultToDay,
718
+ disabled: this.getStorageProperty("disabled") || this.defaultDisabled,
719
+ hidden: this.getStorageProperty("hidden") || this.defaultHidden,
720
+ renderIcon: this._renderIcon
721
+ };
722
+ }
723
+ };
724
+
725
+ // src/classes/navigation/ActivityRoom.ts
726
+ var ActivityRoom = class extends ActivityStoredAbstract {
727
+ constructor(id, room, onRun, props) {
728
+ super(onRun, props);
729
+ this._id = id;
730
+ this._room = room;
731
+ }
732
+ setStorageProperty(_, __) {
733
+ this._room.setActivity(this);
734
+ }
735
+ getStorageProperty(propertyName) {
736
+ let activity = this._room.getActivityMemory(this.id);
737
+ if (!activity || !activity.hasOwnProperty(propertyName)) {
738
+ return void 0;
739
+ }
740
+ return activity[propertyName];
741
+ }
742
+ get id() {
743
+ return this._id;
744
+ }
745
+ get room() {
746
+ return this._room;
747
+ }
748
+ export() {
749
+ let result = {};
750
+ if (this.name !== void 0) {
751
+ result["name"] = this.name;
752
+ }
753
+ if (this.fromHour !== void 0) {
754
+ result["fromHour"] = this.fromHour;
755
+ }
756
+ if (this.toHour !== void 0) {
757
+ result["toHour"] = this.toHour;
758
+ }
759
+ if (this.fromDay !== void 0) {
760
+ result["fromDay"] = this.fromDay;
761
+ }
762
+ if (this.toDay !== void 0) {
763
+ result["toDay"] = this.toDay;
764
+ }
765
+ if (this.disabled !== void 0) {
766
+ result["disabled"] = this.disabled;
767
+ }
768
+ return result;
769
+ }
770
+ };
567
771
 
568
772
  // src/decorators/RoomDecorator.ts
569
773
  var registeredRooms = {};
@@ -806,7 +1010,7 @@ function getCommitmentById(id) {
806
1010
  return;
807
1011
  }
808
1012
  }
809
- function getFixedCommitments() {
1013
+ function getFixedRoutine() {
810
1014
  return Object.values(fixedCommitments);
811
1015
  }
812
1016
  function getTemporaryCommitments() {
@@ -819,273 +1023,80 @@ function getTemporaryCommitments() {
819
1023
  }
820
1024
 
821
1025
  // src/functions/RoutineFunctions.ts
822
- function getCurrentCommitments() {
1026
+ function getCurrentRoutine() {
823
1027
  let character_commitments = {};
824
- let oltherCommitments = [];
825
1028
  getTemporaryCommitments().reverse().forEach((c) => {
826
1029
  if (!c.hidden) {
827
- if (c.characters.length > 1) {
828
- let allAvailable = c.characters.every((ch) => !character_commitments[ch.id]);
1030
+ if (c.characters.length > 0) {
1031
+ let allAvailable = c.characters.every((ch) => !character_commitments[ch.id] || c.priority > character_commitments[ch.id].priority);
829
1032
  if (allAvailable) {
830
1033
  c.characters.forEach((ch) => {
831
1034
  character_commitments[ch.id] = c;
832
1035
  });
833
1036
  }
834
1037
  } else {
835
- oltherCommitments.push(c);
1038
+ console.error(`[NQTR] The commitment ${c.id} has no characters assigned`);
836
1039
  }
837
1040
  }
838
1041
  });
839
- getFixedCommitments().reverse().forEach((c) => {
1042
+ getFixedRoutine().reverse().forEach((c) => {
840
1043
  if (!c.hidden) {
841
- if (c.characters.length > 1) {
842
- c.characters.forEach((ch) => {
843
- if (!character_commitments[ch.id]) {
1044
+ if (c.characters.length > 0) {
1045
+ let allAvailable = c.characters.every((ch) => !character_commitments[ch.id] || c.priority > character_commitments[ch.id].priority);
1046
+ if (allAvailable) {
1047
+ c.characters.forEach((ch) => {
844
1048
  character_commitments[ch.id] = c;
845
- }
846
- });
1049
+ });
1050
+ }
847
1051
  } else {
848
- oltherCommitments.push(c);
1052
+ console.error(`[NQTR] The commitment ${c.id} has no characters assigned`);
849
1053
  }
850
1054
  }
851
1055
  });
852
- return Object.values(character_commitments).concat(oltherCommitments);
1056
+ return Object.values(character_commitments);
853
1057
  }
854
- var ActivityStoredAbstract = class {
1058
+
1059
+ // src/classes/navigation/Room.ts
1060
+ var ROOM_CATEGORY = "__nqtr-room__";
1061
+ var RoomBaseModel = class extends StoredClassModel {
855
1062
  /**
856
- * @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.
857
- * @param props The activity properties.
1063
+ * @param id The id of the room, it must be unique.
1064
+ * @param location The location where the room is.
1065
+ * @param props The properties of the room.
858
1066
  */
859
- constructor(onRun, props) {
860
- this.defaultName = props.name;
861
- this.defaultFromHour = props.fromHour;
862
- this.defaultToHour = props.toHour;
863
- this.defaultFromDay = props.fromDay;
864
- this.defaultToDay = props.toDay;
1067
+ constructor(id, location, props = {}) {
1068
+ var _a;
1069
+ super(ROOM_CATEGORY, id);
1070
+ this._location = location;
1071
+ this.defaultName = props.name || "";
1072
+ this._renderImage = props.renderImage;
1073
+ this.defaultActivityIds = ((_a = props.defaultActivities) == null ? void 0 : _a.map((activity) => activity.id)) || [];
865
1074
  this.defaultDisabled = props.disabled || false;
866
1075
  this.defaultHidden = props.hidden || false;
867
1076
  this._renderIcon = props.renderIcon;
868
- this._onRun = onRun;
1077
+ this._isEntrance = props.isEntrance;
869
1078
  }
870
1079
  /**
871
- * The name
1080
+ * The location where the room is.
872
1081
  */
873
- get name() {
874
- return this.getStorageProperty("name") || this.defaultName || "";
875
- }
876
- set name(value) {
877
- this.setStorageProperty("name", value);
1082
+ get location() {
1083
+ return this._location;
878
1084
  }
879
1085
  /**
880
- * The hour when the activity starts. If the activity is not started yet, it will be hidden.
1086
+ * Whether is an entrance room, so when the player enters in the location, it will be the first room to be shown.
881
1087
  */
882
- get fromHour() {
883
- return this.getStorageProperty("fromHour") || this.defaultFromHour || TimeManager.minDayHours;
884
- }
885
- set fromHour(value) {
886
- this.setStorageProperty("fromHour", value);
1088
+ get isEntrance() {
1089
+ return this._isEntrance || false;
887
1090
  }
888
1091
  /**
889
- * The hour when the activity ends. If the activity is ended yet, it will be hidden.
1092
+ * The name.
1093
+ * If you set undefined, it will return the initial value of name.
890
1094
  */
891
- get toHour() {
892
- return this.getStorageProperty("toHour") || this.defaultToHour || TimeManager.maxDayHours + 1;
1095
+ get name() {
1096
+ return this.getStorageProperty("name") || this.defaultName;
893
1097
  }
894
- set toHour(value) {
895
- this.setStorageProperty("toHour", value);
896
- }
897
- /**
898
- * The day when the activity starts. If the activity is not started yet, it will be hidden.
899
- */
900
- get fromDay() {
901
- return this.getStorageProperty("fromDay") || this.defaultFromDay;
902
- }
903
- set fromDay(value) {
904
- this.setStorageProperty("fromDay", value);
905
- }
906
- /**
907
- * The day when the activity ends. If the activity is ended yet, it will be deleted or hidden.
908
- */
909
- get toDay() {
910
- return this.getStorageProperty("toDay") || this.defaultToDay;
911
- }
912
- set toDay(value) {
913
- this.setStorageProperty("toDay", value);
914
- }
915
- /**
916
- * Whether is disabled.
917
- */
918
- get disabled() {
919
- let value = this.getStorageProperty("disabled") || this.defaultDisabled;
920
- if (typeof value === "string") {
921
- return getFlag(value);
922
- }
923
- return value;
924
- }
925
- set disabled(value) {
926
- this.setStorageProperty("disabled", value);
927
- }
928
- /**
929
- * Whether is hidden. If the activity is not started yet, it will be hidden.
930
- */
931
- get hidden() {
932
- if (this.fromDay && this.fromDay > TimeManager.currentDay) {
933
- return true;
934
- }
935
- if (!TimeManager.nowIsBetween(this.fromHour, this.toHour)) {
936
- return true;
937
- }
938
- if (!this.isExpired) {
939
- return true;
940
- }
941
- let value = this.getStorageProperty("hidden") || this.defaultHidden;
942
- if (typeof value === "string") {
943
- return getFlag(value);
944
- }
945
- return value;
946
- }
947
- set hidden(value) {
948
- this.setStorageProperty("hidden", value);
949
- }
950
- /**
951
- * The function for rendering the icon of the activity.
952
- */
953
- get renderIcon() {
954
- let render = this._renderIcon;
955
- if (render === void 0) {
956
- return void 0;
957
- }
958
- if (typeof render === "function") {
959
- return (props) => {
960
- return render(this, props);
961
- };
962
- }
963
- return (props) => render;
964
- }
965
- /**
966
- * The function that is called when the activity is runned.
967
- */
968
- get onRun() {
969
- return (props) => {
970
- return this._onRun(this, props);
971
- };
972
- }
973
- /**
974
- * Whether the activity is a deadline.
975
- * @returns Whether the activity is a deadline.
976
- */
977
- isExpired() {
978
- if (this.toDay && this.toDay <= TimeManager.currentDay) {
979
- return true;
980
- }
981
- return false;
982
- }
983
- /**
984
- * Export the activity properties.
985
- * @returns The activity properties.
986
- */
987
- export() {
988
- return {
989
- name: this.getStorageProperty("name") || this.defaultName,
990
- fromHour: this.getStorageProperty("fromHour") || this.defaultFromHour,
991
- toHour: this.getStorageProperty("toHour") || this.defaultToHour,
992
- fromDay: this.getStorageProperty("fromDay") || this.defaultFromDay,
993
- toDay: this.getStorageProperty("toDay") || this.defaultToDay,
994
- disabled: this.getStorageProperty("disabled") || this.defaultDisabled,
995
- hidden: this.getStorageProperty("hidden") || this.defaultHidden,
996
- renderIcon: this._renderIcon
997
- };
998
- }
999
- };
1000
-
1001
- // src/classes/navigation/ActivityRoom.ts
1002
- var ActivityRoom = class extends ActivityStoredAbstract {
1003
- constructor(id, room, onRun, props) {
1004
- super(onRun, props);
1005
- this._id = id;
1006
- this._room = room;
1007
- }
1008
- setStorageProperty(_, __) {
1009
- this._room.setActivity(this);
1010
- }
1011
- getStorageProperty(propertyName) {
1012
- let activity = this._room.getActivityMemory(this.id);
1013
- if (!activity || !activity.hasOwnProperty(propertyName)) {
1014
- return void 0;
1015
- }
1016
- return activity[propertyName];
1017
- }
1018
- get id() {
1019
- return this._id;
1020
- }
1021
- get room() {
1022
- return this._room;
1023
- }
1024
- export() {
1025
- let result = {};
1026
- if (this.name !== void 0) {
1027
- result["name"] = this.name;
1028
- }
1029
- if (this.fromHour !== void 0) {
1030
- result["fromHour"] = this.fromHour;
1031
- }
1032
- if (this.toHour !== void 0) {
1033
- result["toHour"] = this.toHour;
1034
- }
1035
- if (this.fromDay !== void 0) {
1036
- result["fromDay"] = this.fromDay;
1037
- }
1038
- if (this.toDay !== void 0) {
1039
- result["toDay"] = this.toDay;
1040
- }
1041
- if (this.disabled !== void 0) {
1042
- result["disabled"] = this.disabled;
1043
- }
1044
- return result;
1045
- }
1046
- };
1047
-
1048
- // src/classes/navigation/Room.ts
1049
- var ROOM_CATEGORY = "__nqtr-room__";
1050
- var RoomBaseModel = class extends StoredClassModel {
1051
- /**
1052
- * @param id The id of the room, it must be unique.
1053
- * @param location The location where the room is.
1054
- * @param props The properties of the room.
1055
- */
1056
- constructor(id, location, props = {}) {
1057
- var _a;
1058
- super(ROOM_CATEGORY, id);
1059
- this._location = location;
1060
- this.defaultName = props.name || "";
1061
- this._renderImage = props.renderImage;
1062
- this.defaultActivityIds = ((_a = props.defaultActivities) == null ? void 0 : _a.map((activity) => activity.id)) || [];
1063
- this.defaultDisabled = props.disabled || false;
1064
- this.defaultHidden = props.hidden || false;
1065
- this._renderIcon = props.renderIcon;
1066
- this._isEntrance = props.isEntrance;
1067
- }
1068
- /**
1069
- * The location where the room is.
1070
- */
1071
- get location() {
1072
- return this._location;
1073
- }
1074
- /**
1075
- * Whether is an entrance room, so when the player enters in the location, it will be the first room to be shown.
1076
- */
1077
- get isEntrance() {
1078
- return this._isEntrance || false;
1079
- }
1080
- /**
1081
- * The name.
1082
- * If you set undefined, it will return the initial value of name.
1083
- */
1084
- get name() {
1085
- return this.getStorageProperty("name") || this.defaultName;
1086
- }
1087
- set name(value) {
1088
- this.setStorageProperty("name", value);
1098
+ set name(value) {
1099
+ this.setStorageProperty("name", value);
1089
1100
  }
1090
1101
  /**
1091
1102
  * The function for rendering the image of the room.
@@ -1277,51 +1288,82 @@ var RoomBaseModel = class extends StoredClassModel {
1277
1288
  * @returns The character commitments of the room.
1278
1289
  */
1279
1290
  getRoutine() {
1280
- let commitments = getCurrentCommitments();
1291
+ let commitments = getCurrentRoutine();
1281
1292
  return commitments.filter((c) => c.room.id === this.id);
1282
1293
  }
1283
1294
  };
1284
-
1285
- // src/classes/quest/Goal.ts
1286
- var Goal = class {
1287
- constructor(props) {
1295
+ var GOAL_CATEGORY = "__nqtr-goal__";
1296
+ var Goal = class extends StoredClassModel {
1297
+ constructor(id, props) {
1298
+ super(GOAL_CATEGORY, id);
1288
1299
  this._description = props.description;
1289
- this.need = props.need || 1;
1290
- this.have = props.have || 0;
1300
+ this._need = props.need || 1;
1301
+ this._defaultHave = props.have || 0;
1291
1302
  }
1303
+ /**
1304
+ * The description of the goal.
1305
+ */
1292
1306
  get description() {
1293
1307
  return this._description;
1294
1308
  }
1295
- get isComplete() {
1309
+ get need() {
1310
+ return this._need;
1311
+ }
1312
+ get defaultHave() {
1313
+ return this._defaultHave;
1314
+ }
1315
+ };
1316
+ var GoalStage = class extends Goal {
1317
+ constructor(id, stageId, props) {
1318
+ super(id, props);
1319
+ this._stageId = stageId;
1320
+ }
1321
+ get stageId() {
1322
+ return this._stageId;
1323
+ }
1324
+ set stageId(value) {
1325
+ this._stageId = value;
1326
+ }
1327
+ get have() {
1328
+ return this.getStorageProperty("have-" + this._stageId) || this.defaultHave;
1329
+ }
1330
+ set have(value) {
1331
+ if (!this._stageId) {
1332
+ console.error(`[NQTR] The stage id is not set for the goal ${this.id}, so the have value can't be set.`);
1333
+ return;
1334
+ }
1335
+ this.setStorageProperty("have-" + this._stageId, value);
1336
+ }
1337
+ get completed() {
1296
1338
  return this.have >= this.need;
1297
1339
  }
1298
- setComplete() {
1299
- this.have = this.need;
1340
+ set completed(value) {
1341
+ if (value) {
1342
+ this.have = this.need;
1343
+ } else {
1344
+ console.warn(`[NQTR] The goal can't be set as not completed. You must edit the have value manually.`);
1345
+ }
1300
1346
  }
1301
1347
  find() {
1302
1348
  this.have++;
1303
1349
  }
1304
- get export() {
1305
- return {
1306
- description: this.description,
1307
- need: this.need,
1308
- have: this.have
1309
- };
1310
- }
1311
1350
  };
1312
- var QUEST_CATEGORY = "__nqtr-quest__";
1313
- var QuestBaseModel = class extends StoredClassModel {
1314
- constructor(id, stages, props) {
1315
- super(QUEST_CATEGORY, id);
1316
- this._stages = stages;
1351
+ var STAGE_CATEGORY = "__nqtr-stage__";
1352
+ var Stage = class extends StoredClassModel {
1353
+ constructor(id, props) {
1354
+ super(STAGE_CATEGORY, id);
1317
1355
  this._name = props.name || "";
1356
+ this._defaultGoals = props.goals || [];
1357
+ this._flags = props.flags || [];
1318
1358
  this._description = props.description || "";
1319
- this._icon = props.icon || "";
1320
- this._image = props.image || "";
1321
- this._isInDevelopment = props.isInDevelopment || false;
1322
- }
1323
- get stages() {
1324
- return this._stages;
1359
+ this._adviceDescription = props.adviceDescription || "";
1360
+ this._renderImage = props.renderImage;
1361
+ this._daysRequiredToStart = props.daysRequiredToStart;
1362
+ this._flagsRequiredToStart = props.flagsRequired || [];
1363
+ this._questsRequiredToStart = props.questsRequired || [];
1364
+ this._requestDescriptionToStart = props.requestDescription || "";
1365
+ this._onStart = props.onStart;
1366
+ this._onEnd = props.onEnd;
1325
1367
  }
1326
1368
  get name() {
1327
1369
  return this._name;
@@ -1329,50 +1371,138 @@ var QuestBaseModel = class extends StoredClassModel {
1329
1371
  get description() {
1330
1372
  return this._description;
1331
1373
  }
1332
- get icon() {
1333
- return this._icon;
1374
+ get adviceDescription() {
1375
+ return this._adviceDescription;
1334
1376
  }
1335
- get image() {
1336
- return this._image;
1377
+ /**
1378
+ * The function for rendering the image of the stage.
1379
+ */
1380
+ get renderImage() {
1381
+ let render = this._renderImage;
1382
+ if (render === void 0) {
1383
+ return void 0;
1384
+ }
1385
+ if (typeof render === "function") {
1386
+ return (props) => {
1387
+ return render(this, props);
1388
+ };
1389
+ }
1390
+ return (props) => render;
1337
1391
  }
1338
- get isInDevelopment() {
1339
- return this._isInDevelopment;
1392
+ get defaultGoals() {
1393
+ return this._defaultGoals;
1394
+ }
1395
+ /**
1396
+ * The list of flags that the player must complete to finish the stage.
1397
+ */
1398
+ get flags() {
1399
+ return this._flags;
1400
+ }
1401
+ get daysRequiredToStart() {
1402
+ return this._daysRequiredToStart || 0;
1403
+ }
1404
+ get flagsRequiredToStart() {
1405
+ return this._flagsRequiredToStart;
1406
+ }
1407
+ get questsRequiredToStart() {
1408
+ return this._questsRequiredToStart || [];
1409
+ }
1410
+ get requestDescriptionToStart() {
1411
+ return this._requestDescriptionToStart;
1412
+ }
1413
+ get onStart() {
1414
+ return this._onStart;
1415
+ }
1416
+ get onEnd() {
1417
+ return this._onEnd;
1340
1418
  }
1341
1419
  };
1342
- var STAGE_CATEGORY = "__nqtr-stage__";
1343
- var StageBaseModel = class extends StoredClassModel {
1420
+ var StageQuest = class extends Stage {
1344
1421
  constructor(id, props) {
1345
- super(STAGE_CATEGORY, id);
1346
- this._completed = false;
1347
- this._active = false;
1348
- this.defaultGoals = [];
1349
- this._name = props.name || "";
1350
- this._description = props.description || "";
1351
- this._adviceDescription = props.adviceDescription || "";
1352
- this._image = props.image || "";
1353
- this._daysRequiredToStart = props.daysRequiredToStart;
1354
- this._flagsRequired = props.flagsRequired;
1355
- this._questsRequired = props.questsRequired;
1356
- this._requestDescription = props.requestDescription || "";
1357
- this._onStart = props.onStart;
1358
- this._onEnd = props.onEnd;
1422
+ super(id, props);
1359
1423
  }
1360
1424
  get completed() {
1361
- return this._completed;
1425
+ let storedCompleted = this.getStorageProperty("completed");
1426
+ if (storedCompleted) {
1427
+ return storedCompleted;
1428
+ }
1429
+ if (!this.flags.every((flag) => getFlag(flag.flag))) {
1430
+ return false;
1431
+ }
1432
+ if (!this.goals.every((goal) => goal.completed)) {
1433
+ return false;
1434
+ }
1435
+ return true;
1362
1436
  }
1363
- get active() {
1364
- return this._active;
1437
+ set completed(value) {
1438
+ this.setStorageProperty("completed", value);
1365
1439
  }
1440
+ /**
1441
+ * The list of goals that the player needs to complete to finish the stage.
1442
+ */
1366
1443
  get goals() {
1367
- let list = this.getStorageProperty("goals");
1368
- if (!list) {
1369
- return this.defaultGoals;
1444
+ return this.defaultGoals.map((goal) => {
1445
+ return new GoalStage(goal.id, this.id, goal);
1446
+ });
1447
+ }
1448
+ get prevStageEndDay() {
1449
+ return this.getStorageProperty("prevStageEndDay");
1450
+ }
1451
+ set prevStageEndDay(value) {
1452
+ this.setStorageProperty("prevStageEndDay", value);
1453
+ }
1454
+ get startDay() {
1455
+ let prevStageEndDay = this.prevStageEndDay;
1456
+ if (prevStageEndDay === void 0) {
1457
+ return void 0;
1458
+ }
1459
+ return prevStageEndDay + this.daysRequiredToStart;
1460
+ }
1461
+ get canStart() {
1462
+ let daysRequired = this.daysRequiredToStart;
1463
+ if (daysRequired > 0) {
1464
+ let prevStageEndDay = this.prevStageEndDay;
1465
+ if (prevStageEndDay === void 0) {
1466
+ return false;
1467
+ }
1468
+ if (prevStageEndDay + daysRequired > TimeManager.currentDay) {
1469
+ return false;
1470
+ }
1370
1471
  }
1371
- return list.map((goal) => new Goal(goal));
1472
+ if (this.flagsRequiredToStart.length > 0 && !this.flagsRequiredToStart.every((flag) => getFlag(flag.flag))) {
1473
+ return false;
1474
+ }
1475
+ if (this.questsRequiredToStart.length > 0 && !this.questsRequiredToStart.every(
1476
+ (q) => q.quest.currentStageIndex && q.quest.currentStageIndex >= q.stageNumber
1477
+ )) {
1478
+ return false;
1479
+ }
1480
+ return true;
1481
+ }
1482
+ get onStart() {
1483
+ if (this.daysRequiredToStart > 0) {
1484
+ this.prevStageEndDay = TimeManager.currentDay;
1485
+ }
1486
+ return super.onStart;
1487
+ }
1488
+ };
1489
+
1490
+ // src/classes/quest/Quest.ts
1491
+ var QUEST_CATEGORY = "__nqtr-quest__";
1492
+ var Quest = class extends StoredClassModel {
1493
+ constructor(id, stages, props) {
1494
+ super(QUEST_CATEGORY, id);
1495
+ this._stages = stages;
1496
+ this._name = props.name || "";
1497
+ this._description = props.description || "";
1498
+ this._renderIcon = props.renderIcon;
1499
+ this._renderImage = props.renderImage;
1500
+ this._isInDevelopment = props.isInDevelopment || false;
1372
1501
  }
1373
- set goals(value) {
1374
- let list = value.map((goal) => goal.export);
1375
- this.setStorageProperty("goals", list);
1502
+ get stages() {
1503
+ return this._stages.map((stage, index) => {
1504
+ return new StageQuest(stage.id, stage);
1505
+ });
1376
1506
  }
1377
1507
  get name() {
1378
1508
  return this._name;
@@ -1380,32 +1510,102 @@ var StageBaseModel = class extends StoredClassModel {
1380
1510
  get description() {
1381
1511
  return this._description;
1382
1512
  }
1383
- get adviceDescription() {
1384
- return this._adviceDescription;
1513
+ /**
1514
+ * The function for rendering the icon of the quest.
1515
+ */
1516
+ get renderIcon() {
1517
+ let render = this._renderIcon;
1518
+ if (render === void 0) {
1519
+ return void 0;
1520
+ }
1521
+ if (typeof render === "function") {
1522
+ return (props) => {
1523
+ return render(this, props);
1524
+ };
1525
+ }
1526
+ return (props) => render;
1527
+ }
1528
+ /**
1529
+ * The function for rendering the image of the quest.
1530
+ */
1531
+ get renderImage() {
1532
+ let render = this._renderImage;
1533
+ if (render === void 0) {
1534
+ return void 0;
1535
+ }
1536
+ if (typeof render === "function") {
1537
+ return (props) => {
1538
+ return render(this, props);
1539
+ };
1540
+ }
1541
+ return (props) => render;
1385
1542
  }
1386
- get image() {
1387
- return this._image;
1543
+ get isInDevelopment() {
1544
+ return this._isInDevelopment;
1388
1545
  }
1389
- get daysRequiredToStart() {
1390
- return this._daysRequiredToStart;
1546
+ get currentStageIndex() {
1547
+ return this.getStorageProperty("currentStageIndex");
1548
+ }
1549
+ set currentStageIndex(value) {
1550
+ this.setStorageProperty("currentStageIndex", value);
1391
1551
  }
1392
- get flagsRequired() {
1393
- return this._flagsRequired;
1552
+ get currentStage() {
1553
+ let index = this.currentStageIndex;
1554
+ if (index === void 0 || index >= this.stages.length) {
1555
+ return void 0;
1556
+ }
1557
+ return this.stages[index];
1394
1558
  }
1395
- get questsRequired() {
1396
- return this._questsRequired;
1559
+ get started() {
1560
+ return this.currentStageIndex !== void 0;
1397
1561
  }
1398
- get requestDescription() {
1399
- return this._requestDescription;
1562
+ get completed() {
1563
+ return this.currentStageIndex === this.stages.length;
1400
1564
  }
1401
- get onStart() {
1402
- return this._onStart;
1565
+ start() {
1566
+ if (this.started) {
1567
+ console.warn(`[NQTR] Quest ${this.id} is already started`);
1568
+ return;
1569
+ }
1570
+ if (this.stages.length === 0) {
1571
+ console.error(`[NQTR] Quest ${this.id} has no stages`);
1572
+ return;
1573
+ }
1574
+ this.currentStageIndex = 0;
1575
+ let currentStage = this.currentStage;
1576
+ if (currentStage && currentStage.onStart) {
1577
+ return currentStage.onStart();
1578
+ } else {
1579
+ console.error(`[NQTR] Quest ${this.id} has no start stage`);
1580
+ }
1403
1581
  }
1404
- get onEnd() {
1405
- return this._onEnd;
1582
+ tryToGoNextStage() {
1583
+ if (!this.started) {
1584
+ return;
1585
+ }
1586
+ if (this.completed) {
1587
+ return;
1588
+ }
1589
+ let currentStage = this.currentStage;
1590
+ let currentStageIndex = this.currentStageIndex;
1591
+ if (!currentStage || currentStageIndex === void 0) {
1592
+ console.error(`[NQTR] Quest ${this.id} has no current stage`);
1593
+ return;
1594
+ }
1595
+ if (currentStage.completed) {
1596
+ let nextStageIndex = currentStageIndex + 1;
1597
+ currentStageIndex = nextStageIndex;
1598
+ let nextStage = this.currentStage;
1599
+ if (currentStage && currentStage.onEnd) {
1600
+ currentStage.onEnd();
1601
+ }
1602
+ if (nextStage && nextStage.onStart) {
1603
+ return nextStage.onStart();
1604
+ }
1605
+ }
1406
1606
  }
1407
1607
  };
1408
1608
 
1409
- export { ActivityModel, CommitmentBaseModel, Goal, LocationBaseModel, MapBaseModel, QuestBaseModel, RoomBaseModel, StageBaseModel };
1609
+ export { ActivityModel, ActivityRoom, CommitmentBaseModel, Goal, LocationBaseModel, MapBaseModel, Quest, RoomBaseModel, Stage };
1410
1610
  //# sourceMappingURL=out.js.map
1411
1611
  //# sourceMappingURL=index.mjs.map