@drincs/nqtr 0.2.11 → 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.
Files changed (281) hide show
  1. package/dist/{ActivityProps-BkHX8xkA.d.ts → ActivityProps-LWY7Zucl.d.ts} +2 -2
  2. package/dist/{ActivityProps-D45DQdcT.d.mts → ActivityProps-WgXDAYbc.d.mts} +2 -2
  3. package/dist/{Commitment-BHB-jYOi.d.mts → Commitment-BujJuTv8.d.mts} +11 -17
  4. package/dist/{Commitment-D-1lsnnU.d.ts → Commitment-DFYAApxl.d.ts} +11 -17
  5. package/dist/{StageProps-CuE_n1Wg.d.mts → StageProps-CqgBUi3e.d.mts} +1 -1
  6. package/dist/{StageProps-CCjGI625.d.ts → StageProps-DghO7WaT.d.ts} +1 -1
  7. package/dist/classes/Activity.d.mts +1 -1
  8. package/dist/classes/Activity.d.ts +1 -1
  9. package/dist/classes/Activity.js +1 -381
  10. package/dist/classes/Activity.js.map +1 -1
  11. package/dist/classes/Activity.mjs +1 -379
  12. package/dist/classes/Activity.mjs.map +1 -1
  13. package/dist/classes/ActivityStoredAbstract.d.mts +1 -1
  14. package/dist/classes/ActivityStoredAbstract.d.ts +1 -1
  15. package/dist/classes/ActivityStoredAbstract.js +1 -398
  16. package/dist/classes/ActivityStoredAbstract.js.map +1 -1
  17. package/dist/classes/ActivityStoredAbstract.mjs +1 -396
  18. package/dist/classes/ActivityStoredAbstract.mjs.map +1 -1
  19. package/dist/classes/Commitment.d.mts +2 -2
  20. package/dist/classes/Commitment.d.ts +2 -2
  21. package/dist/classes/Commitment.js +1 -438
  22. package/dist/classes/Commitment.js.map +1 -1
  23. package/dist/classes/Commitment.mjs +1 -436
  24. package/dist/classes/Commitment.mjs.map +1 -1
  25. package/dist/classes/index.d.mts +3 -3
  26. package/dist/classes/index.d.ts +3 -3
  27. package/dist/classes/index.js +1 -1699
  28. package/dist/classes/index.js.map +1 -1
  29. package/dist/classes/index.mjs +1 -1690
  30. package/dist/classes/index.mjs.map +1 -1
  31. package/dist/classes/navigation/ActivityRoom.d.mts +2 -2
  32. package/dist/classes/navigation/ActivityRoom.d.ts +2 -2
  33. package/dist/classes/navigation/ActivityRoom.js +1 -448
  34. package/dist/classes/navigation/ActivityRoom.js.map +1 -1
  35. package/dist/classes/navigation/ActivityRoom.mjs +1 -446
  36. package/dist/classes/navigation/ActivityRoom.mjs.map +1 -1
  37. package/dist/classes/navigation/Location.d.mts +2 -2
  38. package/dist/classes/navigation/Location.d.ts +2 -2
  39. package/dist/classes/navigation/Location.js +1 -118
  40. package/dist/classes/navigation/Location.js.map +1 -1
  41. package/dist/classes/navigation/Location.mjs +1 -116
  42. package/dist/classes/navigation/Location.mjs.map +1 -1
  43. package/dist/classes/navigation/Map.d.mts +2 -2
  44. package/dist/classes/navigation/Map.d.ts +2 -2
  45. package/dist/classes/navigation/Map.js +1 -113
  46. package/dist/classes/navigation/Map.js.map +1 -1
  47. package/dist/classes/navigation/Map.mjs +1 -111
  48. package/dist/classes/navigation/Map.mjs.map +1 -1
  49. package/dist/classes/navigation/Room.d.mts +2 -2
  50. package/dist/classes/navigation/Room.d.ts +2 -2
  51. package/dist/classes/navigation/Room.js +1 -778
  52. package/dist/classes/navigation/Room.js.map +1 -1
  53. package/dist/classes/navigation/Room.mjs +1 -773
  54. package/dist/classes/navigation/Room.mjs.map +1 -1
  55. package/dist/classes/quest/Goal.js +1 -85
  56. package/dist/classes/quest/Goal.js.map +1 -1
  57. package/dist/classes/quest/Goal.mjs +1 -80
  58. package/dist/classes/quest/Goal.mjs.map +1 -1
  59. package/dist/classes/quest/Quest.d.mts +1 -1
  60. package/dist/classes/quest/Quest.d.ts +1 -1
  61. package/dist/classes/quest/Quest.js +1 -769
  62. package/dist/classes/quest/Quest.js.map +1 -1
  63. package/dist/classes/quest/Quest.mjs +1 -767
  64. package/dist/classes/quest/Quest.mjs.map +1 -1
  65. package/dist/classes/quest/Stage.d.mts +1 -1
  66. package/dist/classes/quest/Stage.d.ts +1 -1
  67. package/dist/classes/quest/Stage.js +1 -536
  68. package/dist/classes/quest/Stage.js.map +1 -1
  69. package/dist/classes/quest/Stage.mjs +1 -531
  70. package/dist/classes/quest/Stage.mjs.map +1 -1
  71. package/dist/constants.d.mts +4 -0
  72. package/dist/constants.d.ts +4 -0
  73. package/dist/constants.js +2 -0
  74. package/dist/constants.js.map +1 -0
  75. package/dist/constants.mjs +2 -0
  76. package/dist/constants.mjs.map +1 -0
  77. package/dist/decorators/ActivityDecorator.d.mts +1 -1
  78. package/dist/decorators/ActivityDecorator.d.ts +1 -1
  79. package/dist/decorators/ActivityDecorator.js +1 -407
  80. package/dist/decorators/ActivityDecorator.js.map +1 -1
  81. package/dist/decorators/ActivityDecorator.mjs +1 -403
  82. package/dist/decorators/ActivityDecorator.mjs.map +1 -1
  83. package/dist/decorators/CommitmentDecorator.d.mts +2 -2
  84. package/dist/decorators/CommitmentDecorator.d.ts +2 -2
  85. package/dist/decorators/CommitmentDecorator.js +1 -91
  86. package/dist/decorators/CommitmentDecorator.js.map +1 -1
  87. package/dist/decorators/CommitmentDecorator.mjs +1 -81
  88. package/dist/decorators/CommitmentDecorator.mjs.map +1 -1
  89. package/dist/decorators/QuestDecorator.d.mts +1 -1
  90. package/dist/decorators/QuestDecorator.d.ts +1 -1
  91. package/dist/decorators/QuestDecorator.js +1 -799
  92. package/dist/decorators/QuestDecorator.js.map +1 -1
  93. package/dist/decorators/QuestDecorator.mjs +1 -794
  94. package/dist/decorators/QuestDecorator.mjs.map +1 -1
  95. package/dist/decorators/RoomDecorator.d.mts +2 -2
  96. package/dist/decorators/RoomDecorator.d.ts +2 -2
  97. package/dist/decorators/RoomDecorator.js +1 -56
  98. package/dist/decorators/RoomDecorator.js.map +1 -1
  99. package/dist/decorators/RoomDecorator.mjs +1 -48
  100. package/dist/decorators/RoomDecorator.mjs.map +1 -1
  101. package/dist/decorators/index.d.mts +3 -3
  102. package/dist/decorators/index.d.ts +3 -3
  103. package/dist/decorators/index.js +1 -1068
  104. package/dist/decorators/index.js.map +1 -1
  105. package/dist/decorators/index.mjs +1 -1053
  106. package/dist/decorators/index.mjs.map +1 -1
  107. package/dist/functions/ActivityFunctions.d.mts +2 -2
  108. package/dist/functions/ActivityFunctions.d.ts +2 -2
  109. package/dist/functions/ActivityFunctions.js +1 -53
  110. package/dist/functions/ActivityFunctions.js.map +1 -1
  111. package/dist/functions/ActivityFunctions.mjs +1 -50
  112. package/dist/functions/ActivityFunctions.mjs.map +1 -1
  113. package/dist/functions/NavigationFunctions.d.mts +2 -2
  114. package/dist/functions/NavigationFunctions.d.ts +2 -2
  115. package/dist/functions/NavigationFunctions.js +1 -181
  116. package/dist/functions/NavigationFunctions.js.map +1 -1
  117. package/dist/functions/NavigationFunctions.mjs +1 -176
  118. package/dist/functions/NavigationFunctions.mjs.map +1 -1
  119. package/dist/functions/QuestFunctions.js +1 -20
  120. package/dist/functions/QuestFunctions.js.map +1 -1
  121. package/dist/functions/QuestFunctions.mjs +1 -18
  122. package/dist/functions/QuestFunctions.mjs.map +1 -1
  123. package/dist/functions/RoutineFunctions.d.mts +4 -4
  124. package/dist/functions/RoutineFunctions.d.ts +4 -4
  125. package/dist/functions/RoutineFunctions.js +1 -126
  126. package/dist/functions/RoutineFunctions.js.map +1 -1
  127. package/dist/functions/RoutineFunctions.mjs +1 -121
  128. package/dist/functions/RoutineFunctions.mjs.map +1 -1
  129. package/dist/functions/index.d.mts +2 -2
  130. package/dist/functions/index.d.ts +2 -2
  131. package/dist/functions/index.js +1 -293
  132. package/dist/functions/index.js.map +1 -1
  133. package/dist/functions/index.mjs +1 -281
  134. package/dist/functions/index.mjs.map +1 -1
  135. package/dist/index.d.mts +55 -13
  136. package/dist/index.d.ts +55 -13
  137. package/dist/index.js +1 -2057
  138. package/dist/index.js.map +1 -1
  139. package/dist/index.mjs +1 -2022
  140. package/dist/index.mjs.map +1 -1
  141. package/dist/interface/ActivityProps.d.mts +1 -1
  142. package/dist/interface/ActivityProps.d.ts +1 -1
  143. package/dist/interface/ActivityProps.js +1 -3
  144. package/dist/interface/ActivityProps.js.map +1 -1
  145. package/dist/interface/ActivityProps.mjs +1 -2
  146. package/dist/interface/ActivityProps.mjs.map +1 -1
  147. package/dist/interface/CommitmentProps.d.mts +2 -2
  148. package/dist/interface/CommitmentProps.d.ts +2 -2
  149. package/dist/interface/CommitmentProps.js +1 -3
  150. package/dist/interface/CommitmentProps.js.map +1 -1
  151. package/dist/interface/CommitmentProps.mjs +1 -2
  152. package/dist/interface/CommitmentProps.mjs.map +1 -1
  153. package/dist/interface/RoomActivityMemory.d.mts +1 -1
  154. package/dist/interface/RoomActivityMemory.d.ts +1 -1
  155. package/dist/interface/RoomActivityMemory.js +1 -3
  156. package/dist/interface/RoomActivityMemory.js.map +1 -1
  157. package/dist/interface/RoomActivityMemory.mjs +1 -2
  158. package/dist/interface/RoomActivityMemory.mjs.map +1 -1
  159. package/dist/interface/RoomProps.d.mts +2 -2
  160. package/dist/interface/RoomProps.d.ts +2 -2
  161. package/dist/interface/RoomProps.js +1 -3
  162. package/dist/interface/RoomProps.js.map +1 -1
  163. package/dist/interface/RoomProps.mjs +1 -2
  164. package/dist/interface/RoomProps.mjs.map +1 -1
  165. package/dist/interface/index.d.mts +3 -3
  166. package/dist/interface/index.d.ts +3 -3
  167. package/dist/interface/index.js +1 -3
  168. package/dist/interface/index.js.map +1 -1
  169. package/dist/interface/index.mjs +1 -2
  170. package/dist/interface/index.mjs.map +1 -1
  171. package/dist/interface/navigation/LocationProps.d.mts +2 -2
  172. package/dist/interface/navigation/LocationProps.d.ts +2 -2
  173. package/dist/interface/navigation/LocationProps.js +1 -3
  174. package/dist/interface/navigation/LocationProps.js.map +1 -1
  175. package/dist/interface/navigation/LocationProps.mjs +1 -2
  176. package/dist/interface/navigation/LocationProps.mjs.map +1 -1
  177. package/dist/interface/navigation/MapProps.d.mts +2 -2
  178. package/dist/interface/navigation/MapProps.d.ts +2 -2
  179. package/dist/interface/navigation/MapProps.js +1 -3
  180. package/dist/interface/navigation/MapProps.js.map +1 -1
  181. package/dist/interface/navigation/MapProps.mjs +1 -2
  182. package/dist/interface/navigation/MapProps.mjs.map +1 -1
  183. package/dist/interface/quest/GoalProps.js +1 -3
  184. package/dist/interface/quest/GoalProps.js.map +1 -1
  185. package/dist/interface/quest/GoalProps.mjs +1 -2
  186. package/dist/interface/quest/GoalProps.mjs.map +1 -1
  187. package/dist/interface/quest/QuestProps.d.mts +1 -1
  188. package/dist/interface/quest/QuestProps.d.ts +1 -1
  189. package/dist/interface/quest/QuestProps.js +1 -3
  190. package/dist/interface/quest/QuestProps.js.map +1 -1
  191. package/dist/interface/quest/QuestProps.mjs +1 -2
  192. package/dist/interface/quest/QuestProps.mjs.map +1 -1
  193. package/dist/interface/quest/StageFlags.js +1 -3
  194. package/dist/interface/quest/StageFlags.js.map +1 -1
  195. package/dist/interface/quest/StageFlags.mjs +1 -2
  196. package/dist/interface/quest/StageFlags.mjs.map +1 -1
  197. package/dist/interface/quest/StageProps.d.mts +1 -1
  198. package/dist/interface/quest/StageProps.d.ts +1 -1
  199. package/dist/interface/quest/StageProps.js +1 -3
  200. package/dist/interface/quest/StageProps.js.map +1 -1
  201. package/dist/interface/quest/StageProps.mjs +1 -2
  202. package/dist/interface/quest/StageProps.mjs.map +1 -1
  203. package/dist/managers/TimeManager.d.mts +30 -31
  204. package/dist/managers/TimeManager.d.ts +30 -31
  205. package/dist/managers/TimeManager.js +1 -250
  206. package/dist/managers/TimeManager.js.map +1 -1
  207. package/dist/managers/TimeManager.mjs +1 -248
  208. package/dist/managers/TimeManager.mjs.map +1 -1
  209. package/dist/managers/index.d.mts +5 -1
  210. package/dist/managers/index.d.ts +5 -1
  211. package/dist/managers/index.js +1 -250
  212. package/dist/managers/index.js.map +1 -1
  213. package/dist/managers/index.mjs +1 -248
  214. package/dist/managers/index.mjs.map +1 -1
  215. package/dist/override/GraphicItemInterface.js +1 -3
  216. package/dist/override/GraphicItemInterface.js.map +1 -1
  217. package/dist/override/GraphicItemInterface.mjs +1 -2
  218. package/dist/override/GraphicItemInterface.mjs.map +1 -1
  219. package/dist/override/GraphicItemType.d.mts +2 -2
  220. package/dist/override/GraphicItemType.d.ts +2 -2
  221. package/dist/override/GraphicItemType.js +1 -3
  222. package/dist/override/GraphicItemType.js.map +1 -1
  223. package/dist/override/GraphicItemType.mjs +1 -2
  224. package/dist/override/GraphicItemType.mjs.map +1 -1
  225. package/dist/override/NeighboringMapsInterface.js +1 -3
  226. package/dist/override/NeighboringMapsInterface.js.map +1 -1
  227. package/dist/override/NeighboringMapsInterface.mjs +1 -2
  228. package/dist/override/NeighboringMapsInterface.mjs.map +1 -1
  229. package/dist/override/OnRenderGraphicItemProps.js +1 -3
  230. package/dist/override/OnRenderGraphicItemProps.js.map +1 -1
  231. package/dist/override/OnRenderGraphicItemProps.mjs +1 -2
  232. package/dist/override/OnRenderGraphicItemProps.mjs.map +1 -1
  233. package/dist/override/OnRunProps.js +1 -3
  234. package/dist/override/OnRunProps.js.map +1 -1
  235. package/dist/override/OnRunProps.mjs +1 -2
  236. package/dist/override/OnRunProps.mjs.map +1 -1
  237. package/dist/override/OnStartEndStageQuest.js +1 -3
  238. package/dist/override/OnStartEndStageQuest.js.map +1 -1
  239. package/dist/override/OnStartEndStageQuest.mjs +1 -2
  240. package/dist/override/OnStartEndStageQuest.mjs.map +1 -1
  241. package/dist/override/index.js +1 -3
  242. package/dist/override/index.js.map +1 -1
  243. package/dist/override/index.mjs +1 -2
  244. package/dist/override/index.mjs.map +1 -1
  245. package/dist/types/ExecutionType.js +1 -3
  246. package/dist/types/ExecutionType.js.map +1 -1
  247. package/dist/types/ExecutionType.mjs +1 -2
  248. package/dist/types/ExecutionType.mjs.map +1 -1
  249. package/dist/types/OnRunActivityEvent.js +1 -3
  250. package/dist/types/OnRunActivityEvent.js.map +1 -1
  251. package/dist/types/OnRunActivityEvent.mjs +1 -2
  252. package/dist/types/OnRunActivityEvent.mjs.map +1 -1
  253. package/dist/types/OnRunCommitmentEvent.js +1 -3
  254. package/dist/types/OnRunCommitmentEvent.js.map +1 -1
  255. package/dist/types/OnRunCommitmentEvent.mjs +1 -2
  256. package/dist/types/OnRunCommitmentEvent.mjs.map +1 -1
  257. package/dist/types/QuestsRequired.d.mts +1 -1
  258. package/dist/types/QuestsRequired.d.ts +1 -1
  259. package/dist/types/QuestsRequired.js +1 -3
  260. package/dist/types/QuestsRequired.js.map +1 -1
  261. package/dist/types/QuestsRequired.mjs +1 -2
  262. package/dist/types/QuestsRequired.mjs.map +1 -1
  263. package/dist/types/TimeDataType.d.mts +6 -0
  264. package/dist/types/TimeDataType.d.ts +6 -0
  265. package/dist/types/TimeDataType.js +2 -0
  266. package/dist/types/TimeDataType.js.map +1 -0
  267. package/dist/types/TimeDataType.mjs +2 -0
  268. package/dist/types/TimeDataType.mjs.map +1 -0
  269. package/dist/types/TimeSettings.d.mts +1 -1
  270. package/dist/types/TimeSettings.d.ts +1 -1
  271. package/dist/types/TimeSettings.js +1 -3
  272. package/dist/types/TimeSettings.js.map +1 -1
  273. package/dist/types/TimeSettings.mjs +1 -2
  274. package/dist/types/TimeSettings.mjs.map +1 -1
  275. package/dist/types/index.d.mts +1 -1
  276. package/dist/types/index.d.ts +1 -1
  277. package/dist/types/index.js +1 -3
  278. package/dist/types/index.js.map +1 -1
  279. package/dist/types/index.mjs +1 -2
  280. package/dist/types/index.mjs.map +1 -1
  281. package/package.json +8 -7
@@ -1,249 +1,2 @@
1
- import { GameStorageManager } from '@drincs/pixi-vn';
2
-
3
- // src/managers/TimeManager.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
- export { TimeManager as default };
248
- //# sourceMappingURL=out.js.map
1
+ import {storage}from'@drincs/pixi-vn';var a="___nqtr-time_manager_settings___",i="___nqtr-time_manager_data___";var s=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(a,t);}get settings(){return storage.getVariable(a)||{}}set settings(e){this.editSettings(e);}get minDayHours(){let e=0,t=storage.getVariable(a);return t&&t.hasOwnProperty("minDayHours")&&(e=t.minDayHours||0),e}get maxDayHours(){let e=24,t=storage.getVariable(a);return t&&t.hasOwnProperty("maxDayHours")&&(e=t.maxDayHours||24),e}get defaultTimeSpent(){let e=1,t=storage.getVariable(a);return t&&t.hasOwnProperty("defaultTimeSpent")&&(e=t.defaultTimeSpent||1),e}get timeSlots(){let e=[],t=storage.getVariable(a);return t&&t.hasOwnProperty("timeSlots")&&(e=t.timeSlots||[]),e}get weekLength(){let e=7,t=storage.getVariable(a);return t&&t.hasOwnProperty("weekLength")&&(e=t.weekLength||7),e}get weekendStartDay(){let e=this.weekLength-1,t=storage.getVariable(a);return t&&t.hasOwnProperty("weekendStartDay")&&(e=t.weekendStartDay||this.weekLength-1),e}get weekDaysNames(){let e=[],t=storage.getVariable(a);return t&&t.hasOwnProperty("weekDaysNames")&&(e=t.weekDaysNames||e),e}get currentHour(){let e=storage.getVariable(i)||{};return e.hasOwnProperty("currentHour")&&typeof e.currentHour=="number"?e.currentHour:this.minDayHours}set currentHour(e){let t=storage.getVariable(i)||{};typeof e=="number"?t.currentHour=e:delete t.currentHour,storage.setVariable(i,t);}get currentDay(){let e=storage.getVariable(i)||{};return e.hasOwnProperty("currentDay")&&typeof e.currentDay=="number"?e.currentDay:0}set currentDay(e){let t=storage.getVariable(i)||{};typeof e=="number"?t.currentDay=e:delete t.currentDay,storage.setVariable(i,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}};export{s as default};//# sourceMappingURL=TimeManager.mjs.map
249
2
  //# sourceMappingURL=TimeManager.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/managers/TimeManager.ts"],"names":[],"mappings":";AAAA,SAAS,0BAA0B;AAGnC,IAAM,oBAAoB;AAC1B,IAAM,gBAAgB;AAOtB,IAAqB,cAArB,MAAqB,aAAY;AAAA,EACrB,cAAc;AAAA,EAAE;AAAA,EACxB,OAAe,aAAa,UAAwB;AAChD,QAAI,OAAY,CAAC;AACjB,QAAI,OAAO,SAAS,gBAAgB,UAAU;AAC1C,WAAK,aAAa,IAAI,SAAS;AAAA,IACnC;AACA,QAAI,OAAO,SAAS,gBAAgB,UAAU;AAC1C,WAAK,aAAa,IAAI,SAAS;AAAA,IACnC;AACA,QAAI,OAAO,SAAS,gBAAgB,UAAU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AW,GAAG;AACpC,cAAQ,KAAK,mCAAmC;AAChD,aAAO;AAAA,IACX;AACA,aAAS,QAAQ,GAAG,QAAQ,aAAY,UAAU,QAAQ,SAAS;AAC/D,UAAI,OAAO,aAAY,UAAU,KAAK;AACtC,UAAI,aAAY,UAAU,SAAS,QAAQ,GAAG;AAC1C,YAAI,aAAY,aAAa,KAAK,WAAW,aAAY,UAAU,QAAQ,CAAC,EAAE,SAAS,GAAG;AACtF,iBAAO;AAAA,QACX;AAAA,MACJ;AAAA,IACJ;AACA,WAAO,aAAY,UAAU,SAAS;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,aAAa,YAAoB,aAAY,kBAA0B;AAC1E,QAAI,UAAU,aAAY,cAAc;AACxC,QAAI,WAAW,aAAY,aAAa;AACpC,mBAAY,YAAY;AACxB,gBAAU,aAAY,eAAe,UAAU,aAAY;AAAA,IAC/D;AACA,iBAAY,cAAc;AAC1B,WAAO,aAAY;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,YAAY,aAAqB,aAAY,aAAa,OAAe,GAAW;AACvF,QAAI,SAAS,aAAY,aAAa;AACtC,iBAAY,aAAa;AACzB,iBAAY,cAAc;AAC1B,WAAO,aAAY;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAO,aAAa,UAAkB,QAAyB;AAC3D,QAAI,cAAc,aAAY;AAC9B,QAAI,WAAW,QAAQ;AACnB,aAAO,eAAe,YAAY,cAAc;AAAA,IACpD;AACA,WAAO,eAAe,YAAY,cAAc;AAAA,EACpD;AACJ","sourcesContent":["import { GameStorageManager } from \"@drincs/pixi-vn\";\nimport { ITimeStlot, TimeSettings } from \"../types/TimeSettings\";\n\nconst TIME_SETTINGS_KEY = '___nqtr-time_manager_settings___';\nconst TIME_DATA_KEY = '___nqtr-time_manager_data___';\n\ntype ITimeData = {\n currentHour?: number\n currentDay?: number\n}\n\nexport default class TimeManager {\n private constructor() { }\n private static editSettings(settings: TimeSettings) {\n let data: any = {}\n if (typeof settings.minDayHours === 'number') {\n data['minDayHours'] = settings.minDayHours\n }\n if (typeof settings.maxDayHours === 'number') {\n data['maxDayHours'] = settings.maxDayHours\n }\n if (typeof settings.minDayHours === 'number') {\n data['defaultTimeSpent'] = settings.defaultTimeSpent\n }\n if (Array.isArray(settings.timeSlots)) {\n data['timeSlots'] = settings.timeSlots\n }\n if (typeof settings.weekLength === 'number') {\n data['weekLength'] = settings.weekLength\n }\n if (typeof settings.weekendStartDay === 'number') {\n let weekLength = settings.weekLength || TimeManager.weekLength\n if (settings.weekendStartDay >= weekLength) {\n console.warn(`[NQTR] Weekend start day should be less than week length ${weekLength}`)\n }\n data['weekendStartDay'] = settings.weekendStartDay\n }\n if (Array.isArray(settings.weekDaysNames)) {\n let weekLength = settings.weekLength || TimeManager.weekLength\n if (settings.weekDaysNames.length !== weekLength) {\n console.warn(`[NQTR] Week days names should be equal to week length ${weekLength}`)\n }\n data['weekDaysNames'] = settings.weekDaysNames\n }\n GameStorageManager.setVariable(TIME_SETTINGS_KEY, data)\n }\n /**\n * Get time settings\n * @default {}\n */\n static get settings(): TimeSettings {\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY) || {}\n return settings\n }\n /**\n * 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.\n */\n static set settings(value: TimeSettings) {\n TimeManager.editSettings(value)\n }\n static get minDayHours(): number {\n let result = 0\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('minDayHours')) {\n result = settings.minDayHours || 0\n }\n return result\n }\n static get maxDayHours(): number {\n let result = 24\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('maxDayHours')) {\n result = settings.maxDayHours || 24\n }\n return result\n }\n static get defaultTimeSpent(): number {\n let result = 1\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('defaultTimeSpent')) {\n result = settings.defaultTimeSpent || 1\n }\n return result\n }\n static get timeSlots(): ITimeStlot[] {\n let result: ITimeStlot[] = []\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('timeSlots')) {\n result = settings.timeSlots || []\n }\n return result\n }\n static get weekLength(): number {\n let result = 7\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('weekLength')) {\n result = settings.weekLength || 7\n }\n return result\n }\n static get weekendStartDay(): number {\n let result = TimeManager.weekLength - 1\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('weekendStartDay')) {\n result = settings.weekendStartDay || TimeManager.weekLength - 1\n }\n return result\n }\n static get weekDaysNames(): string[] {\n let result: string[] = []\n let settings = GameStorageManager.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('weekDaysNames')) {\n result = settings.weekDaysNames || result\n }\n return result\n }\n\n /**\n * Get the current hour\n */\n static get currentHour(): number {\n let data = GameStorageManager.getVariable<ITimeData>(TIME_DATA_KEY) || {}\n if (data.hasOwnProperty('currentHour') && typeof data.currentHour === 'number') {\n return data.currentHour\n }\n return TimeManager.minDayHours\n }\n static set currentHour(value: number | undefined) {\n let data = GameStorageManager.getVariable<ITimeData>(TIME_DATA_KEY) || {}\n if (typeof value === 'number') {\n data.currentHour = value\n } else {\n delete data.currentHour\n }\n GameStorageManager.setVariable(TIME_DATA_KEY, data)\n }\n /**\n * Get the current day\n */\n static get currentDay(): number {\n let data = GameStorageManager.getVariable<ITimeData>(TIME_DATA_KEY) || {}\n if (data.hasOwnProperty('currentDay') && typeof data.currentDay === 'number') {\n return data.currentDay\n }\n return 0\n }\n static set currentDay(value: number | undefined) {\n let data = GameStorageManager.getVariable<ITimeData>(TIME_DATA_KEY) || {}\n if (typeof value === 'number') {\n data.currentDay = value\n }\n else {\n delete data.currentDay\n }\n GameStorageManager.setVariable(TIME_DATA_KEY, data)\n }\n /**\n * If the current day is greater than or equal to the weekend start day, then it will return true.\n */\n static get isWeekend(): boolean {\n return TimeManager.currentWeekDayNumber >= TimeManager.weekendStartDay\n }\n /**\n * Get the current week day number (1-TimeManager.weekLength).\n * For example, if the week length is 7 and the current day is 10, then the result will be 4.\n */\n static get currentWeekDayNumber(): number {\n let result = TimeManager.currentDay % TimeManager.weekLength\n return result + 1\n }\n /**\n * Get the current week day name. If the week days names are not defined, then it will return undefined.\n * 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'.\n * @default \"\"\n */\n static get currentDayName(): string {\n let weekDayNumber = TimeManager.currentWeekDayNumber - 1\n if (weekDayNumber >= TimeManager.weekDaysNames.length) {\n console.warn(`[NQTR] Week day name is not defined for day ${weekDayNumber}`, TimeManager.weekDaysNames)\n return \"\"\n }\n return TimeManager.weekDaysNames[weekDayNumber]\n }\n /**\n * Get the current TimeManager.timeSlots index.\n * You can use this property to create \"Image that changes based on the time period\":\n * @example\n * ```tsx\n * import { TimeManager } from '@drincs/nqtr';\n * \n * function changeBackground() {\n * return (\n * <img src={`background-${TimeManager.currentTimeSlot}.png`} />\n * )\n * }\n */\n static get currentTimeSlot(): number {\n if (TimeManager.timeSlots.length === 0) {\n console.warn('[NQTR] Time slots are not defined')\n return 0\n }\n for (let index = 0; index < TimeManager.timeSlots.length; index++) {\n let slot = TimeManager.timeSlots[index]\n if (TimeManager.timeSlots.length > index + 1) {\n if (TimeManager.nowIsBetween(slot.startHour, TimeManager.timeSlots[index + 1].startHour)) {\n return index\n }\n }\n }\n return TimeManager.timeSlots.length - 1\n }\n\n /**\n * This function will increase the current hour by the given time spent.\n * 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.\n * @param timeSpent is the time spent in hours (default: TimeManager.defaultTimeSpent)\n * @returns TimeManager.currentHour\n */\n static increaseHour(timeSpent: number = TimeManager.defaultTimeSpent): number {\n let newHour = TimeManager.currentHour + timeSpent\n if (newHour >= TimeManager.maxDayHours) {\n TimeManager.increaseDay()\n newHour = TimeManager.minDayHours + (newHour - TimeManager.maxDayHours)\n }\n TimeManager.currentHour = newHour\n return TimeManager.currentHour\n }\n\n /**\n * This function will increase the current day by the given days.\n * @param newDayHour is the hour of the new day (default: TimeManager.minDayHours)\n * @param days is the number of days to increase (default: 1)\n * @returns TimeManager.currentDay\n */\n static increaseDay(newDayHour: number = TimeManager.minDayHours, days: number = 1): number {\n let newDay = TimeManager.currentDay + days\n TimeManager.currentDay = newDay\n TimeManager.currentHour = newDayHour\n return TimeManager.currentDay\n }\n\n /**\n * This function will check if the current hour is between the given hours.\n * @param fromHour the starting hour. If the TimeManager.currentHour is equal to this hour, the function will return true.\n * @param toHour the ending hour.\n * @returns true if the current hour is between the given hours, otherwise false.\n */\n static nowIsBetween(fromHour: number, toHour: number): boolean {\n let currentHour = TimeManager.currentHour\n if (fromHour < toHour) {\n return currentHour >= fromHour && currentHour < toHour\n }\n return currentHour >= fromHour || currentHour < toHour\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/constants.ts","../../src/managers/TimeManager.ts"],"names":["TIME_SETTINGS_KEY","TIME_DATA_KEY","TimeManager","settings","data","weekLength","storage","value","result","weekDayNumber","index","slot","timeSpent","newHour","newDayHour","days","newDay","fromHour","toHour","currentHour"],"mappings":"sCAAO,IAAMA,EAAoB,kCACpBC,CAAAA,CAAAA,CAAgB,8BCI7B,CAAA,IAAqBC,CAArB,CAAA,KAAiC,CACrB,YAAA,CAAaC,EAAwB,CACzC,IAAIC,CAAY,CAAA,EAgBhB,CAAA,GAfI,OAAOD,CAAAA,CAAS,aAAgB,QAChCC,GAAAA,CAAAA,CAAK,WAAiBD,CAAAA,CAAAA,CAAS,WAE/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AA,CAAK,YAAaC,CAAAA,CAAAA,CAAK,SAAW,CAAA,IAAA,CAAK,UAAUD,CAAQ,CAAA,CAAC,CAAE,CAAA,SAAS,EACrE,OAAOA,CAGnB,CACA,OAAO,KAAK,SAAU,CAAA,MAAA,CAAS,CACnC,CAQA,YAAaE,CAAAA,CAAAA,CAAoB,IAAK,CAAA,gBAAA,CAA0B,CAC5D,IAAIC,CAAAA,CAAU,IAAK,CAAA,WAAA,CAAcD,CACjC,CAAA,OAAIC,CAAW,EAAA,IAAA,CAAK,cAChB,IAAK,CAAA,WAAA,EACLA,CAAAA,CAAAA,CAAU,IAAK,CAAA,WAAA,EAAeA,CAAU,CAAA,IAAA,CAAK,cAEjD,IAAK,CAAA,WAAA,CAAcA,CACZ,CAAA,IAAA,CAAK,WAChB,CAQA,WAAYC,CAAAA,CAAAA,CAAqB,KAAK,WAAaC,CAAAA,CAAAA,CAAe,CAAW,CAAA,CACzE,IAAIC,CAAAA,CAAS,IAAK,CAAA,UAAA,CAAaD,EAC/B,OAAK,IAAA,CAAA,UAAA,CAAaC,CAClB,CAAA,IAAA,CAAK,WAAcF,CAAAA,CAAAA,CACZ,IAAK,CAAA,UAChB,CAQA,YAAaG,CAAAA,CAAAA,CAAkBC,CAAyB,CAAA,CACpD,IAAIC,CAAAA,CAAc,IAAK,CAAA,WAAA,CACvB,OAAIF,CAAWC,CAAAA,CAAAA,CACJC,CAAeF,EAAAA,CAAAA,EAAYE,EAAcD,CAE7CC,CAAAA,CAAAA,EAAeF,CAAYE,EAAAA,CAAAA,CAAcD,CACpD,CACJ","file":"TimeManager.mjs","sourcesContent":["export const TIME_SETTINGS_KEY = '___nqtr-time_manager_settings___';\nexport const TIME_DATA_KEY = '___nqtr-time_manager_data___';\n\n","import { storage } from \"@drincs/pixi-vn\";\nimport { TIME_DATA_KEY, TIME_SETTINGS_KEY } from \"../constants\";\nimport TimeDataType from \"../types/TimeDataType\";\nimport { ITimeStlot, TimeSettings } from \"../types/TimeSettings\";\n\nexport default class TimeManager {\n private editSettings(settings: TimeSettings) {\n let data: any = {}\n if (typeof settings.minDayHours === 'number') {\n data['minDayHours'] = settings.minDayHours\n }\n if (typeof settings.maxDayHours === 'number') {\n data['maxDayHours'] = settings.maxDayHours\n }\n if (typeof settings.minDayHours === 'number') {\n data['defaultTimeSpent'] = settings.defaultTimeSpent\n }\n if (Array.isArray(settings.timeSlots)) {\n data['timeSlots'] = settings.timeSlots\n }\n if (typeof settings.weekLength === 'number') {\n data['weekLength'] = settings.weekLength\n }\n if (typeof settings.weekendStartDay === 'number') {\n let weekLength = settings.weekLength || this.weekLength\n if (settings.weekendStartDay >= weekLength) {\n console.warn(`[NQTR] Weekend start day should be less than week length ${weekLength}`)\n }\n data['weekendStartDay'] = settings.weekendStartDay\n }\n if (Array.isArray(settings.weekDaysNames)) {\n let weekLength = settings.weekLength || this.weekLength\n if (settings.weekDaysNames.length !== weekLength) {\n console.warn(`[NQTR] Week days names should be equal to week length ${weekLength}`)\n }\n data['weekDaysNames'] = settings.weekDaysNames\n }\n storage.setVariable(TIME_SETTINGS_KEY, data)\n }\n /**\n * Get time settings\n * @default {}\n */\n get settings(): TimeSettings {\n let settings = storage.getVariable<TimeSettings>(TIME_SETTINGS_KEY) || {}\n return settings\n }\n /**\n * 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.\n */\n set settings(value: TimeSettings) {\n this.editSettings(value)\n }\n get minDayHours(): number {\n let result = 0\n let settings = storage.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('minDayHours')) {\n result = settings.minDayHours || 0\n }\n return result\n }\n get maxDayHours(): number {\n let result = 24\n let settings = storage.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('maxDayHours')) {\n result = settings.maxDayHours || 24\n }\n return result\n }\n get defaultTimeSpent(): number {\n let result = 1\n let settings = storage.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('defaultTimeSpent')) {\n result = settings.defaultTimeSpent || 1\n }\n return result\n }\n get timeSlots(): ITimeStlot[] {\n let result: ITimeStlot[] = []\n let settings = storage.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('timeSlots')) {\n result = settings.timeSlots || []\n }\n return result\n }\n get weekLength(): number {\n let result = 7\n let settings = storage.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('weekLength')) {\n result = settings.weekLength || 7\n }\n return result\n }\n get weekendStartDay(): number {\n let result = this.weekLength - 1\n let settings = storage.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('weekendStartDay')) {\n result = settings.weekendStartDay || this.weekLength - 1\n }\n return result\n }\n get weekDaysNames(): string[] {\n let result: string[] = []\n let settings = storage.getVariable<TimeSettings>(TIME_SETTINGS_KEY)\n if (settings && settings.hasOwnProperty('weekDaysNames')) {\n result = settings.weekDaysNames || result\n }\n return result\n }\n\n /**\n * Get the current hour\n */\n get currentHour(): number {\n let data = storage.getVariable<TimeDataType>(TIME_DATA_KEY) || {}\n if (data.hasOwnProperty('currentHour') && typeof data.currentHour === 'number') {\n return data.currentHour\n }\n return this.minDayHours\n }\n set currentHour(value: number | undefined) {\n let data = storage.getVariable<TimeDataType>(TIME_DATA_KEY) || {}\n if (typeof value === 'number') {\n data.currentHour = value\n } else {\n delete data.currentHour\n }\n storage.setVariable(TIME_DATA_KEY, data)\n }\n /**\n * Get the current day\n */\n get currentDay(): number {\n let data = storage.getVariable<TimeDataType>(TIME_DATA_KEY) || {}\n if (data.hasOwnProperty('currentDay') && typeof data.currentDay === 'number') {\n return data.currentDay\n }\n return 0\n }\n set currentDay(value: number | undefined) {\n let data = storage.getVariable<TimeDataType>(TIME_DATA_KEY) || {}\n if (typeof value === 'number') {\n data.currentDay = value\n }\n else {\n delete data.currentDay\n }\n storage.setVariable(TIME_DATA_KEY, data)\n }\n /**\n * If the current day is greater than or equal to the weekend start day, then it will return true.\n */\n get isWeekend(): boolean {\n return this.currentWeekDayNumber >= this.weekendStartDay\n }\n /**\n * Get the current week day number (1 - {@link weekLength}).\n * For example, if the week length is 7 and the current day is 10, then the result will be 4.\n */\n get currentWeekDayNumber(): number {\n let result = this.currentDay % this.weekLength\n return result + 1\n }\n /**\n * Get the current week day name. If the week days names are not defined, then it will return undefined.\n * 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'.\n * @default \"\"\n */\n get currentDayName(): string {\n let weekDayNumber = this.currentWeekDayNumber - 1\n if (weekDayNumber >= this.weekDaysNames.length) {\n console.warn(`[NQTR] Week day name is not defined for day ${weekDayNumber}`, this.weekDaysNames)\n return \"\"\n }\n return this.weekDaysNames[weekDayNumber]\n }\n /**\n * Get the current {@link timeSlots} index.\n * You can use this property to create \"Image that changes based on the time period\":\n * @example\n * ```tsx\n * import { weekLength } from '@drincs/nqtr';\n * \n * function changeBackground() {\n * return (\n * <img src={`background-currentTimeSlot.currentTimeSlot.png`} />\n * )\n * }\n */\n get currentTimeSlot(): number {\n if (this.timeSlots.length === 0) {\n console.warn('[NQTR] Time slots are not defined')\n return 0\n }\n for (let index = 0; index < this.timeSlots.length; index++) {\n let slot = this.timeSlots[index]\n if (this.timeSlots.length > index + 1) {\n if (this.nowIsBetween(slot.startHour, this.timeSlots[index + 1].startHour)) {\n return index\n }\n }\n }\n return this.timeSlots.length - 1\n }\n\n /**\n * This function will increase the current hour by the given time spent.\n * 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.\n * @param timeSpent is the time spent in hours (default: {@link defaultTimeSpent})\n * @returns currentTimeSlot.currentHour\n */\n increaseHour(timeSpent: number = this.defaultTimeSpent): number {\n let newHour = this.currentHour + timeSpent\n if (newHour >= this.maxDayHours) {\n this.increaseDay()\n newHour = this.minDayHours + (newHour - this.maxDayHours)\n }\n this.currentHour = newHour\n return this.currentHour\n }\n\n /**\n * This function will increase the current day by the given days.\n * @param newDayHour is the hour of the new day (default: {@link minDayHours})\n * @param days is the number of days to increase (default: 1)\n * @returns timeTracker.currentDay\n */\n increaseDay(newDayHour: number = this.minDayHours, days: number = 1): number {\n let newDay = this.currentDay + days\n this.currentDay = newDay\n this.currentHour = newDayHour\n return this.currentDay\n }\n\n /**\n * This function will check if the current hour is between the given hours.\n * @param fromHour the starting hour. If the {@link currentHour} is equal to this hour, the function will return true.\n * @param toHour the ending hour.\n * @returns true if the current hour is between the given hours, otherwise false.\n */\n nowIsBetween(fromHour: number, toHour: number): boolean {\n let currentHour = this.currentHour\n if (fromHour < toHour) {\n return currentHour >= fromHour && currentHour < toHour\n }\n return currentHour >= fromHour || currentHour < toHour\n }\n}\n"]}
@@ -1,2 +1,6 @@
1
- export { default as TimeManager } from './TimeManager.mjs';
1
+ import TimeManager from './TimeManager.mjs';
2
2
  import '../types/TimeSettings.mjs';
3
+
4
+ declare const timeTracker: TimeManager;
5
+
6
+ export { timeTracker };
@@ -1,2 +1,6 @@
1
- export { default as TimeManager } from './TimeManager.js';
1
+ import TimeManager from './TimeManager.js';
2
2
  import '../types/TimeSettings.js';
3
+
4
+ declare const timeTracker: TimeManager;
5
+
6
+ export { timeTracker };
@@ -1,251 +1,2 @@
1
- 'use strict';
2
-
3
- var pixiVn = require('@drincs/pixi-vn');
4
-
5
- // src/managers/TimeManager.ts
6
- var TIME_SETTINGS_KEY = "___nqtr-time_manager_settings___";
7
- var TIME_DATA_KEY = "___nqtr-time_manager_data___";
8
- var TimeManager = class _TimeManager {
9
- constructor() {
10
- }
11
- static editSettings(settings) {
12
- let data = {};
13
- if (typeof settings.minDayHours === "number") {
14
- data["minDayHours"] = settings.minDayHours;
15
- }
16
- if (typeof settings.maxDayHours === "number") {
17
- data["maxDayHours"] = settings.maxDayHours;
18
- }
19
- if (typeof settings.minDayHours === "number") {
20
- data["defaultTimeSpent"] = settings.defaultTimeSpent;
21
- }
22
- if (Array.isArray(settings.timeSlots)) {
23
- data["timeSlots"] = settings.timeSlots;
24
- }
25
- if (typeof settings.weekLength === "number") {
26
- data["weekLength"] = settings.weekLength;
27
- }
28
- if (typeof settings.weekendStartDay === "number") {
29
- let weekLength = settings.weekLength || _TimeManager.weekLength;
30
- if (settings.weekendStartDay >= weekLength) {
31
- console.warn(`[NQTR] Weekend start day should be less than week length ${weekLength}`);
32
- }
33
- data["weekendStartDay"] = settings.weekendStartDay;
34
- }
35
- if (Array.isArray(settings.weekDaysNames)) {
36
- let weekLength = settings.weekLength || _TimeManager.weekLength;
37
- if (settings.weekDaysNames.length !== weekLength) {
38
- console.warn(`[NQTR] Week days names should be equal to week length ${weekLength}`);
39
- }
40
- data["weekDaysNames"] = settings.weekDaysNames;
41
- }
42
- pixiVn.GameStorageManager.setVariable(TIME_SETTINGS_KEY, data);
43
- }
44
- /**
45
- * Get time settings
46
- * @default {}
47
- */
48
- static get settings() {
49
- let settings = pixiVn.GameStorageManager.getVariable(TIME_SETTINGS_KEY) || {};
50
- return settings;
51
- }
52
- /**
53
- * 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.
54
- */
55
- static set settings(value) {
56
- _TimeManager.editSettings(value);
57
- }
58
- static get minDayHours() {
59
- let result = 0;
60
- let settings = pixiVn.GameStorageManager.getVariable(TIME_SETTINGS_KEY);
61
- if (settings && settings.hasOwnProperty("minDayHours")) {
62
- result = settings.minDayHours || 0;
63
- }
64
- return result;
65
- }
66
- static get maxDayHours() {
67
- let result = 24;
68
- let settings = pixiVn.GameStorageManager.getVariable(TIME_SETTINGS_KEY);
69
- if (settings && settings.hasOwnProperty("maxDayHours")) {
70
- result = settings.maxDayHours || 24;
71
- }
72
- return result;
73
- }
74
- static get defaultTimeSpent() {
75
- let result = 1;
76
- let settings = pixiVn.GameStorageManager.getVariable(TIME_SETTINGS_KEY);
77
- if (settings && settings.hasOwnProperty("defaultTimeSpent")) {
78
- result = settings.defaultTimeSpent || 1;
79
- }
80
- return result;
81
- }
82
- static get timeSlots() {
83
- let result = [];
84
- let settings = pixiVn.GameStorageManager.getVariable(TIME_SETTINGS_KEY);
85
- if (settings && settings.hasOwnProperty("timeSlots")) {
86
- result = settings.timeSlots || [];
87
- }
88
- return result;
89
- }
90
- static get weekLength() {
91
- let result = 7;
92
- let settings = pixiVn.GameStorageManager.getVariable(TIME_SETTINGS_KEY);
93
- if (settings && settings.hasOwnProperty("weekLength")) {
94
- result = settings.weekLength || 7;
95
- }
96
- return result;
97
- }
98
- static get weekendStartDay() {
99
- let result = _TimeManager.weekLength - 1;
100
- let settings = pixiVn.GameStorageManager.getVariable(TIME_SETTINGS_KEY);
101
- if (settings && settings.hasOwnProperty("weekendStartDay")) {
102
- result = settings.weekendStartDay || _TimeManager.weekLength - 1;
103
- }
104
- return result;
105
- }
106
- static get weekDaysNames() {
107
- let result = [];
108
- let settings = pixiVn.GameStorageManager.getVariable(TIME_SETTINGS_KEY);
109
- if (settings && settings.hasOwnProperty("weekDaysNames")) {
110
- result = settings.weekDaysNames || result;
111
- }
112
- return result;
113
- }
114
- /**
115
- * Get the current hour
116
- */
117
- static get currentHour() {
118
- let data = pixiVn.GameStorageManager.getVariable(TIME_DATA_KEY) || {};
119
- if (data.hasOwnProperty("currentHour") && typeof data.currentHour === "number") {
120
- return data.currentHour;
121
- }
122
- return _TimeManager.minDayHours;
123
- }
124
- static set currentHour(value) {
125
- let data = pixiVn.GameStorageManager.getVariable(TIME_DATA_KEY) || {};
126
- if (typeof value === "number") {
127
- data.currentHour = value;
128
- } else {
129
- delete data.currentHour;
130
- }
131
- pixiVn.GameStorageManager.setVariable(TIME_DATA_KEY, data);
132
- }
133
- /**
134
- * Get the current day
135
- */
136
- static get currentDay() {
137
- let data = pixiVn.GameStorageManager.getVariable(TIME_DATA_KEY) || {};
138
- if (data.hasOwnProperty("currentDay") && typeof data.currentDay === "number") {
139
- return data.currentDay;
140
- }
141
- return 0;
142
- }
143
- static set currentDay(value) {
144
- let data = pixiVn.GameStorageManager.getVariable(TIME_DATA_KEY) || {};
145
- if (typeof value === "number") {
146
- data.currentDay = value;
147
- } else {
148
- delete data.currentDay;
149
- }
150
- pixiVn.GameStorageManager.setVariable(TIME_DATA_KEY, data);
151
- }
152
- /**
153
- * If the current day is greater than or equal to the weekend start day, then it will return true.
154
- */
155
- static get isWeekend() {
156
- return _TimeManager.currentWeekDayNumber >= _TimeManager.weekendStartDay;
157
- }
158
- /**
159
- * Get the current week day number (1-TimeManager.weekLength).
160
- * For example, if the week length is 7 and the current day is 10, then the result will be 4.
161
- */
162
- static get currentWeekDayNumber() {
163
- let result = _TimeManager.currentDay % _TimeManager.weekLength;
164
- return result + 1;
165
- }
166
- /**
167
- * Get the current week day name. If the week days names are not defined, then it will return undefined.
168
- * 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'.
169
- * @default ""
170
- */
171
- static get currentDayName() {
172
- let weekDayNumber = _TimeManager.currentWeekDayNumber - 1;
173
- if (weekDayNumber >= _TimeManager.weekDaysNames.length) {
174
- console.warn(`[NQTR] Week day name is not defined for day ${weekDayNumber}`, _TimeManager.weekDaysNames);
175
- return "";
176
- }
177
- return _TimeManager.weekDaysNames[weekDayNumber];
178
- }
179
- /**
180
- * Get the current TimeManager.timeSlots index.
181
- * You can use this property to create "Image that changes based on the time period":
182
- * @example
183
- * ```tsx
184
- * import { TimeManager } from '@drincs/nqtr';
185
- *
186
- * function changeBackground() {
187
- * return (
188
- * <img src={`background-${TimeManager.currentTimeSlot}.png`} />
189
- * )
190
- * }
191
- */
192
- static get currentTimeSlot() {
193
- if (_TimeManager.timeSlots.length === 0) {
194
- console.warn("[NQTR] Time slots are not defined");
195
- return 0;
196
- }
197
- for (let index = 0; index < _TimeManager.timeSlots.length; index++) {
198
- let slot = _TimeManager.timeSlots[index];
199
- if (_TimeManager.timeSlots.length > index + 1) {
200
- if (_TimeManager.nowIsBetween(slot.startHour, _TimeManager.timeSlots[index + 1].startHour)) {
201
- return index;
202
- }
203
- }
204
- }
205
- return _TimeManager.timeSlots.length - 1;
206
- }
207
- /**
208
- * This function will increase the current hour by the given time spent.
209
- * 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.
210
- * @param timeSpent is the time spent in hours (default: TimeManager.defaultTimeSpent)
211
- * @returns TimeManager.currentHour
212
- */
213
- static increaseHour(timeSpent = _TimeManager.defaultTimeSpent) {
214
- let newHour = _TimeManager.currentHour + timeSpent;
215
- if (newHour >= _TimeManager.maxDayHours) {
216
- _TimeManager.increaseDay();
217
- newHour = _TimeManager.minDayHours + (newHour - _TimeManager.maxDayHours);
218
- }
219
- _TimeManager.currentHour = newHour;
220
- return _TimeManager.currentHour;
221
- }
222
- /**
223
- * This function will increase the current day by the given days.
224
- * @param newDayHour is the hour of the new day (default: TimeManager.minDayHours)
225
- * @param days is the number of days to increase (default: 1)
226
- * @returns TimeManager.currentDay
227
- */
228
- static increaseDay(newDayHour = _TimeManager.minDayHours, days = 1) {
229
- let newDay = _TimeManager.currentDay + days;
230
- _TimeManager.currentDay = newDay;
231
- _TimeManager.currentHour = newDayHour;
232
- return _TimeManager.currentDay;
233
- }
234
- /**
235
- * This function will check if the current hour is between the given hours.
236
- * @param fromHour the starting hour. If the TimeManager.currentHour is equal to this hour, the function will return true.
237
- * @param toHour the ending hour.
238
- * @returns true if the current hour is between the given hours, otherwise false.
239
- */
240
- static nowIsBetween(fromHour, toHour) {
241
- let currentHour = _TimeManager.currentHour;
242
- if (fromHour < toHour) {
243
- return currentHour >= fromHour && currentHour < toHour;
244
- }
245
- return currentHour >= fromHour || currentHour < toHour;
246
- }
247
- };
248
-
249
- exports.TimeManager = TimeManager;
250
- //# sourceMappingURL=out.js.map
1
+ 'use strict';var pixiVn=require('@drincs/pixi-vn');var a="___nqtr-time_manager_settings___",i="___nqtr-time_manager_data___";var s=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;}pixiVn.storage.setVariable(a,t);}get settings(){return pixiVn.storage.getVariable(a)||{}}set settings(e){this.editSettings(e);}get minDayHours(){let e=0,t=pixiVn.storage.getVariable(a);return t&&t.hasOwnProperty("minDayHours")&&(e=t.minDayHours||0),e}get maxDayHours(){let e=24,t=pixiVn.storage.getVariable(a);return t&&t.hasOwnProperty("maxDayHours")&&(e=t.maxDayHours||24),e}get defaultTimeSpent(){let e=1,t=pixiVn.storage.getVariable(a);return t&&t.hasOwnProperty("defaultTimeSpent")&&(e=t.defaultTimeSpent||1),e}get timeSlots(){let e=[],t=pixiVn.storage.getVariable(a);return t&&t.hasOwnProperty("timeSlots")&&(e=t.timeSlots||[]),e}get weekLength(){let e=7,t=pixiVn.storage.getVariable(a);return t&&t.hasOwnProperty("weekLength")&&(e=t.weekLength||7),e}get weekendStartDay(){let e=this.weekLength-1,t=pixiVn.storage.getVariable(a);return t&&t.hasOwnProperty("weekendStartDay")&&(e=t.weekendStartDay||this.weekLength-1),e}get weekDaysNames(){let e=[],t=pixiVn.storage.getVariable(a);return t&&t.hasOwnProperty("weekDaysNames")&&(e=t.weekDaysNames||e),e}get currentHour(){let e=pixiVn.storage.getVariable(i)||{};return e.hasOwnProperty("currentHour")&&typeof e.currentHour=="number"?e.currentHour:this.minDayHours}set currentHour(e){let t=pixiVn.storage.getVariable(i)||{};typeof e=="number"?t.currentHour=e:delete t.currentHour,pixiVn.storage.setVariable(i,t);}get currentDay(){let e=pixiVn.storage.getVariable(i)||{};return e.hasOwnProperty("currentDay")&&typeof e.currentDay=="number"?e.currentDay:0}set currentDay(e){let t=pixiVn.storage.getVariable(i)||{};typeof e=="number"?t.currentDay=e:delete t.currentDay,pixiVn.storage.setVariable(i,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 g=new s;exports.timeTracker=g;//# sourceMappingURL=index.js.map
251
2
  //# sourceMappingURL=index.js.map