@drincs/nqtr 0.1.20 → 0.2.0

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 (123) hide show
  1. package/dist/{ActivityProps-_79x9-BX.d.ts → ActivityProps-BkHX8xkA.d.ts} +1 -1
  2. package/dist/{ActivityProps-BoJeWa2B.d.mts → ActivityProps-D45DQdcT.d.mts} +1 -1
  3. package/dist/{Commitment-Cc2kZEy0.d.ts → Commitment-BJTIpBQ5.d.ts} +4 -2
  4. package/dist/{Commitment-C3Nc2RJH.d.mts → Commitment-CtNWnNQX.d.mts} +4 -2
  5. package/dist/{Quest-BQ1pwvQ_.d.ts → StageProps-DCZkZHwZ.d.ts} +81 -81
  6. package/dist/{Quest-DaNlPBHb.d.mts → StageProps-xLLR0rjD.d.mts} +81 -81
  7. package/dist/classes/Activity.d.mts +2 -2
  8. package/dist/classes/Activity.d.ts +2 -2
  9. package/dist/classes/Activity.js +1 -1
  10. package/dist/classes/Activity.js.map +1 -1
  11. package/dist/classes/Activity.mjs +1 -1
  12. package/dist/classes/Activity.mjs.map +1 -1
  13. package/dist/classes/ActivityStoredAbstract.d.mts +1 -1
  14. package/dist/classes/ActivityStoredAbstract.d.ts +1 -1
  15. package/dist/classes/ActivityStoredAbstract.js +1 -1
  16. package/dist/classes/ActivityStoredAbstract.js.map +1 -1
  17. package/dist/classes/ActivityStoredAbstract.mjs +1 -1
  18. package/dist/classes/ActivityStoredAbstract.mjs.map +1 -1
  19. package/dist/classes/Commitment.d.mts +2 -2
  20. package/dist/classes/Commitment.d.ts +2 -2
  21. package/dist/classes/Commitment.js +2 -2
  22. package/dist/classes/Commitment.js.map +1 -1
  23. package/dist/classes/Commitment.mjs +2 -2
  24. package/dist/classes/Commitment.mjs.map +1 -1
  25. package/dist/classes/index.d.mts +3 -3
  26. package/dist/classes/index.d.ts +3 -3
  27. package/dist/classes/index.js +96 -318
  28. package/dist/classes/index.js.map +1 -1
  29. package/dist/classes/index.mjs +97 -318
  30. package/dist/classes/index.mjs.map +1 -1
  31. package/dist/classes/navigation/ActivityRoom.d.mts +2 -2
  32. package/dist/classes/navigation/ActivityRoom.d.ts +2 -2
  33. package/dist/classes/navigation/ActivityRoom.js +1 -1
  34. package/dist/classes/navigation/ActivityRoom.js.map +1 -1
  35. package/dist/classes/navigation/ActivityRoom.mjs +1 -1
  36. package/dist/classes/navigation/ActivityRoom.mjs.map +1 -1
  37. package/dist/classes/navigation/Location.d.mts +2 -2
  38. package/dist/classes/navigation/Location.d.ts +2 -2
  39. package/dist/classes/navigation/Map.d.mts +2 -2
  40. package/dist/classes/navigation/Map.d.ts +2 -2
  41. package/dist/classes/navigation/Room.d.mts +2 -2
  42. package/dist/classes/navigation/Room.d.ts +2 -2
  43. package/dist/classes/navigation/Room.js +34 -36
  44. package/dist/classes/navigation/Room.js.map +1 -1
  45. package/dist/classes/navigation/Room.mjs +34 -36
  46. package/dist/classes/navigation/Room.mjs.map +1 -1
  47. package/dist/classes/quest/Quest.d.mts +1 -1
  48. package/dist/classes/quest/Quest.d.ts +1 -1
  49. package/dist/classes/quest/Quest.js +5 -5
  50. package/dist/classes/quest/Quest.js.map +1 -1
  51. package/dist/classes/quest/Quest.mjs +5 -5
  52. package/dist/classes/quest/Quest.mjs.map +1 -1
  53. package/dist/classes/quest/Stage.d.mts +1 -1
  54. package/dist/classes/quest/Stage.d.ts +1 -1
  55. package/dist/classes/quest/Stage.js.map +1 -1
  56. package/dist/classes/quest/Stage.mjs.map +1 -1
  57. package/dist/decorators/ActivityDecorator.d.mts +1 -1
  58. package/dist/decorators/ActivityDecorator.d.ts +1 -1
  59. package/dist/decorators/CommitmentDecorator.d.mts +9 -3
  60. package/dist/decorators/CommitmentDecorator.d.ts +9 -3
  61. package/dist/decorators/CommitmentDecorator.js +15 -0
  62. package/dist/decorators/CommitmentDecorator.js.map +1 -1
  63. package/dist/decorators/CommitmentDecorator.mjs +15 -1
  64. package/dist/decorators/CommitmentDecorator.mjs.map +1 -1
  65. package/dist/decorators/QuestDecorator.d.mts +8 -10
  66. package/dist/decorators/QuestDecorator.d.ts +8 -10
  67. package/dist/decorators/QuestDecorator.js +568 -9
  68. package/dist/decorators/QuestDecorator.js.map +1 -1
  69. package/dist/decorators/QuestDecorator.mjs +568 -9
  70. package/dist/decorators/QuestDecorator.mjs.map +1 -1
  71. package/dist/decorators/RoomDecorator.d.mts +2 -2
  72. package/dist/decorators/RoomDecorator.d.ts +2 -2
  73. package/dist/decorators/index.d.mts +5 -5
  74. package/dist/decorators/index.d.ts +5 -5
  75. package/dist/decorators/index.js +579 -9
  76. package/dist/decorators/index.js.map +1 -1
  77. package/dist/decorators/index.mjs +579 -10
  78. package/dist/decorators/index.mjs.map +1 -1
  79. package/dist/functions/ActivityFunctions.d.mts +2 -2
  80. package/dist/functions/ActivityFunctions.d.ts +2 -2
  81. package/dist/functions/ActivityFunctions.js.map +1 -1
  82. package/dist/functions/ActivityFunctions.mjs.map +1 -1
  83. package/dist/functions/NavigationFunctions.d.mts +2 -2
  84. package/dist/functions/NavigationFunctions.d.ts +2 -2
  85. package/dist/functions/NavigationFunctions.js.map +1 -1
  86. package/dist/functions/NavigationFunctions.mjs.map +1 -1
  87. package/dist/functions/RoutineFunctions.d.mts +2 -2
  88. package/dist/functions/RoutineFunctions.d.ts +2 -2
  89. package/dist/functions/RoutineFunctions.js.map +1 -1
  90. package/dist/functions/RoutineFunctions.mjs.map +1 -1
  91. package/dist/functions/index.d.mts +2 -2
  92. package/dist/functions/index.d.ts +2 -2
  93. package/dist/functions/index.js.map +1 -1
  94. package/dist/functions/index.mjs.map +1 -1
  95. package/dist/index.d.mts +5 -5
  96. package/dist/index.d.ts +5 -5
  97. package/dist/index.js +422 -408
  98. package/dist/index.js.map +1 -1
  99. package/dist/index.mjs +421 -407
  100. package/dist/index.mjs.map +1 -1
  101. package/dist/interface/ActivityProps.d.mts +1 -1
  102. package/dist/interface/ActivityProps.d.ts +1 -1
  103. package/dist/interface/CommitmentProps.d.mts +2 -2
  104. package/dist/interface/CommitmentProps.d.ts +2 -2
  105. package/dist/interface/RoomActivityMemory.d.mts +1 -1
  106. package/dist/interface/RoomActivityMemory.d.ts +1 -1
  107. package/dist/interface/RoomProps.d.mts +2 -2
  108. package/dist/interface/RoomProps.d.ts +2 -2
  109. package/dist/interface/index.d.mts +3 -3
  110. package/dist/interface/index.d.ts +3 -3
  111. package/dist/interface/navigation/LocationProps.d.mts +2 -2
  112. package/dist/interface/navigation/LocationProps.d.ts +2 -2
  113. package/dist/interface/navigation/MapProps.d.mts +2 -2
  114. package/dist/interface/navigation/MapProps.d.ts +2 -2
  115. package/dist/interface/quest/QuestProps.d.mts +1 -1
  116. package/dist/interface/quest/QuestProps.d.ts +1 -1
  117. package/dist/interface/quest/StageProps.d.mts +1 -1
  118. package/dist/interface/quest/StageProps.d.ts +1 -1
  119. package/dist/types/QuestsRequired.d.mts +1 -1
  120. package/dist/types/QuestsRequired.d.ts +1 -1
  121. package/dist/types/index.d.mts +1 -1
  122. package/dist/types/index.d.ts +1 -1
  123. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -359,7 +359,7 @@ var ActivityModel = class {
359
359
  /**
360
360
  * The function that is called when the activity is runned.
361
361
  */
362
- get onRun() {
362
+ get run() {
363
363
  return (props) => this._onRun(this, props);
364
364
  }
365
365
  /**
@@ -489,6 +489,7 @@ var CommitmentBaseModel = class extends StoredClassModel {
489
489
  }
490
490
  /**
491
491
  * Execution type. If is "automatic" the onRun() runned automatically when the palayer is in the room. If is "interaction" the player must interact with the character to run the onRun() function.
492
+ * If you set "automatic" remember to remove the commitment when it is no longer needed, because otherwise it repeats itself every time.
492
493
  */
493
494
  get executionType() {
494
495
  return this._executionType;
@@ -511,10 +512,9 @@ var CommitmentBaseModel = class extends StoredClassModel {
511
512
  /**
512
513
  * Is a function that is called when the player interacts with the character.
513
514
  */
514
- get onRun() {
515
+ get run() {
515
516
  let onRun = this._onRun;
516
517
  if (!onRun) {
517
- console.warn("[NQTR] onRun() is not defined for commitmen, so it will not run.", this);
518
518
  return;
519
519
  }
520
520
  return (props) => onRun(this, props);
@@ -689,7 +689,7 @@ var ActivityStoredAbstract = class {
689
689
  /**
690
690
  * The function that is called when the activity is runned.
691
691
  */
692
- get onRun() {
692
+ get run() {
693
693
  return (props) => {
694
694
  return this._onRun(this, props);
695
695
  };
@@ -1084,6 +1084,20 @@ function addCommitment(commitment) {
1084
1084
  }).filter((id) => id !== void 0);
1085
1085
  GameStorageManager.setVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY, [commitmentsIds]);
1086
1086
  }
1087
+ function removeCommitment(commitment) {
1088
+ if (!Array.isArray(commitment)) {
1089
+ commitment = [commitment];
1090
+ }
1091
+ let commitmentsIds = commitment.map((commitment2) => {
1092
+ return commitment2.id;
1093
+ });
1094
+ let currentCommitments = GameStorageManager.getVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY);
1095
+ if (!currentCommitments) {
1096
+ return;
1097
+ }
1098
+ currentCommitments = currentCommitments.filter((id) => !commitmentsIds.includes(id));
1099
+ GameStorageManager.setVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY, currentCommitments);
1100
+ }
1087
1101
  function getFixedRoutine() {
1088
1102
  return Object.values(fixedCommitments);
1089
1103
  }
@@ -1095,126 +1109,92 @@ function getTemporaryCommitments() {
1095
1109
  let commitments = commitmentsIds.map((id) => getCommitmentById(id)).filter((commitment) => commitment !== void 0);
1096
1110
  return commitments;
1097
1111
  }
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;
1112
+ var GOAL_CATEGORY = "__nqtr-goal__";
1113
+ var Goal = class extends StoredClassModel {
1114
+ constructor(id, props) {
1115
+ super(GOAL_CATEGORY, id);
1116
+ this._description = props.description;
1117
+ this._need = props.need || 1;
1118
+ this._defaultHave = props.have || 0;
1105
1119
  }
1106
- if (registeredQuests[quest.id]) {
1107
- console.warn(`[NQTR] Quest id ${quest.id} already exists, it will be overwritten`);
1120
+ /**
1121
+ * The description of the goal.
1122
+ */
1123
+ get description() {
1124
+ return this._description;
1108
1125
  }
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`);
1126
+ get need() {
1127
+ return this._need;
1128
+ }
1129
+ get defaultHave() {
1130
+ return this._defaultHave;
1131
+ }
1132
+ };
1133
+ var GoalStage = class extends Goal {
1134
+ constructor(id, stageId, props) {
1135
+ super(id, props);
1136
+ this._stageId = stageId;
1137
+ }
1138
+ get stageId() {
1139
+ return this._stageId;
1140
+ }
1141
+ set stageId(value) {
1142
+ this._stageId = value;
1143
+ }
1144
+ get have() {
1145
+ return this.getStorageProperty("have-" + this._stageId) || this.defaultHave;
1146
+ }
1147
+ set have(value) {
1148
+ if (!this._stageId) {
1149
+ console.error(`[NQTR] The stage id is not set for the goal ${this.id}, so the have value can't be set.`);
1116
1150
  return;
1117
1151
  }
1118
- return quest;
1119
- } catch (e) {
1120
- console.error(`[NQTR] Error while getting Quest ${id}`, e);
1121
- return;
1152
+ this.setStorageProperty("have-" + this._stageId, value);
1122
1153
  }
1123
- }
1124
-
1125
- // src/functions/RoutineFunctions.ts
1126
- function clearExpiredRoutine() {
1127
- Object.entries(registeredCommitments).forEach(([_, commitment]) => {
1128
- if (commitment.isExpired()) {
1129
- delete registeredCommitments[commitment.id];
1130
- }
1131
- });
1132
- }
1133
- function getCurrentRoutine() {
1134
- let character_commitments = {};
1135
- getTemporaryCommitments().reverse().forEach((c) => {
1136
- if (!c.hidden) {
1137
- if (c.characters.length > 0) {
1138
- let allAvailable = c.characters.every((ch) => !character_commitments[ch.id] || c.priority > character_commitments[ch.id].priority);
1139
- if (allAvailable) {
1140
- c.characters.forEach((ch) => {
1141
- character_commitments[ch.id] = c;
1142
- });
1143
- }
1144
- } else {
1145
- console.error(`[NQTR] The commitment ${c.id} has no characters assigned`);
1146
- }
1147
- }
1148
- });
1149
- getFixedRoutine().reverse().forEach((c) => {
1150
- if (!c.hidden) {
1151
- if (c.characters.length > 0) {
1152
- let allAvailable = c.characters.every((ch) => !character_commitments[ch.id] || c.priority > character_commitments[ch.id].priority);
1153
- if (allAvailable) {
1154
- c.characters.forEach((ch) => {
1155
- character_commitments[ch.id] = c;
1156
- });
1157
- }
1158
- } else {
1159
- console.error(`[NQTR] The commitment ${c.id} has no characters assigned`);
1160
- }
1161
- }
1162
- });
1163
- return Object.values(character_commitments);
1164
- }
1165
- function getCommitmentByCharacter(character) {
1166
- getCurrentRoutine().forEach((c) => {
1167
- if (c.characters.map((ch) => ch.id).includes(character.id)) {
1168
- return c;
1154
+ get completed() {
1155
+ return this.have >= this.need;
1156
+ }
1157
+ set completed(value) {
1158
+ if (value) {
1159
+ this.have = this.need;
1160
+ } else {
1161
+ console.warn(`[NQTR] The goal can't be set as not completed. You must edit the have value manually.`);
1169
1162
  }
1170
- });
1171
- return void 0;
1172
- }
1173
-
1174
- // src/classes/navigation/Room.ts
1175
- var ROOM_CATEGORY = "__nqtr-room__";
1176
- var RoomBaseModel = class extends StoredClassModel {
1177
- /**
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.
1181
- */
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)) || [];
1189
- this.defaultDisabled = props.disabled || false;
1190
- this.defaultHidden = props.hidden || false;
1191
- this._renderIcon = props.renderIcon;
1192
- this._isEntrance = props.isEntrance;
1193
1163
  }
1194
- /**
1195
- * The location where the room is.
1196
- */
1197
- get location() {
1198
- return this._location;
1164
+ find() {
1165
+ this.have++;
1199
1166
  }
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;
1167
+ };
1168
+
1169
+ // src/classes/quest/Stage.ts
1170
+ var STAGE_CATEGORY = "__nqtr-stage__";
1171
+ var Stage = class extends StoredClassModel {
1172
+ constructor(id, props) {
1173
+ super(STAGE_CATEGORY, id);
1174
+ this._name = props.name || "";
1175
+ this._defaultGoals = props.goals || [];
1176
+ this._flags = props.flags || [];
1177
+ this._description = props.description || "";
1178
+ this._adviceDescription = props.adviceDescription || "";
1179
+ this._renderImage = props.renderImage;
1180
+ this._daysRequiredToStart = props.daysRequiredToStart;
1181
+ this._flagsRequiredToStart = props.flagsRequired || [];
1182
+ this._questsRequiredToStart = props.questsRequired || [];
1183
+ this._requestDescriptionToStart = props.requestDescription || "";
1184
+ this._onStart = props.onStart;
1185
+ this._onEnd = props.onEnd;
1205
1186
  }
1206
- /**
1207
- * The name.
1208
- * If you set undefined, it will return the initial value of name.
1209
- */
1210
1187
  get name() {
1211
- return this.getStorageProperty("name") || this.defaultName;
1188
+ return this._name;
1212
1189
  }
1213
- set name(value) {
1214
- this.setStorageProperty("name", value);
1190
+ get description() {
1191
+ return this._description;
1192
+ }
1193
+ get adviceDescription() {
1194
+ return this._adviceDescription;
1215
1195
  }
1216
1196
  /**
1217
- * The function for rendering the image of the room.
1197
+ * The function for rendering the image of the stage.
1218
1198
  */
1219
1199
  get renderImage() {
1220
1200
  let render = this._renderImage;
@@ -1228,302 +1208,26 @@ var RoomBaseModel = class extends StoredClassModel {
1228
1208
  }
1229
1209
  return (props) => render;
1230
1210
  }
1211
+ get defaultGoals() {
1212
+ return this._defaultGoals;
1213
+ }
1231
1214
  /**
1232
- * The activities that are available in this room.
1215
+ * The list of flags that the player must complete to finish the stage.
1233
1216
  */
1234
- get defaultActivities() {
1235
- let roomMemories = this.getStorageProperty("activities_memory") || {};
1236
- let activities = this.defaultActivityIds.map((id) => {
1237
- let activity = getActivityById(id);
1238
- if (!activity) {
1239
- console.warn(`[NQTR] Activity with id ${id} not found, so it will be ignored.`);
1240
- return void 0;
1241
- }
1242
- let memory = activity.export();
1243
- if (roomMemories && roomMemories[id]) {
1244
- memory = __spreadValues(__spreadValues({}, memory), roomMemories[id]);
1245
- }
1246
- return new ActivityRoom(id, this, activity._initialOnRun, memory);
1247
- }).filter((activity) => activity !== void 0);
1248
- return activities;
1217
+ get flags() {
1218
+ return this._flags;
1249
1219
  }
1250
- get activityIds() {
1251
- let addedActivityIds = this.getStorageProperty(`addedActivityIds`) || [];
1252
- return this.defaultActivityIds.concat(addedActivityIds);
1220
+ get daysRequiredToStart() {
1221
+ return this._daysRequiredToStart || 0;
1253
1222
  }
1254
- /**
1255
- * The activities that are available in this room.
1256
- */
1257
- get activities() {
1258
- let activities = this.activityIds.map((id) => {
1259
- return this.getActivity(id);
1260
- }).filter((activity) => activity !== void 0 && !activity.hidden);
1261
- return activities;
1223
+ get flagsRequiredToStart() {
1224
+ return this._flagsRequiredToStart;
1262
1225
  }
1263
- /**
1264
- * Get the memory of an activity. This function can be used into olther libraries to get the memory of the activity.
1265
- * @param id The id of the activity.
1266
- * @returns The memory of the activity.
1267
- */
1268
- getActivityMemory(id) {
1269
- let roomMemories = this.getStorageProperty("activities_memory") || {};
1270
- let roomMemory = roomMemories[id] || {};
1271
- return roomMemory;
1226
+ get questsRequiredToStart() {
1227
+ return this._questsRequiredToStart || [];
1272
1228
  }
1273
- /**
1274
- * Get the activity by id.
1275
- * @param id The id of the activity.
1276
- * @returns The room activity.
1277
- */
1278
- getActivity(id) {
1279
- if (!this.activityIds.includes(id)) {
1280
- console.error(`[NQTR] Activity with id ${id} not found in room ${this.id}`);
1281
- return void 0;
1282
- }
1283
- let activity = getActivityById(id);
1284
- if (!activity) {
1285
- console.error(`[NQTR] Activity with id ${id} not found`);
1286
- return void 0;
1287
- }
1288
- let roomMemories = this.getStorageProperty("activities_memory") || {};
1289
- let roomMemory = roomMemories[id] || {};
1290
- roomMemory = __spreadValues(__spreadValues({}, activity.export()), roomMemory);
1291
- return new ActivityRoom(id, this, activity._initialOnRun, roomMemory);
1292
- }
1293
- /**
1294
- * Set the memory of an activity. This function can be used into olther libraries to set the memory of the activity.
1295
- * @param id The id of the activity.
1296
- * @param memory The memory of the activity.
1297
- */
1298
- setActivity(activity) {
1299
- let roomMemories = this.getStorageProperty("activities_memory") || {};
1300
- roomMemories[activity.id] = activity.export();
1301
- this.setStorageProperty("activities_memory", roomMemories);
1302
- }
1303
- /**
1304
- * Add an activity to the room.
1305
- * @param activity The activity to add.
1306
- */
1307
- addActivity(activity) {
1308
- if (this.activityIds.includes(activity.id)) {
1309
- let currentActivity = this.getActivity(activity.id);
1310
- if (currentActivity && currentActivity.isExpired()) {
1311
- this.removeActivity(activity.id);
1312
- return;
1313
- } else {
1314
- console.error(`[NQTR] Activity with id ${activity.id} already exists in room ${this.id}, so it will be ignored.`);
1315
- return;
1316
- }
1317
- }
1318
- let addedActivityIds = this.getStorageProperty(`addedActivityIds`) || [];
1319
- addedActivityIds.push(activity.id);
1320
- this.setStorageProperty("addedActivityIds", addedActivityIds);
1321
- }
1322
- /**
1323
- * Remove an activity from the room.
1324
- * @param activity The activity to remove.
1325
- */
1326
- removeActivity(activity) {
1327
- let activityId = typeof activity === "string" ? activity : activity.id;
1328
- if (this.defaultActivityIds.includes(activityId)) {
1329
- console.warn(`[NQTR] Activity with id ${activityId} is a default activity, so it can't be removed. It will be hidden instead.`);
1330
- let activityToEdit = this.getActivity(activityId);
1331
- if (!activityToEdit) {
1332
- console.error(`[NQTR] Activity with id ${activityId} not found, so it can't be hidden.`);
1333
- return;
1334
- }
1335
- activityToEdit.hidden = true;
1336
- return;
1337
- }
1338
- let addedActivityIds = this.getStorageProperty(`addedActivityIds`) || [];
1339
- let index = addedActivityIds.indexOf(activityId);
1340
- if (index === -1) {
1341
- console.error(`[NQTR] Activity with id ${activityId} not found, so it can't be removed.`);
1342
- return;
1343
- }
1344
- addedActivityIds.splice(index, 1);
1345
- this.setStorageProperty("addedActivityIds", addedActivityIds);
1346
- let roomMemories = this.getStorageProperty("activities_memory") || {};
1347
- delete roomMemories[activityId];
1348
- this.setStorageProperty("activities_memory", roomMemories);
1349
- }
1350
- /**
1351
- * Clear all expired activities.
1352
- */
1353
- clearExpiredActivities() {
1354
- this.activities.forEach((activity) => {
1355
- if (activity.isExpired()) {
1356
- this.removeActivity(activity.id);
1357
- }
1358
- });
1359
- }
1360
- /**
1361
- * Whether is disabled. If it is a string, it is a Pixi'VN flag name.
1362
- */
1363
- get disabled() {
1364
- let value = this.getStorageProperty("disabled") || this.defaultDisabled;
1365
- if (typeof value === "string") {
1366
- return getFlag(value);
1367
- }
1368
- return value;
1369
- }
1370
- set disabled(value) {
1371
- this.setStorageProperty("disabled", value);
1372
- }
1373
- /**
1374
- * Whether is hidden. If it is a string, it is a Pixi'VN flag name.
1375
- */
1376
- get hidden() {
1377
- let value = this.getStorageProperty("hidden") || this.defaultHidden;
1378
- if (typeof value === "string") {
1379
- return getFlag(value);
1380
- }
1381
- return value;
1382
- }
1383
- set hidden(value) {
1384
- this.setStorageProperty("hidden", value);
1385
- }
1386
- /**
1387
- * The function for rendering the icon of the room.
1388
- */
1389
- get renderIcon() {
1390
- let render = this._renderIcon;
1391
- if (render === void 0) {
1392
- return void 0;
1393
- }
1394
- if (typeof render === "function") {
1395
- return (props) => {
1396
- return render(this, props);
1397
- };
1398
- }
1399
- return (props) => render;
1400
- }
1401
- /**
1402
- * Get the character commitments of the room.
1403
- * @returns The character commitments of the room.
1404
- */
1405
- getRoutine() {
1406
- let commitments = getCurrentRoutine();
1407
- return commitments.filter((c) => c.room.id === this.id);
1408
- }
1409
- };
1410
- var GOAL_CATEGORY = "__nqtr-goal__";
1411
- var Goal = class extends StoredClassModel {
1412
- constructor(id, props) {
1413
- super(GOAL_CATEGORY, id);
1414
- this._description = props.description;
1415
- this._need = props.need || 1;
1416
- this._defaultHave = props.have || 0;
1417
- }
1418
- /**
1419
- * The description of the goal.
1420
- */
1421
- get description() {
1422
- return this._description;
1423
- }
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() {
1453
- return this.have >= this.need;
1454
- }
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
- }
1461
- }
1462
- find() {
1463
- this.have++;
1464
- }
1465
- };
1466
- var STAGE_CATEGORY = "__nqtr-stage__";
1467
- var Stage = class extends StoredClassModel {
1468
- constructor(id, props) {
1469
- super(STAGE_CATEGORY, id);
1470
- this._name = props.name || "";
1471
- this._defaultGoals = props.goals || [];
1472
- this._flags = props.flags || [];
1473
- this._description = props.description || "";
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;
1482
- }
1483
- get name() {
1484
- return this._name;
1485
- }
1486
- get description() {
1487
- return this._description;
1488
- }
1489
- get adviceDescription() {
1490
- return this._adviceDescription;
1491
- }
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;
1506
- }
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;
1229
+ get requestDescriptionToStart() {
1230
+ return this._requestDescriptionToStart;
1527
1231
  }
1528
1232
  get onStart() {
1529
1233
  return this._onStart;
@@ -1677,7 +1381,7 @@ var Quest = class extends StoredClassModel {
1677
1381
  get completed() {
1678
1382
  return this.currentStageIndex === this.stages.length;
1679
1383
  }
1680
- start() {
1384
+ start(props) {
1681
1385
  if (this.started) {
1682
1386
  console.warn(`[NQTR] Quest ${this.id} is already started`);
1683
1387
  return;
@@ -1689,12 +1393,12 @@ var Quest = class extends StoredClassModel {
1689
1393
  this.currentStageIndex = 0;
1690
1394
  let currentStage = this.currentStage;
1691
1395
  if (currentStage && currentStage.onStart) {
1692
- return currentStage.onStart();
1396
+ return currentStage.onStart(props);
1693
1397
  } else {
1694
1398
  console.error(`[NQTR] Quest ${this.id} has no start stage`);
1695
1399
  }
1696
1400
  }
1697
- tryToGoNextStage() {
1401
+ tryToGoNextStage(startProps, endProps) {
1698
1402
  if (!this.started) {
1699
1403
  return;
1700
1404
  }
@@ -1712,14 +1416,324 @@ var Quest = class extends StoredClassModel {
1712
1416
  currentStageIndex = nextStageIndex;
1713
1417
  let nextStage = this.currentStage;
1714
1418
  if (currentStage && currentStage.onEnd) {
1715
- currentStage.onEnd();
1419
+ currentStage.onEnd(endProps);
1716
1420
  }
1717
1421
  if (nextStage && nextStage.onStart) {
1718
- return nextStage.onStart();
1422
+ return nextStage.onStart(startProps);
1719
1423
  }
1720
1424
  }
1721
1425
  }
1722
1426
  };
1427
+
1428
+ // src/decorators/QuestDecorator.ts
1429
+ var registeredQuests = {};
1430
+ function newQuest(id, stages, props) {
1431
+ if (registeredQuests[id]) {
1432
+ console.warn(`[NQTR] Quest ${id} already exists, it will be overwritten`);
1433
+ }
1434
+ let quest = new Quest(id, stages, props);
1435
+ registeredQuests[id] = quest;
1436
+ return quest;
1437
+ }
1438
+ function getQuestById(id) {
1439
+ try {
1440
+ let quest = registeredQuests[id];
1441
+ if (!quest) {
1442
+ console.error(`[NQTR] Quest ${id} not found`);
1443
+ return;
1444
+ }
1445
+ return quest;
1446
+ } catch (e) {
1447
+ console.error(`[NQTR] Error while getting Quest ${id}`, e);
1448
+ return;
1449
+ }
1450
+ }
1451
+
1452
+ // src/functions/RoutineFunctions.ts
1453
+ function clearExpiredRoutine() {
1454
+ Object.entries(registeredCommitments).forEach(([_, commitment]) => {
1455
+ if (commitment.isExpired()) {
1456
+ delete registeredCommitments[commitment.id];
1457
+ }
1458
+ });
1459
+ }
1460
+ function getCurrentRoutine() {
1461
+ let character_commitments = {};
1462
+ getTemporaryCommitments().reverse().forEach((c) => {
1463
+ if (!c.hidden) {
1464
+ if (c.characters.length > 0) {
1465
+ let allAvailable = c.characters.every((ch) => !character_commitments[ch.id] || c.priority > character_commitments[ch.id].priority);
1466
+ if (allAvailable) {
1467
+ c.characters.forEach((ch) => {
1468
+ character_commitments[ch.id] = c;
1469
+ });
1470
+ }
1471
+ } else {
1472
+ console.error(`[NQTR] The commitment ${c.id} has no characters assigned`);
1473
+ }
1474
+ }
1475
+ });
1476
+ getFixedRoutine().reverse().forEach((c) => {
1477
+ if (!c.hidden) {
1478
+ if (c.characters.length > 0) {
1479
+ let allAvailable = c.characters.every((ch) => !character_commitments[ch.id] || c.priority > character_commitments[ch.id].priority);
1480
+ if (allAvailable) {
1481
+ c.characters.forEach((ch) => {
1482
+ character_commitments[ch.id] = c;
1483
+ });
1484
+ }
1485
+ } else {
1486
+ console.error(`[NQTR] The commitment ${c.id} has no characters assigned`);
1487
+ }
1488
+ }
1489
+ });
1490
+ return Object.values(character_commitments);
1491
+ }
1492
+ function getCommitmentByCharacter(character) {
1493
+ getCurrentRoutine().forEach((c) => {
1494
+ if (c.characters.map((ch) => ch.id).includes(character.id)) {
1495
+ return c;
1496
+ }
1497
+ });
1498
+ return void 0;
1499
+ }
1500
+
1501
+ // src/classes/navigation/Room.ts
1502
+ var ROOM_CATEGORY = "__nqtr-room__";
1503
+ var RoomBaseModel = class extends StoredClassModel {
1504
+ /**
1505
+ * @param id The id of the room, it must be unique.
1506
+ * @param location The location where the room is.
1507
+ * @param props The properties of the room.
1508
+ */
1509
+ constructor(id, location, props = {}) {
1510
+ var _a;
1511
+ super(ROOM_CATEGORY, id);
1512
+ this._location = location;
1513
+ this.defaultName = props.name || "";
1514
+ this._renderImage = props.renderImage;
1515
+ this.defaultActivityIds = ((_a = props.defaultActivities) == null ? void 0 : _a.map((activity) => activity.id)) || [];
1516
+ this.defaultDisabled = props.disabled || false;
1517
+ this.defaultHidden = props.hidden || false;
1518
+ this._renderIcon = props.renderIcon;
1519
+ this._isEntrance = props.isEntrance;
1520
+ }
1521
+ /**
1522
+ * The location where the room is.
1523
+ */
1524
+ get location() {
1525
+ return this._location;
1526
+ }
1527
+ /**
1528
+ * Whether is an entrance room, so when the player enters in the location, it will be the first room to be shown.
1529
+ */
1530
+ get isEntrance() {
1531
+ return this._isEntrance || false;
1532
+ }
1533
+ /**
1534
+ * The name.
1535
+ * If you set undefined, it will return the initial value of name.
1536
+ */
1537
+ get name() {
1538
+ return this.getStorageProperty("name") || this.defaultName;
1539
+ }
1540
+ set name(value) {
1541
+ this.setStorageProperty("name", value);
1542
+ }
1543
+ /**
1544
+ * The function for rendering the image of the room.
1545
+ */
1546
+ get renderImage() {
1547
+ let render = this._renderImage;
1548
+ if (render === void 0) {
1549
+ return void 0;
1550
+ }
1551
+ if (typeof render === "function") {
1552
+ return (props) => {
1553
+ return render(this, props);
1554
+ };
1555
+ }
1556
+ return (props) => render;
1557
+ }
1558
+ /**
1559
+ * The activities that are available in this room.
1560
+ */
1561
+ get defaultActivities() {
1562
+ let roomMemories = this.getStorageProperty("activities_memory") || {};
1563
+ let activities = this.defaultActivityIds.map((id) => {
1564
+ let activity = getActivityById(id);
1565
+ if (!activity) {
1566
+ console.warn(`[NQTR] Activity with id ${id} not found, so it will be ignored.`);
1567
+ return void 0;
1568
+ }
1569
+ let memory = activity.export();
1570
+ if (roomMemories && roomMemories[id]) {
1571
+ memory = __spreadValues(__spreadValues({}, memory), roomMemories[id]);
1572
+ }
1573
+ return new ActivityRoom(id, this, activity._initialOnRun, memory);
1574
+ }).filter((activity) => activity !== void 0);
1575
+ return activities;
1576
+ }
1577
+ get activityIds() {
1578
+ let addedActivityIds = this.getStorageProperty(`addedActivityIds`) || [];
1579
+ return this.defaultActivityIds.concat(addedActivityIds);
1580
+ }
1581
+ /**
1582
+ * The activities that are available in this room.
1583
+ */
1584
+ get activities() {
1585
+ let activities = this.activityIds.map((id) => {
1586
+ return this.getActivity(id);
1587
+ }).filter((activity) => activity !== void 0 && !activity.hidden);
1588
+ return activities;
1589
+ }
1590
+ /**
1591
+ * Get the memory of an activity. This function can be used into olther libraries to get the memory of the activity.
1592
+ * @param id The id of the activity.
1593
+ * @returns The memory of the activity.
1594
+ */
1595
+ getActivityMemory(id) {
1596
+ let roomMemories = this.getStorageProperty("activities_memory") || {};
1597
+ let roomMemory = roomMemories[id] || {};
1598
+ return roomMemory;
1599
+ }
1600
+ /**
1601
+ * Get the activity by id.
1602
+ * @param id The id of the activity.
1603
+ * @returns The room activity.
1604
+ */
1605
+ getActivity(id) {
1606
+ if (!this.activityIds.includes(id)) {
1607
+ console.error(`[NQTR] Activity with id ${id} not found in room ${this.id}`);
1608
+ return void 0;
1609
+ }
1610
+ let activity = getActivityById(id);
1611
+ if (!activity) {
1612
+ console.error(`[NQTR] Activity with id ${id} not found`);
1613
+ return void 0;
1614
+ }
1615
+ let roomMemories = this.getStorageProperty("activities_memory") || {};
1616
+ let roomMemory = roomMemories[id] || {};
1617
+ roomMemory = __spreadValues(__spreadValues({}, activity.export()), roomMemory);
1618
+ return new ActivityRoom(id, this, activity._initialOnRun, roomMemory);
1619
+ }
1620
+ /**
1621
+ * Set the memory of an activity. This function can be used into olther libraries to set the memory of the activity.
1622
+ * @param id The id of the activity.
1623
+ * @param memory The memory of the activity.
1624
+ */
1625
+ setActivity(activity) {
1626
+ let roomMemories = this.getStorageProperty("activities_memory") || {};
1627
+ roomMemories[activity.id] = activity.export();
1628
+ this.setStorageProperty("activities_memory", roomMemories);
1629
+ }
1630
+ /**
1631
+ * Add an activity to the room.
1632
+ * @param activity The activity to add.
1633
+ */
1634
+ addActivity(activity) {
1635
+ if (this.activityIds.includes(activity.id)) {
1636
+ let currentActivity = this.getActivity(activity.id);
1637
+ if (currentActivity && currentActivity.isExpired()) {
1638
+ this.removeActivity(activity.id);
1639
+ return;
1640
+ } else {
1641
+ console.error(`[NQTR] Activity with id ${activity.id} already exists in room ${this.id}, so it will be ignored.`);
1642
+ return;
1643
+ }
1644
+ }
1645
+ let addedActivityIds = this.getStorageProperty(`addedActivityIds`) || [];
1646
+ addedActivityIds.push(activity.id);
1647
+ this.setStorageProperty("addedActivityIds", addedActivityIds);
1648
+ }
1649
+ /**
1650
+ * Remove an activity from the room.
1651
+ * @param activity The activity to remove.
1652
+ */
1653
+ removeActivity(activity) {
1654
+ let activityId = typeof activity === "string" ? activity : activity.id;
1655
+ if (this.defaultActivityIds.includes(activityId)) {
1656
+ console.warn(`[NQTR] Activity with id ${activityId} is a default activity, so it can't be removed. It will be hidden instead.`);
1657
+ let activityToEdit = this.getActivity(activityId);
1658
+ if (!activityToEdit) {
1659
+ console.error(`[NQTR] Activity with id ${activityId} not found, so it can't be hidden.`);
1660
+ return;
1661
+ }
1662
+ activityToEdit.hidden = true;
1663
+ return;
1664
+ }
1665
+ let addedActivityIds = this.getStorageProperty(`addedActivityIds`) || [];
1666
+ let index = addedActivityIds.indexOf(activityId);
1667
+ if (index === -1) {
1668
+ console.error(`[NQTR] Activity with id ${activityId} not found, so it can't be removed.`);
1669
+ return;
1670
+ }
1671
+ addedActivityIds.splice(index, 1);
1672
+ this.setStorageProperty("addedActivityIds", addedActivityIds);
1673
+ let roomMemories = this.getStorageProperty("activities_memory") || {};
1674
+ delete roomMemories[activityId];
1675
+ this.setStorageProperty("activities_memory", roomMemories);
1676
+ }
1677
+ /**
1678
+ * Clear all expired activities.
1679
+ */
1680
+ clearExpiredActivities() {
1681
+ this.activities.forEach((activity) => {
1682
+ if (activity.isExpired()) {
1683
+ this.removeActivity(activity.id);
1684
+ }
1685
+ });
1686
+ }
1687
+ /**
1688
+ * Whether is disabled. If it is a string, it is a Pixi'VN flag name.
1689
+ */
1690
+ get disabled() {
1691
+ let value = this.getStorageProperty("disabled") || this.defaultDisabled;
1692
+ if (typeof value === "string") {
1693
+ return getFlag(value);
1694
+ }
1695
+ return value;
1696
+ }
1697
+ set disabled(value) {
1698
+ this.setStorageProperty("disabled", value);
1699
+ }
1700
+ /**
1701
+ * Whether is hidden. If it is a string, it is a Pixi'VN flag name.
1702
+ */
1703
+ get hidden() {
1704
+ let value = this.getStorageProperty("hidden") || this.defaultHidden;
1705
+ if (typeof value === "string") {
1706
+ return getFlag(value);
1707
+ }
1708
+ return value;
1709
+ }
1710
+ set hidden(value) {
1711
+ this.setStorageProperty("hidden", value);
1712
+ }
1713
+ /**
1714
+ * The function for rendering the icon of the room.
1715
+ */
1716
+ get renderIcon() {
1717
+ let render = this._renderIcon;
1718
+ if (render === void 0) {
1719
+ return void 0;
1720
+ }
1721
+ if (typeof render === "function") {
1722
+ return (props) => {
1723
+ return render(this, props);
1724
+ };
1725
+ }
1726
+ return (props) => render;
1727
+ }
1728
+ /**
1729
+ * Get the character commitments of the room.
1730
+ * @returns The character commitments of the room.
1731
+ */
1732
+ getRoutine() {
1733
+ let commitments = getCurrentRoutine();
1734
+ return commitments.filter((c) => c.room.id === this.id);
1735
+ }
1736
+ };
1723
1737
  var CURRENT_ROOM_MEMORY_KEY = "___nqtr-current_room_memory___";
1724
1738
  function setCurrentRoom(room) {
1725
1739
  if (room instanceof LocationBaseModel) {
@@ -1780,6 +1794,6 @@ function currentActivities() {
1780
1794
  return currentRoom.activities.filter((activity) => !activity.hidden);
1781
1795
  }
1782
1796
 
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 };
1797
+ export { ActivityModel, ActivityRoom, CommitmentBaseModel, Goal, LocationBaseModel, MapBaseModel, RoomBaseModel, Stage, TimeManager, addCommitment, clearExpiredActivities, clearExpiredRoutine, currentActivities, getActivityById, getAllLocations, getAllMaps, getCommitmentByCharacter, getCommitmentById, getCueerntMap, getCurrenrLocation, getCurrentRoom, getCurrentRoutine, getQuestById, getRoomById, newQuest, removeCommitment, saveActivity, saveCommitment, saveRoom, setCurrentRoom, setFixedRoutine };
1784
1798
  //# sourceMappingURL=out.js.map
1785
1799
  //# sourceMappingURL=index.mjs.map