@drincs/nqtr 0.0.2 → 0.0.4

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/index.d.mts CHANGED
@@ -315,11 +315,17 @@ interface RoomBaseModelProps {
315
315
  * The icon element. Can be a string or an HTMLElement or a Pixi'VN CanvasItem
316
316
  */
317
317
  iconElement?: GraphicItemType;
318
+ /**
319
+ * Whether is an entrance room, so when the player enters in the location, it will be the first room to be shown.
320
+ */
321
+ isEntrance?: boolean;
318
322
  }
319
323
  declare class RoomBaseModel<TLocation extends LocationBaseModel = LocationBaseModel> extends StoredClassModel {
320
324
  constructor(id: string, location: TLocation, props: RoomBaseModelProps);
321
325
  private _location;
322
326
  get location(): TLocation;
327
+ private _isEntrance?;
328
+ get isEntrance(): boolean;
323
329
  private defaultName;
324
330
  get name(): string;
325
331
  set name(value: string);
@@ -370,9 +376,8 @@ interface LocationBaseModelProps {
370
376
  iconElement?: GraphicItemType;
371
377
  }
372
378
  declare class LocationBaseModel<TMap extends MapBaseModel = MapBaseModel> extends StoredClassModel {
373
- constructor(id: string, map: TMap, entrance: RoomBaseModel, props: LocationBaseModelProps);
374
- private _entrance;
375
- get entrance(): RoomBaseModel;
379
+ constructor(id: string, map: TMap, props: LocationBaseModelProps);
380
+ getEntrance<TRoom extends RoomBaseModel = RoomBaseModel>(): TRoom | undefined;
376
381
  private defaultName;
377
382
  get name(): string;
378
383
  set name(value: string);
@@ -574,15 +579,64 @@ declare class TimeManager {
574
579
  static get weekLength(): number;
575
580
  static get weekendStartDay(): number;
576
581
  static get weekDaysNames(): string[];
582
+ /**
583
+ * Get the current hour
584
+ */
577
585
  static get currentHour(): number;
578
586
  static set currentHour(value: number | undefined);
587
+ /**
588
+ * Get the current day
589
+ */
579
590
  static get currentDay(): number;
580
591
  static set currentDay(value: number | undefined);
592
+ /**
593
+ * If the current day is greater than or equal to the weekend start day, then it will return true.
594
+ */
581
595
  static get isWeekend(): boolean;
582
- static get weekDayNumber(): number;
583
- static get weekDayName(): string | undefined;
584
- static newHour(timeSpent?: number): number;
585
- static newDay(days?: number): number;
596
+ /**
597
+ * Get the current week day number (1-TimeManager.weekLength).
598
+ * For example, if the week length is 7 and the current day is 10, then the result will be 4.
599
+ */
600
+ static get currentWeekDayNumber(): number;
601
+ /**
602
+ * Get the current week day name. If the week days names are not defined, then it will return undefined.
603
+ * 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'.
604
+ */
605
+ static get currentDayName(): string | undefined;
606
+ /**
607
+ * Get the current TimeManager.timeSlots index.
608
+ * You can use this property to create "Image that changes based on the time period":
609
+ * @example
610
+ * ```ts
611
+ * import { TimeManager } from '@drincs/nqtr';
612
+ *
613
+ * function changeBackground() {
614
+ * return (
615
+ * <img src={`background-${TimeManager.currentTimeSlot}.png`} />
616
+ * )
617
+ * }
618
+ */
619
+ static get currentTimeSlots(): number;
620
+ /**
621
+ * This function will increase the current hour by the given time spent.
622
+ * 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.
623
+ * @param timeSpent is the time spent in hours (default: TimeManager.defaultTimeSpent)
624
+ * @returns TimeManager.currentHour
625
+ */
626
+ static increaseHour(timeSpent?: number): number;
627
+ /**
628
+ * This function will increase the current day by the given days.
629
+ * @param newDayHour is the hour of the new day (default: TimeManager.minDayHours)
630
+ * @param days is the number of days to increase (default: 1)
631
+ * @returns TimeManager.currentDay
632
+ */
633
+ static increaseDay(newDayHour?: number, days?: number): number;
634
+ /**
635
+ * This function will check if the current hour is between the given hours.
636
+ * @param fromHour the starting hour. If the TimeManager.currentHour is equal to this hour, the function will return true.
637
+ * @param toHour the ending hour.
638
+ * @returns true if the current hour is between the given hours, otherwise false.
639
+ */
586
640
  static nowIsBetween(fromHour: number, toHour: number): boolean;
587
641
  }
588
642
 
package/dist/index.d.ts CHANGED
@@ -315,11 +315,17 @@ interface RoomBaseModelProps {
315
315
  * The icon element. Can be a string or an HTMLElement or a Pixi'VN CanvasItem
316
316
  */
317
317
  iconElement?: GraphicItemType;
318
+ /**
319
+ * Whether is an entrance room, so when the player enters in the location, it will be the first room to be shown.
320
+ */
321
+ isEntrance?: boolean;
318
322
  }
319
323
  declare class RoomBaseModel<TLocation extends LocationBaseModel = LocationBaseModel> extends StoredClassModel {
320
324
  constructor(id: string, location: TLocation, props: RoomBaseModelProps);
321
325
  private _location;
322
326
  get location(): TLocation;
327
+ private _isEntrance?;
328
+ get isEntrance(): boolean;
323
329
  private defaultName;
324
330
  get name(): string;
325
331
  set name(value: string);
@@ -370,9 +376,8 @@ interface LocationBaseModelProps {
370
376
  iconElement?: GraphicItemType;
371
377
  }
372
378
  declare class LocationBaseModel<TMap extends MapBaseModel = MapBaseModel> extends StoredClassModel {
373
- constructor(id: string, map: TMap, entrance: RoomBaseModel, props: LocationBaseModelProps);
374
- private _entrance;
375
- get entrance(): RoomBaseModel;
379
+ constructor(id: string, map: TMap, props: LocationBaseModelProps);
380
+ getEntrance<TRoom extends RoomBaseModel = RoomBaseModel>(): TRoom | undefined;
376
381
  private defaultName;
377
382
  get name(): string;
378
383
  set name(value: string);
@@ -574,15 +579,64 @@ declare class TimeManager {
574
579
  static get weekLength(): number;
575
580
  static get weekendStartDay(): number;
576
581
  static get weekDaysNames(): string[];
582
+ /**
583
+ * Get the current hour
584
+ */
577
585
  static get currentHour(): number;
578
586
  static set currentHour(value: number | undefined);
587
+ /**
588
+ * Get the current day
589
+ */
579
590
  static get currentDay(): number;
580
591
  static set currentDay(value: number | undefined);
592
+ /**
593
+ * If the current day is greater than or equal to the weekend start day, then it will return true.
594
+ */
581
595
  static get isWeekend(): boolean;
582
- static get weekDayNumber(): number;
583
- static get weekDayName(): string | undefined;
584
- static newHour(timeSpent?: number): number;
585
- static newDay(days?: number): number;
596
+ /**
597
+ * Get the current week day number (1-TimeManager.weekLength).
598
+ * For example, if the week length is 7 and the current day is 10, then the result will be 4.
599
+ */
600
+ static get currentWeekDayNumber(): number;
601
+ /**
602
+ * Get the current week day name. If the week days names are not defined, then it will return undefined.
603
+ * 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'.
604
+ */
605
+ static get currentDayName(): string | undefined;
606
+ /**
607
+ * Get the current TimeManager.timeSlots index.
608
+ * You can use this property to create "Image that changes based on the time period":
609
+ * @example
610
+ * ```ts
611
+ * import { TimeManager } from '@drincs/nqtr';
612
+ *
613
+ * function changeBackground() {
614
+ * return (
615
+ * <img src={`background-${TimeManager.currentTimeSlot}.png`} />
616
+ * )
617
+ * }
618
+ */
619
+ static get currentTimeSlots(): number;
620
+ /**
621
+ * This function will increase the current hour by the given time spent.
622
+ * 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.
623
+ * @param timeSpent is the time spent in hours (default: TimeManager.defaultTimeSpent)
624
+ * @returns TimeManager.currentHour
625
+ */
626
+ static increaseHour(timeSpent?: number): number;
627
+ /**
628
+ * This function will increase the current day by the given days.
629
+ * @param newDayHour is the hour of the new day (default: TimeManager.minDayHours)
630
+ * @param days is the number of days to increase (default: 1)
631
+ * @returns TimeManager.currentDay
632
+ */
633
+ static increaseDay(newDayHour?: number, days?: number): number;
634
+ /**
635
+ * This function will check if the current hour is between the given hours.
636
+ * @param fromHour the starting hour. If the TimeManager.currentHour is equal to this hour, the function will return true.
637
+ * @param toHour the ending hour.
638
+ * @returns true if the current hour is between the given hours, otherwise false.
639
+ */
586
640
  static nowIsBetween(fromHour: number, toHour: number): boolean;
587
641
  }
588
642
 
package/dist/index.js CHANGED
@@ -177,6 +177,9 @@ var TimeManager = class _TimeManager {
177
177
  }
178
178
  return result;
179
179
  }
180
+ /**
181
+ * Get the current hour
182
+ */
180
183
  static get currentHour() {
181
184
  let data = import_pixi_vn.GameStorageManager.getVariable(TIME_DATA_KEY) || {};
182
185
  if (data.hasOwnProperty("currentHour") && typeof data.currentHour === "number") {
@@ -193,6 +196,9 @@ var TimeManager = class _TimeManager {
193
196
  }
194
197
  import_pixi_vn.GameStorageManager.setVariable(TIME_DATA_KEY, data);
195
198
  }
199
+ /**
200
+ * Get the current day
201
+ */
196
202
  static get currentDay() {
197
203
  let data = import_pixi_vn.GameStorageManager.getVariable(TIME_DATA_KEY) || {};
198
204
  if (data.hasOwnProperty("currentDay") && typeof data.currentDay === "number") {
@@ -209,35 +215,92 @@ var TimeManager = class _TimeManager {
209
215
  }
210
216
  import_pixi_vn.GameStorageManager.setVariable(TIME_DATA_KEY, data);
211
217
  }
218
+ /**
219
+ * If the current day is greater than or equal to the weekend start day, then it will return true.
220
+ */
212
221
  static get isWeekend() {
213
- return _TimeManager.weekDayNumber >= _TimeManager.weekendStartDay;
222
+ return _TimeManager.currentWeekDayNumber >= _TimeManager.weekendStartDay;
214
223
  }
215
- static get weekDayNumber() {
224
+ /**
225
+ * Get the current week day number (1-TimeManager.weekLength).
226
+ * For example, if the week length is 7 and the current day is 10, then the result will be 4.
227
+ */
228
+ static get currentWeekDayNumber() {
216
229
  let result = _TimeManager.currentDay % _TimeManager.weekLength;
217
230
  return result + 1;
218
231
  }
219
- static get weekDayName() {
220
- let weekDayNumber = _TimeManager.weekDayNumber - 1;
232
+ /**
233
+ * Get the current week day name. If the week days names are not defined, then it will return undefined.
234
+ * 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'.
235
+ */
236
+ static get currentDayName() {
237
+ let weekDayNumber = _TimeManager.currentWeekDayNumber - 1;
221
238
  if (weekDayNumber >= _TimeManager.weekDaysNames.length) {
222
239
  console.warn(`[NQTR] Week day name is not defined for day ${weekDayNumber}`, _TimeManager.weekDaysNames);
223
240
  return void 0;
224
241
  }
225
242
  return _TimeManager.weekDaysNames[weekDayNumber];
226
243
  }
227
- static newHour(timeSpent = _TimeManager.defaultTimeSpent) {
244
+ /**
245
+ * Get the current TimeManager.timeSlots index.
246
+ * You can use this property to create "Image that changes based on the time period":
247
+ * @example
248
+ * ```ts
249
+ * import { TimeManager } from '@drincs/nqtr';
250
+ *
251
+ * function changeBackground() {
252
+ * return (
253
+ * <img src={`background-${TimeManager.currentTimeSlot}.png`} />
254
+ * )
255
+ * }
256
+ */
257
+ static get currentTimeSlots() {
258
+ if (_TimeManager.timeSlots.length === 0) {
259
+ console.warn("[NQTR] Time slots are not defined");
260
+ return 0;
261
+ }
262
+ _TimeManager.timeSlots.forEach((slot, index) => {
263
+ if (_TimeManager.timeSlots.length > index + 1) {
264
+ if (_TimeManager.nowIsBetween(slot.startHour, _TimeManager.timeSlots[index + 1].startHour)) {
265
+ return index;
266
+ }
267
+ }
268
+ });
269
+ return 0;
270
+ }
271
+ /**
272
+ * This function will increase the current hour by the given time spent.
273
+ * 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.
274
+ * @param timeSpent is the time spent in hours (default: TimeManager.defaultTimeSpent)
275
+ * @returns TimeManager.currentHour
276
+ */
277
+ static increaseHour(timeSpent = _TimeManager.defaultTimeSpent) {
228
278
  let newHour = _TimeManager.currentHour + timeSpent;
229
279
  if (newHour >= _TimeManager.maxDayHours) {
230
- _TimeManager.newDay();
280
+ _TimeManager.increaseDay();
231
281
  newHour = _TimeManager.minDayHours + (newHour - _TimeManager.maxDayHours);
232
282
  }
233
283
  _TimeManager.currentHour = newHour;
234
- return newHour;
284
+ return _TimeManager.currentHour;
235
285
  }
236
- static newDay(days = 1) {
286
+ /**
287
+ * This function will increase the current day by the given days.
288
+ * @param newDayHour is the hour of the new day (default: TimeManager.minDayHours)
289
+ * @param days is the number of days to increase (default: 1)
290
+ * @returns TimeManager.currentDay
291
+ */
292
+ static increaseDay(newDayHour = _TimeManager.minDayHours, days = 1) {
237
293
  let newDay = _TimeManager.currentDay + days;
238
294
  _TimeManager.currentDay = newDay;
239
- return newDay;
295
+ _TimeManager.currentHour = newDayHour;
296
+ return _TimeManager.currentDay;
240
297
  }
298
+ /**
299
+ * This function will check if the current hour is between the given hours.
300
+ * @param fromHour the starting hour. If the TimeManager.currentHour is equal to this hour, the function will return true.
301
+ * @param toHour the ending hour.
302
+ * @returns true if the current hour is between the given hours, otherwise false.
303
+ */
241
304
  static nowIsBetween(fromHour, toHour) {
242
305
  let currentHour = _TimeManager.currentHour;
243
306
  if (fromHour < toHour) {
@@ -421,22 +484,53 @@ var ActivityModel = class {
421
484
 
422
485
  // src/classes/navigation/Location.ts
423
486
  var import_pixi_vn3 = require("@drincs/pixi-vn");
487
+
488
+ // src/decorators/RoomDecorator.ts
489
+ var registeredRooms = {};
490
+ function saveRoom(room) {
491
+ if (Array.isArray(room)) {
492
+ room.forEach((c) => saveRoom(c));
493
+ return;
494
+ }
495
+ if (registeredRooms[room.id]) {
496
+ console.warn(`[NQTR] Room id ${room.id} already exists, it will be overwritten`);
497
+ }
498
+ registeredRooms[room.id] = room;
499
+ }
500
+ function getRoomById(id) {
501
+ try {
502
+ let room = registeredRooms[id];
503
+ if (!room) {
504
+ console.error(`[NQTR] Room ${id} not found`);
505
+ return;
506
+ }
507
+ return room;
508
+ } catch (e) {
509
+ console.error(`[NQTR] Error while getting Room ${id}`, e);
510
+ return;
511
+ }
512
+ }
513
+ function getRoomByLocation(location) {
514
+ return Object.values(registeredRooms).filter((room) => room.location === location);
515
+ }
516
+
517
+ // src/classes/navigation/Location.ts
424
518
  var LOCATION_CATEGORY = "__nqtr-location__";
425
519
  var LocationBaseModel = class extends import_pixi_vn3.StoredClassModel {
426
- constructor(id, map, entrance, props) {
520
+ constructor(id, map, props) {
427
521
  super(LOCATION_CATEGORY, id);
428
- if (entrance.location.id !== id) {
429
- throw new Error(`[NQTR] Entrance room ${entrance.id} is not in location ${id}`);
430
- }
431
- this._entrance = entrance;
432
522
  this.defaultName = props.name || "";
433
523
  this.defaultDisabled = props.disabled || false;
434
524
  this.defaultHidden = props.hidden || false;
435
525
  this._iconElement = props.iconElement;
436
526
  this._map = map;
437
527
  }
438
- get entrance() {
439
- return this._entrance;
528
+ getEntrance() {
529
+ let rooms = getRoomByLocation(this);
530
+ if (rooms.length === 0) {
531
+ return;
532
+ }
533
+ return rooms.find((room) => room.isEntrance) || rooms[0];
440
534
  }
441
535
  get name() {
442
536
  return this.getStorageProperty("name") || this.defaultName;
@@ -610,32 +704,6 @@ function getTemporaryCommitments() {
610
704
  return commitments;
611
705
  }
612
706
 
613
- // src/decorators/RoomDecorator.ts
614
- var registeredRooms = {};
615
- function saveRoom(room) {
616
- if (Array.isArray(room)) {
617
- room.forEach((c) => saveRoom(c));
618
- return;
619
- }
620
- if (registeredRooms[room.id]) {
621
- console.warn(`[NQTR] Room id ${room.id} already exists, it will be overwritten`);
622
- }
623
- registeredRooms[room.id] = room;
624
- }
625
- function getRoomById(id) {
626
- try {
627
- let room = registeredRooms[id];
628
- if (!room) {
629
- console.error(`[NQTR] Room ${id} not found`);
630
- return;
631
- }
632
- return room;
633
- } catch (e) {
634
- console.error(`[NQTR] Error while getting Room ${id}`, e);
635
- return;
636
- }
637
- }
638
-
639
707
  // src/functions/RoutineFunctions.ts
640
708
  function clearExpiredRoutine() {
641
709
  Object.entries(registeredCommitments).forEach(([_, commitment]) => {
@@ -745,10 +813,14 @@ var RoomBaseModel = class extends import_pixi_vn6.StoredClassModel {
745
813
  this.defaultDisabled = props.disabled || false;
746
814
  this.defaultHidden = props.hidden || false;
747
815
  this._iconElement = props.iconElement;
816
+ this._isEntrance = props.isEntrance;
748
817
  }
749
818
  get location() {
750
819
  return this._location;
751
820
  }
821
+ get isEntrance() {
822
+ return this._isEntrance || false;
823
+ }
752
824
  get name() {
753
825
  return this.getStorageProperty("name") || this.defaultName;
754
826
  }