@drincs/nqtr 0.2.12 → 0.2.13
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-BkHX8xkA.d.ts → ActivityProps-LWY7Zucl.d.ts} +2 -2
- package/dist/{ActivityProps-D45DQdcT.d.mts → ActivityProps-WgXDAYbc.d.mts} +2 -2
- package/dist/{Commitment-DJD0f8AH.d.mts → Commitment-BujJuTv8.d.mts} +7 -7
- package/dist/{Commitment-C_qBgeF9.d.ts → Commitment-DFYAApxl.d.ts} +7 -7
- package/dist/{StageProps-CuE_n1Wg.d.mts → StageProps-CqgBUi3e.d.mts} +1 -1
- package/dist/{StageProps-CCjGI625.d.ts → StageProps-DghO7WaT.d.ts} +1 -1
- package/dist/classes/Activity.d.mts +1 -1
- package/dist/classes/Activity.d.ts +1 -1
- package/dist/classes/Activity.js +1 -381
- package/dist/classes/Activity.js.map +1 -1
- package/dist/classes/Activity.mjs +1 -379
- 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 -398
- package/dist/classes/ActivityStoredAbstract.js.map +1 -1
- package/dist/classes/ActivityStoredAbstract.mjs +1 -396
- 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 +1 -438
- package/dist/classes/Commitment.js.map +1 -1
- package/dist/classes/Commitment.mjs +1 -436
- 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 +1 -1700
- package/dist/classes/index.js.map +1 -1
- package/dist/classes/index.mjs +1 -1691
- 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 -448
- package/dist/classes/navigation/ActivityRoom.js.map +1 -1
- package/dist/classes/navigation/ActivityRoom.mjs +1 -446
- 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/Location.js +1 -118
- package/dist/classes/navigation/Location.js.map +1 -1
- package/dist/classes/navigation/Location.mjs +1 -116
- package/dist/classes/navigation/Location.mjs.map +1 -1
- package/dist/classes/navigation/Map.d.mts +2 -2
- package/dist/classes/navigation/Map.d.ts +2 -2
- package/dist/classes/navigation/Map.js +1 -114
- package/dist/classes/navigation/Map.js.map +1 -1
- package/dist/classes/navigation/Map.mjs +1 -112
- package/dist/classes/navigation/Map.mjs.map +1 -1
- package/dist/classes/navigation/Room.d.mts +2 -2
- package/dist/classes/navigation/Room.d.ts +2 -2
- package/dist/classes/navigation/Room.js +1 -778
- package/dist/classes/navigation/Room.js.map +1 -1
- package/dist/classes/navigation/Room.mjs +1 -773
- package/dist/classes/navigation/Room.mjs.map +1 -1
- package/dist/classes/quest/Goal.js +1 -85
- package/dist/classes/quest/Goal.js.map +1 -1
- package/dist/classes/quest/Goal.mjs +1 -80
- 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 +1 -769
- package/dist/classes/quest/Quest.js.map +1 -1
- package/dist/classes/quest/Quest.mjs +1 -767
- 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 +1 -536
- package/dist/classes/quest/Stage.js.map +1 -1
- package/dist/classes/quest/Stage.mjs +1 -531
- package/dist/classes/quest/Stage.mjs.map +1 -1
- package/dist/constants.d.mts +4 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +2 -0
- package/dist/constants.js.map +1 -0
- package/dist/constants.mjs +2 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/decorators/ActivityDecorator.d.mts +1 -1
- package/dist/decorators/ActivityDecorator.d.ts +1 -1
- package/dist/decorators/ActivityDecorator.js +1 -407
- package/dist/decorators/ActivityDecorator.js.map +1 -1
- package/dist/decorators/ActivityDecorator.mjs +1 -403
- package/dist/decorators/ActivityDecorator.mjs.map +1 -1
- package/dist/decorators/CommitmentDecorator.d.mts +2 -2
- package/dist/decorators/CommitmentDecorator.d.ts +2 -2
- package/dist/decorators/CommitmentDecorator.js +1 -91
- package/dist/decorators/CommitmentDecorator.js.map +1 -1
- package/dist/decorators/CommitmentDecorator.mjs +1 -81
- package/dist/decorators/CommitmentDecorator.mjs.map +1 -1
- package/dist/decorators/QuestDecorator.d.mts +1 -1
- package/dist/decorators/QuestDecorator.d.ts +1 -1
- package/dist/decorators/QuestDecorator.js +1 -799
- package/dist/decorators/QuestDecorator.js.map +1 -1
- package/dist/decorators/QuestDecorator.mjs +1 -794
- 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/RoomDecorator.js +1 -56
- package/dist/decorators/RoomDecorator.js.map +1 -1
- package/dist/decorators/RoomDecorator.mjs +1 -48
- package/dist/decorators/RoomDecorator.mjs.map +1 -1
- package/dist/decorators/index.d.mts +3 -3
- package/dist/decorators/index.d.ts +3 -3
- package/dist/decorators/index.js +1 -1068
- package/dist/decorators/index.js.map +1 -1
- package/dist/decorators/index.mjs +1 -1053
- 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 +1 -53
- package/dist/functions/ActivityFunctions.js.map +1 -1
- package/dist/functions/ActivityFunctions.mjs +1 -50
- 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 +1 -181
- package/dist/functions/NavigationFunctions.js.map +1 -1
- package/dist/functions/NavigationFunctions.mjs +1 -176
- package/dist/functions/NavigationFunctions.mjs.map +1 -1
- package/dist/functions/QuestFunctions.js +1 -20
- package/dist/functions/QuestFunctions.js.map +1 -1
- package/dist/functions/QuestFunctions.mjs +1 -18
- package/dist/functions/QuestFunctions.mjs.map +1 -1
- package/dist/functions/RoutineFunctions.d.mts +4 -4
- package/dist/functions/RoutineFunctions.d.ts +4 -4
- package/dist/functions/RoutineFunctions.js +1 -126
- package/dist/functions/RoutineFunctions.js.map +1 -1
- package/dist/functions/RoutineFunctions.mjs +1 -121
- 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 +1 -293
- package/dist/functions/index.js.map +1 -1
- package/dist/functions/index.mjs +1 -281
- package/dist/functions/index.mjs.map +1 -1
- package/dist/index.d.mts +55 -13
- package/dist/index.d.ts +55 -13
- package/dist/index.js +1 -2058
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -2023
- 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/ActivityProps.js +1 -3
- package/dist/interface/ActivityProps.js.map +1 -1
- package/dist/interface/ActivityProps.mjs +1 -2
- package/dist/interface/ActivityProps.mjs.map +1 -1
- package/dist/interface/CommitmentProps.d.mts +2 -2
- package/dist/interface/CommitmentProps.d.ts +2 -2
- package/dist/interface/CommitmentProps.js +1 -3
- package/dist/interface/CommitmentProps.js.map +1 -1
- package/dist/interface/CommitmentProps.mjs +1 -2
- package/dist/interface/CommitmentProps.mjs.map +1 -1
- package/dist/interface/RoomActivityMemory.d.mts +1 -1
- package/dist/interface/RoomActivityMemory.d.ts +1 -1
- package/dist/interface/RoomActivityMemory.js +1 -3
- package/dist/interface/RoomActivityMemory.js.map +1 -1
- package/dist/interface/RoomActivityMemory.mjs +1 -2
- package/dist/interface/RoomActivityMemory.mjs.map +1 -1
- package/dist/interface/RoomProps.d.mts +2 -2
- package/dist/interface/RoomProps.d.ts +2 -2
- package/dist/interface/RoomProps.js +1 -3
- package/dist/interface/RoomProps.js.map +1 -1
- package/dist/interface/RoomProps.mjs +1 -2
- package/dist/interface/RoomProps.mjs.map +1 -1
- package/dist/interface/index.d.mts +3 -3
- package/dist/interface/index.d.ts +3 -3
- package/dist/interface/index.js +1 -3
- package/dist/interface/index.js.map +1 -1
- package/dist/interface/index.mjs +1 -2
- package/dist/interface/index.mjs.map +1 -1
- package/dist/interface/navigation/LocationProps.d.mts +2 -2
- package/dist/interface/navigation/LocationProps.d.ts +2 -2
- package/dist/interface/navigation/LocationProps.js +1 -3
- package/dist/interface/navigation/LocationProps.js.map +1 -1
- package/dist/interface/navigation/LocationProps.mjs +1 -2
- package/dist/interface/navigation/LocationProps.mjs.map +1 -1
- package/dist/interface/navigation/MapProps.d.mts +2 -2
- package/dist/interface/navigation/MapProps.d.ts +2 -2
- package/dist/interface/navigation/MapProps.js +1 -3
- package/dist/interface/navigation/MapProps.js.map +1 -1
- package/dist/interface/navigation/MapProps.mjs +1 -2
- package/dist/interface/navigation/MapProps.mjs.map +1 -1
- package/dist/interface/quest/GoalProps.js +1 -3
- package/dist/interface/quest/GoalProps.js.map +1 -1
- package/dist/interface/quest/GoalProps.mjs +1 -2
- package/dist/interface/quest/GoalProps.mjs.map +1 -1
- package/dist/interface/quest/QuestProps.d.mts +1 -1
- package/dist/interface/quest/QuestProps.d.ts +1 -1
- package/dist/interface/quest/QuestProps.js +1 -3
- package/dist/interface/quest/QuestProps.js.map +1 -1
- package/dist/interface/quest/QuestProps.mjs +1 -2
- package/dist/interface/quest/QuestProps.mjs.map +1 -1
- package/dist/interface/quest/StageFlags.js +1 -3
- package/dist/interface/quest/StageFlags.js.map +1 -1
- package/dist/interface/quest/StageFlags.mjs +1 -2
- package/dist/interface/quest/StageFlags.mjs.map +1 -1
- package/dist/interface/quest/StageProps.d.mts +1 -1
- package/dist/interface/quest/StageProps.d.ts +1 -1
- package/dist/interface/quest/StageProps.js +1 -3
- package/dist/interface/quest/StageProps.js.map +1 -1
- package/dist/interface/quest/StageProps.mjs +1 -2
- package/dist/interface/quest/StageProps.mjs.map +1 -1
- package/dist/managers/TimeManager.d.mts +30 -31
- package/dist/managers/TimeManager.d.ts +30 -31
- package/dist/managers/TimeManager.js +1 -250
- package/dist/managers/TimeManager.js.map +1 -1
- package/dist/managers/TimeManager.mjs +1 -248
- package/dist/managers/TimeManager.mjs.map +1 -1
- package/dist/managers/index.d.mts +5 -1
- package/dist/managers/index.d.ts +5 -1
- package/dist/managers/index.js +1 -250
- package/dist/managers/index.js.map +1 -1
- package/dist/managers/index.mjs +1 -248
- package/dist/managers/index.mjs.map +1 -1
- package/dist/override/GraphicItemInterface.js +1 -3
- package/dist/override/GraphicItemInterface.js.map +1 -1
- package/dist/override/GraphicItemInterface.mjs +1 -2
- package/dist/override/GraphicItemInterface.mjs.map +1 -1
- package/dist/override/GraphicItemType.d.mts +2 -2
- package/dist/override/GraphicItemType.d.ts +2 -2
- package/dist/override/GraphicItemType.js +1 -3
- package/dist/override/GraphicItemType.js.map +1 -1
- package/dist/override/GraphicItemType.mjs +1 -2
- package/dist/override/GraphicItemType.mjs.map +1 -1
- package/dist/override/NeighboringMapsInterface.js +1 -3
- package/dist/override/NeighboringMapsInterface.js.map +1 -1
- package/dist/override/NeighboringMapsInterface.mjs +1 -2
- package/dist/override/NeighboringMapsInterface.mjs.map +1 -1
- package/dist/override/OnRenderGraphicItemProps.js +1 -3
- package/dist/override/OnRenderGraphicItemProps.js.map +1 -1
- package/dist/override/OnRenderGraphicItemProps.mjs +1 -2
- package/dist/override/OnRenderGraphicItemProps.mjs.map +1 -1
- package/dist/override/OnRunProps.js +1 -3
- package/dist/override/OnRunProps.js.map +1 -1
- package/dist/override/OnRunProps.mjs +1 -2
- package/dist/override/OnRunProps.mjs.map +1 -1
- package/dist/override/OnStartEndStageQuest.js +1 -3
- package/dist/override/OnStartEndStageQuest.js.map +1 -1
- package/dist/override/OnStartEndStageQuest.mjs +1 -2
- package/dist/override/OnStartEndStageQuest.mjs.map +1 -1
- package/dist/override/index.js +1 -3
- package/dist/override/index.js.map +1 -1
- package/dist/override/index.mjs +1 -2
- package/dist/override/index.mjs.map +1 -1
- package/dist/types/ExecutionType.js +1 -3
- package/dist/types/ExecutionType.js.map +1 -1
- package/dist/types/ExecutionType.mjs +1 -2
- package/dist/types/ExecutionType.mjs.map +1 -1
- package/dist/types/OnRunActivityEvent.js +1 -3
- package/dist/types/OnRunActivityEvent.js.map +1 -1
- package/dist/types/OnRunActivityEvent.mjs +1 -2
- package/dist/types/OnRunActivityEvent.mjs.map +1 -1
- package/dist/types/OnRunCommitmentEvent.js +1 -3
- package/dist/types/OnRunCommitmentEvent.js.map +1 -1
- package/dist/types/OnRunCommitmentEvent.mjs +1 -2
- package/dist/types/OnRunCommitmentEvent.mjs.map +1 -1
- package/dist/types/QuestsRequired.d.mts +1 -1
- package/dist/types/QuestsRequired.d.ts +1 -1
- package/dist/types/QuestsRequired.js +1 -3
- package/dist/types/QuestsRequired.js.map +1 -1
- package/dist/types/QuestsRequired.mjs +1 -2
- package/dist/types/QuestsRequired.mjs.map +1 -1
- package/dist/types/TimeDataType.d.mts +6 -0
- package/dist/types/TimeDataType.d.ts +6 -0
- package/dist/types/TimeDataType.js +2 -0
- package/dist/types/TimeDataType.js.map +1 -0
- package/dist/types/TimeDataType.mjs +2 -0
- package/dist/types/TimeDataType.mjs.map +1 -0
- package/dist/types/TimeSettings.d.mts +1 -1
- package/dist/types/TimeSettings.d.ts +1 -1
- package/dist/types/TimeSettings.js +1 -3
- package/dist/types/TimeSettings.js.map +1 -1
- package/dist/types/TimeSettings.mjs +1 -2
- package/dist/types/TimeSettings.mjs.map +1 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +1 -3
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +1 -2
- package/dist/types/index.mjs.map +1 -1
- package/package.json +8 -7
|
@@ -1,1054 +1,2 @@
|
|
|
1
|
-
import { GameStorageManager, getFlag, StoredClassModel } from '@drincs/pixi-vn';
|
|
2
|
-
|
|
3
|
-
// src/classes/Activity.ts
|
|
4
|
-
var TIME_SETTINGS_KEY = "___nqtr-time_manager_settings___";
|
|
5
|
-
var TIME_DATA_KEY = "___nqtr-time_manager_data___";
|
|
6
|
-
var TimeManager = class _TimeManager {
|
|
7
|
-
constructor() {
|
|
8
|
-
}
|
|
9
|
-
static editSettings(settings) {
|
|
10
|
-
let data = {};
|
|
11
|
-
if (typeof settings.minDayHours === "number") {
|
|
12
|
-
data["minDayHours"] = settings.minDayHours;
|
|
13
|
-
}
|
|
14
|
-
if (typeof settings.maxDayHours === "number") {
|
|
15
|
-
data["maxDayHours"] = settings.maxDayHours;
|
|
16
|
-
}
|
|
17
|
-
if (typeof settings.minDayHours === "number") {
|
|
18
|
-
data["defaultTimeSpent"] = settings.defaultTimeSpent;
|
|
19
|
-
}
|
|
20
|
-
if (Array.isArray(settings.timeSlots)) {
|
|
21
|
-
data["timeSlots"] = settings.timeSlots;
|
|
22
|
-
}
|
|
23
|
-
if (typeof settings.weekLength === "number") {
|
|
24
|
-
data["weekLength"] = settings.weekLength;
|
|
25
|
-
}
|
|
26
|
-
if (typeof settings.weekendStartDay === "number") {
|
|
27
|
-
let weekLength = settings.weekLength || _TimeManager.weekLength;
|
|
28
|
-
if (settings.weekendStartDay >= weekLength) {
|
|
29
|
-
console.warn(`[NQTR] Weekend start day should be less than week length ${weekLength}`);
|
|
30
|
-
}
|
|
31
|
-
data["weekendStartDay"] = settings.weekendStartDay;
|
|
32
|
-
}
|
|
33
|
-
if (Array.isArray(settings.weekDaysNames)) {
|
|
34
|
-
let weekLength = settings.weekLength || _TimeManager.weekLength;
|
|
35
|
-
if (settings.weekDaysNames.length !== weekLength) {
|
|
36
|
-
console.warn(`[NQTR] Week days names should be equal to week length ${weekLength}`);
|
|
37
|
-
}
|
|
38
|
-
data["weekDaysNames"] = settings.weekDaysNames;
|
|
39
|
-
}
|
|
40
|
-
GameStorageManager.setVariable(TIME_SETTINGS_KEY, data);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Get time settings
|
|
44
|
-
* @default {}
|
|
45
|
-
*/
|
|
46
|
-
static get settings() {
|
|
47
|
-
let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY) || {};
|
|
48
|
-
return settings;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* 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.
|
|
52
|
-
*/
|
|
53
|
-
static set settings(value) {
|
|
54
|
-
_TimeManager.editSettings(value);
|
|
55
|
-
}
|
|
56
|
-
static get minDayHours() {
|
|
57
|
-
let result = 0;
|
|
58
|
-
let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY);
|
|
59
|
-
if (settings && settings.hasOwnProperty("minDayHours")) {
|
|
60
|
-
result = settings.minDayHours || 0;
|
|
61
|
-
}
|
|
62
|
-
return result;
|
|
63
|
-
}
|
|
64
|
-
static get maxDayHours() {
|
|
65
|
-
let result = 24;
|
|
66
|
-
let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY);
|
|
67
|
-
if (settings && settings.hasOwnProperty("maxDayHours")) {
|
|
68
|
-
result = settings.maxDayHours || 24;
|
|
69
|
-
}
|
|
70
|
-
return result;
|
|
71
|
-
}
|
|
72
|
-
static get defaultTimeSpent() {
|
|
73
|
-
let result = 1;
|
|
74
|
-
let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY);
|
|
75
|
-
if (settings && settings.hasOwnProperty("defaultTimeSpent")) {
|
|
76
|
-
result = settings.defaultTimeSpent || 1;
|
|
77
|
-
}
|
|
78
|
-
return result;
|
|
79
|
-
}
|
|
80
|
-
static get timeSlots() {
|
|
81
|
-
let result = [];
|
|
82
|
-
let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY);
|
|
83
|
-
if (settings && settings.hasOwnProperty("timeSlots")) {
|
|
84
|
-
result = settings.timeSlots || [];
|
|
85
|
-
}
|
|
86
|
-
return result;
|
|
87
|
-
}
|
|
88
|
-
static get weekLength() {
|
|
89
|
-
let result = 7;
|
|
90
|
-
let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY);
|
|
91
|
-
if (settings && settings.hasOwnProperty("weekLength")) {
|
|
92
|
-
result = settings.weekLength || 7;
|
|
93
|
-
}
|
|
94
|
-
return result;
|
|
95
|
-
}
|
|
96
|
-
static get weekendStartDay() {
|
|
97
|
-
let result = _TimeManager.weekLength - 1;
|
|
98
|
-
let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY);
|
|
99
|
-
if (settings && settings.hasOwnProperty("weekendStartDay")) {
|
|
100
|
-
result = settings.weekendStartDay || _TimeManager.weekLength - 1;
|
|
101
|
-
}
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
|
-
static get weekDaysNames() {
|
|
105
|
-
let result = [];
|
|
106
|
-
let settings = GameStorageManager.getVariable(TIME_SETTINGS_KEY);
|
|
107
|
-
if (settings && settings.hasOwnProperty("weekDaysNames")) {
|
|
108
|
-
result = settings.weekDaysNames || result;
|
|
109
|
-
}
|
|
110
|
-
return result;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Get the current hour
|
|
114
|
-
*/
|
|
115
|
-
static get currentHour() {
|
|
116
|
-
let data = GameStorageManager.getVariable(TIME_DATA_KEY) || {};
|
|
117
|
-
if (data.hasOwnProperty("currentHour") && typeof data.currentHour === "number") {
|
|
118
|
-
return data.currentHour;
|
|
119
|
-
}
|
|
120
|
-
return _TimeManager.minDayHours;
|
|
121
|
-
}
|
|
122
|
-
static set currentHour(value) {
|
|
123
|
-
let data = GameStorageManager.getVariable(TIME_DATA_KEY) || {};
|
|
124
|
-
if (typeof value === "number") {
|
|
125
|
-
data.currentHour = value;
|
|
126
|
-
} else {
|
|
127
|
-
delete data.currentHour;
|
|
128
|
-
}
|
|
129
|
-
GameStorageManager.setVariable(TIME_DATA_KEY, data);
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Get the current day
|
|
133
|
-
*/
|
|
134
|
-
static get currentDay() {
|
|
135
|
-
let data = GameStorageManager.getVariable(TIME_DATA_KEY) || {};
|
|
136
|
-
if (data.hasOwnProperty("currentDay") && typeof data.currentDay === "number") {
|
|
137
|
-
return data.currentDay;
|
|
138
|
-
}
|
|
139
|
-
return 0;
|
|
140
|
-
}
|
|
141
|
-
static set currentDay(value) {
|
|
142
|
-
let data = GameStorageManager.getVariable(TIME_DATA_KEY) || {};
|
|
143
|
-
if (typeof value === "number") {
|
|
144
|
-
data.currentDay = value;
|
|
145
|
-
} else {
|
|
146
|
-
delete data.currentDay;
|
|
147
|
-
}
|
|
148
|
-
GameStorageManager.setVariable(TIME_DATA_KEY, data);
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* If the current day is greater than or equal to the weekend start day, then it will return true.
|
|
152
|
-
*/
|
|
153
|
-
static get isWeekend() {
|
|
154
|
-
return _TimeManager.currentWeekDayNumber >= _TimeManager.weekendStartDay;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Get the current week day number (1-TimeManager.weekLength).
|
|
158
|
-
* For example, if the week length is 7 and the current day is 10, then the result will be 4.
|
|
159
|
-
*/
|
|
160
|
-
static get currentWeekDayNumber() {
|
|
161
|
-
let result = _TimeManager.currentDay % _TimeManager.weekLength;
|
|
162
|
-
return result + 1;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Get the current week day name. If the week days names are not defined, then it will return undefined.
|
|
166
|
-
* 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'.
|
|
167
|
-
* @default ""
|
|
168
|
-
*/
|
|
169
|
-
static get currentDayName() {
|
|
170
|
-
let weekDayNumber = _TimeManager.currentWeekDayNumber - 1;
|
|
171
|
-
if (weekDayNumber >= _TimeManager.weekDaysNames.length) {
|
|
172
|
-
console.warn(`[NQTR] Week day name is not defined for day ${weekDayNumber}`, _TimeManager.weekDaysNames);
|
|
173
|
-
return "";
|
|
174
|
-
}
|
|
175
|
-
return _TimeManager.weekDaysNames[weekDayNumber];
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Get the current TimeManager.timeSlots index.
|
|
179
|
-
* You can use this property to create "Image that changes based on the time period":
|
|
180
|
-
* @example
|
|
181
|
-
* ```tsx
|
|
182
|
-
* import { TimeManager } from '@drincs/nqtr';
|
|
183
|
-
*
|
|
184
|
-
* function changeBackground() {
|
|
185
|
-
* return (
|
|
186
|
-
* <img src={`background-${TimeManager.currentTimeSlot}.png`} />
|
|
187
|
-
* )
|
|
188
|
-
* }
|
|
189
|
-
*/
|
|
190
|
-
static get currentTimeSlot() {
|
|
191
|
-
if (_TimeManager.timeSlots.length === 0) {
|
|
192
|
-
console.warn("[NQTR] Time slots are not defined");
|
|
193
|
-
return 0;
|
|
194
|
-
}
|
|
195
|
-
for (let index = 0; index < _TimeManager.timeSlots.length; index++) {
|
|
196
|
-
let slot = _TimeManager.timeSlots[index];
|
|
197
|
-
if (_TimeManager.timeSlots.length > index + 1) {
|
|
198
|
-
if (_TimeManager.nowIsBetween(slot.startHour, _TimeManager.timeSlots[index + 1].startHour)) {
|
|
199
|
-
return index;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
return _TimeManager.timeSlots.length - 1;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* This function will increase the current hour by the given time spent.
|
|
207
|
-
* 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.
|
|
208
|
-
* @param timeSpent is the time spent in hours (default: TimeManager.defaultTimeSpent)
|
|
209
|
-
* @returns TimeManager.currentHour
|
|
210
|
-
*/
|
|
211
|
-
static increaseHour(timeSpent = _TimeManager.defaultTimeSpent) {
|
|
212
|
-
let newHour = _TimeManager.currentHour + timeSpent;
|
|
213
|
-
if (newHour >= _TimeManager.maxDayHours) {
|
|
214
|
-
_TimeManager.increaseDay();
|
|
215
|
-
newHour = _TimeManager.minDayHours + (newHour - _TimeManager.maxDayHours);
|
|
216
|
-
}
|
|
217
|
-
_TimeManager.currentHour = newHour;
|
|
218
|
-
return _TimeManager.currentHour;
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* This function will increase the current day by the given days.
|
|
222
|
-
* @param newDayHour is the hour of the new day (default: TimeManager.minDayHours)
|
|
223
|
-
* @param days is the number of days to increase (default: 1)
|
|
224
|
-
* @returns TimeManager.currentDay
|
|
225
|
-
*/
|
|
226
|
-
static increaseDay(newDayHour = _TimeManager.minDayHours, days = 1) {
|
|
227
|
-
let newDay = _TimeManager.currentDay + days;
|
|
228
|
-
_TimeManager.currentDay = newDay;
|
|
229
|
-
_TimeManager.currentHour = newDayHour;
|
|
230
|
-
return _TimeManager.currentDay;
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* This function will check if the current hour is between the given hours.
|
|
234
|
-
* @param fromHour the starting hour. If the TimeManager.currentHour is equal to this hour, the function will return true.
|
|
235
|
-
* @param toHour the ending hour.
|
|
236
|
-
* @returns true if the current hour is between the given hours, otherwise false.
|
|
237
|
-
*/
|
|
238
|
-
static nowIsBetween(fromHour, toHour) {
|
|
239
|
-
let currentHour = _TimeManager.currentHour;
|
|
240
|
-
if (fromHour < toHour) {
|
|
241
|
-
return currentHour >= fromHour && currentHour < toHour;
|
|
242
|
-
}
|
|
243
|
-
return currentHour >= fromHour || currentHour < toHour;
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
// src/classes/Activity.ts
|
|
248
|
-
var ActivityModel = class {
|
|
249
|
-
/**
|
|
250
|
-
* @param id The activity id, that must be unique.
|
|
251
|
-
* @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.
|
|
252
|
-
* @param props The activity properties.
|
|
253
|
-
*/
|
|
254
|
-
constructor(id, onRun, props) {
|
|
255
|
-
this._id = id;
|
|
256
|
-
this._name = props.name;
|
|
257
|
-
this._fromHour = props.fromHour;
|
|
258
|
-
this._toHour = props.toHour;
|
|
259
|
-
this._fromDay = props.fromDay;
|
|
260
|
-
this._toDay = props.toDay;
|
|
261
|
-
this._disabled = props.disabled || false;
|
|
262
|
-
this._hidden = props.hidden || false;
|
|
263
|
-
this._renderIcon = props.renderIcon;
|
|
264
|
-
this._onRun = onRun;
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* The activity id, that is unique.
|
|
268
|
-
*/
|
|
269
|
-
get id() {
|
|
270
|
-
return this._id;
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* The name
|
|
274
|
-
*/
|
|
275
|
-
get name() {
|
|
276
|
-
return this._name;
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* The hour when the activity starts. If the activity is not started yet, it will be hidden.
|
|
280
|
-
*/
|
|
281
|
-
get fromHour() {
|
|
282
|
-
return this._fromHour;
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* The hour when the activity ends. If the activity is ended yet, it will be hidden.
|
|
286
|
-
*/
|
|
287
|
-
get toHour() {
|
|
288
|
-
return this._toHour;
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* The day when the activity starts. If the activity is not started yet, it will be hidden.
|
|
292
|
-
*/
|
|
293
|
-
get fromDay() {
|
|
294
|
-
return this._fromDay;
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* The day when the activity ends. If the activity is ended yet, it will be deleted or hidden.
|
|
298
|
-
*/
|
|
299
|
-
get toDay() {
|
|
300
|
-
return this._toDay;
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Whether is disabled.
|
|
304
|
-
*/
|
|
305
|
-
get disabled() {
|
|
306
|
-
if (typeof this._disabled === "string") {
|
|
307
|
-
return getFlag(this._disabled);
|
|
308
|
-
}
|
|
309
|
-
return this._disabled;
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Whether is hidden. If the activity is not started yet, it will be hidden.
|
|
313
|
-
*/
|
|
314
|
-
get hidden() {
|
|
315
|
-
if (this.fromDay && this.fromDay > TimeManager.currentDay) {
|
|
316
|
-
return true;
|
|
317
|
-
}
|
|
318
|
-
if (!this.isDeadline) {
|
|
319
|
-
return true;
|
|
320
|
-
}
|
|
321
|
-
if (typeof this._hidden === "string") {
|
|
322
|
-
return getFlag(this._hidden);
|
|
323
|
-
}
|
|
324
|
-
return this._hidden;
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* The function for rendering the icon of the activity.
|
|
328
|
-
*/
|
|
329
|
-
get renderIcon() {
|
|
330
|
-
let render = this._renderIcon;
|
|
331
|
-
if (render === void 0) {
|
|
332
|
-
return void 0;
|
|
333
|
-
}
|
|
334
|
-
if (typeof render === "function") {
|
|
335
|
-
return (props) => {
|
|
336
|
-
return render(this, props);
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
return (props) => render;
|
|
340
|
-
}
|
|
341
|
-
get _initialOnRun() {
|
|
342
|
-
return this._onRun;
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* The function that is called when the activity is runned.
|
|
346
|
-
*/
|
|
347
|
-
get run() {
|
|
348
|
-
return (props) => this._onRun(this, props);
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Whether the activity is a deadline.
|
|
352
|
-
* @returns Whether the activity is a deadline.
|
|
353
|
-
*/
|
|
354
|
-
isDeadline() {
|
|
355
|
-
if (this.toDay && this.toDay <= TimeManager.currentDay) {
|
|
356
|
-
return true;
|
|
357
|
-
}
|
|
358
|
-
return false;
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
361
|
-
* Export the activity properties.
|
|
362
|
-
* @returns The activity properties.
|
|
363
|
-
*/
|
|
364
|
-
export() {
|
|
365
|
-
return {
|
|
366
|
-
name: this._name,
|
|
367
|
-
fromHour: this._fromHour,
|
|
368
|
-
toHour: this._toHour,
|
|
369
|
-
fromDay: this._fromDay,
|
|
370
|
-
toDay: this._toDay,
|
|
371
|
-
disabled: this._disabled,
|
|
372
|
-
hidden: this._hidden,
|
|
373
|
-
renderIcon: this._renderIcon
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
// src/decorators/ActivityDecorator.ts
|
|
379
|
-
var registeredActivities = {};
|
|
380
|
-
function newActivity(id, onRun, props) {
|
|
381
|
-
if (registeredActivities[id]) {
|
|
382
|
-
console.warn(`[NQTR] Activity ${id} already exists, it will be overwritten`);
|
|
383
|
-
}
|
|
384
|
-
let activity = new ActivityModel(id, onRun, props);
|
|
385
|
-
registeredActivities[id] = activity;
|
|
386
|
-
return activity;
|
|
387
|
-
}
|
|
388
|
-
function getActivityById(id) {
|
|
389
|
-
try {
|
|
390
|
-
let activity = registeredActivities[id];
|
|
391
|
-
if (!activity) {
|
|
392
|
-
console.error(`[NQTR] Activity ${id} not found`);
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
395
|
-
return activity;
|
|
396
|
-
} catch (e) {
|
|
397
|
-
console.error(`[NQTR] Error while getting Activity ${id}`, e);
|
|
398
|
-
return;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
var TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY = "___nqtr-temporary_commitment___";
|
|
402
|
-
var registeredCommitments = {};
|
|
403
|
-
var fixedCommitments = {};
|
|
404
|
-
function saveCommitment(commitment) {
|
|
405
|
-
if (Array.isArray(commitment)) {
|
|
406
|
-
commitment.forEach((c) => saveCommitment(c));
|
|
407
|
-
return;
|
|
408
|
-
}
|
|
409
|
-
if (registeredCommitments[commitment.id]) {
|
|
410
|
-
console.warn(`[NQTR] Commitment id ${commitment.id} already exists, it will be overwritten`);
|
|
411
|
-
}
|
|
412
|
-
registeredCommitments[commitment.id] = commitment;
|
|
413
|
-
}
|
|
414
|
-
function getCommitmentById(id) {
|
|
415
|
-
try {
|
|
416
|
-
let commitment = registeredCommitments[id];
|
|
417
|
-
if (!commitment) {
|
|
418
|
-
console.error(`[NQTR] Commitment ${id} not found`);
|
|
419
|
-
return;
|
|
420
|
-
}
|
|
421
|
-
return commitment;
|
|
422
|
-
} catch (e) {
|
|
423
|
-
console.error(`[NQTR] Error while getting Commitment ${id}`, e);
|
|
424
|
-
return;
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
function setFixedRoutine(commitments) {
|
|
428
|
-
if (Array.isArray(commitments)) {
|
|
429
|
-
commitments.forEach((c) => setFixedRoutine(c));
|
|
430
|
-
return;
|
|
431
|
-
}
|
|
432
|
-
if (fixedCommitments[commitments.id]) {
|
|
433
|
-
console.warn(`[NQTR] Commitment id ${commitments.id} already exists, it will be overwritten`);
|
|
434
|
-
}
|
|
435
|
-
fixedCommitments[commitments.id] = commitments;
|
|
436
|
-
}
|
|
437
|
-
function addCommitment(commitment) {
|
|
438
|
-
if (!Array.isArray(commitment)) {
|
|
439
|
-
commitment = [commitment];
|
|
440
|
-
}
|
|
441
|
-
let commitmentsIds = commitment.map((commitment2) => {
|
|
442
|
-
let commitmentTest = getCommitmentById(commitment2.id);
|
|
443
|
-
if (!commitmentTest) {
|
|
444
|
-
console.warn(`[NQTR] Commitment ${commitment2.id} not found, it will be ignored`);
|
|
445
|
-
return void 0;
|
|
446
|
-
}
|
|
447
|
-
return commitment2.id;
|
|
448
|
-
}).filter((id) => id !== void 0);
|
|
449
|
-
GameStorageManager.setVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY, commitmentsIds);
|
|
450
|
-
}
|
|
451
|
-
function removeCommitment(commitment) {
|
|
452
|
-
if (!Array.isArray(commitment)) {
|
|
453
|
-
commitment = [commitment];
|
|
454
|
-
}
|
|
455
|
-
let commitmentsIds = commitment.map((commitment2) => {
|
|
456
|
-
return commitment2.id;
|
|
457
|
-
});
|
|
458
|
-
let currentCommitments = GameStorageManager.getVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY);
|
|
459
|
-
if (!currentCommitments) {
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
462
|
-
currentCommitments = currentCommitments.filter((id) => !commitmentsIds.includes(id));
|
|
463
|
-
GameStorageManager.setVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY, currentCommitments);
|
|
464
|
-
}
|
|
465
|
-
var GOAL_CATEGORY = "__nqtr-goal__";
|
|
466
|
-
var Goal = class extends StoredClassModel {
|
|
467
|
-
constructor(id, props) {
|
|
468
|
-
super(GOAL_CATEGORY, id);
|
|
469
|
-
this._description = props.description;
|
|
470
|
-
this._need = props.need || 1;
|
|
471
|
-
this._defaultHave = props.have || 0;
|
|
472
|
-
}
|
|
473
|
-
/**
|
|
474
|
-
* The description of the goal.
|
|
475
|
-
*/
|
|
476
|
-
get description() {
|
|
477
|
-
return this._description;
|
|
478
|
-
}
|
|
479
|
-
/**
|
|
480
|
-
* The number of times the goal must be completed.
|
|
481
|
-
*/
|
|
482
|
-
get need() {
|
|
483
|
-
return this._need;
|
|
484
|
-
}
|
|
485
|
-
/**
|
|
486
|
-
* The default number of times the goal has been completed.
|
|
487
|
-
*/
|
|
488
|
-
get defaultHave() {
|
|
489
|
-
return this._defaultHave;
|
|
490
|
-
}
|
|
491
|
-
};
|
|
492
|
-
var GoalStage = class extends Goal {
|
|
493
|
-
constructor(id, stageId, props) {
|
|
494
|
-
super(id, props);
|
|
495
|
-
this._stageId = stageId;
|
|
496
|
-
}
|
|
497
|
-
/**
|
|
498
|
-
* The id of the stage that the goal belongs to.
|
|
499
|
-
*/
|
|
500
|
-
get stageId() {
|
|
501
|
-
return this._stageId;
|
|
502
|
-
}
|
|
503
|
-
set stageId(value) {
|
|
504
|
-
this._stageId = value;
|
|
505
|
-
}
|
|
506
|
-
/**
|
|
507
|
-
* The number of times the goal has been completed.
|
|
508
|
-
*/
|
|
509
|
-
get have() {
|
|
510
|
-
return this.getStorageProperty("have-" + this._stageId) || this.defaultHave;
|
|
511
|
-
}
|
|
512
|
-
set have(value) {
|
|
513
|
-
if (!this._stageId) {
|
|
514
|
-
console.error(`[NQTR] The stage id is not set for the goal ${this.id}, so the have value can't be set.`);
|
|
515
|
-
return;
|
|
516
|
-
}
|
|
517
|
-
this.setStorageProperty("have-" + this._stageId, value);
|
|
518
|
-
}
|
|
519
|
-
/**
|
|
520
|
-
* If the goal is completed.
|
|
521
|
-
*/
|
|
522
|
-
get completed() {
|
|
523
|
-
return this.have >= this.need;
|
|
524
|
-
}
|
|
525
|
-
set completed(value) {
|
|
526
|
-
if (value) {
|
|
527
|
-
this.have = this.need;
|
|
528
|
-
} else {
|
|
529
|
-
console.warn(`[NQTR] The goal can't be set as not completed. You must edit the have value manually.`);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
/**
|
|
533
|
-
* Find the goal. It will increment the have value.
|
|
534
|
-
*/
|
|
535
|
-
find() {
|
|
536
|
-
this.have++;
|
|
537
|
-
}
|
|
538
|
-
};
|
|
539
|
-
|
|
540
|
-
// src/classes/quest/Stage.ts
|
|
541
|
-
var STAGE_CATEGORY = "__nqtr-stage__";
|
|
542
|
-
var Stage = class extends StoredClassModel {
|
|
543
|
-
constructor(id, props) {
|
|
544
|
-
super(STAGE_CATEGORY, id);
|
|
545
|
-
this._name = props.name || "";
|
|
546
|
-
this._defaultGoals = props.goals || [];
|
|
547
|
-
this._flags = props.flags || [];
|
|
548
|
-
this._description = props.description || "";
|
|
549
|
-
this._adviceDescription = props.adviceDescription || "";
|
|
550
|
-
this._renderImage = props.renderImage;
|
|
551
|
-
this._daysRequiredToStart = props.daysRequiredToStart;
|
|
552
|
-
this._flagsRequiredToStart = props.flagsRequiredToStart || [];
|
|
553
|
-
this._questsRequiredToStart = props.questsRequiredToStart || [];
|
|
554
|
-
this._requestDescriptionToStart = props.requestDescriptionToStart || "";
|
|
555
|
-
this._onStart = props.onStart;
|
|
556
|
-
this._onEnd = props.onEnd;
|
|
557
|
-
}
|
|
558
|
-
/**
|
|
559
|
-
* The name of the stage.
|
|
560
|
-
*/
|
|
561
|
-
get name() {
|
|
562
|
-
return this._name;
|
|
563
|
-
}
|
|
564
|
-
/**
|
|
565
|
-
* The description of the stage.
|
|
566
|
-
*/
|
|
567
|
-
get description() {
|
|
568
|
-
return this._description;
|
|
569
|
-
}
|
|
570
|
-
/**
|
|
571
|
-
* The advice description of the stage.
|
|
572
|
-
*/
|
|
573
|
-
get adviceDescription() {
|
|
574
|
-
return this._adviceDescription;
|
|
575
|
-
}
|
|
576
|
-
/**
|
|
577
|
-
* The function for rendering the image of the stage.
|
|
578
|
-
*/
|
|
579
|
-
get renderImage() {
|
|
580
|
-
let render = this._renderImage;
|
|
581
|
-
if (render === void 0) {
|
|
582
|
-
return void 0;
|
|
583
|
-
}
|
|
584
|
-
if (typeof render === "function") {
|
|
585
|
-
return (props) => {
|
|
586
|
-
return render(this, props);
|
|
587
|
-
};
|
|
588
|
-
}
|
|
589
|
-
return (props) => render;
|
|
590
|
-
}
|
|
591
|
-
/**
|
|
592
|
-
* The list of goals that the player needs to complete to finish the stage.
|
|
593
|
-
* This is the list set by the developer. if you want to get the current goals, use the goals property.
|
|
594
|
-
*/
|
|
595
|
-
get defaultGoals() {
|
|
596
|
-
return this._defaultGoals;
|
|
597
|
-
}
|
|
598
|
-
/**
|
|
599
|
-
* The list of flags that the player must complete to finish the stage.
|
|
600
|
-
*/
|
|
601
|
-
get flags() {
|
|
602
|
-
return this._flags;
|
|
603
|
-
}
|
|
604
|
-
/**
|
|
605
|
-
* The number of days required to start the stage.
|
|
606
|
-
*/
|
|
607
|
-
get daysRequiredToStart() {
|
|
608
|
-
return this._daysRequiredToStart || 0;
|
|
609
|
-
}
|
|
610
|
-
/**
|
|
611
|
-
* The list of flags required to start the stage.
|
|
612
|
-
*/
|
|
613
|
-
get flagsRequiredToStart() {
|
|
614
|
-
return this._flagsRequiredToStart;
|
|
615
|
-
}
|
|
616
|
-
/**
|
|
617
|
-
* The list of quests required to start the stage.
|
|
618
|
-
*/
|
|
619
|
-
get questsRequiredToStart() {
|
|
620
|
-
return this._questsRequiredToStart || [];
|
|
621
|
-
}
|
|
622
|
-
/**
|
|
623
|
-
* The description of the request to start the stage.
|
|
624
|
-
*/
|
|
625
|
-
get requestDescriptionToStart() {
|
|
626
|
-
return this._requestDescriptionToStart;
|
|
627
|
-
}
|
|
628
|
-
/**
|
|
629
|
-
* The function that will be called when the stage starts.
|
|
630
|
-
*/
|
|
631
|
-
get onStart() {
|
|
632
|
-
return this._onStart;
|
|
633
|
-
}
|
|
634
|
-
/**
|
|
635
|
-
* The function that will be called when the stage ends.
|
|
636
|
-
*/
|
|
637
|
-
get onEnd() {
|
|
638
|
-
return this._onEnd;
|
|
639
|
-
}
|
|
640
|
-
};
|
|
641
|
-
var StageQuest = class extends Stage {
|
|
642
|
-
constructor(id, props) {
|
|
643
|
-
super(id, props);
|
|
644
|
-
}
|
|
645
|
-
/**
|
|
646
|
-
* Check if the flag and goals are completed.
|
|
647
|
-
* You can force the completion of the stage by setting the completed property to true.
|
|
648
|
-
*/
|
|
649
|
-
get completed() {
|
|
650
|
-
let storedCompleted = this.getStorageProperty("completed");
|
|
651
|
-
if (storedCompleted) {
|
|
652
|
-
return storedCompleted;
|
|
653
|
-
}
|
|
654
|
-
if (this.flags.length > 0 && this.goals.length > 0) {
|
|
655
|
-
if (!this.flags.every((flag) => getFlag(flag.flag))) {
|
|
656
|
-
return false;
|
|
657
|
-
}
|
|
658
|
-
if (!this.goals.every((goal) => goal.completed)) {
|
|
659
|
-
return false;
|
|
660
|
-
}
|
|
661
|
-
return true;
|
|
662
|
-
}
|
|
663
|
-
return false;
|
|
664
|
-
}
|
|
665
|
-
set completed(value) {
|
|
666
|
-
this.setStorageProperty("completed", value);
|
|
667
|
-
}
|
|
668
|
-
/**
|
|
669
|
-
* If the stage is started.
|
|
670
|
-
*/
|
|
671
|
-
get started() {
|
|
672
|
-
return this.getStorageProperty("started") || false;
|
|
673
|
-
}
|
|
674
|
-
set started(value) {
|
|
675
|
-
this.setStorageProperty("started", value);
|
|
676
|
-
}
|
|
677
|
-
/**
|
|
678
|
-
* The list of goals that the player needs to complete to finish the stage.
|
|
679
|
-
*/
|
|
680
|
-
get goals() {
|
|
681
|
-
return this.defaultGoals.map((goal) => {
|
|
682
|
-
return new GoalStage(goal.id, this.id, goal);
|
|
683
|
-
});
|
|
684
|
-
}
|
|
685
|
-
get prevStageEndDay() {
|
|
686
|
-
return this.getStorageProperty("prevStageEndDay");
|
|
687
|
-
}
|
|
688
|
-
set prevStageEndDay(value) {
|
|
689
|
-
this.setStorageProperty("prevStageEndDay", value);
|
|
690
|
-
}
|
|
691
|
-
/**
|
|
692
|
-
* The day when the stage starts.
|
|
693
|
-
*/
|
|
694
|
-
get startDay() {
|
|
695
|
-
let prevStageEndDay = this.prevStageEndDay;
|
|
696
|
-
if (prevStageEndDay === void 0) {
|
|
697
|
-
return void 0;
|
|
698
|
-
}
|
|
699
|
-
return prevStageEndDay + this.daysRequiredToStart;
|
|
700
|
-
}
|
|
701
|
-
/**
|
|
702
|
-
* Check if the stage can start.
|
|
703
|
-
*/
|
|
704
|
-
get canStart() {
|
|
705
|
-
let daysRequired = this.daysRequiredToStart;
|
|
706
|
-
if (daysRequired > 0) {
|
|
707
|
-
let prevStageEndDay = this.prevStageEndDay;
|
|
708
|
-
if (prevStageEndDay === void 0) {
|
|
709
|
-
return false;
|
|
710
|
-
}
|
|
711
|
-
if (prevStageEndDay + daysRequired > TimeManager.currentDay) {
|
|
712
|
-
return false;
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
if (this.flagsRequiredToStart.length > 0 && !this.flagsRequiredToStart.every((flag) => getFlag(flag.flag))) {
|
|
716
|
-
return false;
|
|
717
|
-
}
|
|
718
|
-
if (this.questsRequiredToStart.length > 0 && !this.questsRequiredToStart.every(
|
|
719
|
-
(q) => q.quest.currentStageIndex && q.quest.currentStageIndex >= q.stageNumber
|
|
720
|
-
)) {
|
|
721
|
-
return false;
|
|
722
|
-
}
|
|
723
|
-
return true;
|
|
724
|
-
}
|
|
725
|
-
/**
|
|
726
|
-
* Inizialize the stage. **This function should be called only by the Quest class.**
|
|
727
|
-
*/
|
|
728
|
-
inizialize() {
|
|
729
|
-
if (this.daysRequiredToStart > 0) {
|
|
730
|
-
this.prevStageEndDay = TimeManager.currentDay;
|
|
731
|
-
console.log(`[NQTR] Stage ${this.id} will start on day ${this.startDay}`);
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
/**
|
|
735
|
-
* The function that will be called when the stage starts.
|
|
736
|
-
*/
|
|
737
|
-
start(props) {
|
|
738
|
-
if (this.canStart) {
|
|
739
|
-
this.started = true;
|
|
740
|
-
if (this.onStart) {
|
|
741
|
-
this.onStart(this, props);
|
|
742
|
-
}
|
|
743
|
-
} else {
|
|
744
|
-
console.warn(`[NQTR] Stage ${this.id} can't start`);
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
};
|
|
748
|
-
|
|
749
|
-
// src/classes/quest/Quest.ts
|
|
750
|
-
var QUEST_CATEGORY = "__nqtr-quest__";
|
|
751
|
-
var Quest = class extends StoredClassModel {
|
|
752
|
-
constructor(id, stages, props) {
|
|
753
|
-
super(QUEST_CATEGORY, id);
|
|
754
|
-
this._stages = stages;
|
|
755
|
-
this._name = props.name || "";
|
|
756
|
-
this._description = props.description || "";
|
|
757
|
-
this._renderIcon = props.renderIcon;
|
|
758
|
-
this._renderImage = props.renderImage;
|
|
759
|
-
this._isInDevelopment = props.isInDevelopment || false;
|
|
760
|
-
this._onStart = props.onStart;
|
|
761
|
-
this._onNextStage = props.onNextStage;
|
|
762
|
-
}
|
|
763
|
-
/**
|
|
764
|
-
* The stages of the quest.
|
|
765
|
-
*/
|
|
766
|
-
get stages() {
|
|
767
|
-
return this._stages.map((stage, index) => {
|
|
768
|
-
return new StageQuest(stage.id, stage);
|
|
769
|
-
});
|
|
770
|
-
}
|
|
771
|
-
/**
|
|
772
|
-
* The name of the quest.
|
|
773
|
-
*/
|
|
774
|
-
get name() {
|
|
775
|
-
return this._name;
|
|
776
|
-
}
|
|
777
|
-
/**
|
|
778
|
-
* The description of the quest.
|
|
779
|
-
*/
|
|
780
|
-
get description() {
|
|
781
|
-
return this._description;
|
|
782
|
-
}
|
|
783
|
-
/**
|
|
784
|
-
* The function for rendering the icon of the quest.
|
|
785
|
-
*/
|
|
786
|
-
get renderIcon() {
|
|
787
|
-
let render = this._renderIcon;
|
|
788
|
-
if (render === void 0) {
|
|
789
|
-
return void 0;
|
|
790
|
-
}
|
|
791
|
-
if (typeof render === "function") {
|
|
792
|
-
return (props) => {
|
|
793
|
-
return render(this, props);
|
|
794
|
-
};
|
|
795
|
-
}
|
|
796
|
-
return (props) => render;
|
|
797
|
-
}
|
|
798
|
-
/**
|
|
799
|
-
* The function for rendering the image of the quest.
|
|
800
|
-
*/
|
|
801
|
-
get renderImage() {
|
|
802
|
-
let render = this._renderImage;
|
|
803
|
-
if (render === void 0) {
|
|
804
|
-
return void 0;
|
|
805
|
-
}
|
|
806
|
-
if (typeof render === "function") {
|
|
807
|
-
return (props) => {
|
|
808
|
-
return render(this, props);
|
|
809
|
-
};
|
|
810
|
-
}
|
|
811
|
-
return (props) => render;
|
|
812
|
-
}
|
|
813
|
-
/**
|
|
814
|
-
* If the quest is in development.
|
|
815
|
-
*/
|
|
816
|
-
get isInDevelopment() {
|
|
817
|
-
return this._isInDevelopment;
|
|
818
|
-
}
|
|
819
|
-
/**
|
|
820
|
-
* The index of the current stage.
|
|
821
|
-
*/
|
|
822
|
-
get currentStageIndex() {
|
|
823
|
-
return this.getStorageProperty("currentStageIndex");
|
|
824
|
-
}
|
|
825
|
-
set currentStageIndex(value) {
|
|
826
|
-
this.setStorageProperty("currentStageIndex", value);
|
|
827
|
-
}
|
|
828
|
-
/**
|
|
829
|
-
* The current stage.
|
|
830
|
-
*/
|
|
831
|
-
get currentStage() {
|
|
832
|
-
let index = this.currentStageIndex;
|
|
833
|
-
if (index === void 0 || index >= this.stages.length) {
|
|
834
|
-
return void 0;
|
|
835
|
-
}
|
|
836
|
-
return this.stages[index];
|
|
837
|
-
}
|
|
838
|
-
/**
|
|
839
|
-
* If the quest is started.
|
|
840
|
-
*/
|
|
841
|
-
get started() {
|
|
842
|
-
return this.currentStageIndex !== void 0;
|
|
843
|
-
}
|
|
844
|
-
/**
|
|
845
|
-
* If the quest is completed.
|
|
846
|
-
*/
|
|
847
|
-
get completed() {
|
|
848
|
-
if (this.currentStageIndex === void 0) {
|
|
849
|
-
return false;
|
|
850
|
-
}
|
|
851
|
-
return this.currentStageIndex > this.stages.length - 1;
|
|
852
|
-
}
|
|
853
|
-
/**
|
|
854
|
-
* The function that will be called when the quest starts.
|
|
855
|
-
*/
|
|
856
|
-
get onStart() {
|
|
857
|
-
return this._onStart;
|
|
858
|
-
}
|
|
859
|
-
/**
|
|
860
|
-
* The function that will be called when the quest goes to the next stage.
|
|
861
|
-
*/
|
|
862
|
-
get onNextStage() {
|
|
863
|
-
return this._onNextStage;
|
|
864
|
-
}
|
|
865
|
-
/**
|
|
866
|
-
* Start the quest.
|
|
867
|
-
* @param props The properties for the start stage. If you not want to pass any property, you can pass an {}.
|
|
868
|
-
* @returns
|
|
869
|
-
*/
|
|
870
|
-
start(props) {
|
|
871
|
-
if (this.started) {
|
|
872
|
-
console.warn(`[NQTR] Quest ${this.id} is already started`);
|
|
873
|
-
return;
|
|
874
|
-
}
|
|
875
|
-
if (this.stages.length === 0) {
|
|
876
|
-
console.error(`[NQTR] Quest ${this.id} has no stages`);
|
|
877
|
-
return;
|
|
878
|
-
}
|
|
879
|
-
this.currentStageIndex = 0;
|
|
880
|
-
let currentStage = this.currentStage;
|
|
881
|
-
if (currentStage && currentStage.start) {
|
|
882
|
-
this.onStart && this.onStart(this, props);
|
|
883
|
-
return currentStage.start(props);
|
|
884
|
-
} else {
|
|
885
|
-
console.error(`[NQTR] Quest ${this.id} has no start stage`);
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
/**
|
|
889
|
-
* Go to the next stage if the current stage is completed.
|
|
890
|
-
* If you want to force the change of stage, use goNextStage.
|
|
891
|
-
* @param props The properties. If you not want to pass any property, you can pass an {}.
|
|
892
|
-
* @returns true if the stage was changed, false otherwise.
|
|
893
|
-
*/
|
|
894
|
-
tryToGoNextStage(props) {
|
|
895
|
-
if (!this.started) {
|
|
896
|
-
return false;
|
|
897
|
-
}
|
|
898
|
-
if (this.completed) {
|
|
899
|
-
return false;
|
|
900
|
-
}
|
|
901
|
-
let currentStage = this.currentStage;
|
|
902
|
-
if (!currentStage) {
|
|
903
|
-
console.error(`[NQTR] Quest ${this.id} has no current stage`);
|
|
904
|
-
return false;
|
|
905
|
-
}
|
|
906
|
-
if (currentStage.completed) {
|
|
907
|
-
return this.goNextStage(props);
|
|
908
|
-
}
|
|
909
|
-
return false;
|
|
910
|
-
}
|
|
911
|
-
/**
|
|
912
|
-
* Complete the current stage and go to the next stage.
|
|
913
|
-
* If you want to go to the next stage only if the current stage is completed, use tryToGoNextStage.
|
|
914
|
-
* @param props The properties. If you not want to pass any property, you can pass an {}.
|
|
915
|
-
* @returns true if the stage was changed, false otherwise.
|
|
916
|
-
*/
|
|
917
|
-
completeCurrentStageAndGoNext(props) {
|
|
918
|
-
let currentStage = this.currentStage;
|
|
919
|
-
if (!currentStage) {
|
|
920
|
-
console.error(`[NQTR] Quest ${this.id} has no current stage`);
|
|
921
|
-
return false;
|
|
922
|
-
}
|
|
923
|
-
currentStage.completed = true;
|
|
924
|
-
return this.goNextStage(props);
|
|
925
|
-
}
|
|
926
|
-
/**
|
|
927
|
-
* Go to the next stage without checking if the current stage is completed.
|
|
928
|
-
* If you want to go to the next stage only if the current stage is completed, use tryToGoNextStage.
|
|
929
|
-
* @param props The properties. If you not want to pass any property, you can pass an {}.
|
|
930
|
-
* @returns returns true if the stage was changed, false otherwise.
|
|
931
|
-
*/
|
|
932
|
-
goNextStage(props) {
|
|
933
|
-
if (!this.started) {
|
|
934
|
-
console.warn(`[NQTR] Quest ${this.id} is not started`);
|
|
935
|
-
return false;
|
|
936
|
-
}
|
|
937
|
-
if (this.completed) {
|
|
938
|
-
console.warn(`[NQTR] Quest ${this.id} is already completed`);
|
|
939
|
-
return false;
|
|
940
|
-
}
|
|
941
|
-
let prevStage = this.currentStage;
|
|
942
|
-
let currentStageIndex = this.currentStageIndex;
|
|
943
|
-
if (!prevStage || currentStageIndex === void 0) {
|
|
944
|
-
console.error(`[NQTR] Quest ${this.id} has no current stage`);
|
|
945
|
-
return false;
|
|
946
|
-
}
|
|
947
|
-
this.currentStageIndex = currentStageIndex + 1;
|
|
948
|
-
this.onNextStage && this.onNextStage(this, props);
|
|
949
|
-
if (prevStage && prevStage.onEnd) {
|
|
950
|
-
prevStage.onEnd(prevStage, props);
|
|
951
|
-
}
|
|
952
|
-
let nextCurrentStage = this.currentStage;
|
|
953
|
-
if (nextCurrentStage) {
|
|
954
|
-
nextCurrentStage.inizialize();
|
|
955
|
-
if (this.currentStageMustStart) {
|
|
956
|
-
this.startCurrentStage(props);
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
return true;
|
|
960
|
-
}
|
|
961
|
-
/**
|
|
962
|
-
* If the current stage must start. It is true if the current stage is not started, can start and not completed.
|
|
963
|
-
*/
|
|
964
|
-
get currentStageMustStart() {
|
|
965
|
-
let currentStage = this.currentStage;
|
|
966
|
-
if (!currentStage) {
|
|
967
|
-
return false;
|
|
968
|
-
}
|
|
969
|
-
return !currentStage.started && currentStage.canStart && !currentStage.completed;
|
|
970
|
-
}
|
|
971
|
-
/**
|
|
972
|
-
* Start the current stage.
|
|
973
|
-
* @param props The properties for the start stage. If you not want to pass any property, you can pass an {}.
|
|
974
|
-
*/
|
|
975
|
-
startCurrentStage(props) {
|
|
976
|
-
let newCurrentStage = this.currentStage;
|
|
977
|
-
if (newCurrentStage && this.currentStageMustStart) {
|
|
978
|
-
newCurrentStage.start(props);
|
|
979
|
-
} else {
|
|
980
|
-
console.warn(`[NQTR] Quest ${this.id} can't start the current stage`);
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
};
|
|
984
|
-
|
|
985
|
-
// src/decorators/QuestDecorator.ts
|
|
986
|
-
var registeredQuests = {};
|
|
987
|
-
function newQuest(id, stages, props) {
|
|
988
|
-
if (registeredQuests[id]) {
|
|
989
|
-
console.warn(`[NQTR] Quest ${id} already exists, it will be overwritten`);
|
|
990
|
-
}
|
|
991
|
-
let quest = new Quest(id, stages, props);
|
|
992
|
-
registeredQuests[id] = quest;
|
|
993
|
-
return quest;
|
|
994
|
-
}
|
|
995
|
-
function getQuestById(id) {
|
|
996
|
-
try {
|
|
997
|
-
let quest = registeredQuests[id];
|
|
998
|
-
if (!quest) {
|
|
999
|
-
console.error(`[NQTR] Quest ${id} not found`);
|
|
1000
|
-
return;
|
|
1001
|
-
}
|
|
1002
|
-
return quest;
|
|
1003
|
-
} catch (e) {
|
|
1004
|
-
console.error(`[NQTR] Error while getting Quest ${id}`, e);
|
|
1005
|
-
return;
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
function getAllStartedQuests() {
|
|
1009
|
-
return Object.values(registeredQuests).filter((quest) => quest.started);
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
// src/decorators/RoomDecorator.ts
|
|
1013
|
-
var registeredRooms = {};
|
|
1014
|
-
function saveRoom(room) {
|
|
1015
|
-
if (Array.isArray(room)) {
|
|
1016
|
-
room.forEach((c) => saveRoom(c));
|
|
1017
|
-
return;
|
|
1018
|
-
}
|
|
1019
|
-
if (registeredRooms[room.id]) {
|
|
1020
|
-
console.warn(`[NQTR] Room id ${room.id} already exists, it will be overwritten`);
|
|
1021
|
-
}
|
|
1022
|
-
registeredRooms[room.id] = room;
|
|
1023
|
-
}
|
|
1024
|
-
function getRoomById(id) {
|
|
1025
|
-
try {
|
|
1026
|
-
let room = registeredRooms[id];
|
|
1027
|
-
if (!room) {
|
|
1028
|
-
console.error(`[NQTR] Room ${id} not found`);
|
|
1029
|
-
return;
|
|
1030
|
-
}
|
|
1031
|
-
return room;
|
|
1032
|
-
} catch (e) {
|
|
1033
|
-
console.error(`[NQTR] Error while getting Room ${id}`, e);
|
|
1034
|
-
return;
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
function getAllLocations() {
|
|
1038
|
-
let result = {};
|
|
1039
|
-
Object.values(registeredRooms).forEach((room) => {
|
|
1040
|
-
result[room.location.id] = room.location;
|
|
1041
|
-
});
|
|
1042
|
-
return Object.values(result);
|
|
1043
|
-
}
|
|
1044
|
-
function getAllMaps() {
|
|
1045
|
-
let result = {};
|
|
1046
|
-
Object.values(registeredRooms).forEach((room) => {
|
|
1047
|
-
result[room.location.map.id] = room.location.map;
|
|
1048
|
-
});
|
|
1049
|
-
return Object.values(result);
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
|
-
export { addCommitment, getActivityById, getAllLocations, getAllMaps, getAllStartedQuests, getCommitmentById, getQuestById, getRoomById, newActivity, newQuest, removeCommitment, saveCommitment, saveRoom, setFixedRoutine };
|
|
1053
|
-
//# sourceMappingURL=out.js.map
|
|
1
|
+
import {storage,getFlag,StoredClassModel}from'@drincs/pixi-vn';var s="___nqtr-time_manager_settings___",a="___nqtr-time_manager_data___";var u=class{editSettings(e){let t={};if(typeof e.minDayHours=="number"&&(t.minDayHours=e.minDayHours),typeof e.maxDayHours=="number"&&(t.maxDayHours=e.maxDayHours),typeof e.minDayHours=="number"&&(t.defaultTimeSpent=e.defaultTimeSpent),Array.isArray(e.timeSlots)&&(t.timeSlots=e.timeSlots),typeof e.weekLength=="number"&&(t.weekLength=e.weekLength),typeof e.weekendStartDay=="number"){let n=e.weekLength||this.weekLength;e.weekendStartDay>=n&&console.warn(`[NQTR] Weekend start day should be less than week length ${n}`),t.weekendStartDay=e.weekendStartDay;}if(Array.isArray(e.weekDaysNames)){let n=e.weekLength||this.weekLength;e.weekDaysNames.length!==n&&console.warn(`[NQTR] Week days names should be equal to week length ${n}`),t.weekDaysNames=e.weekDaysNames;}storage.setVariable(s,t);}get settings(){return storage.getVariable(s)||{}}set settings(e){this.editSettings(e);}get minDayHours(){let e=0,t=storage.getVariable(s);return t&&t.hasOwnProperty("minDayHours")&&(e=t.minDayHours||0),e}get maxDayHours(){let e=24,t=storage.getVariable(s);return t&&t.hasOwnProperty("maxDayHours")&&(e=t.maxDayHours||24),e}get defaultTimeSpent(){let e=1,t=storage.getVariable(s);return t&&t.hasOwnProperty("defaultTimeSpent")&&(e=t.defaultTimeSpent||1),e}get timeSlots(){let e=[],t=storage.getVariable(s);return t&&t.hasOwnProperty("timeSlots")&&(e=t.timeSlots||[]),e}get weekLength(){let e=7,t=storage.getVariable(s);return t&&t.hasOwnProperty("weekLength")&&(e=t.weekLength||7),e}get weekendStartDay(){let e=this.weekLength-1,t=storage.getVariable(s);return t&&t.hasOwnProperty("weekendStartDay")&&(e=t.weekendStartDay||this.weekLength-1),e}get weekDaysNames(){let e=[],t=storage.getVariable(s);return t&&t.hasOwnProperty("weekDaysNames")&&(e=t.weekDaysNames||e),e}get currentHour(){let e=storage.getVariable(a)||{};return e.hasOwnProperty("currentHour")&&typeof e.currentHour=="number"?e.currentHour:this.minDayHours}set currentHour(e){let t=storage.getVariable(a)||{};typeof e=="number"?t.currentHour=e:delete t.currentHour,storage.setVariable(a,t);}get currentDay(){let e=storage.getVariable(a)||{};return e.hasOwnProperty("currentDay")&&typeof e.currentDay=="number"?e.currentDay:0}set currentDay(e){let t=storage.getVariable(a)||{};typeof e=="number"?t.currentDay=e:delete t.currentDay,storage.setVariable(a,t);}get isWeekend(){return this.currentWeekDayNumber>=this.weekendStartDay}get currentWeekDayNumber(){return this.currentDay%this.weekLength+1}get currentDayName(){let e=this.currentWeekDayNumber-1;return e>=this.weekDaysNames.length?(console.warn(`[NQTR] Week day name is not defined for day ${e}`,this.weekDaysNames),""):this.weekDaysNames[e]}get currentTimeSlot(){if(this.timeSlots.length===0)return console.warn("[NQTR] Time slots are not defined"),0;for(let e=0;e<this.timeSlots.length;e++){let t=this.timeSlots[e];if(this.timeSlots.length>e+1&&this.nowIsBetween(t.startHour,this.timeSlots[e+1].startHour))return e}return this.timeSlots.length-1}increaseHour(e=this.defaultTimeSpent){let t=this.currentHour+e;return t>=this.maxDayHours&&(this.increaseDay(),t=this.minDayHours+(t-this.maxDayHours)),this.currentHour=t,this.currentHour}increaseDay(e=this.minDayHours,t=1){let n=this.currentDay+t;return this.currentDay=n,this.currentHour=e,this.currentDay}nowIsBetween(e,t){let n=this.currentHour;return e<t?n>=e&&n<t:n>=e||n<t}};var o=new u;var d=class{constructor(e,t,n){this._id=e,this._name=n.name,this._fromHour=n.fromHour,this._toHour=n.toHour,this._fromDay=n.fromDay,this._toDay=n.toDay,this._disabled=n.disabled||false,this._hidden=n.hidden||false,this._renderIcon=n.renderIcon,this._onRun=t;}_id;get id(){return this._id}_name;get name(){return this._name}_fromHour;get fromHour(){return this._fromHour}_toHour;get toHour(){return this._toHour}_fromDay;get fromDay(){return this._fromDay}_toDay;get toDay(){return this._toDay}_disabled;get disabled(){return typeof this._disabled=="string"?getFlag(this._disabled):this._disabled}_hidden;get hidden(){return this.fromDay&&this.fromDay>o.currentDay||!this.isDeadline?true:typeof this._hidden=="string"?getFlag(this._hidden):this._hidden}_renderIcon;get renderIcon(){let e=this._renderIcon;if(e!==undefined)return typeof e=="function"?t=>e(this,t):t=>e}_onRun;get _initialOnRun(){return this._onRun}get run(){return e=>this._onRun(this,e)}isDeadline(){return !!(this.toDay&&this.toDay<=o.currentDay)}export(){return {name:this._name,fromHour:this._fromHour,toHour:this._toHour,fromDay:this._fromDay,toDay:this._toDay,disabled:this._disabled,hidden:this._hidden,renderIcon:this._renderIcon}}};var y={};function C(r,e,t){y[r]&&console.warn(`[NQTR] Activity ${r} already exists, it will be overwritten`);let n=new d(r,e,t);return y[r]=n,n}function M(r){try{let e=y[r];if(!e){console.error(`[NQTR] Activity ${r} not found`);return}return e}catch(e){console.error(`[NQTR] Error while getting Activity ${r}`,e);return}}var T="___nqtr-temporary_commitment___",_={},R={};function D(r){if(Array.isArray(r)){r.forEach(e=>D(e));return}_[r.id]&&console.warn(`[NQTR] Commitment id ${r.id} already exists, it will be overwritten`),_[r.id]=r;}function I(r){try{let e=_[r];if(!e){console.error(`[NQTR] Commitment ${r} not found`);return}return e}catch(e){console.error(`[NQTR] Error while getting Commitment ${r}`,e);return}}function x(r){if(Array.isArray(r)){r.forEach(e=>x(e));return}R[r.id]&&console.warn(`[NQTR] Commitment id ${r.id} already exists, it will be overwritten`),R[r.id]=r;}function O(r){Array.isArray(r)||(r=[r]);let e=r.map(t=>{if(!I(t.id)){console.warn(`[NQTR] Commitment ${t.id} not found, it will be ignored`);return}return t.id}).filter(t=>t!==undefined);storage.setVariable(T,e);}function E(r){Array.isArray(r)||(r=[r]);let e=r.map(n=>n.id),t=storage.getVariable(T);t&&(t=t.filter(n=>!e.includes(n)),storage.setVariable(T,t));}var N="__nqtr-goal__",g=class extends StoredClassModel{constructor(e,t){super(N,e),this._description=t.description,this._need=t.need||1,this._defaultHave=t.have||0;}_description;get description(){return this._description}_need;get need(){return this._need}_defaultHave;get defaultHave(){return this._defaultHave}},h=class extends g{constructor(e,t,n){super(e,n),this._stageId=t;}_stageId;get stageId(){return this._stageId}set stageId(e){this._stageId=e;}get have(){return this.getStorageProperty("have-"+this._stageId)||this.defaultHave}set have(e){if(!this._stageId){console.error(`[NQTR] The stage id is not set for the goal ${this.id}, so the have value can't be set.`);return}this.setStorageProperty("have-"+this._stageId,e);}get completed(){return this.have>=this.need}set completed(e){e?this.have=this.need:console.warn("[NQTR] The goal can't be set as not completed. You must edit the have value manually.");}find(){this.have++;}};var G="__nqtr-stage__",c=class extends StoredClassModel{constructor(e,t){super(G,e),this._name=t.name||"",this._defaultGoals=t.goals||[],this._flags=t.flags||[],this._description=t.description||"",this._adviceDescription=t.adviceDescription||"",this._renderImage=t.renderImage,this._daysRequiredToStart=t.daysRequiredToStart,this._flagsRequiredToStart=t.flagsRequiredToStart||[],this._questsRequiredToStart=t.questsRequiredToStart||[],this._requestDescriptionToStart=t.requestDescriptionToStart||"",this._onStart=t.onStart,this._onEnd=t.onEnd;}_name;get name(){return this._name}_description;get description(){return this._description}_adviceDescription;get adviceDescription(){return this._adviceDescription}_renderImage;get renderImage(){let e=this._renderImage;if(e!==undefined)return typeof e=="function"?t=>e(this,t):t=>e}_defaultGoals;get defaultGoals(){return this._defaultGoals}_flags;get flags(){return this._flags}_daysRequiredToStart;get daysRequiredToStart(){return this._daysRequiredToStart||0}_flagsRequiredToStart;get flagsRequiredToStart(){return this._flagsRequiredToStart}_questsRequiredToStart;get questsRequiredToStart(){return this._questsRequiredToStart||[]}_requestDescriptionToStart;get requestDescriptionToStart(){return this._requestDescriptionToStart}_onStart;get onStart(){return this._onStart}_onEnd;get onEnd(){return this._onEnd}},p=class extends c{constructor(e,t){super(e,t);}get completed(){let e=this.getStorageProperty("completed");return e||(this.flags.length>0&&this.goals.length>0?!(!this.flags.every(t=>getFlag(t.flag))||!this.goals.every(t=>t.completed)):false)}set completed(e){this.setStorageProperty("completed",e);}get started(){return this.getStorageProperty("started")||false}set started(e){this.setStorageProperty("started",e);}get goals(){return this.defaultGoals.map(e=>new h(e.id,this.id,e))}get prevStageEndDay(){return this.getStorageProperty("prevStageEndDay")}set prevStageEndDay(e){this.setStorageProperty("prevStageEndDay",e);}get startDay(){let e=this.prevStageEndDay;if(e!==undefined)return e+this.daysRequiredToStart}get canStart(){let e=this.daysRequiredToStart;if(e>0){let t=this.prevStageEndDay;if(t===undefined||t+e>o.currentDay)return false}return !(this.flagsRequiredToStart.length>0&&!this.flagsRequiredToStart.every(t=>getFlag(t.flag))||this.questsRequiredToStart.length>0&&!this.questsRequiredToStart.every(t=>t.quest.currentStageIndex&&t.quest.currentStageIndex>=t.stageNumber))}inizialize(){this.daysRequiredToStart>0&&(this.prevStageEndDay=o.currentDay,console.log(`[NQTR] Stage ${this.id} will start on day ${this.startDay}`));}start(e){this.canStart?(this.started=true,this.onStart&&this.onStart(this,e)):console.warn(`[NQTR] Stage ${this.id} can't start`);}};var q="__nqtr-quest__",m=class extends StoredClassModel{constructor(e,t,n){super(q,e),this._stages=t,this._name=n.name||"",this._description=n.description||"",this._renderIcon=n.renderIcon,this._renderImage=n.renderImage,this._isInDevelopment=n.isInDevelopment||false,this._onStart=n.onStart,this._onNextStage=n.onNextStage;}_stages;get stages(){return this._stages.map((e,t)=>new p(e.id,e))}_name;get name(){return this._name}_description;get description(){return this._description}_renderIcon;get renderIcon(){let e=this._renderIcon;if(e!==undefined)return typeof e=="function"?t=>e(this,t):t=>e}_renderImage;get renderImage(){let e=this._renderImage;if(e!==undefined)return typeof e=="function"?t=>e(this,t):t=>e}_isInDevelopment;get isInDevelopment(){return this._isInDevelopment}get currentStageIndex(){return this.getStorageProperty("currentStageIndex")}set currentStageIndex(e){this.setStorageProperty("currentStageIndex",e);}get currentStage(){let e=this.currentStageIndex;if(!(e===undefined||e>=this.stages.length))return this.stages[e]}get started(){return this.currentStageIndex!==undefined}get completed(){return this.currentStageIndex===undefined?false:this.currentStageIndex>this.stages.length-1}_onStart;get onStart(){return this._onStart}_onNextStage;get onNextStage(){return this._onNextStage}start(e){if(this.started){console.warn(`[NQTR] Quest ${this.id} is already started`);return}if(this.stages.length===0){console.error(`[NQTR] Quest ${this.id} has no stages`);return}this.currentStageIndex=0;let t=this.currentStage;if(t&&t.start)return this.onStart&&this.onStart(this,e),t.start(e);console.error(`[NQTR] Quest ${this.id} has no start stage`);}tryToGoNextStage(e){if(!this.started||this.completed)return false;let t=this.currentStage;return t?t.completed?this.goNextStage(e):false:(console.error(`[NQTR] Quest ${this.id} has no current stage`),false)}completeCurrentStageAndGoNext(e){let t=this.currentStage;return t?(t.completed=true,this.goNextStage(e)):(console.error(`[NQTR] Quest ${this.id} has no current stage`),false)}goNextStage(e){if(!this.started)return console.warn(`[NQTR] Quest ${this.id} is not started`),false;if(this.completed)return console.warn(`[NQTR] Quest ${this.id} is already completed`),false;let t=this.currentStage,n=this.currentStageIndex;if(!t||n===undefined)return console.error(`[NQTR] Quest ${this.id} has no current stage`),false;this.currentStageIndex=n+1,this.onNextStage&&this.onNextStage(this,e),t&&t.onEnd&&t.onEnd(t,e);let v=this.currentStage;return v&&(v.inizialize(),this.currentStageMustStart&&this.startCurrentStage(e)),true}get currentStageMustStart(){let e=this.currentStage;return e?!e.started&&e.canStart&&!e.completed:false}startCurrentStage(e){let t=this.currentStage;t&&this.currentStageMustStart?t.start(e):console.warn(`[NQTR] Quest ${this.id} can't start the current stage`);}};var f={};function B(r,e,t){f[r]&&console.warn(`[NQTR] Quest ${r} already exists, it will be overwritten`);let n=new m(r,e,t);return f[r]=n,n}function k(r){try{let e=f[r];if(!e){console.error(`[NQTR] Quest ${r} not found`);return}return e}catch(e){console.error(`[NQTR] Error while getting Quest ${r}`,e);return}}function L(){return Object.values(f).filter(r=>r.started)}var l={};function Q(r){if(Array.isArray(r)){r.forEach(e=>Q(e));return}l[r.id]&&console.warn(`[NQTR] Room id ${r.id} already exists, it will be overwritten`),l[r.id]=r;}function $(r){try{let e=l[r];if(!e){console.error(`[NQTR] Room ${r} not found`);return}return e}catch(e){console.error(`[NQTR] Error while getting Room ${r}`,e);return}}function V(){let r={};return Object.values(l).forEach(e=>{r[e.location.id]=e.location;}),Object.values(r)}function Y(){let r={};return Object.values(l).forEach(e=>{r[e.location.map.id]=e.location.map;}),Object.values(r)}export{O as addCommitment,M as getActivityById,V as getAllLocations,Y as getAllMaps,L as getAllStartedQuests,I as getCommitmentById,k as getQuestById,$ as getRoomById,C as newActivity,B as newQuest,E as removeCommitment,D as saveCommitment,Q as saveRoom,x as setFixedRoutine};//# sourceMappingURL=index.mjs.map
|
|
1054
2
|
//# sourceMappingURL=index.mjs.map
|