@drincs/nqtr 0.1.19 → 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 (93) hide show
  1. package/dist/Quest-BQ1pwvQ_.d.ts +197 -0
  2. package/dist/Quest-DaNlPBHb.d.mts +197 -0
  3. package/dist/classes/index.d.mts +3 -3
  4. package/dist/classes/index.d.ts +3 -3
  5. package/dist/classes/index.js +488 -298
  6. package/dist/classes/index.js.map +1 -1
  7. package/dist/classes/index.mjs +486 -297
  8. package/dist/classes/index.mjs.map +1 -1
  9. package/dist/classes/navigation/ActivityRoom.d.mts +1 -1
  10. package/dist/classes/navigation/ActivityRoom.d.ts +1 -1
  11. package/dist/classes/navigation/ActivityRoom.js +1 -1
  12. package/dist/classes/navigation/ActivityRoom.js.map +1 -1
  13. package/dist/classes/navigation/ActivityRoom.mjs +1 -1
  14. package/dist/classes/navigation/ActivityRoom.mjs.map +1 -1
  15. package/dist/classes/navigation/Room.js.map +1 -1
  16. package/dist/classes/navigation/Room.mjs.map +1 -1
  17. package/dist/classes/quest/Goal.d.mts +21 -13
  18. package/dist/classes/quest/Goal.d.ts +21 -13
  19. package/dist/classes/quest/Goal.js +50 -15
  20. package/dist/classes/quest/Goal.js.map +1 -1
  21. package/dist/classes/quest/Goal.mjs +47 -15
  22. package/dist/classes/quest/Goal.mjs.map +1 -1
  23. package/dist/classes/quest/Quest.d.mts +3 -2
  24. package/dist/classes/quest/Quest.d.ts +3 -2
  25. package/dist/classes/quest/Quest.js +536 -9
  26. package/dist/classes/quest/Quest.js.map +1 -1
  27. package/dist/classes/quest/Quest.mjs +537 -10
  28. package/dist/classes/quest/Quest.mjs.map +1 -1
  29. package/dist/classes/quest/Stage.d.mts +3 -2
  30. package/dist/classes/quest/Stage.d.ts +3 -2
  31. package/dist/classes/quest/Stage.js +396 -51
  32. package/dist/classes/quest/Stage.js.map +1 -1
  33. package/dist/classes/quest/Stage.mjs +394 -52
  34. package/dist/classes/quest/Stage.mjs.map +1 -1
  35. package/dist/decorators/QuestDecorator.d.mts +28 -0
  36. package/dist/decorators/QuestDecorator.d.ts +28 -0
  37. package/dist/decorators/QuestDecorator.js +33 -0
  38. package/dist/decorators/QuestDecorator.js.map +1 -0
  39. package/dist/decorators/QuestDecorator.mjs +29 -0
  40. package/dist/decorators/QuestDecorator.mjs.map +1 -0
  41. package/dist/decorators/index.d.mts +5 -0
  42. package/dist/decorators/index.d.ts +5 -0
  43. package/dist/decorators/index.js +28 -0
  44. package/dist/decorators/index.js.map +1 -1
  45. package/dist/decorators/index.mjs +27 -1
  46. package/dist/decorators/index.mjs.map +1 -1
  47. package/dist/functions/ActivityFunctions.js.map +1 -1
  48. package/dist/functions/ActivityFunctions.mjs.map +1 -1
  49. package/dist/functions/NavigationFunctions.js.map +1 -1
  50. package/dist/functions/NavigationFunctions.mjs.map +1 -1
  51. package/dist/functions/index.js.map +1 -1
  52. package/dist/functions/index.mjs.map +1 -1
  53. package/dist/index.d.mts +4 -3
  54. package/dist/index.d.ts +4 -3
  55. package/dist/index.js +518 -300
  56. package/dist/index.js.map +1 -1
  57. package/dist/index.mjs +514 -299
  58. package/dist/index.mjs.map +1 -1
  59. package/dist/interface/index.d.mts +2 -2
  60. package/dist/interface/index.d.ts +2 -2
  61. package/dist/interface/quest/GoalProps.d.mts +12 -0
  62. package/dist/interface/quest/GoalProps.d.ts +12 -0
  63. package/dist/interface/quest/QuestProps.d.mts +6 -9
  64. package/dist/interface/quest/QuestProps.d.ts +6 -9
  65. package/dist/interface/quest/StageFlags.d.mts +12 -0
  66. package/dist/interface/quest/StageFlags.d.ts +12 -0
  67. package/dist/interface/quest/StageFlags.js +4 -0
  68. package/dist/interface/quest/StageFlags.js.map +1 -0
  69. package/dist/interface/quest/StageFlags.mjs +3 -0
  70. package/dist/interface/quest/StageFlags.mjs.map +1 -0
  71. package/dist/interface/quest/StageProps.d.mts +3 -2
  72. package/dist/interface/quest/StageProps.d.ts +3 -2
  73. package/dist/override/OnEndStage.d.mts +19 -0
  74. package/dist/override/OnEndStage.d.ts +19 -0
  75. package/dist/override/OnEndStage.js +4 -0
  76. package/dist/override/OnEndStage.js.map +1 -0
  77. package/dist/override/OnEndStage.mjs +3 -0
  78. package/dist/override/OnEndStage.mjs.map +1 -0
  79. package/dist/override/OnStartStage.d.mts +19 -0
  80. package/dist/override/OnStartStage.d.ts +19 -0
  81. package/dist/override/OnStartStage.js +4 -0
  82. package/dist/override/OnStartStage.js.map +1 -0
  83. package/dist/override/OnStartStage.mjs +3 -0
  84. package/dist/override/OnStartStage.mjs.map +1 -0
  85. package/dist/override/index.d.mts +2 -0
  86. package/dist/override/index.d.ts +2 -0
  87. package/dist/types/QuestsRequired.d.mts +3 -2
  88. package/dist/types/QuestsRequired.d.ts +3 -2
  89. package/dist/types/index.d.mts +3 -2
  90. package/dist/types/index.d.ts +3 -2
  91. package/package.json +1 -1
  92. package/dist/Quest-Bdm0R9LA.d.mts +0 -71
  93. package/dist/Quest-CxJcXETG.d.ts +0 -71
package/dist/index.mjs CHANGED
@@ -575,6 +575,199 @@ var CommitmentBaseModel = class extends StoredClassModel {
575
575
  return false;
576
576
  }
577
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
+ };
578
771
 
579
772
  // src/decorators/RoomDecorator.ts
580
773
  var registeredRooms = {};
@@ -903,6 +1096,32 @@ function getTemporaryCommitments() {
903
1096
  return commitments;
904
1097
  }
905
1098
 
1099
+ // src/decorators/QuestDecorator.ts
1100
+ var registeredQuests = {};
1101
+ function saveQuest(quest) {
1102
+ if (Array.isArray(quest)) {
1103
+ quest.forEach((c) => saveQuest(c));
1104
+ return;
1105
+ }
1106
+ if (registeredQuests[quest.id]) {
1107
+ console.warn(`[NQTR] Quest id ${quest.id} already exists, it will be overwritten`);
1108
+ }
1109
+ registeredQuests[quest.id] = quest;
1110
+ }
1111
+ function getQuestById(id) {
1112
+ try {
1113
+ let quest = registeredQuests[id];
1114
+ if (!quest) {
1115
+ console.error(`[NQTR] Quest ${id} not found`);
1116
+ return;
1117
+ }
1118
+ return quest;
1119
+ } catch (e) {
1120
+ console.error(`[NQTR] Error while getting Quest ${id}`, e);
1121
+ return;
1122
+ }
1123
+ }
1124
+
906
1125
  // src/functions/RoutineFunctions.ts
907
1126
  function clearExpiredRoutine() {
908
1127
  Object.entries(registeredCommitments).forEach(([_, commitment]) => {
@@ -951,244 +1170,51 @@ function getCommitmentByCharacter(character) {
951
1170
  });
952
1171
  return void 0;
953
1172
  }
954
- var ActivityStoredAbstract = class {
1173
+
1174
+ // src/classes/navigation/Room.ts
1175
+ var ROOM_CATEGORY = "__nqtr-room__";
1176
+ var RoomBaseModel = class extends StoredClassModel {
955
1177
  /**
956
- * @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.
957
- * @param props The activity properties.
1178
+ * @param id The id of the room, it must be unique.
1179
+ * @param location The location where the room is.
1180
+ * @param props The properties of the room.
958
1181
  */
959
- constructor(onRun, props) {
960
- this.defaultName = props.name;
961
- this.defaultFromHour = props.fromHour;
962
- this.defaultToHour = props.toHour;
963
- this.defaultFromDay = props.fromDay;
964
- this.defaultToDay = props.toDay;
1182
+ constructor(id, location, props = {}) {
1183
+ var _a;
1184
+ super(ROOM_CATEGORY, id);
1185
+ this._location = location;
1186
+ this.defaultName = props.name || "";
1187
+ this._renderImage = props.renderImage;
1188
+ this.defaultActivityIds = ((_a = props.defaultActivities) == null ? void 0 : _a.map((activity) => activity.id)) || [];
965
1189
  this.defaultDisabled = props.disabled || false;
966
1190
  this.defaultHidden = props.hidden || false;
967
1191
  this._renderIcon = props.renderIcon;
968
- this._onRun = onRun;
1192
+ this._isEntrance = props.isEntrance;
969
1193
  }
970
1194
  /**
971
- * The name
1195
+ * The location where the room is.
972
1196
  */
973
- get name() {
974
- return this.getStorageProperty("name") || this.defaultName || "";
1197
+ get location() {
1198
+ return this._location;
975
1199
  }
976
- set name(value) {
977
- this.setStorageProperty("name", value);
1200
+ /**
1201
+ * Whether is an entrance room, so when the player enters in the location, it will be the first room to be shown.
1202
+ */
1203
+ get isEntrance() {
1204
+ return this._isEntrance || false;
978
1205
  }
979
1206
  /**
980
- * The hour when the activity starts. If the activity is not started yet, it will be hidden.
1207
+ * The name.
1208
+ * If you set undefined, it will return the initial value of name.
981
1209
  */
982
- get fromHour() {
983
- return this.getStorageProperty("fromHour") || this.defaultFromHour || TimeManager.minDayHours;
1210
+ get name() {
1211
+ return this.getStorageProperty("name") || this.defaultName;
984
1212
  }
985
- set fromHour(value) {
986
- this.setStorageProperty("fromHour", value);
1213
+ set name(value) {
1214
+ this.setStorageProperty("name", value);
987
1215
  }
988
1216
  /**
989
- * The hour when the activity ends. If the activity is ended yet, it will be hidden.
990
- */
991
- get toHour() {
992
- return this.getStorageProperty("toHour") || this.defaultToHour || TimeManager.maxDayHours + 1;
993
- }
994
- set toHour(value) {
995
- this.setStorageProperty("toHour", value);
996
- }
997
- /**
998
- * The day when the activity starts. If the activity is not started yet, it will be hidden.
999
- */
1000
- get fromDay() {
1001
- return this.getStorageProperty("fromDay") || this.defaultFromDay;
1002
- }
1003
- set fromDay(value) {
1004
- this.setStorageProperty("fromDay", value);
1005
- }
1006
- /**
1007
- * The day when the activity ends. If the activity is ended yet, it will be deleted or hidden.
1008
- */
1009
- get toDay() {
1010
- return this.getStorageProperty("toDay") || this.defaultToDay;
1011
- }
1012
- set toDay(value) {
1013
- this.setStorageProperty("toDay", value);
1014
- }
1015
- /**
1016
- * Whether is disabled.
1017
- */
1018
- get disabled() {
1019
- let value = this.getStorageProperty("disabled") || this.defaultDisabled;
1020
- if (typeof value === "string") {
1021
- return getFlag(value);
1022
- }
1023
- return value;
1024
- }
1025
- set disabled(value) {
1026
- this.setStorageProperty("disabled", value);
1027
- }
1028
- /**
1029
- * Whether is hidden. If the activity is not started yet, it will be hidden.
1030
- */
1031
- get hidden() {
1032
- if (this.fromDay && this.fromDay > TimeManager.currentDay) {
1033
- return true;
1034
- }
1035
- if (!TimeManager.nowIsBetween(this.fromHour, this.toHour)) {
1036
- return true;
1037
- }
1038
- if (!this.isExpired) {
1039
- return true;
1040
- }
1041
- let value = this.getStorageProperty("hidden") || this.defaultHidden;
1042
- if (typeof value === "string") {
1043
- return getFlag(value);
1044
- }
1045
- return value;
1046
- }
1047
- set hidden(value) {
1048
- this.setStorageProperty("hidden", value);
1049
- }
1050
- /**
1051
- * The function for rendering the icon of the activity.
1052
- */
1053
- get renderIcon() {
1054
- let render = this._renderIcon;
1055
- if (render === void 0) {
1056
- return void 0;
1057
- }
1058
- if (typeof render === "function") {
1059
- return (props) => {
1060
- return render(this, props);
1061
- };
1062
- }
1063
- return (props) => render;
1064
- }
1065
- /**
1066
- * The function that is called when the activity is runned.
1067
- */
1068
- get onRun() {
1069
- return (props) => {
1070
- return this._onRun(this, props);
1071
- };
1072
- }
1073
- /**
1074
- * Whether the activity is a deadline.
1075
- * @returns Whether the activity is a deadline.
1076
- */
1077
- isExpired() {
1078
- if (this.toDay && this.toDay <= TimeManager.currentDay) {
1079
- return true;
1080
- }
1081
- return false;
1082
- }
1083
- /**
1084
- * Export the activity properties.
1085
- * @returns The activity properties.
1086
- */
1087
- export() {
1088
- return {
1089
- name: this.getStorageProperty("name") || this.defaultName,
1090
- fromHour: this.getStorageProperty("fromHour") || this.defaultFromHour,
1091
- toHour: this.getStorageProperty("toHour") || this.defaultToHour,
1092
- fromDay: this.getStorageProperty("fromDay") || this.defaultFromDay,
1093
- toDay: this.getStorageProperty("toDay") || this.defaultToDay,
1094
- disabled: this.getStorageProperty("disabled") || this.defaultDisabled,
1095
- hidden: this.getStorageProperty("hidden") || this.defaultHidden,
1096
- renderIcon: this._renderIcon
1097
- };
1098
- }
1099
- };
1100
-
1101
- // src/classes/navigation/ActivityRoom.ts
1102
- var ActivityRoom = class extends ActivityStoredAbstract {
1103
- constructor(id, room, onRun, props) {
1104
- super(onRun, props);
1105
- this._id = id;
1106
- this._room = room;
1107
- }
1108
- setStorageProperty(_, __) {
1109
- this._room.setActivity(this);
1110
- }
1111
- getStorageProperty(propertyName) {
1112
- let activity = this._room.getActivityMemory(this.id);
1113
- if (!activity || !activity.hasOwnProperty(propertyName)) {
1114
- return void 0;
1115
- }
1116
- return activity[propertyName];
1117
- }
1118
- get id() {
1119
- return this._id;
1120
- }
1121
- get room() {
1122
- return this._room;
1123
- }
1124
- export() {
1125
- let result = {};
1126
- if (this.name !== void 0) {
1127
- result["name"] = this.name;
1128
- }
1129
- if (this.fromHour !== void 0) {
1130
- result["fromHour"] = this.fromHour;
1131
- }
1132
- if (this.toHour !== void 0) {
1133
- result["toHour"] = this.toHour;
1134
- }
1135
- if (this.fromDay !== void 0) {
1136
- result["fromDay"] = this.fromDay;
1137
- }
1138
- if (this.toDay !== void 0) {
1139
- result["toDay"] = this.toDay;
1140
- }
1141
- if (this.disabled !== void 0) {
1142
- result["disabled"] = this.disabled;
1143
- }
1144
- return result;
1145
- }
1146
- };
1147
-
1148
- // src/classes/navigation/Room.ts
1149
- var ROOM_CATEGORY = "__nqtr-room__";
1150
- var RoomBaseModel = class extends StoredClassModel {
1151
- /**
1152
- * @param id The id of the room, it must be unique.
1153
- * @param location The location where the room is.
1154
- * @param props The properties of the room.
1155
- */
1156
- constructor(id, location, props = {}) {
1157
- var _a;
1158
- super(ROOM_CATEGORY, id);
1159
- this._location = location;
1160
- this.defaultName = props.name || "";
1161
- this._renderImage = props.renderImage;
1162
- this.defaultActivityIds = ((_a = props.defaultActivities) == null ? void 0 : _a.map((activity) => activity.id)) || [];
1163
- this.defaultDisabled = props.disabled || false;
1164
- this.defaultHidden = props.hidden || false;
1165
- this._renderIcon = props.renderIcon;
1166
- this._isEntrance = props.isEntrance;
1167
- }
1168
- /**
1169
- * The location where the room is.
1170
- */
1171
- get location() {
1172
- return this._location;
1173
- }
1174
- /**
1175
- * Whether is an entrance room, so when the player enters in the location, it will be the first room to be shown.
1176
- */
1177
- get isEntrance() {
1178
- return this._isEntrance || false;
1179
- }
1180
- /**
1181
- * The name.
1182
- * If you set undefined, it will return the initial value of name.
1183
- */
1184
- get name() {
1185
- return this.getStorageProperty("name") || this.defaultName;
1186
- }
1187
- set name(value) {
1188
- this.setStorageProperty("name", value);
1189
- }
1190
- /**
1191
- * The function for rendering the image of the room.
1217
+ * The function for rendering the image of the room.
1192
1218
  */
1193
1219
  get renderImage() {
1194
1220
  let render = this._renderImage;
@@ -1381,47 +1407,78 @@ var RoomBaseModel = class extends StoredClassModel {
1381
1407
  return commitments.filter((c) => c.room.id === this.id);
1382
1408
  }
1383
1409
  };
1384
-
1385
- // src/classes/quest/Goal.ts
1386
- var Goal = class {
1387
- constructor(props) {
1410
+ var GOAL_CATEGORY = "__nqtr-goal__";
1411
+ var Goal = class extends StoredClassModel {
1412
+ constructor(id, props) {
1413
+ super(GOAL_CATEGORY, id);
1388
1414
  this._description = props.description;
1389
- this.need = props.need || 1;
1390
- this.have = props.have || 0;
1415
+ this._need = props.need || 1;
1416
+ this._defaultHave = props.have || 0;
1391
1417
  }
1418
+ /**
1419
+ * The description of the goal.
1420
+ */
1392
1421
  get description() {
1393
1422
  return this._description;
1394
1423
  }
1395
- get isComplete() {
1424
+ get need() {
1425
+ return this._need;
1426
+ }
1427
+ get defaultHave() {
1428
+ return this._defaultHave;
1429
+ }
1430
+ };
1431
+ var GoalStage = class extends Goal {
1432
+ constructor(id, stageId, props) {
1433
+ super(id, props);
1434
+ this._stageId = stageId;
1435
+ }
1436
+ get stageId() {
1437
+ return this._stageId;
1438
+ }
1439
+ set stageId(value) {
1440
+ this._stageId = value;
1441
+ }
1442
+ get have() {
1443
+ return this.getStorageProperty("have-" + this._stageId) || this.defaultHave;
1444
+ }
1445
+ set have(value) {
1446
+ if (!this._stageId) {
1447
+ console.error(`[NQTR] The stage id is not set for the goal ${this.id}, so the have value can't be set.`);
1448
+ return;
1449
+ }
1450
+ this.setStorageProperty("have-" + this._stageId, value);
1451
+ }
1452
+ get completed() {
1396
1453
  return this.have >= this.need;
1397
1454
  }
1398
- setComplete() {
1399
- this.have = this.need;
1455
+ set completed(value) {
1456
+ if (value) {
1457
+ this.have = this.need;
1458
+ } else {
1459
+ console.warn(`[NQTR] The goal can't be set as not completed. You must edit the have value manually.`);
1460
+ }
1400
1461
  }
1401
1462
  find() {
1402
1463
  this.have++;
1403
1464
  }
1404
- get export() {
1405
- return {
1406
- description: this.description,
1407
- need: this.need,
1408
- have: this.have
1409
- };
1410
- }
1411
1465
  };
1412
- var QUEST_CATEGORY = "__nqtr-quest__";
1413
- var QuestBaseModel = class extends StoredClassModel {
1414
- constructor(id, stages, props) {
1415
- super(QUEST_CATEGORY, id);
1416
- this._stages = stages;
1466
+ var STAGE_CATEGORY = "__nqtr-stage__";
1467
+ var Stage = class extends StoredClassModel {
1468
+ constructor(id, props) {
1469
+ super(STAGE_CATEGORY, id);
1417
1470
  this._name = props.name || "";
1471
+ this._defaultGoals = props.goals || [];
1472
+ this._flags = props.flags || [];
1418
1473
  this._description = props.description || "";
1419
- this._icon = props.icon || "";
1420
- this._image = props.image || "";
1421
- this._isInDevelopment = props.isInDevelopment || false;
1422
- }
1423
- get stages() {
1424
- return this._stages;
1474
+ this._adviceDescription = props.adviceDescription || "";
1475
+ this._renderImage = props.renderImage;
1476
+ this._daysRequiredToStart = props.daysRequiredToStart;
1477
+ this._flagsRequiredToStart = props.flagsRequired || [];
1478
+ this._questsRequiredToStart = props.questsRequired || [];
1479
+ this._requestDescriptionToStart = props.requestDescription || "";
1480
+ this._onStart = props.onStart;
1481
+ this._onEnd = props.onEnd;
1425
1482
  }
1426
1483
  get name() {
1427
1484
  return this._name;
@@ -1429,50 +1486,138 @@ var QuestBaseModel = class extends StoredClassModel {
1429
1486
  get description() {
1430
1487
  return this._description;
1431
1488
  }
1432
- get icon() {
1433
- return this._icon;
1489
+ get adviceDescription() {
1490
+ return this._adviceDescription;
1434
1491
  }
1435
- get image() {
1436
- return this._image;
1492
+ /**
1493
+ * The function for rendering the image of the stage.
1494
+ */
1495
+ get renderImage() {
1496
+ let render = this._renderImage;
1497
+ if (render === void 0) {
1498
+ return void 0;
1499
+ }
1500
+ if (typeof render === "function") {
1501
+ return (props) => {
1502
+ return render(this, props);
1503
+ };
1504
+ }
1505
+ return (props) => render;
1437
1506
  }
1438
- get isInDevelopment() {
1439
- return this._isInDevelopment;
1507
+ get defaultGoals() {
1508
+ return this._defaultGoals;
1509
+ }
1510
+ /**
1511
+ * The list of flags that the player must complete to finish the stage.
1512
+ */
1513
+ get flags() {
1514
+ return this._flags;
1515
+ }
1516
+ get daysRequiredToStart() {
1517
+ return this._daysRequiredToStart || 0;
1518
+ }
1519
+ get flagsRequiredToStart() {
1520
+ return this._flagsRequiredToStart;
1521
+ }
1522
+ get questsRequiredToStart() {
1523
+ return this._questsRequiredToStart || [];
1524
+ }
1525
+ get requestDescriptionToStart() {
1526
+ return this._requestDescriptionToStart;
1527
+ }
1528
+ get onStart() {
1529
+ return this._onStart;
1530
+ }
1531
+ get onEnd() {
1532
+ return this._onEnd;
1440
1533
  }
1441
1534
  };
1442
- var STAGE_CATEGORY = "__nqtr-stage__";
1443
- var StageBaseModel = class extends StoredClassModel {
1535
+ var StageQuest = class extends Stage {
1444
1536
  constructor(id, props) {
1445
- super(STAGE_CATEGORY, id);
1446
- this._completed = false;
1447
- this._active = false;
1448
- this.defaultGoals = [];
1449
- this._name = props.name || "";
1450
- this._description = props.description || "";
1451
- this._adviceDescription = props.adviceDescription || "";
1452
- this._image = props.image || "";
1453
- this._daysRequiredToStart = props.daysRequiredToStart;
1454
- this._flagsRequired = props.flagsRequired;
1455
- this._questsRequired = props.questsRequired;
1456
- this._requestDescription = props.requestDescription || "";
1457
- this._onStart = props.onStart;
1458
- this._onEnd = props.onEnd;
1537
+ super(id, props);
1459
1538
  }
1460
1539
  get completed() {
1461
- return this._completed;
1540
+ let storedCompleted = this.getStorageProperty("completed");
1541
+ if (storedCompleted) {
1542
+ return storedCompleted;
1543
+ }
1544
+ if (!this.flags.every((flag) => getFlag(flag.flag))) {
1545
+ return false;
1546
+ }
1547
+ if (!this.goals.every((goal) => goal.completed)) {
1548
+ return false;
1549
+ }
1550
+ return true;
1462
1551
  }
1463
- get active() {
1464
- return this._active;
1552
+ set completed(value) {
1553
+ this.setStorageProperty("completed", value);
1465
1554
  }
1555
+ /**
1556
+ * The list of goals that the player needs to complete to finish the stage.
1557
+ */
1466
1558
  get goals() {
1467
- let list = this.getStorageProperty("goals");
1468
- if (!list) {
1469
- return this.defaultGoals;
1559
+ return this.defaultGoals.map((goal) => {
1560
+ return new GoalStage(goal.id, this.id, goal);
1561
+ });
1562
+ }
1563
+ get prevStageEndDay() {
1564
+ return this.getStorageProperty("prevStageEndDay");
1565
+ }
1566
+ set prevStageEndDay(value) {
1567
+ this.setStorageProperty("prevStageEndDay", value);
1568
+ }
1569
+ get startDay() {
1570
+ let prevStageEndDay = this.prevStageEndDay;
1571
+ if (prevStageEndDay === void 0) {
1572
+ return void 0;
1573
+ }
1574
+ return prevStageEndDay + this.daysRequiredToStart;
1575
+ }
1576
+ get canStart() {
1577
+ let daysRequired = this.daysRequiredToStart;
1578
+ if (daysRequired > 0) {
1579
+ let prevStageEndDay = this.prevStageEndDay;
1580
+ if (prevStageEndDay === void 0) {
1581
+ return false;
1582
+ }
1583
+ if (prevStageEndDay + daysRequired > TimeManager.currentDay) {
1584
+ return false;
1585
+ }
1586
+ }
1587
+ if (this.flagsRequiredToStart.length > 0 && !this.flagsRequiredToStart.every((flag) => getFlag(flag.flag))) {
1588
+ return false;
1470
1589
  }
1471
- return list.map((goal) => new Goal(goal));
1590
+ if (this.questsRequiredToStart.length > 0 && !this.questsRequiredToStart.every(
1591
+ (q) => q.quest.currentStageIndex && q.quest.currentStageIndex >= q.stageNumber
1592
+ )) {
1593
+ return false;
1594
+ }
1595
+ return true;
1596
+ }
1597
+ get onStart() {
1598
+ if (this.daysRequiredToStart > 0) {
1599
+ this.prevStageEndDay = TimeManager.currentDay;
1600
+ }
1601
+ return super.onStart;
1602
+ }
1603
+ };
1604
+
1605
+ // src/classes/quest/Quest.ts
1606
+ var QUEST_CATEGORY = "__nqtr-quest__";
1607
+ var Quest = class extends StoredClassModel {
1608
+ constructor(id, stages, props) {
1609
+ super(QUEST_CATEGORY, id);
1610
+ this._stages = stages;
1611
+ this._name = props.name || "";
1612
+ this._description = props.description || "";
1613
+ this._renderIcon = props.renderIcon;
1614
+ this._renderImage = props.renderImage;
1615
+ this._isInDevelopment = props.isInDevelopment || false;
1472
1616
  }
1473
- set goals(value) {
1474
- let list = value.map((goal) => goal.export);
1475
- this.setStorageProperty("goals", list);
1617
+ get stages() {
1618
+ return this._stages.map((stage, index) => {
1619
+ return new StageQuest(stage.id, stage);
1620
+ });
1476
1621
  }
1477
1622
  get name() {
1478
1623
  return this._name;
@@ -1480,29 +1625,99 @@ var StageBaseModel = class extends StoredClassModel {
1480
1625
  get description() {
1481
1626
  return this._description;
1482
1627
  }
1483
- get adviceDescription() {
1484
- return this._adviceDescription;
1628
+ /**
1629
+ * The function for rendering the icon of the quest.
1630
+ */
1631
+ get renderIcon() {
1632
+ let render = this._renderIcon;
1633
+ if (render === void 0) {
1634
+ return void 0;
1635
+ }
1636
+ if (typeof render === "function") {
1637
+ return (props) => {
1638
+ return render(this, props);
1639
+ };
1640
+ }
1641
+ return (props) => render;
1485
1642
  }
1486
- get image() {
1487
- return this._image;
1643
+ /**
1644
+ * The function for rendering the image of the quest.
1645
+ */
1646
+ get renderImage() {
1647
+ let render = this._renderImage;
1648
+ if (render === void 0) {
1649
+ return void 0;
1650
+ }
1651
+ if (typeof render === "function") {
1652
+ return (props) => {
1653
+ return render(this, props);
1654
+ };
1655
+ }
1656
+ return (props) => render;
1488
1657
  }
1489
- get daysRequiredToStart() {
1490
- return this._daysRequiredToStart;
1658
+ get isInDevelopment() {
1659
+ return this._isInDevelopment;
1491
1660
  }
1492
- get flagsRequired() {
1493
- return this._flagsRequired;
1661
+ get currentStageIndex() {
1662
+ return this.getStorageProperty("currentStageIndex");
1494
1663
  }
1495
- get questsRequired() {
1496
- return this._questsRequired;
1664
+ set currentStageIndex(value) {
1665
+ this.setStorageProperty("currentStageIndex", value);
1497
1666
  }
1498
- get requestDescription() {
1499
- return this._requestDescription;
1667
+ get currentStage() {
1668
+ let index = this.currentStageIndex;
1669
+ if (index === void 0 || index >= this.stages.length) {
1670
+ return void 0;
1671
+ }
1672
+ return this.stages[index];
1500
1673
  }
1501
- get onStart() {
1502
- return this._onStart;
1674
+ get started() {
1675
+ return this.currentStageIndex !== void 0;
1503
1676
  }
1504
- get onEnd() {
1505
- return this._onEnd;
1677
+ get completed() {
1678
+ return this.currentStageIndex === this.stages.length;
1679
+ }
1680
+ start() {
1681
+ if (this.started) {
1682
+ console.warn(`[NQTR] Quest ${this.id} is already started`);
1683
+ return;
1684
+ }
1685
+ if (this.stages.length === 0) {
1686
+ console.error(`[NQTR] Quest ${this.id} has no stages`);
1687
+ return;
1688
+ }
1689
+ this.currentStageIndex = 0;
1690
+ let currentStage = this.currentStage;
1691
+ if (currentStage && currentStage.onStart) {
1692
+ return currentStage.onStart();
1693
+ } else {
1694
+ console.error(`[NQTR] Quest ${this.id} has no start stage`);
1695
+ }
1696
+ }
1697
+ tryToGoNextStage() {
1698
+ if (!this.started) {
1699
+ return;
1700
+ }
1701
+ if (this.completed) {
1702
+ return;
1703
+ }
1704
+ let currentStage = this.currentStage;
1705
+ let currentStageIndex = this.currentStageIndex;
1706
+ if (!currentStage || currentStageIndex === void 0) {
1707
+ console.error(`[NQTR] Quest ${this.id} has no current stage`);
1708
+ return;
1709
+ }
1710
+ if (currentStage.completed) {
1711
+ let nextStageIndex = currentStageIndex + 1;
1712
+ currentStageIndex = nextStageIndex;
1713
+ let nextStage = this.currentStage;
1714
+ if (currentStage && currentStage.onEnd) {
1715
+ currentStage.onEnd();
1716
+ }
1717
+ if (nextStage && nextStage.onStart) {
1718
+ return nextStage.onStart();
1719
+ }
1720
+ }
1506
1721
  }
1507
1722
  };
1508
1723
  var CURRENT_ROOM_MEMORY_KEY = "___nqtr-current_room_memory___";
@@ -1565,6 +1780,6 @@ function currentActivities() {
1565
1780
  return currentRoom.activities.filter((activity) => !activity.hidden);
1566
1781
  }
1567
1782
 
1568
- export { ActivityModel, CommitmentBaseModel, Goal, LocationBaseModel, MapBaseModel, QuestBaseModel, RoomBaseModel, StageBaseModel, TimeManager, addCommitment, clearExpiredActivities, clearExpiredRoutine, currentActivities, getActivityById, getAllLocations, getAllMaps, getCommitmentByCharacter, getCommitmentById, getCueerntMap, getCurrenrLocation, getCurrentRoom, getCurrentRoutine, getRoomById, saveActivity, saveCommitment, saveRoom, setCurrentRoom, setFixedRoutine };
1783
+ export { ActivityModel, ActivityRoom, CommitmentBaseModel, Goal, LocationBaseModel, MapBaseModel, Quest, RoomBaseModel, Stage, TimeManager, addCommitment, clearExpiredActivities, clearExpiredRoutine, currentActivities, getActivityById, getAllLocations, getAllMaps, getCommitmentByCharacter, getCommitmentById, getCueerntMap, getCurrenrLocation, getCurrentRoom, getCurrentRoutine, getQuestById, getRoomById, saveActivity, saveCommitment, saveQuest, saveRoom, setCurrentRoom, setFixedRoutine };
1569
1784
  //# sourceMappingURL=out.js.map
1570
1785
  //# sourceMappingURL=index.mjs.map