@drincs/nqtr 0.1.1 → 0.1.2
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/classes/Activity.d.mts +199 -0
- package/dist/classes/Activity.d.ts +199 -0
- package/dist/classes/Activity.js +508 -0
- package/dist/classes/Activity.js.map +1 -0
- package/dist/classes/Activity.mjs +503 -0
- package/dist/classes/Activity.mjs.map +1 -0
- package/dist/classes/Commitment.d.mts +6 -0
- package/dist/classes/Commitment.d.ts +6 -0
- package/dist/classes/Commitment.js +402 -0
- package/dist/classes/Commitment.js.map +1 -0
- package/dist/classes/Commitment.mjs +400 -0
- package/dist/classes/Commitment.mjs.map +1 -0
- package/dist/classes/index.d.mts +6 -0
- package/dist/classes/index.d.ts +6 -0
- package/dist/classes/index.js +520 -0
- package/dist/classes/index.js.map +1 -0
- package/dist/classes/index.mjs +517 -0
- package/dist/classes/index.mjs.map +1 -0
- package/dist/classes/navigation/ActivityRoom.d.mts +6 -0
- package/dist/classes/navigation/ActivityRoom.d.ts +6 -0
- package/dist/classes/navigation/ActivityRoom.js +435 -0
- package/dist/classes/navigation/ActivityRoom.js.map +1 -0
- package/dist/classes/navigation/ActivityRoom.mjs +433 -0
- package/dist/classes/navigation/ActivityRoom.mjs.map +1 -0
- package/dist/classes/navigation/Location.d.mts +6 -0
- package/dist/classes/navigation/Location.d.ts +6 -0
- package/dist/classes/navigation/Location.js +110 -0
- package/dist/classes/navigation/Location.js.map +1 -0
- package/dist/classes/navigation/Location.mjs +108 -0
- package/dist/classes/navigation/Location.mjs.map +1 -0
- package/dist/classes/navigation/Map.d.mts +6 -0
- package/dist/classes/navigation/Map.d.ts +6 -0
- package/dist/classes/navigation/Map.js +109 -0
- package/dist/classes/navigation/Map.js.map +1 -0
- package/dist/classes/navigation/Map.mjs +107 -0
- package/dist/classes/navigation/Map.mjs.map +1 -0
- package/dist/classes/navigation/Room.d.mts +6 -0
- package/dist/classes/navigation/Room.d.ts +6 -0
- package/dist/classes/navigation/Room.js +750 -0
- package/dist/classes/navigation/Room.js.map +1 -0
- package/dist/classes/navigation/Room.mjs +745 -0
- package/dist/classes/navigation/Room.mjs.map +1 -0
- package/dist/classes/navigation/index.d.mts +6 -0
- package/dist/classes/navigation/index.d.ts +6 -0
- package/dist/classes/navigation/index.js +945 -0
- package/dist/classes/navigation/index.js.map +1 -0
- package/dist/classes/navigation/index.mjs +941 -0
- package/dist/classes/navigation/index.mjs.map +1 -0
- package/dist/classes/quest/Goal.d.mts +23 -0
- package/dist/classes/quest/Goal.d.ts +23 -0
- package/dist/classes/quest/Goal.js +33 -0
- package/dist/classes/quest/Goal.js.map +1 -0
- package/dist/classes/quest/Goal.mjs +31 -0
- package/dist/classes/quest/Goal.mjs.map +1 -0
- package/dist/classes/quest/Quest.d.mts +3 -0
- package/dist/classes/quest/Quest.d.ts +3 -0
- package/dist/classes/quest/Quest.js +39 -0
- package/dist/classes/quest/Quest.js.map +1 -0
- package/dist/classes/quest/Quest.mjs +37 -0
- package/dist/classes/quest/Quest.mjs.map +1 -0
- package/dist/classes/quest/Stage.d.mts +3 -0
- package/dist/classes/quest/Stage.d.ts +3 -0
- package/dist/classes/quest/Stage.js +105 -0
- package/dist/classes/quest/Stage.js.map +1 -0
- package/dist/classes/quest/Stage.mjs +103 -0
- package/dist/classes/quest/Stage.mjs.map +1 -0
- package/dist/classes/quest/index.d.mts +3 -0
- package/dist/classes/quest/index.d.ts +3 -0
- package/dist/classes/quest/index.js +133 -0
- package/dist/classes/quest/index.js.map +1 -0
- package/dist/classes/quest/index.mjs +129 -0
- package/dist/classes/quest/index.mjs.map +1 -0
- package/dist/decorators/ActivityDecorator.d.mts +12 -0
- package/dist/decorators/ActivityDecorator.d.ts +12 -0
- package/dist/decorators/ActivityDecorator.js +33 -0
- package/dist/decorators/ActivityDecorator.js.map +1 -0
- package/dist/decorators/ActivityDecorator.mjs +29 -0
- package/dist/decorators/ActivityDecorator.mjs.map +1 -0
- package/dist/decorators/CommitmentDecorator.d.mts +21 -0
- package/dist/decorators/CommitmentDecorator.d.ts +21 -0
- package/dist/decorators/CommitmentDecorator.js +77 -0
- package/dist/decorators/CommitmentDecorator.js.map +1 -0
- package/dist/decorators/CommitmentDecorator.mjs +68 -0
- package/dist/decorators/CommitmentDecorator.mjs.map +1 -0
- package/dist/decorators/RoomDecorator.d.mts +46 -0
- package/dist/decorators/RoomDecorator.d.ts +46 -0
- package/dist/decorators/RoomDecorator.js +57 -0
- package/dist/decorators/RoomDecorator.js.map +1 -0
- package/dist/decorators/RoomDecorator.mjs +49 -0
- package/dist/decorators/RoomDecorator.mjs.map +1 -0
- package/dist/decorators/index.d.mts +9 -0
- package/dist/decorators/index.d.ts +9 -0
- package/dist/decorators/index.js +145 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/index.mjs +132 -0
- package/dist/decorators/index.mjs.map +1 -0
- package/dist/enums/ExecutionTypeEnum.d.mts +6 -0
- package/dist/enums/ExecutionTypeEnum.d.ts +6 -0
- package/dist/enums/ExecutionTypeEnum.js +12 -0
- package/dist/enums/ExecutionTypeEnum.js.map +1 -0
- package/dist/enums/ExecutionTypeEnum.mjs +10 -0
- package/dist/enums/ExecutionTypeEnum.mjs.map +1 -0
- package/dist/enums/index.d.mts +1 -0
- package/dist/enums/index.d.ts +1 -0
- package/dist/enums/index.js +12 -0
- package/dist/enums/index.js.map +1 -0
- package/dist/enums/index.mjs +10 -0
- package/dist/enums/index.mjs.map +1 -0
- package/dist/functions/ActivityFunctions.d.mts +11 -0
- package/dist/functions/ActivityFunctions.d.ts +11 -0
- package/dist/functions/ActivityFunctions.js +54 -0
- package/dist/functions/ActivityFunctions.js.map +1 -0
- package/dist/functions/ActivityFunctions.mjs +51 -0
- package/dist/functions/ActivityFunctions.mjs.map +1 -0
- package/dist/functions/NavigationFunctions.d.mts +13 -0
- package/dist/functions/NavigationFunctions.d.ts +13 -0
- package/dist/functions/NavigationFunctions.js +173 -0
- package/dist/functions/NavigationFunctions.js.map +1 -0
- package/dist/functions/NavigationFunctions.mjs +168 -0
- package/dist/functions/NavigationFunctions.mjs.map +1 -0
- package/dist/functions/RoutineFunctions.d.mts +12 -0
- package/dist/functions/RoutineFunctions.d.ts +12 -0
- package/dist/functions/RoutineFunctions.js +87 -0
- package/dist/functions/RoutineFunctions.js.map +1 -0
- package/dist/functions/RoutineFunctions.mjs +83 -0
- package/dist/functions/RoutineFunctions.mjs.map +1 -0
- package/dist/functions/index.d.mts +9 -0
- package/dist/functions/index.d.ts +9 -0
- package/dist/functions/index.js +264 -0
- package/dist/functions/index.js.map +1 -0
- package/dist/functions/index.mjs +254 -0
- package/dist/functions/index.mjs.map +1 -0
- package/dist/index-BjOzVDyw.d.ts +76 -0
- package/dist/index-BvCfRbJB.d.mts +564 -0
- package/dist/index-Ci6Aw7YE.d.ts +564 -0
- package/dist/index-gJ26gdgL.d.mts +76 -0
- package/dist/index.d.mts +16 -1031
- package/dist/index.d.ts +16 -1031
- package/dist/index.js +83 -154
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -80
- package/dist/index.mjs.map +1 -1
- package/dist/managers/TimeManager.d.mts +84 -0
- package/dist/managers/TimeManager.d.ts +84 -0
- package/dist/managers/TimeManager.js +251 -0
- package/dist/managers/TimeManager.js.map +1 -0
- package/dist/managers/TimeManager.mjs +249 -0
- package/dist/managers/TimeManager.mjs.map +1 -0
- package/dist/managers/index.d.mts +2 -0
- package/dist/managers/index.d.ts +2 -0
- package/dist/managers/index.js +251 -0
- package/dist/managers/index.js.map +1 -0
- package/dist/managers/index.mjs +249 -0
- package/dist/managers/index.mjs.map +1 -0
- package/dist/override/OnRunActivityProps.d.mts +19 -0
- package/dist/override/OnRunActivityProps.d.ts +19 -0
- package/dist/override/OnRunActivityProps.js +4 -0
- package/dist/override/OnRunActivityProps.js.map +1 -0
- package/dist/override/OnRunActivityProps.mjs +3 -0
- package/dist/override/OnRunActivityProps.mjs.map +1 -0
- package/dist/override/index.d.mts +1 -0
- package/dist/override/index.d.ts +1 -0
- package/dist/override/index.js +4 -0
- package/dist/override/index.js.map +1 -0
- package/dist/override/index.mjs +3 -0
- package/dist/override/index.mjs.map +1 -0
- package/dist/types/GraphicItem.d.mts +5 -0
- package/dist/types/GraphicItem.d.ts +5 -0
- package/dist/types/GraphicItem.js +4 -0
- package/dist/types/GraphicItem.js.map +1 -0
- package/dist/types/GraphicItem.mjs +3 -0
- package/dist/types/GraphicItem.mjs.map +1 -0
- package/dist/types/QuestsRequired.d.mts +3 -0
- package/dist/types/QuestsRequired.d.ts +3 -0
- package/dist/types/QuestsRequired.js +4 -0
- package/dist/types/QuestsRequired.js.map +1 -0
- package/dist/types/QuestsRequired.mjs +3 -0
- package/dist/types/QuestsRequired.mjs.map +1 -0
- package/dist/types/TimeSettings.d.mts +58 -0
- package/dist/types/TimeSettings.d.ts +58 -0
- package/dist/types/TimeSettings.js +4 -0
- package/dist/types/TimeSettings.js.map +1 -0
- package/dist/types/TimeSettings.mjs +3 -0
- package/dist/types/TimeSettings.mjs.map +1 -0
- package/dist/types/index.d.mts +4 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +3 -0
- package/dist/types/index.mjs.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,941 @@
|
|
|
1
|
+
import { StoredClassModel, getFlag, GameStorageManager } from '@drincs/pixi-vn';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// src/decorators/RoomDecorator.ts
|
|
21
|
+
var registeredRooms = {};
|
|
22
|
+
function getRoomsByLocation(location) {
|
|
23
|
+
return Object.values(registeredRooms).filter((room) => room.location.id === location.id);
|
|
24
|
+
}
|
|
25
|
+
function getAllLocations() {
|
|
26
|
+
let result = {};
|
|
27
|
+
Object.values(registeredRooms).forEach((room) => {
|
|
28
|
+
result[room.location.id] = room.location;
|
|
29
|
+
});
|
|
30
|
+
return Object.values(result);
|
|
31
|
+
}
|
|
32
|
+
function getLocationsByMap(map) {
|
|
33
|
+
return getAllLocations().filter((location) => location.map.id === map.id);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/classes/navigation/Location.ts
|
|
37
|
+
var LOCATION_CATEGORY = "__nqtr-location__";
|
|
38
|
+
var LocationBaseModel = class extends StoredClassModel {
|
|
39
|
+
/**
|
|
40
|
+
* @param id The id of the location, it must be unique.
|
|
41
|
+
* @param map The map where the location is.
|
|
42
|
+
* @param props The properties of the location.
|
|
43
|
+
*/
|
|
44
|
+
constructor(id, map, props = {}) {
|
|
45
|
+
super(LOCATION_CATEGORY, id);
|
|
46
|
+
this.defaultName = props.name || "";
|
|
47
|
+
this.defaultDisabled = props.disabled || false;
|
|
48
|
+
this.defaultHidden = props.hidden || false;
|
|
49
|
+
this._icon = props.icon;
|
|
50
|
+
this._map = map;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The name of the location.
|
|
54
|
+
* If you set undefined, it will return the initial value of name.
|
|
55
|
+
*/
|
|
56
|
+
get name() {
|
|
57
|
+
return this.getStorageProperty("name") || this.defaultName;
|
|
58
|
+
}
|
|
59
|
+
set name(value) {
|
|
60
|
+
this.setStorageProperty("name", value);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Whether is disabled. If it is a string, it is a Pixi'VN flag name.
|
|
64
|
+
*/
|
|
65
|
+
get disabled() {
|
|
66
|
+
let value = this.getStorageProperty("disabled") || this.defaultDisabled;
|
|
67
|
+
if (typeof value === "string") {
|
|
68
|
+
return getFlag(value);
|
|
69
|
+
}
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
set disabled(value) {
|
|
73
|
+
this.setStorageProperty("disabled", value);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Whether is hidden. If it is a string, it is a Pixi'VN flag name.
|
|
77
|
+
*/
|
|
78
|
+
get hidden() {
|
|
79
|
+
let value = this.getStorageProperty("hidden") || this.defaultHidden;
|
|
80
|
+
if (typeof value === "string") {
|
|
81
|
+
return getFlag(value);
|
|
82
|
+
}
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
set hidden(value) {
|
|
86
|
+
this.setStorageProperty("hidden", value);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The icon element. Can be a string or an Element or a Pixi'VN CanvasItem
|
|
90
|
+
*/
|
|
91
|
+
get icon() {
|
|
92
|
+
return this._icon;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The map where the location is.
|
|
96
|
+
*/
|
|
97
|
+
get map() {
|
|
98
|
+
return this._map;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get the entrance room of the location.
|
|
102
|
+
* You can cast the room to a specific type that extends RoomBaseModel.
|
|
103
|
+
* @returns The entrance room or the first room if there is no entrance.
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* const entranceHome = new RoomBaseModel("entrance-home", home, { isEntrance: true })
|
|
107
|
+
* saveRoom(entranceHome)
|
|
108
|
+
* const home = new LocationBaseModel("home", map, { name: "Home" })
|
|
109
|
+
*
|
|
110
|
+
* const entrance = home.getEntrance() // entrance === entranceHome
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
getEntrance() {
|
|
114
|
+
let rooms = this.getRooms();
|
|
115
|
+
if (rooms.length === 0) {
|
|
116
|
+
console.error(`[NQTR] The location ${this.id} has no rooms`);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
return rooms.find((room) => room.isEntrance) || rooms[0];
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get all rooms in the location.
|
|
123
|
+
* You can cast the rooms to a specific type that extends RoomBaseModel.
|
|
124
|
+
* @returns The rooms in the location.
|
|
125
|
+
*/
|
|
126
|
+
getRooms() {
|
|
127
|
+
return getRoomsByLocation(this);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var MAP_CATEGORY = "__nqtr-map__";
|
|
131
|
+
var MapBaseModel = class extends StoredClassModel {
|
|
132
|
+
/**
|
|
133
|
+
* @param id The id of the map, it must be unique.
|
|
134
|
+
* @param props The properties of the map.
|
|
135
|
+
*/
|
|
136
|
+
constructor(id, props = {}) {
|
|
137
|
+
super(MAP_CATEGORY, id);
|
|
138
|
+
this.defaultName = props.name || "";
|
|
139
|
+
this.defaultImage = props.image;
|
|
140
|
+
this.defaultDisabled = props.disabled || false;
|
|
141
|
+
this.defaultHidden = props.hidden || false;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* The name of the map.
|
|
145
|
+
* If you set undefined, it will return the initial value of name.
|
|
146
|
+
*/
|
|
147
|
+
get name() {
|
|
148
|
+
return this.getStorageProperty("name") || this.defaultName;
|
|
149
|
+
}
|
|
150
|
+
set name(value) {
|
|
151
|
+
this.setStorageProperty("name", value);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The image of the map. It can be a string, an Element or a Pixi'VN Canvas Item.
|
|
155
|
+
* If you set undefined, it will return the initial value of image.
|
|
156
|
+
*/
|
|
157
|
+
get image() {
|
|
158
|
+
return this.getStorageProperty("image") || this.defaultImage;
|
|
159
|
+
}
|
|
160
|
+
set image(value) {
|
|
161
|
+
this.setStorageProperty("image", value);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Whether is disabled. If it is a string, it is a Pixi'VN flag name.
|
|
165
|
+
*/
|
|
166
|
+
get disabled() {
|
|
167
|
+
let value = this.getStorageProperty("disabled") || this.defaultDisabled;
|
|
168
|
+
if (typeof value === "string") {
|
|
169
|
+
return getFlag(value);
|
|
170
|
+
}
|
|
171
|
+
return value;
|
|
172
|
+
}
|
|
173
|
+
set disabled(value) {
|
|
174
|
+
this.setStorageProperty("disabled", value);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Whether is hidden. If it is a string, it is a Pixi'VN flag name.
|
|
178
|
+
*/
|
|
179
|
+
get hidden() {
|
|
180
|
+
let value = this.getStorageProperty("hidden") || this.defaultHidden;
|
|
181
|
+
if (typeof value === "string") {
|
|
182
|
+
return getFlag(value);
|
|
183
|
+
}
|
|
184
|
+
return value;
|
|
185
|
+
}
|
|
186
|
+
set hidden(value) {
|
|
187
|
+
this.setStorageProperty("hidden", value);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* The neighboring maps that are available in this map.
|
|
191
|
+
* @example
|
|
192
|
+
* ```ts
|
|
193
|
+
* {
|
|
194
|
+
* "north": "atlanta_map_id",
|
|
195
|
+
* "south": "miami_map_id",
|
|
196
|
+
* "east": "new_york_map_id",
|
|
197
|
+
* "west": "los_angeles_map_id"
|
|
198
|
+
* }
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
get neighboringMaps() {
|
|
202
|
+
return this._neighboringMaps || {};
|
|
203
|
+
}
|
|
204
|
+
set neighboringMaps(value) {
|
|
205
|
+
this._neighboringMaps = value;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Get all locations in the map.
|
|
209
|
+
* @returns The locations in the map.
|
|
210
|
+
*/
|
|
211
|
+
getLocations() {
|
|
212
|
+
return getLocationsByMap(this);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
// src/decorators/ActivityDecorator.ts
|
|
217
|
+
var registeredActivities = {};
|
|
218
|
+
function getActivityById(id) {
|
|
219
|
+
try {
|
|
220
|
+
let activity = registeredActivities[id];
|
|
221
|
+
if (!activity) {
|
|
222
|
+
console.error(`[NQTR] Activity ${id} not found`);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
return activity;
|
|
226
|
+
} catch (e) {
|
|
227
|
+
console.error(`[NQTR] Error while getting Activity ${id}`, e);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
var TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY = "___nqtr-temporary_commitment___";
|
|
232
|
+
var registeredCommitments = {};
|
|
233
|
+
var fixedCommitments = {};
|
|
234
|
+
function getCommitmentById(id) {
|
|
235
|
+
try {
|
|
236
|
+
let commitment = registeredCommitments[id];
|
|
237
|
+
if (!commitment) {
|
|
238
|
+
console.error(`[NQTR] Commitment ${id} not found`);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
return commitment;
|
|
242
|
+
} catch (e) {
|
|
243
|
+
console.error(`[NQTR] Error while getting Commitment ${id}`, e);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function getFixedCommitments() {
|
|
248
|
+
return Object.values(fixedCommitments);
|
|
249
|
+
}
|
|
250
|
+
function getTemporaryCommitments() {
|
|
251
|
+
let commitmentsIds = GameStorageManager.getVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY);
|
|
252
|
+
if (!commitmentsIds) {
|
|
253
|
+
return [];
|
|
254
|
+
}
|
|
255
|
+
let commitments = commitmentsIds.map((id) => getCommitmentById(id)).filter((commitment) => commitment !== void 0);
|
|
256
|
+
return commitments;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// src/functions/RoutineFunctions.ts
|
|
260
|
+
function getCurrentCommitments() {
|
|
261
|
+
let character_commitments = {};
|
|
262
|
+
let oltherCommitments = [];
|
|
263
|
+
getTemporaryCommitments().reverse().forEach((c) => {
|
|
264
|
+
if (!c.hidden) {
|
|
265
|
+
if (c.characters.length > 1) {
|
|
266
|
+
let allAvailable = c.characters.every((ch) => !character_commitments[ch.id]);
|
|
267
|
+
if (allAvailable) {
|
|
268
|
+
c.characters.forEach((ch) => {
|
|
269
|
+
character_commitments[ch.id] = c;
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
} else {
|
|
273
|
+
oltherCommitments.push(c);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
getFixedCommitments().reverse().forEach((c) => {
|
|
278
|
+
if (!c.hidden) {
|
|
279
|
+
if (c.characters.length > 1) {
|
|
280
|
+
c.characters.forEach((ch) => {
|
|
281
|
+
if (!character_commitments[ch.id]) {
|
|
282
|
+
character_commitments[ch.id] = c;
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
} else {
|
|
286
|
+
oltherCommitments.push(c);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
return Object.values(character_commitments).concat(oltherCommitments);
|
|
291
|
+
}
|
|
292
|
+
var TIME_SETTINGS_KEY = "___nqtr-time_manager_settings___";
|
|
293
|
+
var TIME_DATA_KEY = "___nqtr-time_manager_data___";
|
|
294
|
+
var TimeManager = class _TimeManager {
|
|
295
|
+
constructor() {
|
|
296
|
+
}
|
|
297
|
+
static editSettings(settings) {
|
|
298
|
+
let data = {};
|
|
299
|
+
if (typeof settings.minDayHours === "number") {
|
|
300
|
+
data["minDayHours"] = settings.minDayHours;
|
|
301
|
+
}
|
|
302
|
+
if (typeof settings.maxDayHours === "number") {
|
|
303
|
+
data["maxDayHours"] = settings.maxDayHours;
|
|
304
|
+
}
|
|
305
|
+
if (typeof settings.minDayHours === "number") {
|
|
306
|
+
data["defaultTimeSpent"] = settings.defaultTimeSpent;
|
|
307
|
+
}
|
|
308
|
+
if (Array.isArray(settings.timeSlots)) {
|
|
309
|
+
data["timeSlots"] = settings.timeSlots;
|
|
310
|
+
}
|
|
311
|
+
if (typeof settings.weekLength === "number") {
|
|
312
|
+
data["weekLength"] = settings.weekLength;
|
|
313
|
+
}
|
|
314
|
+
if (typeof settings.weekendStartDay === "number") {
|
|
315
|
+
let weekLength = settings.weekLength || _TimeManager.weekLength;
|
|
316
|
+
if (settings.weekendStartDay >= weekLength) {
|
|
317
|
+
console.warn(`[NQTR] Weekend start day should be less than week length ${weekLength}`);
|
|
318
|
+
}
|
|
319
|
+
data["weekendStartDay"] = settings.weekendStartDay;
|
|
320
|
+
}
|
|
321
|
+
if (Array.isArray(settings.weekDaysNames)) {
|
|
322
|
+
let weekLength = settings.weekLength || _TimeManager.weekLength;
|
|
323
|
+
if (settings.weekDaysNames.length !== weekLength) {
|
|
324
|
+
console.warn(`[NQTR] Week days names should be equal to week length ${weekLength}`);
|
|
325
|
+
}
|
|
326
|
+
data["weekDaysNames"] = settings.weekDaysNames;
|
|
327
|
+
}
|
|
328
|
+
GameStorageManager.setVariable(TIME_SETTINGS_KEY, data);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Get time settings
|
|
332
|
+
* @default {}
|
|
333
|
+
*/
|
|
334
|
+
static get settings() {
|
|
335
|
+
let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY) || {};
|
|
336
|
+
return settings;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Set time settings, Is very important to set the settings before using the nqtr library, bacause more of the features are based on the time settings.
|
|
340
|
+
*/
|
|
341
|
+
static set settings(value) {
|
|
342
|
+
_TimeManager.editSettings(value);
|
|
343
|
+
}
|
|
344
|
+
static get minDayHours() {
|
|
345
|
+
let result = 0;
|
|
346
|
+
let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY);
|
|
347
|
+
if (settings && settings.hasOwnProperty("minDayHours")) {
|
|
348
|
+
result = settings.minDayHours || 0;
|
|
349
|
+
}
|
|
350
|
+
return result;
|
|
351
|
+
}
|
|
352
|
+
static get maxDayHours() {
|
|
353
|
+
let result = 24;
|
|
354
|
+
let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY);
|
|
355
|
+
if (settings && settings.hasOwnProperty("maxDayHours")) {
|
|
356
|
+
result = settings.maxDayHours || 24;
|
|
357
|
+
}
|
|
358
|
+
return result;
|
|
359
|
+
}
|
|
360
|
+
static get defaultTimeSpent() {
|
|
361
|
+
let result = 1;
|
|
362
|
+
let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY);
|
|
363
|
+
if (settings && settings.hasOwnProperty("defaultTimeSpent")) {
|
|
364
|
+
result = settings.defaultTimeSpent || 1;
|
|
365
|
+
}
|
|
366
|
+
return result;
|
|
367
|
+
}
|
|
368
|
+
static get timeSlots() {
|
|
369
|
+
let result = [];
|
|
370
|
+
let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY);
|
|
371
|
+
if (settings && settings.hasOwnProperty("timeSlots")) {
|
|
372
|
+
result = settings.timeSlots || [];
|
|
373
|
+
}
|
|
374
|
+
return result;
|
|
375
|
+
}
|
|
376
|
+
static get weekLength() {
|
|
377
|
+
let result = 7;
|
|
378
|
+
let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY);
|
|
379
|
+
if (settings && settings.hasOwnProperty("weekLength")) {
|
|
380
|
+
result = settings.weekLength || 7;
|
|
381
|
+
}
|
|
382
|
+
return result;
|
|
383
|
+
}
|
|
384
|
+
static get weekendStartDay() {
|
|
385
|
+
let result = _TimeManager.weekLength - 1;
|
|
386
|
+
let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY);
|
|
387
|
+
if (settings && settings.hasOwnProperty("weekendStartDay")) {
|
|
388
|
+
result = settings.weekendStartDay || _TimeManager.weekLength - 1;
|
|
389
|
+
}
|
|
390
|
+
return result;
|
|
391
|
+
}
|
|
392
|
+
static get weekDaysNames() {
|
|
393
|
+
let result = [];
|
|
394
|
+
let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY);
|
|
395
|
+
if (settings && settings.hasOwnProperty("weekDaysNames")) {
|
|
396
|
+
result = settings.weekDaysNames || result;
|
|
397
|
+
}
|
|
398
|
+
return result;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Get the current hour
|
|
402
|
+
*/
|
|
403
|
+
static get currentHour() {
|
|
404
|
+
let data = GameStorageManager.getVariable(TIME_DATA_KEY) || {};
|
|
405
|
+
if (data.hasOwnProperty("currentHour") && typeof data.currentHour === "number") {
|
|
406
|
+
return data.currentHour;
|
|
407
|
+
}
|
|
408
|
+
return _TimeManager.minDayHours;
|
|
409
|
+
}
|
|
410
|
+
static set currentHour(value) {
|
|
411
|
+
let data = GameStorageManager.getVariable(TIME_DATA_KEY) || {};
|
|
412
|
+
if (typeof value === "number") {
|
|
413
|
+
data.currentHour = value;
|
|
414
|
+
} else {
|
|
415
|
+
delete data.currentHour;
|
|
416
|
+
}
|
|
417
|
+
GameStorageManager.setVariable(TIME_DATA_KEY, data);
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Get the current day
|
|
421
|
+
*/
|
|
422
|
+
static get currentDay() {
|
|
423
|
+
let data = GameStorageManager.getVariable(TIME_DATA_KEY) || {};
|
|
424
|
+
if (data.hasOwnProperty("currentDay") && typeof data.currentDay === "number") {
|
|
425
|
+
return data.currentDay;
|
|
426
|
+
}
|
|
427
|
+
return 0;
|
|
428
|
+
}
|
|
429
|
+
static set currentDay(value) {
|
|
430
|
+
let data = GameStorageManager.getVariable(TIME_DATA_KEY) || {};
|
|
431
|
+
if (typeof value === "number") {
|
|
432
|
+
data.currentDay = value;
|
|
433
|
+
} else {
|
|
434
|
+
delete data.currentDay;
|
|
435
|
+
}
|
|
436
|
+
GameStorageManager.setVariable(TIME_DATA_KEY, data);
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* If the current day is greater than or equal to the weekend start day, then it will return true.
|
|
440
|
+
*/
|
|
441
|
+
static get isWeekend() {
|
|
442
|
+
return _TimeManager.currentWeekDayNumber >= _TimeManager.weekendStartDay;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Get the current week day number (1-TimeManager.weekLength).
|
|
446
|
+
* For example, if the week length is 7 and the current day is 10, then the result will be 4.
|
|
447
|
+
*/
|
|
448
|
+
static get currentWeekDayNumber() {
|
|
449
|
+
let result = _TimeManager.currentDay % _TimeManager.weekLength;
|
|
450
|
+
return result + 1;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Get the current week day name. If the week days names are not defined, then it will return undefined.
|
|
454
|
+
* For example, if the week days names are ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] and the current day is 10, then the result will be 'Thursday'.
|
|
455
|
+
* @default ""
|
|
456
|
+
*/
|
|
457
|
+
static get currentDayName() {
|
|
458
|
+
let weekDayNumber = _TimeManager.currentWeekDayNumber - 1;
|
|
459
|
+
if (weekDayNumber >= _TimeManager.weekDaysNames.length) {
|
|
460
|
+
console.warn(`[NQTR] Week day name is not defined for day ${weekDayNumber}`, _TimeManager.weekDaysNames);
|
|
461
|
+
return "";
|
|
462
|
+
}
|
|
463
|
+
return _TimeManager.weekDaysNames[weekDayNumber];
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Get the current TimeManager.timeSlots index.
|
|
467
|
+
* You can use this property to create "Image that changes based on the time period":
|
|
468
|
+
* @example
|
|
469
|
+
* ```ts
|
|
470
|
+
* import { TimeManager } from '@drincs/nqtr';
|
|
471
|
+
*
|
|
472
|
+
* function changeBackground() {
|
|
473
|
+
* return (
|
|
474
|
+
* <img src={`background-${TimeManager.currentTimeSlot}.png`} />
|
|
475
|
+
* )
|
|
476
|
+
* }
|
|
477
|
+
*/
|
|
478
|
+
static get currentTimeSlot() {
|
|
479
|
+
if (_TimeManager.timeSlots.length === 0) {
|
|
480
|
+
console.warn("[NQTR] Time slots are not defined");
|
|
481
|
+
return 0;
|
|
482
|
+
}
|
|
483
|
+
for (let index = 0; index < _TimeManager.timeSlots.length; index++) {
|
|
484
|
+
let slot = _TimeManager.timeSlots[index];
|
|
485
|
+
if (_TimeManager.timeSlots.length > index + 1) {
|
|
486
|
+
if (_TimeManager.nowIsBetween(slot.startHour, _TimeManager.timeSlots[index + 1].startHour)) {
|
|
487
|
+
return index;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
return _TimeManager.timeSlots.length - 1;
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* This function will increase the current hour by the given time spent.
|
|
495
|
+
* If the new hour is greater than or equal to the max day hours, then it will increase the day and set the new hour.
|
|
496
|
+
* @param timeSpent is the time spent in hours (default: TimeManager.defaultTimeSpent)
|
|
497
|
+
* @returns TimeManager.currentHour
|
|
498
|
+
*/
|
|
499
|
+
static increaseHour(timeSpent = _TimeManager.defaultTimeSpent) {
|
|
500
|
+
let newHour = _TimeManager.currentHour + timeSpent;
|
|
501
|
+
if (newHour >= _TimeManager.maxDayHours) {
|
|
502
|
+
_TimeManager.increaseDay();
|
|
503
|
+
newHour = _TimeManager.minDayHours + (newHour - _TimeManager.maxDayHours);
|
|
504
|
+
}
|
|
505
|
+
_TimeManager.currentHour = newHour;
|
|
506
|
+
return _TimeManager.currentHour;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* This function will increase the current day by the given days.
|
|
510
|
+
* @param newDayHour is the hour of the new day (default: TimeManager.minDayHours)
|
|
511
|
+
* @param days is the number of days to increase (default: 1)
|
|
512
|
+
* @returns TimeManager.currentDay
|
|
513
|
+
*/
|
|
514
|
+
static increaseDay(newDayHour = _TimeManager.minDayHours, days = 1) {
|
|
515
|
+
let newDay = _TimeManager.currentDay + days;
|
|
516
|
+
_TimeManager.currentDay = newDay;
|
|
517
|
+
_TimeManager.currentHour = newDayHour;
|
|
518
|
+
return _TimeManager.currentDay;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* This function will check if the current hour is between the given hours.
|
|
522
|
+
* @param fromHour the starting hour. If the TimeManager.currentHour is equal to this hour, the function will return true.
|
|
523
|
+
* @param toHour the ending hour.
|
|
524
|
+
* @returns true if the current hour is between the given hours, otherwise false.
|
|
525
|
+
*/
|
|
526
|
+
static nowIsBetween(fromHour, toHour) {
|
|
527
|
+
let currentHour = _TimeManager.currentHour;
|
|
528
|
+
if (fromHour < toHour) {
|
|
529
|
+
return currentHour >= fromHour && currentHour < toHour;
|
|
530
|
+
}
|
|
531
|
+
return currentHour >= fromHour || currentHour < toHour;
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
// src/classes/Activity.ts
|
|
536
|
+
var ActivityStoredAbstract = class {
|
|
537
|
+
/**
|
|
538
|
+
* @param onRun The function that is called when the activity is runned. Have 2 parameters: the runned activity and the yourParams object, that is an object with the parameters that you want to pass to the onRun function.
|
|
539
|
+
* @param props The activity properties.
|
|
540
|
+
*/
|
|
541
|
+
constructor(onRun, props) {
|
|
542
|
+
this.defaultName = props.name;
|
|
543
|
+
this.defaultFromHour = props.fromHour;
|
|
544
|
+
this.defaultToHour = props.toHour;
|
|
545
|
+
this.defaultFromDay = props.fromDay;
|
|
546
|
+
this.defaultToDay = props.toDay;
|
|
547
|
+
this.defaultDisabled = props.disabled || false;
|
|
548
|
+
this.defaultHidden = props.hidden || false;
|
|
549
|
+
this._icon = props.icon;
|
|
550
|
+
this._onRun = onRun;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* The name
|
|
554
|
+
*/
|
|
555
|
+
get name() {
|
|
556
|
+
return this.getStorageProperty("name") || this.defaultName || "";
|
|
557
|
+
}
|
|
558
|
+
set name(value) {
|
|
559
|
+
this.setStorageProperty("name", value);
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* The hour when the activity starts. If the activity is not started yet, it will be hidden.
|
|
563
|
+
*/
|
|
564
|
+
get fromHour() {
|
|
565
|
+
return this.getStorageProperty("fromHour") || this.defaultFromHour || TimeManager.minDayHours;
|
|
566
|
+
}
|
|
567
|
+
set fromHour(value) {
|
|
568
|
+
this.setStorageProperty("fromHour", value);
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* The hour when the activity ends. If the activity is ended yet, it will be hidden.
|
|
572
|
+
*/
|
|
573
|
+
get toHour() {
|
|
574
|
+
return this.getStorageProperty("toHour") || this.defaultToHour || TimeManager.maxDayHours + 1;
|
|
575
|
+
}
|
|
576
|
+
set toHour(value) {
|
|
577
|
+
this.setStorageProperty("toHour", value);
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* The day when the activity starts. If the activity is not started yet, it will be hidden.
|
|
581
|
+
*/
|
|
582
|
+
get fromDay() {
|
|
583
|
+
return this.getStorageProperty("fromDay") || this.defaultFromDay;
|
|
584
|
+
}
|
|
585
|
+
set fromDay(value) {
|
|
586
|
+
this.setStorageProperty("fromDay", value);
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* The day when the activity ends. If the activity is ended yet, it will be deleted or hidden.
|
|
590
|
+
*/
|
|
591
|
+
get toDay() {
|
|
592
|
+
return this.getStorageProperty("toDay") || this.defaultToDay;
|
|
593
|
+
}
|
|
594
|
+
set toDay(value) {
|
|
595
|
+
this.setStorageProperty("toDay", value);
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Whether is disabled.
|
|
599
|
+
*/
|
|
600
|
+
get disabled() {
|
|
601
|
+
let value = this.getStorageProperty("disabled") || this.defaultDisabled;
|
|
602
|
+
if (typeof value === "string") {
|
|
603
|
+
return getFlag(value);
|
|
604
|
+
}
|
|
605
|
+
return value;
|
|
606
|
+
}
|
|
607
|
+
set disabled(value) {
|
|
608
|
+
this.setStorageProperty("disabled", value);
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Whether is hidden. If the activity is not started yet, it will be hidden.
|
|
612
|
+
*/
|
|
613
|
+
get hidden() {
|
|
614
|
+
if (this.fromDay && this.fromDay > TimeManager.currentDay) {
|
|
615
|
+
return true;
|
|
616
|
+
}
|
|
617
|
+
if (!TimeManager.nowIsBetween(this.fromHour, this.toHour)) {
|
|
618
|
+
return true;
|
|
619
|
+
}
|
|
620
|
+
if (!this.isExpired) {
|
|
621
|
+
return true;
|
|
622
|
+
}
|
|
623
|
+
let value = this.getStorageProperty("hidden") || this.defaultHidden;
|
|
624
|
+
if (typeof value === "string") {
|
|
625
|
+
return getFlag(value);
|
|
626
|
+
}
|
|
627
|
+
return value;
|
|
628
|
+
}
|
|
629
|
+
set hidden(value) {
|
|
630
|
+
this.setStorageProperty("hidden", value);
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* The icon element.
|
|
634
|
+
*/
|
|
635
|
+
get icon() {
|
|
636
|
+
return this._icon;
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* The function that is called when the activity is runned.
|
|
640
|
+
*/
|
|
641
|
+
get onRun() {
|
|
642
|
+
return () => this._onRun(this);
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Whether the activity is a deadline.
|
|
646
|
+
* @returns Whether the activity is a deadline.
|
|
647
|
+
*/
|
|
648
|
+
isExpired() {
|
|
649
|
+
if (this.toDay && this.toDay <= TimeManager.currentDay) {
|
|
650
|
+
return true;
|
|
651
|
+
}
|
|
652
|
+
return false;
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* Export the activity properties.
|
|
656
|
+
* @returns The activity properties.
|
|
657
|
+
*/
|
|
658
|
+
export() {
|
|
659
|
+
return {
|
|
660
|
+
name: this.getStorageProperty("name") || this.defaultName,
|
|
661
|
+
fromHour: this.getStorageProperty("fromHour") || this.defaultFromHour,
|
|
662
|
+
toHour: this.getStorageProperty("toHour") || this.defaultToHour,
|
|
663
|
+
fromDay: this.getStorageProperty("fromDay") || this.defaultFromDay,
|
|
664
|
+
toDay: this.getStorageProperty("toDay") || this.defaultToDay,
|
|
665
|
+
disabled: this.getStorageProperty("disabled") || this.defaultDisabled,
|
|
666
|
+
hidden: this.getStorageProperty("hidden") || this.defaultHidden,
|
|
667
|
+
icon: this._icon
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
// src/classes/navigation/ActivityRoom.ts
|
|
673
|
+
var ActivityRoom = class extends ActivityStoredAbstract {
|
|
674
|
+
constructor(id, room, onRun, props) {
|
|
675
|
+
super(onRun, props);
|
|
676
|
+
this._id = id;
|
|
677
|
+
this._room = room;
|
|
678
|
+
}
|
|
679
|
+
setStorageProperty(_, __) {
|
|
680
|
+
this._room.setActivity(this);
|
|
681
|
+
}
|
|
682
|
+
getStorageProperty(propertyName) {
|
|
683
|
+
let activity = this._room.getActivityMemory(this.id);
|
|
684
|
+
if (!activity || !activity.hasOwnProperty(propertyName)) {
|
|
685
|
+
return void 0;
|
|
686
|
+
}
|
|
687
|
+
return activity[propertyName];
|
|
688
|
+
}
|
|
689
|
+
get id() {
|
|
690
|
+
return this._id;
|
|
691
|
+
}
|
|
692
|
+
get room() {
|
|
693
|
+
return this._room;
|
|
694
|
+
}
|
|
695
|
+
export() {
|
|
696
|
+
let result = {};
|
|
697
|
+
if (this.name !== void 0) {
|
|
698
|
+
result["name"] = this.name;
|
|
699
|
+
}
|
|
700
|
+
if (this.fromHour !== void 0) {
|
|
701
|
+
result["fromHour"] = this.fromHour;
|
|
702
|
+
}
|
|
703
|
+
if (this.toHour !== void 0) {
|
|
704
|
+
result["toHour"] = this.toHour;
|
|
705
|
+
}
|
|
706
|
+
if (this.fromDay !== void 0) {
|
|
707
|
+
result["fromDay"] = this.fromDay;
|
|
708
|
+
}
|
|
709
|
+
if (this.toDay !== void 0) {
|
|
710
|
+
result["toDay"] = this.toDay;
|
|
711
|
+
}
|
|
712
|
+
if (this.disabled !== void 0) {
|
|
713
|
+
result["disabled"] = this.disabled;
|
|
714
|
+
}
|
|
715
|
+
return result;
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
|
|
719
|
+
// src/classes/navigation/Room.ts
|
|
720
|
+
var ROOM_CATEGORY = "__nqtr-room__";
|
|
721
|
+
var RoomBaseModel = class extends StoredClassModel {
|
|
722
|
+
/**
|
|
723
|
+
* @param id The id of the room, it must be unique.
|
|
724
|
+
* @param location The location where the room is.
|
|
725
|
+
* @param props The properties of the room.
|
|
726
|
+
*/
|
|
727
|
+
constructor(id, location, props = {}) {
|
|
728
|
+
var _a;
|
|
729
|
+
super(ROOM_CATEGORY, id);
|
|
730
|
+
this._location = location;
|
|
731
|
+
this.defaultName = props.name || "";
|
|
732
|
+
this.defaultImage = props.image;
|
|
733
|
+
this.defaultActivityIds = ((_a = props.defaultActivities) == null ? void 0 : _a.map((activity) => activity.id)) || [];
|
|
734
|
+
this.defaultDisabled = props.disabled || false;
|
|
735
|
+
this.defaultHidden = props.hidden || false;
|
|
736
|
+
this._icon = props.icon;
|
|
737
|
+
this._isEntrance = props.isEntrance;
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* The location where the room is.
|
|
741
|
+
*/
|
|
742
|
+
get location() {
|
|
743
|
+
return this._location;
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Whether is an entrance room, so when the player enters in the location, it will be the first room to be shown.
|
|
747
|
+
*/
|
|
748
|
+
get isEntrance() {
|
|
749
|
+
return this._isEntrance || false;
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* The name.
|
|
753
|
+
* If you set undefined, it will return the initial value of name.
|
|
754
|
+
*/
|
|
755
|
+
get name() {
|
|
756
|
+
return this.getStorageProperty("name") || this.defaultName;
|
|
757
|
+
}
|
|
758
|
+
set name(value) {
|
|
759
|
+
this.setStorageProperty("name", value);
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* The image. It can be a string, an Element or a Pixi'VN Canvas Item.
|
|
763
|
+
* If you set undefined, it will return the initial value of image.
|
|
764
|
+
*/
|
|
765
|
+
get image() {
|
|
766
|
+
return this.getStorageProperty("image") || this.defaultImage;
|
|
767
|
+
}
|
|
768
|
+
set image(value) {
|
|
769
|
+
this.setStorageProperty("image", value);
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* The activities that are available in this room.
|
|
773
|
+
*/
|
|
774
|
+
get defaultActivities() {
|
|
775
|
+
let roomMemories = this.getStorageProperty("activities_memory") || {};
|
|
776
|
+
let activities = this.defaultActivityIds.map((id) => {
|
|
777
|
+
let activity = getActivityById(id);
|
|
778
|
+
if (!activity) {
|
|
779
|
+
console.warn(`[NQTR] Activity with id ${id} not found, so it will be ignored.`);
|
|
780
|
+
return void 0;
|
|
781
|
+
}
|
|
782
|
+
let memory = activity.export();
|
|
783
|
+
if (roomMemories && roomMemories[id]) {
|
|
784
|
+
memory = __spreadValues(__spreadValues({}, memory), roomMemories[id]);
|
|
785
|
+
}
|
|
786
|
+
return new ActivityRoom(id, this, activity.onRun, memory);
|
|
787
|
+
}).filter((activity) => activity !== void 0);
|
|
788
|
+
return activities;
|
|
789
|
+
}
|
|
790
|
+
get activityIds() {
|
|
791
|
+
let addedActivityIds = this.getStorageProperty(`addedActivityIds`) || [];
|
|
792
|
+
return this.defaultActivityIds.concat(addedActivityIds);
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* The activities that are available in this room.
|
|
796
|
+
*/
|
|
797
|
+
get activities() {
|
|
798
|
+
let activities = this.activityIds.map((id) => {
|
|
799
|
+
return this.getActivity(id);
|
|
800
|
+
}).filter((activity) => activity !== void 0);
|
|
801
|
+
return activities;
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Get the memory of an activity. This function can be used into olther libraries to get the memory of the activity.
|
|
805
|
+
* @param id The id of the activity.
|
|
806
|
+
* @returns The memory of the activity.
|
|
807
|
+
*/
|
|
808
|
+
getActivityMemory(id) {
|
|
809
|
+
let roomMemories = this.getStorageProperty("activities_memory") || {};
|
|
810
|
+
let roomMemory = roomMemories[id] || {};
|
|
811
|
+
return roomMemory;
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* Get the activity by id.
|
|
815
|
+
* @param id The id of the activity.
|
|
816
|
+
* @returns The room activity.
|
|
817
|
+
*/
|
|
818
|
+
getActivity(id) {
|
|
819
|
+
if (!this.activityIds.includes(id)) {
|
|
820
|
+
console.error(`[NQTR] Activity with id ${id} not found in room ${this.id}`);
|
|
821
|
+
return void 0;
|
|
822
|
+
}
|
|
823
|
+
let activity = getActivityById(id);
|
|
824
|
+
if (!activity) {
|
|
825
|
+
console.error(`[NQTR] Activity with id ${id} not found`);
|
|
826
|
+
return void 0;
|
|
827
|
+
}
|
|
828
|
+
let roomMemories = this.getStorageProperty("activities_memory") || {};
|
|
829
|
+
let roomMemory = roomMemories[id] || {};
|
|
830
|
+
roomMemory = __spreadValues(__spreadValues({}, activity.export()), roomMemory);
|
|
831
|
+
return new ActivityRoom(id, this, activity.onRun, roomMemory);
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Set the memory of an activity. This function can be used into olther libraries to set the memory of the activity.
|
|
835
|
+
* @param id The id of the activity.
|
|
836
|
+
* @param memory The memory of the activity.
|
|
837
|
+
*/
|
|
838
|
+
setActivity(activity) {
|
|
839
|
+
let roomMemories = this.getStorageProperty("activities_memory") || {};
|
|
840
|
+
roomMemories[activity.id] = activity.export();
|
|
841
|
+
this.setStorageProperty("activities_memory", roomMemories);
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Add an activity to the room.
|
|
845
|
+
* @param activity The activity to add.
|
|
846
|
+
*/
|
|
847
|
+
addActivity(activity) {
|
|
848
|
+
if (this.activityIds.includes(activity.id)) {
|
|
849
|
+
let currentActivity = this.getActivity(activity.id);
|
|
850
|
+
if (currentActivity && currentActivity.isExpired()) {
|
|
851
|
+
this.removeActivity(activity.id);
|
|
852
|
+
return;
|
|
853
|
+
} else {
|
|
854
|
+
console.error(`[NQTR] Activity with id ${activity.id} already exists in room ${this.id}, so it will be ignored.`);
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
let addedActivityIds = this.getStorageProperty(`addedActivityIds`) || [];
|
|
859
|
+
addedActivityIds.push(activity.id);
|
|
860
|
+
this.setStorageProperty("addedActivityIds", addedActivityIds);
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* Remove an activity from the room.
|
|
864
|
+
* @param activity The activity to remove.
|
|
865
|
+
*/
|
|
866
|
+
removeActivity(activity) {
|
|
867
|
+
let activityId = typeof activity === "string" ? activity : activity.id;
|
|
868
|
+
if (this.defaultActivityIds.includes(activityId)) {
|
|
869
|
+
console.warn(`[NQTR] Activity with id ${activityId} is a default activity, so it can't be removed. It will be hidden instead.`);
|
|
870
|
+
let activityToEdit = this.getActivity(activityId);
|
|
871
|
+
if (!activityToEdit) {
|
|
872
|
+
console.error(`[NQTR] Activity with id ${activityId} not found, so it can't be hidden.`);
|
|
873
|
+
return;
|
|
874
|
+
}
|
|
875
|
+
activityToEdit.hidden = true;
|
|
876
|
+
return;
|
|
877
|
+
}
|
|
878
|
+
let addedActivityIds = this.getStorageProperty(`addedActivityIds`) || [];
|
|
879
|
+
let index = addedActivityIds.indexOf(activityId);
|
|
880
|
+
if (index === -1) {
|
|
881
|
+
console.error(`[NQTR] Activity with id ${activityId} not found, so it can't be removed.`);
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
addedActivityIds.splice(index, 1);
|
|
885
|
+
this.setStorageProperty("addedActivityIds", addedActivityIds);
|
|
886
|
+
let roomMemories = this.getStorageProperty("activities_memory") || {};
|
|
887
|
+
delete roomMemories[activityId];
|
|
888
|
+
this.setStorageProperty("activities_memory", roomMemories);
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* Clear all expired activities.
|
|
892
|
+
*/
|
|
893
|
+
clearExpiredActivities() {
|
|
894
|
+
this.activities.forEach((activity) => {
|
|
895
|
+
if (activity.isExpired()) {
|
|
896
|
+
this.removeActivity(activity.id);
|
|
897
|
+
}
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
901
|
+
* Whether is disabled. If it is a string, it is a Pixi'VN flag name.
|
|
902
|
+
*/
|
|
903
|
+
get disabled() {
|
|
904
|
+
let value = this.getStorageProperty("disabled") || this.defaultDisabled;
|
|
905
|
+
if (typeof value === "string") {
|
|
906
|
+
return getFlag(value);
|
|
907
|
+
}
|
|
908
|
+
return value;
|
|
909
|
+
}
|
|
910
|
+
set disabled(value) {
|
|
911
|
+
this.setStorageProperty("disabled", value);
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Whether is hidden. If it is a string, it is a Pixi'VN flag name.
|
|
915
|
+
*/
|
|
916
|
+
get hidden() {
|
|
917
|
+
let value = this.getStorageProperty("hidden") || this.defaultHidden;
|
|
918
|
+
if (typeof value === "string") {
|
|
919
|
+
return getFlag(value);
|
|
920
|
+
}
|
|
921
|
+
return value;
|
|
922
|
+
}
|
|
923
|
+
set hidden(value) {
|
|
924
|
+
this.setStorageProperty("hidden", value);
|
|
925
|
+
}
|
|
926
|
+
get icon() {
|
|
927
|
+
return this._icon;
|
|
928
|
+
}
|
|
929
|
+
/**
|
|
930
|
+
* Get the character commitments of the room.
|
|
931
|
+
* @returns The character commitments of the room.
|
|
932
|
+
*/
|
|
933
|
+
getRoutine() {
|
|
934
|
+
let commitments = getCurrentCommitments();
|
|
935
|
+
return commitments.filter((c) => c.room.id === this.id);
|
|
936
|
+
}
|
|
937
|
+
};
|
|
938
|
+
|
|
939
|
+
export { LocationBaseModel, MapBaseModel, RoomBaseModel };
|
|
940
|
+
//# sourceMappingURL=out.js.map
|
|
941
|
+
//# sourceMappingURL=index.mjs.map
|