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