@drincs/nqtr 0.1.20 → 0.2.1
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.
- package/dist/{ActivityProps-_79x9-BX.d.ts → ActivityProps-BkHX8xkA.d.ts} +1 -1
- package/dist/{ActivityProps-BoJeWa2B.d.mts → ActivityProps-D45DQdcT.d.mts} +1 -1
- package/dist/{Commitment-Cc2kZEy0.d.ts → Commitment-BJTIpBQ5.d.ts} +4 -2
- package/dist/{Commitment-C3Nc2RJH.d.mts → Commitment-CtNWnNQX.d.mts} +4 -2
- package/dist/{Quest-BQ1pwvQ_.d.ts → StageProps-BFsiCaZT.d.ts} +160 -81
- package/dist/{Quest-DaNlPBHb.d.mts → StageProps-CkXejAbn.d.mts} +160 -81
- package/dist/classes/Activity.d.mts +2 -2
- package/dist/classes/Activity.d.ts +2 -2
- package/dist/classes/Activity.js +1 -1
- package/dist/classes/Activity.js.map +1 -1
- package/dist/classes/Activity.mjs +1 -1
- package/dist/classes/Activity.mjs.map +1 -1
- package/dist/classes/ActivityStoredAbstract.d.mts +1 -1
- package/dist/classes/ActivityStoredAbstract.d.ts +1 -1
- package/dist/classes/ActivityStoredAbstract.js +1 -1
- package/dist/classes/ActivityStoredAbstract.js.map +1 -1
- package/dist/classes/ActivityStoredAbstract.mjs +1 -1
- package/dist/classes/ActivityStoredAbstract.mjs.map +1 -1
- package/dist/classes/Commitment.d.mts +2 -2
- package/dist/classes/Commitment.d.ts +2 -2
- package/dist/classes/Commitment.js +2 -2
- package/dist/classes/Commitment.js.map +1 -1
- package/dist/classes/Commitment.mjs +2 -2
- package/dist/classes/Commitment.mjs.map +1 -1
- package/dist/classes/index.d.mts +3 -3
- package/dist/classes/index.d.ts +3 -3
- package/dist/classes/index.js +133 -318
- package/dist/classes/index.js.map +1 -1
- package/dist/classes/index.mjs +134 -318
- package/dist/classes/index.mjs.map +1 -1
- package/dist/classes/navigation/ActivityRoom.d.mts +2 -2
- package/dist/classes/navigation/ActivityRoom.d.ts +2 -2
- package/dist/classes/navigation/ActivityRoom.js +1 -1
- package/dist/classes/navigation/ActivityRoom.js.map +1 -1
- package/dist/classes/navigation/ActivityRoom.mjs +1 -1
- package/dist/classes/navigation/ActivityRoom.mjs.map +1 -1
- package/dist/classes/navigation/Location.d.mts +2 -2
- package/dist/classes/navigation/Location.d.ts +2 -2
- package/dist/classes/navigation/Map.d.mts +2 -2
- package/dist/classes/navigation/Map.d.ts +2 -2
- package/dist/classes/navigation/Room.d.mts +2 -2
- package/dist/classes/navigation/Room.d.ts +2 -2
- package/dist/classes/navigation/Room.js +34 -36
- package/dist/classes/navigation/Room.js.map +1 -1
- package/dist/classes/navigation/Room.mjs +34 -36
- package/dist/classes/navigation/Room.mjs.map +1 -1
- package/dist/classes/quest/Goal.d.mts +18 -0
- package/dist/classes/quest/Goal.d.ts +18 -0
- package/dist/classes/quest/Goal.js +18 -0
- package/dist/classes/quest/Goal.js.map +1 -1
- package/dist/classes/quest/Goal.mjs +18 -0
- package/dist/classes/quest/Goal.mjs.map +1 -1
- package/dist/classes/quest/Quest.d.mts +1 -1
- package/dist/classes/quest/Quest.d.ts +1 -1
- package/dist/classes/quest/Quest.js +107 -8
- package/dist/classes/quest/Quest.js.map +1 -1
- package/dist/classes/quest/Quest.mjs +107 -8
- package/dist/classes/quest/Quest.mjs.map +1 -1
- package/dist/classes/quest/Stage.d.mts +1 -1
- package/dist/classes/quest/Stage.d.ts +1 -1
- package/dist/classes/quest/Stage.js +62 -0
- package/dist/classes/quest/Stage.js.map +1 -1
- package/dist/classes/quest/Stage.mjs +62 -0
- package/dist/classes/quest/Stage.mjs.map +1 -1
- package/dist/decorators/ActivityDecorator.d.mts +1 -1
- package/dist/decorators/ActivityDecorator.d.ts +1 -1
- package/dist/decorators/CommitmentDecorator.d.mts +9 -3
- package/dist/decorators/CommitmentDecorator.d.ts +9 -3
- package/dist/decorators/CommitmentDecorator.js +16 -1
- package/dist/decorators/CommitmentDecorator.js.map +1 -1
- package/dist/decorators/CommitmentDecorator.mjs +16 -2
- package/dist/decorators/CommitmentDecorator.mjs.map +1 -1
- package/dist/decorators/QuestDecorator.d.mts +8 -10
- package/dist/decorators/QuestDecorator.d.ts +8 -10
- package/dist/decorators/QuestDecorator.js +667 -9
- package/dist/decorators/QuestDecorator.js.map +1 -1
- package/dist/decorators/QuestDecorator.mjs +667 -9
- package/dist/decorators/QuestDecorator.mjs.map +1 -1
- package/dist/decorators/RoomDecorator.d.mts +2 -2
- package/dist/decorators/RoomDecorator.d.ts +2 -2
- package/dist/decorators/index.d.mts +5 -5
- package/dist/decorators/index.d.ts +5 -5
- package/dist/decorators/index.js +679 -10
- package/dist/decorators/index.js.map +1 -1
- package/dist/decorators/index.mjs +679 -11
- package/dist/decorators/index.mjs.map +1 -1
- package/dist/functions/ActivityFunctions.d.mts +2 -2
- package/dist/functions/ActivityFunctions.d.ts +2 -2
- package/dist/functions/ActivityFunctions.js.map +1 -1
- package/dist/functions/ActivityFunctions.mjs.map +1 -1
- package/dist/functions/NavigationFunctions.d.mts +2 -2
- package/dist/functions/NavigationFunctions.d.ts +2 -2
- package/dist/functions/NavigationFunctions.js.map +1 -1
- package/dist/functions/NavigationFunctions.mjs.map +1 -1
- package/dist/functions/RoutineFunctions.d.mts +2 -2
- package/dist/functions/RoutineFunctions.d.ts +2 -2
- package/dist/functions/RoutineFunctions.js.map +1 -1
- package/dist/functions/RoutineFunctions.mjs.map +1 -1
- package/dist/functions/index.d.mts +2 -2
- package/dist/functions/index.d.ts +2 -2
- package/dist/functions/index.js.map +1 -1
- package/dist/functions/index.mjs.map +1 -1
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +505 -392
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +504 -391
- package/dist/index.mjs.map +1 -1
- package/dist/interface/ActivityProps.d.mts +1 -1
- package/dist/interface/ActivityProps.d.ts +1 -1
- package/dist/interface/CommitmentProps.d.mts +2 -2
- package/dist/interface/CommitmentProps.d.ts +2 -2
- package/dist/interface/RoomActivityMemory.d.mts +1 -1
- package/dist/interface/RoomActivityMemory.d.ts +1 -1
- package/dist/interface/RoomProps.d.mts +2 -2
- package/dist/interface/RoomProps.d.ts +2 -2
- package/dist/interface/index.d.mts +3 -3
- package/dist/interface/index.d.ts +3 -3
- package/dist/interface/navigation/LocationProps.d.mts +2 -2
- package/dist/interface/navigation/LocationProps.d.ts +2 -2
- package/dist/interface/navigation/MapProps.d.mts +2 -2
- package/dist/interface/navigation/MapProps.d.ts +2 -2
- package/dist/interface/quest/QuestProps.d.mts +1 -1
- package/dist/interface/quest/QuestProps.d.ts +1 -1
- package/dist/interface/quest/StageProps.d.mts +1 -1
- package/dist/interface/quest/StageProps.d.ts +1 -1
- package/dist/types/QuestsRequired.d.mts +1 -1
- package/dist/types/QuestsRequired.d.ts +1 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/types/index.d.ts +1 -1
- 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
|
|
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
|
|
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
|
|
692
|
+
get run() {
|
|
693
693
|
return (props) => {
|
|
694
694
|
return this._onRun(this, props);
|
|
695
695
|
};
|
|
@@ -1082,7 +1082,21 @@ function addCommitment(commitment) {
|
|
|
1082
1082
|
}
|
|
1083
1083
|
return commitment2.id;
|
|
1084
1084
|
}).filter((id) => id !== void 0);
|
|
1085
|
-
GameStorageManager.setVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY,
|
|
1085
|
+
GameStorageManager.setVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY, commitmentsIds);
|
|
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);
|
|
1086
1100
|
}
|
|
1087
1101
|
function getFixedRoutine() {
|
|
1088
1102
|
return Object.values(fixedCommitments);
|
|
@@ -1095,126 +1109,119 @@ function getTemporaryCommitments() {
|
|
|
1095
1109
|
let commitments = commitmentsIds.map((id) => getCommitmentById(id)).filter((commitment) => commitment !== void 0);
|
|
1096
1110
|
return commitments;
|
|
1097
1111
|
}
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
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
|
-
|
|
1107
|
-
|
|
1120
|
+
/**
|
|
1121
|
+
* The description of the goal.
|
|
1122
|
+
*/
|
|
1123
|
+
get description() {
|
|
1124
|
+
return this._description;
|
|
1108
1125
|
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1126
|
+
/**
|
|
1127
|
+
* The number of times the goal must be completed.
|
|
1128
|
+
*/
|
|
1129
|
+
get need() {
|
|
1130
|
+
return this._need;
|
|
1131
|
+
}
|
|
1132
|
+
/**
|
|
1133
|
+
* The default number of times the goal has been completed.
|
|
1134
|
+
*/
|
|
1135
|
+
get defaultHave() {
|
|
1136
|
+
return this._defaultHave;
|
|
1137
|
+
}
|
|
1138
|
+
};
|
|
1139
|
+
var GoalStage = class extends Goal {
|
|
1140
|
+
constructor(id, stageId, props) {
|
|
1141
|
+
super(id, props);
|
|
1142
|
+
this._stageId = stageId;
|
|
1143
|
+
}
|
|
1144
|
+
/**
|
|
1145
|
+
* The id of the stage that the goal belongs to.
|
|
1146
|
+
*/
|
|
1147
|
+
get stageId() {
|
|
1148
|
+
return this._stageId;
|
|
1149
|
+
}
|
|
1150
|
+
set stageId(value) {
|
|
1151
|
+
this._stageId = value;
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* The number of times the goal has been completed.
|
|
1155
|
+
*/
|
|
1156
|
+
get have() {
|
|
1157
|
+
return this.getStorageProperty("have-" + this._stageId) || this.defaultHave;
|
|
1158
|
+
}
|
|
1159
|
+
set have(value) {
|
|
1160
|
+
if (!this._stageId) {
|
|
1161
|
+
console.error(`[NQTR] The stage id is not set for the goal ${this.id}, so the have value can't be set.`);
|
|
1116
1162
|
return;
|
|
1117
1163
|
}
|
|
1118
|
-
|
|
1119
|
-
} catch (e) {
|
|
1120
|
-
console.error(`[NQTR] Error while getting Quest ${id}`, e);
|
|
1121
|
-
return;
|
|
1164
|
+
this.setStorageProperty("have-" + this._stageId, value);
|
|
1122
1165
|
}
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
}
|
|
1133
|
-
|
|
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;
|
|
1166
|
+
/**
|
|
1167
|
+
* If the goal is completed.
|
|
1168
|
+
*/
|
|
1169
|
+
get completed() {
|
|
1170
|
+
return this.have >= this.need;
|
|
1171
|
+
}
|
|
1172
|
+
set completed(value) {
|
|
1173
|
+
if (value) {
|
|
1174
|
+
this.have = this.need;
|
|
1175
|
+
} else {
|
|
1176
|
+
console.warn(`[NQTR] The goal can't be set as not completed. You must edit the have value manually.`);
|
|
1169
1177
|
}
|
|
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 {
|
|
1178
|
+
}
|
|
1177
1179
|
/**
|
|
1178
|
-
*
|
|
1179
|
-
* @param location The location where the room is.
|
|
1180
|
-
* @param props The properties of the room.
|
|
1180
|
+
* Find the goal. It will increment the have value.
|
|
1181
1181
|
*/
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1182
|
+
find() {
|
|
1183
|
+
this.have++;
|
|
1184
|
+
}
|
|
1185
|
+
};
|
|
1186
|
+
|
|
1187
|
+
// src/classes/quest/Stage.ts
|
|
1188
|
+
var STAGE_CATEGORY = "__nqtr-stage__";
|
|
1189
|
+
var Stage = class extends StoredClassModel {
|
|
1190
|
+
constructor(id, props) {
|
|
1191
|
+
super(STAGE_CATEGORY, id);
|
|
1192
|
+
this._name = props.name || "";
|
|
1193
|
+
this._defaultGoals = props.goals || [];
|
|
1194
|
+
this._flags = props.flags || [];
|
|
1195
|
+
this._description = props.description || "";
|
|
1196
|
+
this._adviceDescription = props.adviceDescription || "";
|
|
1187
1197
|
this._renderImage = props.renderImage;
|
|
1188
|
-
this.
|
|
1189
|
-
this.
|
|
1190
|
-
this.
|
|
1191
|
-
this.
|
|
1192
|
-
this.
|
|
1198
|
+
this._daysRequiredToStart = props.daysRequiredToStart;
|
|
1199
|
+
this._flagsRequiredToStart = props.flagsRequired || [];
|
|
1200
|
+
this._questsRequiredToStart = props.questsRequired || [];
|
|
1201
|
+
this._requestDescriptionToStart = props.requestDescription || "";
|
|
1202
|
+
this._onStart = props.onStart;
|
|
1203
|
+
this._onEnd = props.onEnd;
|
|
1193
1204
|
}
|
|
1194
1205
|
/**
|
|
1195
|
-
* The
|
|
1206
|
+
* The name of the stage.
|
|
1196
1207
|
*/
|
|
1197
|
-
get
|
|
1198
|
-
return this.
|
|
1208
|
+
get name() {
|
|
1209
|
+
return this._name;
|
|
1199
1210
|
}
|
|
1200
1211
|
/**
|
|
1201
|
-
*
|
|
1212
|
+
* The description of the stage.
|
|
1202
1213
|
*/
|
|
1203
|
-
get
|
|
1204
|
-
return this.
|
|
1214
|
+
get description() {
|
|
1215
|
+
return this._description;
|
|
1205
1216
|
}
|
|
1206
1217
|
/**
|
|
1207
|
-
* The
|
|
1208
|
-
* If you set undefined, it will return the initial value of name.
|
|
1218
|
+
* The advice description of the stage.
|
|
1209
1219
|
*/
|
|
1210
|
-
get
|
|
1211
|
-
return this.
|
|
1212
|
-
}
|
|
1213
|
-
set name(value) {
|
|
1214
|
-
this.setStorageProperty("name", value);
|
|
1220
|
+
get adviceDescription() {
|
|
1221
|
+
return this._adviceDescription;
|
|
1215
1222
|
}
|
|
1216
1223
|
/**
|
|
1217
|
-
* The function for rendering the image of the
|
|
1224
|
+
* The function for rendering the image of the stage.
|
|
1218
1225
|
*/
|
|
1219
1226
|
get renderImage() {
|
|
1220
1227
|
let render = this._renderImage;
|
|
@@ -1229,305 +1236,51 @@ var RoomBaseModel = class extends StoredClassModel {
|
|
|
1229
1236
|
return (props) => render;
|
|
1230
1237
|
}
|
|
1231
1238
|
/**
|
|
1232
|
-
* The
|
|
1239
|
+
* The list of goals that the player needs to complete to finish the stage.
|
|
1240
|
+
* This is the list set by the developer. if you want to get the current goals, use the goals property.
|
|
1233
1241
|
*/
|
|
1234
|
-
get
|
|
1235
|
-
|
|
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;
|
|
1249
|
-
}
|
|
1250
|
-
get activityIds() {
|
|
1251
|
-
let addedActivityIds = this.getStorageProperty(`addedActivityIds`) || [];
|
|
1252
|
-
return this.defaultActivityIds.concat(addedActivityIds);
|
|
1242
|
+
get defaultGoals() {
|
|
1243
|
+
return this._defaultGoals;
|
|
1253
1244
|
}
|
|
1254
1245
|
/**
|
|
1255
|
-
* The
|
|
1246
|
+
* The list of flags that the player must complete to finish the stage.
|
|
1256
1247
|
*/
|
|
1257
|
-
get
|
|
1258
|
-
|
|
1259
|
-
return this.getActivity(id);
|
|
1260
|
-
}).filter((activity) => activity !== void 0 && !activity.hidden);
|
|
1261
|
-
return activities;
|
|
1248
|
+
get flags() {
|
|
1249
|
+
return this._flags;
|
|
1262
1250
|
}
|
|
1263
1251
|
/**
|
|
1264
|
-
*
|
|
1265
|
-
* @param id The id of the activity.
|
|
1266
|
-
* @returns The memory of the activity.
|
|
1252
|
+
* The number of days required to start the stage.
|
|
1267
1253
|
*/
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
let roomMemory = roomMemories[id] || {};
|
|
1271
|
-
return roomMemory;
|
|
1254
|
+
get daysRequiredToStart() {
|
|
1255
|
+
return this._daysRequiredToStart || 0;
|
|
1272
1256
|
}
|
|
1273
1257
|
/**
|
|
1274
|
-
*
|
|
1275
|
-
* @param id The id of the activity.
|
|
1276
|
-
* @returns The room activity.
|
|
1258
|
+
* The list of flags required to start the stage.
|
|
1277
1259
|
*/
|
|
1278
|
-
|
|
1279
|
-
|
|
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);
|
|
1260
|
+
get flagsRequiredToStart() {
|
|
1261
|
+
return this._flagsRequiredToStart;
|
|
1292
1262
|
}
|
|
1293
1263
|
/**
|
|
1294
|
-
*
|
|
1295
|
-
* @param id The id of the activity.
|
|
1296
|
-
* @param memory The memory of the activity.
|
|
1264
|
+
* The list of quests required to start the stage.
|
|
1297
1265
|
*/
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
roomMemories[activity.id] = activity.export();
|
|
1301
|
-
this.setStorageProperty("activities_memory", roomMemories);
|
|
1266
|
+
get questsRequiredToStart() {
|
|
1267
|
+
return this._questsRequiredToStart || [];
|
|
1302
1268
|
}
|
|
1303
1269
|
/**
|
|
1304
|
-
*
|
|
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.
|
|
1270
|
+
* The description of the request to start the stage.
|
|
1512
1271
|
*/
|
|
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
1272
|
get requestDescriptionToStart() {
|
|
1526
1273
|
return this._requestDescriptionToStart;
|
|
1527
1274
|
}
|
|
1275
|
+
/**
|
|
1276
|
+
* The function that will be called when the stage starts.
|
|
1277
|
+
*/
|
|
1528
1278
|
get onStart() {
|
|
1529
1279
|
return this._onStart;
|
|
1530
1280
|
}
|
|
1281
|
+
/**
|
|
1282
|
+
* The function that will be called when the stage ends.
|
|
1283
|
+
*/
|
|
1531
1284
|
get onEnd() {
|
|
1532
1285
|
return this._onEnd;
|
|
1533
1286
|
}
|
|
@@ -1536,6 +1289,10 @@ var StageQuest = class extends Stage {
|
|
|
1536
1289
|
constructor(id, props) {
|
|
1537
1290
|
super(id, props);
|
|
1538
1291
|
}
|
|
1292
|
+
/**
|
|
1293
|
+
* Check if the flag and goals are completed.
|
|
1294
|
+
* You can force the completion of the stage by setting the completed property to true.
|
|
1295
|
+
*/
|
|
1539
1296
|
get completed() {
|
|
1540
1297
|
let storedCompleted = this.getStorageProperty("completed");
|
|
1541
1298
|
if (storedCompleted) {
|
|
@@ -1566,6 +1323,9 @@ var StageQuest = class extends Stage {
|
|
|
1566
1323
|
set prevStageEndDay(value) {
|
|
1567
1324
|
this.setStorageProperty("prevStageEndDay", value);
|
|
1568
1325
|
}
|
|
1326
|
+
/**
|
|
1327
|
+
* The day when the stage starts.
|
|
1328
|
+
*/
|
|
1569
1329
|
get startDay() {
|
|
1570
1330
|
let prevStageEndDay = this.prevStageEndDay;
|
|
1571
1331
|
if (prevStageEndDay === void 0) {
|
|
@@ -1573,6 +1333,9 @@ var StageQuest = class extends Stage {
|
|
|
1573
1333
|
}
|
|
1574
1334
|
return prevStageEndDay + this.daysRequiredToStart;
|
|
1575
1335
|
}
|
|
1336
|
+
/**
|
|
1337
|
+
* Check if the stage can start.
|
|
1338
|
+
*/
|
|
1576
1339
|
get canStart() {
|
|
1577
1340
|
let daysRequired = this.daysRequiredToStart;
|
|
1578
1341
|
if (daysRequired > 0) {
|
|
@@ -1594,6 +1357,9 @@ var StageQuest = class extends Stage {
|
|
|
1594
1357
|
}
|
|
1595
1358
|
return true;
|
|
1596
1359
|
}
|
|
1360
|
+
/**
|
|
1361
|
+
* The function that will be called when the stage starts.
|
|
1362
|
+
*/
|
|
1597
1363
|
get onStart() {
|
|
1598
1364
|
if (this.daysRequiredToStart > 0) {
|
|
1599
1365
|
this.prevStageEndDay = TimeManager.currentDay;
|
|
@@ -1614,14 +1380,23 @@ var Quest = class extends StoredClassModel {
|
|
|
1614
1380
|
this._renderImage = props.renderImage;
|
|
1615
1381
|
this._isInDevelopment = props.isInDevelopment || false;
|
|
1616
1382
|
}
|
|
1383
|
+
/**
|
|
1384
|
+
* The stages of the quest.
|
|
1385
|
+
*/
|
|
1617
1386
|
get stages() {
|
|
1618
1387
|
return this._stages.map((stage, index) => {
|
|
1619
1388
|
return new StageQuest(stage.id, stage);
|
|
1620
1389
|
});
|
|
1621
1390
|
}
|
|
1391
|
+
/**
|
|
1392
|
+
* The name of the quest.
|
|
1393
|
+
*/
|
|
1622
1394
|
get name() {
|
|
1623
1395
|
return this._name;
|
|
1624
1396
|
}
|
|
1397
|
+
/**
|
|
1398
|
+
* The description of the quest.
|
|
1399
|
+
*/
|
|
1625
1400
|
get description() {
|
|
1626
1401
|
return this._description;
|
|
1627
1402
|
}
|
|
@@ -1655,15 +1430,24 @@ var Quest = class extends StoredClassModel {
|
|
|
1655
1430
|
}
|
|
1656
1431
|
return (props) => render;
|
|
1657
1432
|
}
|
|
1433
|
+
/**
|
|
1434
|
+
* If the quest is in development.
|
|
1435
|
+
*/
|
|
1658
1436
|
get isInDevelopment() {
|
|
1659
1437
|
return this._isInDevelopment;
|
|
1660
1438
|
}
|
|
1439
|
+
/**
|
|
1440
|
+
* The index of the current stage.
|
|
1441
|
+
*/
|
|
1661
1442
|
get currentStageIndex() {
|
|
1662
1443
|
return this.getStorageProperty("currentStageIndex");
|
|
1663
1444
|
}
|
|
1664
1445
|
set currentStageIndex(value) {
|
|
1665
1446
|
this.setStorageProperty("currentStageIndex", value);
|
|
1666
1447
|
}
|
|
1448
|
+
/**
|
|
1449
|
+
* The current stage.
|
|
1450
|
+
*/
|
|
1667
1451
|
get currentStage() {
|
|
1668
1452
|
let index = this.currentStageIndex;
|
|
1669
1453
|
if (index === void 0 || index >= this.stages.length) {
|
|
@@ -1671,13 +1455,24 @@ var Quest = class extends StoredClassModel {
|
|
|
1671
1455
|
}
|
|
1672
1456
|
return this.stages[index];
|
|
1673
1457
|
}
|
|
1458
|
+
/**
|
|
1459
|
+
* If the quest is started.
|
|
1460
|
+
*/
|
|
1674
1461
|
get started() {
|
|
1675
1462
|
return this.currentStageIndex !== void 0;
|
|
1676
1463
|
}
|
|
1464
|
+
/**
|
|
1465
|
+
* If the quest is completed.
|
|
1466
|
+
*/
|
|
1677
1467
|
get completed() {
|
|
1678
1468
|
return this.currentStageIndex === this.stages.length;
|
|
1679
1469
|
}
|
|
1680
|
-
|
|
1470
|
+
/**
|
|
1471
|
+
* Start the quest.
|
|
1472
|
+
* @param props The properties for the start stage. If you not want to pass any property, you can pass an {}.
|
|
1473
|
+
* @returns
|
|
1474
|
+
*/
|
|
1475
|
+
start(props) {
|
|
1681
1476
|
if (this.started) {
|
|
1682
1477
|
console.warn(`[NQTR] Quest ${this.id} is already started`);
|
|
1683
1478
|
return;
|
|
@@ -1689,35 +1484,353 @@ var Quest = class extends StoredClassModel {
|
|
|
1689
1484
|
this.currentStageIndex = 0;
|
|
1690
1485
|
let currentStage = this.currentStage;
|
|
1691
1486
|
if (currentStage && currentStage.onStart) {
|
|
1692
|
-
return currentStage.onStart();
|
|
1487
|
+
return currentStage.onStart(props);
|
|
1693
1488
|
} else {
|
|
1694
1489
|
console.error(`[NQTR] Quest ${this.id} has no start stage`);
|
|
1695
1490
|
}
|
|
1696
1491
|
}
|
|
1697
|
-
|
|
1492
|
+
/**
|
|
1493
|
+
* Try to go to the next stage.
|
|
1494
|
+
* @param startProps The properties for the start stage. If you not want to pass any property, you can pass an {}.
|
|
1495
|
+
* @param endProps The properties for the end stage. If you not want to pass any property, you can pass an {}.
|
|
1496
|
+
* @returns true if the stage was changed, false otherwise.
|
|
1497
|
+
*/
|
|
1498
|
+
tryToGoNextStage(startProps, endProps) {
|
|
1698
1499
|
if (!this.started) {
|
|
1699
|
-
return;
|
|
1500
|
+
return false;
|
|
1700
1501
|
}
|
|
1701
1502
|
if (this.completed) {
|
|
1702
|
-
return;
|
|
1503
|
+
return false;
|
|
1703
1504
|
}
|
|
1704
1505
|
let currentStage = this.currentStage;
|
|
1705
1506
|
let currentStageIndex = this.currentStageIndex;
|
|
1706
1507
|
if (!currentStage || currentStageIndex === void 0) {
|
|
1707
1508
|
console.error(`[NQTR] Quest ${this.id} has no current stage`);
|
|
1708
|
-
return;
|
|
1509
|
+
return false;
|
|
1709
1510
|
}
|
|
1710
1511
|
if (currentStage.completed) {
|
|
1711
1512
|
let nextStageIndex = currentStageIndex + 1;
|
|
1712
1513
|
currentStageIndex = nextStageIndex;
|
|
1713
1514
|
let nextStage = this.currentStage;
|
|
1714
1515
|
if (currentStage && currentStage.onEnd) {
|
|
1715
|
-
currentStage.onEnd();
|
|
1516
|
+
currentStage.onEnd(endProps);
|
|
1716
1517
|
}
|
|
1717
1518
|
if (nextStage && nextStage.onStart) {
|
|
1718
|
-
|
|
1519
|
+
nextStage.onStart(startProps);
|
|
1719
1520
|
}
|
|
1521
|
+
return true;
|
|
1522
|
+
}
|
|
1523
|
+
return false;
|
|
1524
|
+
}
|
|
1525
|
+
};
|
|
1526
|
+
|
|
1527
|
+
// src/decorators/QuestDecorator.ts
|
|
1528
|
+
var registeredQuests = {};
|
|
1529
|
+
function newQuest(id, stages, props) {
|
|
1530
|
+
if (registeredQuests[id]) {
|
|
1531
|
+
console.warn(`[NQTR] Quest ${id} already exists, it will be overwritten`);
|
|
1532
|
+
}
|
|
1533
|
+
let quest = new Quest(id, stages, props);
|
|
1534
|
+
registeredQuests[id] = quest;
|
|
1535
|
+
return quest;
|
|
1536
|
+
}
|
|
1537
|
+
function getQuestById(id) {
|
|
1538
|
+
try {
|
|
1539
|
+
let quest = registeredQuests[id];
|
|
1540
|
+
if (!quest) {
|
|
1541
|
+
console.error(`[NQTR] Quest ${id} not found`);
|
|
1542
|
+
return;
|
|
1543
|
+
}
|
|
1544
|
+
return quest;
|
|
1545
|
+
} catch (e) {
|
|
1546
|
+
console.error(`[NQTR] Error while getting Quest ${id}`, e);
|
|
1547
|
+
return;
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
// src/functions/RoutineFunctions.ts
|
|
1552
|
+
function clearExpiredRoutine() {
|
|
1553
|
+
Object.entries(registeredCommitments).forEach(([_, commitment]) => {
|
|
1554
|
+
if (commitment.isExpired()) {
|
|
1555
|
+
delete registeredCommitments[commitment.id];
|
|
1556
|
+
}
|
|
1557
|
+
});
|
|
1558
|
+
}
|
|
1559
|
+
function getCurrentRoutine() {
|
|
1560
|
+
let character_commitments = {};
|
|
1561
|
+
getTemporaryCommitments().reverse().forEach((c) => {
|
|
1562
|
+
if (!c.hidden) {
|
|
1563
|
+
if (c.characters.length > 0) {
|
|
1564
|
+
let allAvailable = c.characters.every((ch) => !character_commitments[ch.id] || c.priority > character_commitments[ch.id].priority);
|
|
1565
|
+
if (allAvailable) {
|
|
1566
|
+
c.characters.forEach((ch) => {
|
|
1567
|
+
character_commitments[ch.id] = c;
|
|
1568
|
+
});
|
|
1569
|
+
}
|
|
1570
|
+
} else {
|
|
1571
|
+
console.error(`[NQTR] The commitment ${c.id} has no characters assigned`);
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
});
|
|
1575
|
+
getFixedRoutine().reverse().forEach((c) => {
|
|
1576
|
+
if (!c.hidden) {
|
|
1577
|
+
if (c.characters.length > 0) {
|
|
1578
|
+
let allAvailable = c.characters.every((ch) => !character_commitments[ch.id] || c.priority > character_commitments[ch.id].priority);
|
|
1579
|
+
if (allAvailable) {
|
|
1580
|
+
c.characters.forEach((ch) => {
|
|
1581
|
+
character_commitments[ch.id] = c;
|
|
1582
|
+
});
|
|
1583
|
+
}
|
|
1584
|
+
} else {
|
|
1585
|
+
console.error(`[NQTR] The commitment ${c.id} has no characters assigned`);
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
});
|
|
1589
|
+
return Object.values(character_commitments);
|
|
1590
|
+
}
|
|
1591
|
+
function getCommitmentByCharacter(character) {
|
|
1592
|
+
getCurrentRoutine().forEach((c) => {
|
|
1593
|
+
if (c.characters.map((ch) => ch.id).includes(character.id)) {
|
|
1594
|
+
return c;
|
|
1595
|
+
}
|
|
1596
|
+
});
|
|
1597
|
+
return void 0;
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
// src/classes/navigation/Room.ts
|
|
1601
|
+
var ROOM_CATEGORY = "__nqtr-room__";
|
|
1602
|
+
var RoomBaseModel = class extends StoredClassModel {
|
|
1603
|
+
/**
|
|
1604
|
+
* @param id The id of the room, it must be unique.
|
|
1605
|
+
* @param location The location where the room is.
|
|
1606
|
+
* @param props The properties of the room.
|
|
1607
|
+
*/
|
|
1608
|
+
constructor(id, location, props = {}) {
|
|
1609
|
+
var _a;
|
|
1610
|
+
super(ROOM_CATEGORY, id);
|
|
1611
|
+
this._location = location;
|
|
1612
|
+
this.defaultName = props.name || "";
|
|
1613
|
+
this._renderImage = props.renderImage;
|
|
1614
|
+
this.defaultActivityIds = ((_a = props.defaultActivities) == null ? void 0 : _a.map((activity) => activity.id)) || [];
|
|
1615
|
+
this.defaultDisabled = props.disabled || false;
|
|
1616
|
+
this.defaultHidden = props.hidden || false;
|
|
1617
|
+
this._renderIcon = props.renderIcon;
|
|
1618
|
+
this._isEntrance = props.isEntrance;
|
|
1619
|
+
}
|
|
1620
|
+
/**
|
|
1621
|
+
* The location where the room is.
|
|
1622
|
+
*/
|
|
1623
|
+
get location() {
|
|
1624
|
+
return this._location;
|
|
1625
|
+
}
|
|
1626
|
+
/**
|
|
1627
|
+
* Whether is an entrance room, so when the player enters in the location, it will be the first room to be shown.
|
|
1628
|
+
*/
|
|
1629
|
+
get isEntrance() {
|
|
1630
|
+
return this._isEntrance || false;
|
|
1631
|
+
}
|
|
1632
|
+
/**
|
|
1633
|
+
* The name.
|
|
1634
|
+
* If you set undefined, it will return the initial value of name.
|
|
1635
|
+
*/
|
|
1636
|
+
get name() {
|
|
1637
|
+
return this.getStorageProperty("name") || this.defaultName;
|
|
1638
|
+
}
|
|
1639
|
+
set name(value) {
|
|
1640
|
+
this.setStorageProperty("name", value);
|
|
1641
|
+
}
|
|
1642
|
+
/**
|
|
1643
|
+
* The function for rendering the image of the room.
|
|
1644
|
+
*/
|
|
1645
|
+
get renderImage() {
|
|
1646
|
+
let render = this._renderImage;
|
|
1647
|
+
if (render === void 0) {
|
|
1648
|
+
return void 0;
|
|
1720
1649
|
}
|
|
1650
|
+
if (typeof render === "function") {
|
|
1651
|
+
return (props) => {
|
|
1652
|
+
return render(this, props);
|
|
1653
|
+
};
|
|
1654
|
+
}
|
|
1655
|
+
return (props) => render;
|
|
1656
|
+
}
|
|
1657
|
+
/**
|
|
1658
|
+
* The activities that are available in this room.
|
|
1659
|
+
*/
|
|
1660
|
+
get defaultActivities() {
|
|
1661
|
+
let roomMemories = this.getStorageProperty("activities_memory") || {};
|
|
1662
|
+
let activities = this.defaultActivityIds.map((id) => {
|
|
1663
|
+
let activity = getActivityById(id);
|
|
1664
|
+
if (!activity) {
|
|
1665
|
+
console.warn(`[NQTR] Activity with id ${id} not found, so it will be ignored.`);
|
|
1666
|
+
return void 0;
|
|
1667
|
+
}
|
|
1668
|
+
let memory = activity.export();
|
|
1669
|
+
if (roomMemories && roomMemories[id]) {
|
|
1670
|
+
memory = __spreadValues(__spreadValues({}, memory), roomMemories[id]);
|
|
1671
|
+
}
|
|
1672
|
+
return new ActivityRoom(id, this, activity._initialOnRun, memory);
|
|
1673
|
+
}).filter((activity) => activity !== void 0);
|
|
1674
|
+
return activities;
|
|
1675
|
+
}
|
|
1676
|
+
get activityIds() {
|
|
1677
|
+
let addedActivityIds = this.getStorageProperty(`addedActivityIds`) || [];
|
|
1678
|
+
return this.defaultActivityIds.concat(addedActivityIds);
|
|
1679
|
+
}
|
|
1680
|
+
/**
|
|
1681
|
+
* The activities that are available in this room.
|
|
1682
|
+
*/
|
|
1683
|
+
get activities() {
|
|
1684
|
+
let activities = this.activityIds.map((id) => {
|
|
1685
|
+
return this.getActivity(id);
|
|
1686
|
+
}).filter((activity) => activity !== void 0 && !activity.hidden);
|
|
1687
|
+
return activities;
|
|
1688
|
+
}
|
|
1689
|
+
/**
|
|
1690
|
+
* Get the memory of an activity. This function can be used into olther libraries to get the memory of the activity.
|
|
1691
|
+
* @param id The id of the activity.
|
|
1692
|
+
* @returns The memory of the activity.
|
|
1693
|
+
*/
|
|
1694
|
+
getActivityMemory(id) {
|
|
1695
|
+
let roomMemories = this.getStorageProperty("activities_memory") || {};
|
|
1696
|
+
let roomMemory = roomMemories[id] || {};
|
|
1697
|
+
return roomMemory;
|
|
1698
|
+
}
|
|
1699
|
+
/**
|
|
1700
|
+
* Get the activity by id.
|
|
1701
|
+
* @param id The id of the activity.
|
|
1702
|
+
* @returns The room activity.
|
|
1703
|
+
*/
|
|
1704
|
+
getActivity(id) {
|
|
1705
|
+
if (!this.activityIds.includes(id)) {
|
|
1706
|
+
console.error(`[NQTR] Activity with id ${id} not found in room ${this.id}`);
|
|
1707
|
+
return void 0;
|
|
1708
|
+
}
|
|
1709
|
+
let activity = getActivityById(id);
|
|
1710
|
+
if (!activity) {
|
|
1711
|
+
console.error(`[NQTR] Activity with id ${id} not found`);
|
|
1712
|
+
return void 0;
|
|
1713
|
+
}
|
|
1714
|
+
let roomMemories = this.getStorageProperty("activities_memory") || {};
|
|
1715
|
+
let roomMemory = roomMemories[id] || {};
|
|
1716
|
+
roomMemory = __spreadValues(__spreadValues({}, activity.export()), roomMemory);
|
|
1717
|
+
return new ActivityRoom(id, this, activity._initialOnRun, roomMemory);
|
|
1718
|
+
}
|
|
1719
|
+
/**
|
|
1720
|
+
* Set the memory of an activity. This function can be used into olther libraries to set the memory of the activity.
|
|
1721
|
+
* @param id The id of the activity.
|
|
1722
|
+
* @param memory The memory of the activity.
|
|
1723
|
+
*/
|
|
1724
|
+
setActivity(activity) {
|
|
1725
|
+
let roomMemories = this.getStorageProperty("activities_memory") || {};
|
|
1726
|
+
roomMemories[activity.id] = activity.export();
|
|
1727
|
+
this.setStorageProperty("activities_memory", roomMemories);
|
|
1728
|
+
}
|
|
1729
|
+
/**
|
|
1730
|
+
* Add an activity to the room.
|
|
1731
|
+
* @param activity The activity to add.
|
|
1732
|
+
*/
|
|
1733
|
+
addActivity(activity) {
|
|
1734
|
+
if (this.activityIds.includes(activity.id)) {
|
|
1735
|
+
let currentActivity = this.getActivity(activity.id);
|
|
1736
|
+
if (currentActivity && currentActivity.isExpired()) {
|
|
1737
|
+
this.removeActivity(activity.id);
|
|
1738
|
+
return;
|
|
1739
|
+
} else {
|
|
1740
|
+
console.error(`[NQTR] Activity with id ${activity.id} already exists in room ${this.id}, so it will be ignored.`);
|
|
1741
|
+
return;
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
let addedActivityIds = this.getStorageProperty(`addedActivityIds`) || [];
|
|
1745
|
+
addedActivityIds.push(activity.id);
|
|
1746
|
+
this.setStorageProperty("addedActivityIds", addedActivityIds);
|
|
1747
|
+
}
|
|
1748
|
+
/**
|
|
1749
|
+
* Remove an activity from the room.
|
|
1750
|
+
* @param activity The activity to remove.
|
|
1751
|
+
*/
|
|
1752
|
+
removeActivity(activity) {
|
|
1753
|
+
let activityId = typeof activity === "string" ? activity : activity.id;
|
|
1754
|
+
if (this.defaultActivityIds.includes(activityId)) {
|
|
1755
|
+
console.warn(`[NQTR] Activity with id ${activityId} is a default activity, so it can't be removed. It will be hidden instead.`);
|
|
1756
|
+
let activityToEdit = this.getActivity(activityId);
|
|
1757
|
+
if (!activityToEdit) {
|
|
1758
|
+
console.error(`[NQTR] Activity with id ${activityId} not found, so it can't be hidden.`);
|
|
1759
|
+
return;
|
|
1760
|
+
}
|
|
1761
|
+
activityToEdit.hidden = true;
|
|
1762
|
+
return;
|
|
1763
|
+
}
|
|
1764
|
+
let addedActivityIds = this.getStorageProperty(`addedActivityIds`) || [];
|
|
1765
|
+
let index = addedActivityIds.indexOf(activityId);
|
|
1766
|
+
if (index === -1) {
|
|
1767
|
+
console.error(`[NQTR] Activity with id ${activityId} not found, so it can't be removed.`);
|
|
1768
|
+
return;
|
|
1769
|
+
}
|
|
1770
|
+
addedActivityIds.splice(index, 1);
|
|
1771
|
+
this.setStorageProperty("addedActivityIds", addedActivityIds);
|
|
1772
|
+
let roomMemories = this.getStorageProperty("activities_memory") || {};
|
|
1773
|
+
delete roomMemories[activityId];
|
|
1774
|
+
this.setStorageProperty("activities_memory", roomMemories);
|
|
1775
|
+
}
|
|
1776
|
+
/**
|
|
1777
|
+
* Clear all expired activities.
|
|
1778
|
+
*/
|
|
1779
|
+
clearExpiredActivities() {
|
|
1780
|
+
this.activities.forEach((activity) => {
|
|
1781
|
+
if (activity.isExpired()) {
|
|
1782
|
+
this.removeActivity(activity.id);
|
|
1783
|
+
}
|
|
1784
|
+
});
|
|
1785
|
+
}
|
|
1786
|
+
/**
|
|
1787
|
+
* Whether is disabled. If it is a string, it is a Pixi'VN flag name.
|
|
1788
|
+
*/
|
|
1789
|
+
get disabled() {
|
|
1790
|
+
let value = this.getStorageProperty("disabled") || this.defaultDisabled;
|
|
1791
|
+
if (typeof value === "string") {
|
|
1792
|
+
return getFlag(value);
|
|
1793
|
+
}
|
|
1794
|
+
return value;
|
|
1795
|
+
}
|
|
1796
|
+
set disabled(value) {
|
|
1797
|
+
this.setStorageProperty("disabled", value);
|
|
1798
|
+
}
|
|
1799
|
+
/**
|
|
1800
|
+
* Whether is hidden. If it is a string, it is a Pixi'VN flag name.
|
|
1801
|
+
*/
|
|
1802
|
+
get hidden() {
|
|
1803
|
+
let value = this.getStorageProperty("hidden") || this.defaultHidden;
|
|
1804
|
+
if (typeof value === "string") {
|
|
1805
|
+
return getFlag(value);
|
|
1806
|
+
}
|
|
1807
|
+
return value;
|
|
1808
|
+
}
|
|
1809
|
+
set hidden(value) {
|
|
1810
|
+
this.setStorageProperty("hidden", value);
|
|
1811
|
+
}
|
|
1812
|
+
/**
|
|
1813
|
+
* The function for rendering the icon of the room.
|
|
1814
|
+
*/
|
|
1815
|
+
get renderIcon() {
|
|
1816
|
+
let render = this._renderIcon;
|
|
1817
|
+
if (render === void 0) {
|
|
1818
|
+
return void 0;
|
|
1819
|
+
}
|
|
1820
|
+
if (typeof render === "function") {
|
|
1821
|
+
return (props) => {
|
|
1822
|
+
return render(this, props);
|
|
1823
|
+
};
|
|
1824
|
+
}
|
|
1825
|
+
return (props) => render;
|
|
1826
|
+
}
|
|
1827
|
+
/**
|
|
1828
|
+
* Get the character commitments of the room.
|
|
1829
|
+
* @returns The character commitments of the room.
|
|
1830
|
+
*/
|
|
1831
|
+
getRoutine() {
|
|
1832
|
+
let commitments = getCurrentRoutine();
|
|
1833
|
+
return commitments.filter((c) => c.room.id === this.id);
|
|
1721
1834
|
}
|
|
1722
1835
|
};
|
|
1723
1836
|
var CURRENT_ROOM_MEMORY_KEY = "___nqtr-current_room_memory___";
|
|
@@ -1780,6 +1893,6 @@ function currentActivities() {
|
|
|
1780
1893
|
return currentRoom.activities.filter((activity) => !activity.hidden);
|
|
1781
1894
|
}
|
|
1782
1895
|
|
|
1783
|
-
export { ActivityModel, ActivityRoom, CommitmentBaseModel, Goal, LocationBaseModel, MapBaseModel,
|
|
1896
|
+
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
1897
|
//# sourceMappingURL=out.js.map
|
|
1785
1898
|
//# sourceMappingURL=index.mjs.map
|