@drincs/nqtr 0.0.3 → 0.0.5

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.mjs CHANGED
@@ -270,7 +270,7 @@ var ActivityStoredAbstract = class {
270
270
  this.defaultToDay = props.toDay;
271
271
  this.defaultDisabled = props.disabled || false;
272
272
  this.defaultHidden = props.hidden || false;
273
- this._iconElement = props.iconElement;
273
+ this._icon = props.icon;
274
274
  this._onRun = onRun;
275
275
  }
276
276
  get name() {
@@ -332,8 +332,8 @@ var ActivityStoredAbstract = class {
332
332
  set hidden(value) {
333
333
  this.setStorageProperty("hidden", value);
334
334
  }
335
- get iconElement() {
336
- return this._iconElement;
335
+ get icon() {
336
+ return this._icon;
337
337
  }
338
338
  get onRun() {
339
339
  return this._onRun;
@@ -353,7 +353,7 @@ var ActivityStoredAbstract = class {
353
353
  toDay: this.getStorageProperty("toDay") || this.defaultToDay,
354
354
  disabled: this.getStorageProperty("disabled") || this.defaultDisabled,
355
355
  hidden: this.getStorageProperty("hidden") || this.defaultHidden,
356
- iconElement: this._iconElement
356
+ icon: this._icon
357
357
  };
358
358
  }
359
359
  };
@@ -367,7 +367,7 @@ var ActivityModel = class {
367
367
  this._toDay = props.toDay;
368
368
  this._disabled = props.disabled || false;
369
369
  this._hidden = props.hidden || false;
370
- this._iconElement = props.iconElement;
370
+ this._icon = props.icon;
371
371
  this._onRun = onRun;
372
372
  }
373
373
  get id() {
@@ -406,8 +406,8 @@ var ActivityModel = class {
406
406
  }
407
407
  return this._hidden;
408
408
  }
409
- get iconElement() {
410
- return this._iconElement;
409
+ get icon() {
410
+ return this._icon;
411
411
  }
412
412
  get onRun() {
413
413
  return this._onRun;
@@ -427,36 +427,89 @@ var ActivityModel = class {
427
427
  toDay: this._toDay,
428
428
  disabled: this._disabled,
429
429
  hidden: this._hidden,
430
- iconElement: this._iconElement
430
+ icon: this._icon
431
431
  };
432
432
  }
433
433
  };
434
434
 
435
435
  // src/classes/navigation/Location.ts
436
436
  import { getFlag as getFlag2, StoredClassModel } from "@drincs/pixi-vn";
437
+
438
+ // src/decorators/RoomDecorator.ts
439
+ var registeredRooms = {};
440
+ function saveRoom(room) {
441
+ if (Array.isArray(room)) {
442
+ room.forEach((c) => saveRoom(c));
443
+ return;
444
+ }
445
+ if (registeredRooms[room.id]) {
446
+ console.warn(`[NQTR] Room id ${room.id} already exists, it will be overwritten`);
447
+ }
448
+ registeredRooms[room.id] = room;
449
+ }
450
+ function getRoomById(id) {
451
+ try {
452
+ let room = registeredRooms[id];
453
+ if (!room) {
454
+ console.error(`[NQTR] Room ${id} not found`);
455
+ return;
456
+ }
457
+ return room;
458
+ } catch (e) {
459
+ console.error(`[NQTR] Error while getting Room ${id}`, e);
460
+ return;
461
+ }
462
+ }
463
+ function getRoomsByLocation(location) {
464
+ return Object.values(registeredRooms).filter((room) => room.location.id === location.id);
465
+ }
466
+ function getAllLocations() {
467
+ let result = {};
468
+ Object.values(registeredRooms).forEach((room) => {
469
+ result[room.location.id] = room.location;
470
+ });
471
+ return Object.values(result);
472
+ }
473
+ function getLocationsByMap(map) {
474
+ return getAllLocations().filter((location) => location.map.id === map.id);
475
+ }
476
+ function getAllMaps() {
477
+ let result = {};
478
+ Object.values(registeredRooms).forEach((room) => {
479
+ result[room.location.map.id] = room.location.map;
480
+ });
481
+ return Object.values(result);
482
+ }
483
+
484
+ // src/classes/navigation/Location.ts
437
485
  var LOCATION_CATEGORY = "__nqtr-location__";
438
486
  var LocationBaseModel = class extends StoredClassModel {
439
- constructor(id, map, entrance, props) {
487
+ /**
488
+ * @param id The id of the location, it must be unique.
489
+ * @param map The map where the location is.
490
+ * @param props The properties of the location.
491
+ */
492
+ constructor(id, map, props = {}) {
440
493
  super(LOCATION_CATEGORY, id);
441
- if (entrance.location.id !== id) {
442
- throw new Error(`[NQTR] Entrance room ${entrance.id} is not in location ${id}`);
443
- }
444
- this._entrance = entrance;
445
494
  this.defaultName = props.name || "";
446
495
  this.defaultDisabled = props.disabled || false;
447
496
  this.defaultHidden = props.hidden || false;
448
- this._iconElement = props.iconElement;
497
+ this._icon = props.icon;
449
498
  this._map = map;
450
499
  }
451
- get entrance() {
452
- return this._entrance;
453
- }
500
+ /**
501
+ * The name of the location.
502
+ * If you set undefined, it will return the default name.
503
+ */
454
504
  get name() {
455
505
  return this.getStorageProperty("name") || this.defaultName;
456
506
  }
457
507
  set name(value) {
458
508
  this.setStorageProperty("name", value);
459
509
  }
510
+ /**
511
+ * Whether is disabled. If it is a string, it is a Pixi'VN flag name.
512
+ */
460
513
  get disabled() {
461
514
  let value = this.getStorageProperty("disabled") || this.defaultDisabled;
462
515
  if (typeof value === "string") {
@@ -467,6 +520,9 @@ var LocationBaseModel = class extends StoredClassModel {
467
520
  set disabled(value) {
468
521
  this.setStorageProperty("disabled", value);
469
522
  }
523
+ /**
524
+ * Whether is hidden. If it is a string, it is a Pixi'VN flag name.
525
+ */
470
526
  get hidden() {
471
527
  let value = this.getStorageProperty("hidden") || this.defaultHidden;
472
528
  if (typeof value === "string") {
@@ -477,37 +533,87 @@ var LocationBaseModel = class extends StoredClassModel {
477
533
  set hidden(value) {
478
534
  this.setStorageProperty("hidden", value);
479
535
  }
480
- get iconElement() {
481
- return this._iconElement;
536
+ /**
537
+ * The icon element. Can be a string or an Element or a Pixi'VN CanvasItem
538
+ */
539
+ get icon() {
540
+ return this._icon;
482
541
  }
542
+ /**
543
+ * The map where the location is.
544
+ */
483
545
  get map() {
484
546
  return this._map;
485
547
  }
548
+ /**
549
+ * Get the entrance room of the location.
550
+ * You can cast the room to a specific type that extends RoomBaseModel.
551
+ * @returns The entrance room or the first room if there is no entrance.
552
+ * @example
553
+ * ```typescript
554
+ * const entranceHome = new RoomBaseModel("entrance-home", home, { isEntrance: true })
555
+ * saveRoom(entranceHome)
556
+ * const home = new LocationBaseModel("home", map, { name: "Home" })
557
+ *
558
+ * const entrance = home.getEntrance() // entrance === entranceHome
559
+ * ```
560
+ */
561
+ getEntrance() {
562
+ let rooms = this.getRooms();
563
+ if (rooms.length === 0) {
564
+ console.error(`[NQTR] The location ${this.id} has no rooms`);
565
+ return;
566
+ }
567
+ return rooms.find((room) => room.isEntrance) || rooms[0];
568
+ }
569
+ /**
570
+ * Get all rooms in the location.
571
+ * You can cast the rooms to a specific type that extends RoomBaseModel.
572
+ * @returns The rooms in the location.
573
+ */
574
+ getRooms() {
575
+ return getRoomsByLocation(this);
576
+ }
486
577
  };
487
578
 
488
579
  // src/classes/navigation/Map.ts
489
580
  import { getFlag as getFlag3, StoredClassModel as StoredClassModel2 } from "@drincs/pixi-vn";
490
581
  var MAP_CATEGORY = "__nqtr-map__";
491
582
  var MapBaseModel = class extends StoredClassModel2 {
492
- constructor(id, props) {
583
+ /**
584
+ * @param id The id of the map, it must be unique.
585
+ * @param props The properties of the map.
586
+ */
587
+ constructor(id, props = {}) {
493
588
  super(MAP_CATEGORY, id);
494
589
  this.defaultName = props.name || "";
495
590
  this.defaultImage = props.image;
496
591
  this.defaultDisabled = props.disabled || false;
497
592
  this.defaultHidden = props.hidden || false;
498
593
  }
594
+ /**
595
+ * The name of the map.
596
+ * If you set undefined, it will return the default name.
597
+ */
499
598
  get name() {
500
599
  return this.getStorageProperty("name") || this.defaultName;
501
600
  }
502
601
  set name(value) {
503
602
  this.setStorageProperty("name", value);
504
603
  }
604
+ /**
605
+ * The image of the map. It can be a string, an Element or a Pixi'VN Canvas Item.
606
+ * If you set undefined, it will return the default image.
607
+ */
505
608
  get image() {
506
609
  return this.getStorageProperty("image") || this.defaultImage;
507
610
  }
508
611
  set image(value) {
509
612
  this.setStorageProperty("image", value);
510
613
  }
614
+ /**
615
+ * Whether is disabled. If it is a string, it is a Pixi'VN flag name.
616
+ */
511
617
  get disabled() {
512
618
  let value = this.getStorageProperty("disabled") || this.defaultDisabled;
513
619
  if (typeof value === "string") {
@@ -518,6 +624,9 @@ var MapBaseModel = class extends StoredClassModel2 {
518
624
  set disabled(value) {
519
625
  this.setStorageProperty("disabled", value);
520
626
  }
627
+ /**
628
+ * Whether is hidden. If it is a string, it is a Pixi'VN flag name.
629
+ */
521
630
  get hidden() {
522
631
  let value = this.getStorageProperty("hidden") || this.defaultHidden;
523
632
  if (typeof value === "string") {
@@ -528,6 +637,13 @@ var MapBaseModel = class extends StoredClassModel2 {
528
637
  set hidden(value) {
529
638
  this.setStorageProperty("hidden", value);
530
639
  }
640
+ /**
641
+ * Get all locations in the map.
642
+ * @returns The locations in the map.
643
+ */
644
+ getLocations() {
645
+ return getLocationsByMap(this);
646
+ }
531
647
  };
532
648
 
533
649
  // src/classes/navigation/Room.ts
@@ -623,32 +739,6 @@ function getTemporaryCommitments() {
623
739
  return commitments;
624
740
  }
625
741
 
626
- // src/decorators/RoomDecorator.ts
627
- var registeredRooms = {};
628
- function saveRoom(room) {
629
- if (Array.isArray(room)) {
630
- room.forEach((c) => saveRoom(c));
631
- return;
632
- }
633
- if (registeredRooms[room.id]) {
634
- console.warn(`[NQTR] Room id ${room.id} already exists, it will be overwritten`);
635
- }
636
- registeredRooms[room.id] = room;
637
- }
638
- function getRoomById(id) {
639
- try {
640
- let room = registeredRooms[id];
641
- if (!room) {
642
- console.error(`[NQTR] Room ${id} not found`);
643
- return;
644
- }
645
- return room;
646
- } catch (e) {
647
- console.error(`[NQTR] Error while getting Room ${id}`, e);
648
- return;
649
- }
650
- }
651
-
652
742
  // src/functions/RoutineFunctions.ts
653
743
  function clearExpiredRoutine() {
654
744
  Object.entries(registeredCommitments).forEach(([_, commitment]) => {
@@ -748,7 +838,12 @@ var ActivityRoom = class extends ActivityStoredAbstract {
748
838
  // src/classes/navigation/Room.ts
749
839
  var ROOM_CATEGORY = "__nqtr-room__";
750
840
  var RoomBaseModel = class extends StoredClassModel3 {
751
- constructor(id, location, props) {
841
+ /**
842
+ * @param id The id of the room, it must be unique.
843
+ * @param location The location where the room is.
844
+ * @param props The properties of the room.
845
+ */
846
+ constructor(id, location, props = {}) {
752
847
  var _a;
753
848
  super(ROOM_CATEGORY, id);
754
849
  this._location = location;
@@ -757,23 +852,44 @@ var RoomBaseModel = class extends StoredClassModel3 {
757
852
  this.defaultActivityIds = ((_a = props.defaultActivities) == null ? void 0 : _a.map((activity) => activity.id)) || [];
758
853
  this.defaultDisabled = props.disabled || false;
759
854
  this.defaultHidden = props.hidden || false;
760
- this._iconElement = props.iconElement;
855
+ this._icon = props.icon;
856
+ this._isEntrance = props.isEntrance;
761
857
  }
858
+ /**
859
+ * The location where the room is.
860
+ */
762
861
  get location() {
763
862
  return this._location;
764
863
  }
864
+ /**
865
+ * Whether is an entrance room, so when the player enters in the location, it will be the first room to be shown.
866
+ */
867
+ get isEntrance() {
868
+ return this._isEntrance || false;
869
+ }
870
+ /**
871
+ * The name.
872
+ * If you set undefined, it will return the default name.
873
+ */
765
874
  get name() {
766
875
  return this.getStorageProperty("name") || this.defaultName;
767
876
  }
768
877
  set name(value) {
769
878
  this.setStorageProperty("name", value);
770
879
  }
880
+ /**
881
+ * The image. It can be a string, an Element or a Pixi'VN Canvas Item.
882
+ * If you set undefined, it will return the default image.
883
+ */
771
884
  get image() {
772
885
  return this.getStorageProperty("image") || this.defaultImage;
773
886
  }
774
887
  set image(value) {
775
888
  this.setStorageProperty("image", value);
776
889
  }
890
+ /**
891
+ * The activities that are available in this room.
892
+ */
777
893
  get defaultActivities() {
778
894
  let roomMemories = this.getStorageProperty("activities_memory") || {};
779
895
  let activities = this.defaultActivityIds.map((id) => {
@@ -794,17 +910,30 @@ var RoomBaseModel = class extends StoredClassModel3 {
794
910
  let addedActivityIds = this.getStorageProperty(`addedActivityIds`) || [];
795
911
  return this.defaultActivityIds.concat(addedActivityIds);
796
912
  }
913
+ /**
914
+ * The activities that are available in this room.
915
+ */
797
916
  get activities() {
798
917
  let activities = this.activityIds.map((id) => {
799
918
  return this.getActivity(id);
800
919
  }).filter((activity) => activity !== void 0);
801
920
  return activities;
802
921
  }
922
+ /**
923
+ * Get the memory of an activity. This function can be used into olther libraries to get the memory of the activity.
924
+ * @param id The id of the activity.
925
+ * @returns The memory of the activity.
926
+ */
803
927
  getActivityMemory(id) {
804
928
  let roomMemories = this.getStorageProperty("activities_memory") || {};
805
929
  let roomMemory = roomMemories[id] || {};
806
930
  return roomMemory;
807
931
  }
932
+ /**
933
+ * Get the activity by id.
934
+ * @param id The id of the activity.
935
+ * @returns The room activity.
936
+ */
808
937
  getActivity(id) {
809
938
  if (!this.activityIds.includes(id)) {
810
939
  console.error(`[NQTR] Activity with id ${id} not found in room ${this.id}`);
@@ -820,11 +949,20 @@ var RoomBaseModel = class extends StoredClassModel3 {
820
949
  roomMemory = __spreadValues(__spreadValues({}, activity.export()), roomMemory);
821
950
  return new ActivityRoom(id, this, activity.onRun, roomMemory);
822
951
  }
952
+ /**
953
+ * Set the memory of an activity. This function can be used into olther libraries to set the memory of the activity.
954
+ * @param id The id of the activity.
955
+ * @param memory The memory of the activity.
956
+ */
823
957
  setActivity(activity) {
824
958
  let roomMemories = this.getStorageProperty("activities_memory") || {};
825
959
  roomMemories[activity.id] = activity.export();
826
960
  this.setStorageProperty("activities_memory", roomMemories);
827
961
  }
962
+ /**
963
+ * Add an activity to the room.
964
+ * @param activity The activity to add.
965
+ */
828
966
  addActivity(activity) {
829
967
  if (this.activityIds.includes(activity.id)) {
830
968
  let currentActivity = this.getActivity(activity.id);
@@ -840,6 +978,10 @@ var RoomBaseModel = class extends StoredClassModel3 {
840
978
  addedActivityIds.push(activity.id);
841
979
  this.setStorageProperty("addedActivityIds", addedActivityIds);
842
980
  }
981
+ /**
982
+ * Remove an activity from the room.
983
+ * @param activity The activity to remove.
984
+ */
843
985
  removeActivity(activity) {
844
986
  let activityId = typeof activity === "string" ? activity : activity.id;
845
987
  if (this.defaultActivityIds.includes(activityId)) {
@@ -864,6 +1006,9 @@ var RoomBaseModel = class extends StoredClassModel3 {
864
1006
  delete roomMemories[activityId];
865
1007
  this.setStorageProperty("activities_memory", roomMemories);
866
1008
  }
1009
+ /**
1010
+ * Clear all expired activities.
1011
+ */
867
1012
  clearExpiredActivities() {
868
1013
  this.activities.forEach((activity) => {
869
1014
  if (activity.isExpired()) {
@@ -871,6 +1016,9 @@ var RoomBaseModel = class extends StoredClassModel3 {
871
1016
  }
872
1017
  });
873
1018
  }
1019
+ /**
1020
+ * Whether is disabled. If it is a string, it is a Pixi'VN flag name.
1021
+ */
874
1022
  get disabled() {
875
1023
  let value = this.getStorageProperty("disabled") || this.defaultDisabled;
876
1024
  if (typeof value === "string") {
@@ -881,6 +1029,9 @@ var RoomBaseModel = class extends StoredClassModel3 {
881
1029
  set disabled(value) {
882
1030
  this.setStorageProperty("disabled", value);
883
1031
  }
1032
+ /**
1033
+ * Whether is hidden. If it is a string, it is a Pixi'VN flag name.
1034
+ */
884
1035
  get hidden() {
885
1036
  let value = this.getStorageProperty("hidden") || this.defaultHidden;
886
1037
  if (typeof value === "string") {
@@ -891,9 +1042,13 @@ var RoomBaseModel = class extends StoredClassModel3 {
891
1042
  set hidden(value) {
892
1043
  this.setStorageProperty("hidden", value);
893
1044
  }
894
- get iconElement() {
895
- return this._iconElement;
1045
+ get icon() {
1046
+ return this._icon;
896
1047
  }
1048
+ /**
1049
+ * Get the character commitments of the room.
1050
+ * @returns The character commitments of the room.
1051
+ */
897
1052
  getRoutine() {
898
1053
  let commitments = getCurrentCommitments();
899
1054
  return commitments.filter((c) => c.room.id === this.id);
@@ -1041,10 +1196,19 @@ var ExecutionTypeEnum = /* @__PURE__ */ ((ExecutionTypeEnum2) => {
1041
1196
  import { GameStorageManager as GameStorageManager3 } from "@drincs/pixi-vn";
1042
1197
  var CURRENT_ROOM_MEMORY_KEY = "___nqtr-current_room_memory___";
1043
1198
  function setCurrentRoom(room) {
1044
- let roomRegistrated = getRoomById(room.id);
1045
- if (!roomRegistrated) {
1046
- console.error(`[NQTR] The room ${room.id} is not registered, so it can't be set as current room`);
1047
- return;
1199
+ if (room instanceof LocationBaseModel) {
1200
+ let entrance = room.getEntrance();
1201
+ if (!entrance) {
1202
+ console.error(`[NQTR] The location ${room.id} has no entrance room`);
1203
+ return;
1204
+ }
1205
+ room = entrance;
1206
+ } else {
1207
+ let roomRegistrated = getRoomById(room.id);
1208
+ if (!roomRegistrated) {
1209
+ console.error(`[NQTR] The room ${room.id} is not registered, so it can't be set as current room`);
1210
+ return;
1211
+ }
1048
1212
  }
1049
1213
  localStorage.setItem(CURRENT_ROOM_MEMORY_KEY, room.id);
1050
1214
  }
@@ -1104,6 +1268,8 @@ export {
1104
1268
  clearExpiredRoutine,
1105
1269
  currentActivities,
1106
1270
  getActivityById,
1271
+ getAllLocations,
1272
+ getAllMaps,
1107
1273
  getCommitmentByCharacter,
1108
1274
  getCommitmentById,
1109
1275
  getCueerntMap,