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