@drincs/nqtr 0.0.4 → 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.js CHANGED
@@ -48,6 +48,8 @@ __export(src_exports, {
48
48
  clearExpiredRoutine: () => clearExpiredRoutine,
49
49
  currentActivities: () => currentActivities,
50
50
  getActivityById: () => getActivityById,
51
+ getAllLocations: () => getAllLocations,
52
+ getAllMaps: () => getAllMaps,
51
53
  getCommitmentByCharacter: () => getCommitmentByCharacter,
52
54
  getCommitmentById: () => getCommitmentById,
53
55
  getCueerntMap: () => getCueerntMap,
@@ -320,7 +322,7 @@ var ActivityStoredAbstract = class {
320
322
  this.defaultToDay = props.toDay;
321
323
  this.defaultDisabled = props.disabled || false;
322
324
  this.defaultHidden = props.hidden || false;
323
- this._iconElement = props.iconElement;
325
+ this._icon = props.icon;
324
326
  this._onRun = onRun;
325
327
  }
326
328
  get name() {
@@ -382,8 +384,8 @@ var ActivityStoredAbstract = class {
382
384
  set hidden(value) {
383
385
  this.setStorageProperty("hidden", value);
384
386
  }
385
- get iconElement() {
386
- return this._iconElement;
387
+ get icon() {
388
+ return this._icon;
387
389
  }
388
390
  get onRun() {
389
391
  return this._onRun;
@@ -403,7 +405,7 @@ var ActivityStoredAbstract = class {
403
405
  toDay: this.getStorageProperty("toDay") || this.defaultToDay,
404
406
  disabled: this.getStorageProperty("disabled") || this.defaultDisabled,
405
407
  hidden: this.getStorageProperty("hidden") || this.defaultHidden,
406
- iconElement: this._iconElement
408
+ icon: this._icon
407
409
  };
408
410
  }
409
411
  };
@@ -417,7 +419,7 @@ var ActivityModel = class {
417
419
  this._toDay = props.toDay;
418
420
  this._disabled = props.disabled || false;
419
421
  this._hidden = props.hidden || false;
420
- this._iconElement = props.iconElement;
422
+ this._icon = props.icon;
421
423
  this._onRun = onRun;
422
424
  }
423
425
  get id() {
@@ -456,8 +458,8 @@ var ActivityModel = class {
456
458
  }
457
459
  return this._hidden;
458
460
  }
459
- get iconElement() {
460
- return this._iconElement;
461
+ get icon() {
462
+ return this._icon;
461
463
  }
462
464
  get onRun() {
463
465
  return this._onRun;
@@ -477,7 +479,7 @@ var ActivityModel = class {
477
479
  toDay: this._toDay,
478
480
  disabled: this._disabled,
479
481
  hidden: this._hidden,
480
- iconElement: this._iconElement
482
+ icon: this._icon
481
483
  };
482
484
  }
483
485
  };
@@ -510,34 +512,56 @@ function getRoomById(id) {
510
512
  return;
511
513
  }
512
514
  }
513
- function getRoomByLocation(location) {
514
- return Object.values(registeredRooms).filter((room) => room.location === location);
515
+ function getRoomsByLocation(location) {
516
+ return Object.values(registeredRooms).filter((room) => room.location.id === location.id);
517
+ }
518
+ function getAllLocations() {
519
+ let result = {};
520
+ Object.values(registeredRooms).forEach((room) => {
521
+ result[room.location.id] = room.location;
522
+ });
523
+ return Object.values(result);
524
+ }
525
+ function getLocationsByMap(map) {
526
+ return getAllLocations().filter((location) => location.map.id === map.id);
527
+ }
528
+ function getAllMaps() {
529
+ let result = {};
530
+ Object.values(registeredRooms).forEach((room) => {
531
+ result[room.location.map.id] = room.location.map;
532
+ });
533
+ return Object.values(result);
515
534
  }
516
535
 
517
536
  // src/classes/navigation/Location.ts
518
537
  var LOCATION_CATEGORY = "__nqtr-location__";
519
538
  var LocationBaseModel = class extends import_pixi_vn3.StoredClassModel {
520
- constructor(id, map, props) {
539
+ /**
540
+ * @param id The id of the location, it must be unique.
541
+ * @param map The map where the location is.
542
+ * @param props The properties of the location.
543
+ */
544
+ constructor(id, map, props = {}) {
521
545
  super(LOCATION_CATEGORY, id);
522
546
  this.defaultName = props.name || "";
523
547
  this.defaultDisabled = props.disabled || false;
524
548
  this.defaultHidden = props.hidden || false;
525
- this._iconElement = props.iconElement;
549
+ this._icon = props.icon;
526
550
  this._map = map;
527
551
  }
528
- getEntrance() {
529
- let rooms = getRoomByLocation(this);
530
- if (rooms.length === 0) {
531
- return;
532
- }
533
- return rooms.find((room) => room.isEntrance) || rooms[0];
534
- }
552
+ /**
553
+ * The name of the location.
554
+ * If you set undefined, it will return the default name.
555
+ */
535
556
  get name() {
536
557
  return this.getStorageProperty("name") || this.defaultName;
537
558
  }
538
559
  set name(value) {
539
560
  this.setStorageProperty("name", value);
540
561
  }
562
+ /**
563
+ * Whether is disabled. If it is a string, it is a Pixi'VN flag name.
564
+ */
541
565
  get disabled() {
542
566
  let value = this.getStorageProperty("disabled") || this.defaultDisabled;
543
567
  if (typeof value === "string") {
@@ -548,6 +572,9 @@ var LocationBaseModel = class extends import_pixi_vn3.StoredClassModel {
548
572
  set disabled(value) {
549
573
  this.setStorageProperty("disabled", value);
550
574
  }
575
+ /**
576
+ * Whether is hidden. If it is a string, it is a Pixi'VN flag name.
577
+ */
551
578
  get hidden() {
552
579
  let value = this.getStorageProperty("hidden") || this.defaultHidden;
553
580
  if (typeof value === "string") {
@@ -558,37 +585,87 @@ var LocationBaseModel = class extends import_pixi_vn3.StoredClassModel {
558
585
  set hidden(value) {
559
586
  this.setStorageProperty("hidden", value);
560
587
  }
561
- get iconElement() {
562
- return this._iconElement;
588
+ /**
589
+ * The icon element. Can be a string or an Element or a Pixi'VN CanvasItem
590
+ */
591
+ get icon() {
592
+ return this._icon;
563
593
  }
594
+ /**
595
+ * The map where the location is.
596
+ */
564
597
  get map() {
565
598
  return this._map;
566
599
  }
600
+ /**
601
+ * Get the entrance room of the location.
602
+ * You can cast the room to a specific type that extends RoomBaseModel.
603
+ * @returns The entrance room or the first room if there is no entrance.
604
+ * @example
605
+ * ```typescript
606
+ * const entranceHome = new RoomBaseModel("entrance-home", home, { isEntrance: true })
607
+ * saveRoom(entranceHome)
608
+ * const home = new LocationBaseModel("home", map, { name: "Home" })
609
+ *
610
+ * const entrance = home.getEntrance() // entrance === entranceHome
611
+ * ```
612
+ */
613
+ getEntrance() {
614
+ let rooms = this.getRooms();
615
+ if (rooms.length === 0) {
616
+ console.error(`[NQTR] The location ${this.id} has no rooms`);
617
+ return;
618
+ }
619
+ return rooms.find((room) => room.isEntrance) || rooms[0];
620
+ }
621
+ /**
622
+ * Get all rooms in the location.
623
+ * You can cast the rooms to a specific type that extends RoomBaseModel.
624
+ * @returns The rooms in the location.
625
+ */
626
+ getRooms() {
627
+ return getRoomsByLocation(this);
628
+ }
567
629
  };
568
630
 
569
631
  // src/classes/navigation/Map.ts
570
632
  var import_pixi_vn4 = require("@drincs/pixi-vn");
571
633
  var MAP_CATEGORY = "__nqtr-map__";
572
634
  var MapBaseModel = class extends import_pixi_vn4.StoredClassModel {
573
- constructor(id, props) {
635
+ /**
636
+ * @param id The id of the map, it must be unique.
637
+ * @param props The properties of the map.
638
+ */
639
+ constructor(id, props = {}) {
574
640
  super(MAP_CATEGORY, id);
575
641
  this.defaultName = props.name || "";
576
642
  this.defaultImage = props.image;
577
643
  this.defaultDisabled = props.disabled || false;
578
644
  this.defaultHidden = props.hidden || false;
579
645
  }
646
+ /**
647
+ * The name of the map.
648
+ * If you set undefined, it will return the default name.
649
+ */
580
650
  get name() {
581
651
  return this.getStorageProperty("name") || this.defaultName;
582
652
  }
583
653
  set name(value) {
584
654
  this.setStorageProperty("name", value);
585
655
  }
656
+ /**
657
+ * The image of the map. It can be a string, an Element or a Pixi'VN Canvas Item.
658
+ * If you set undefined, it will return the default image.
659
+ */
586
660
  get image() {
587
661
  return this.getStorageProperty("image") || this.defaultImage;
588
662
  }
589
663
  set image(value) {
590
664
  this.setStorageProperty("image", value);
591
665
  }
666
+ /**
667
+ * Whether is disabled. If it is a string, it is a Pixi'VN flag name.
668
+ */
592
669
  get disabled() {
593
670
  let value = this.getStorageProperty("disabled") || this.defaultDisabled;
594
671
  if (typeof value === "string") {
@@ -599,6 +676,9 @@ var MapBaseModel = class extends import_pixi_vn4.StoredClassModel {
599
676
  set disabled(value) {
600
677
  this.setStorageProperty("disabled", value);
601
678
  }
679
+ /**
680
+ * Whether is hidden. If it is a string, it is a Pixi'VN flag name.
681
+ */
602
682
  get hidden() {
603
683
  let value = this.getStorageProperty("hidden") || this.defaultHidden;
604
684
  if (typeof value === "string") {
@@ -609,6 +689,13 @@ var MapBaseModel = class extends import_pixi_vn4.StoredClassModel {
609
689
  set hidden(value) {
610
690
  this.setStorageProperty("hidden", value);
611
691
  }
692
+ /**
693
+ * Get all locations in the map.
694
+ * @returns The locations in the map.
695
+ */
696
+ getLocations() {
697
+ return getLocationsByMap(this);
698
+ }
612
699
  };
613
700
 
614
701
  // src/classes/navigation/Room.ts
@@ -803,7 +890,12 @@ var ActivityRoom = class extends ActivityStoredAbstract {
803
890
  // src/classes/navigation/Room.ts
804
891
  var ROOM_CATEGORY = "__nqtr-room__";
805
892
  var RoomBaseModel = class extends import_pixi_vn6.StoredClassModel {
806
- constructor(id, location, props) {
893
+ /**
894
+ * @param id The id of the room, it must be unique.
895
+ * @param location The location where the room is.
896
+ * @param props The properties of the room.
897
+ */
898
+ constructor(id, location, props = {}) {
807
899
  var _a;
808
900
  super(ROOM_CATEGORY, id);
809
901
  this._location = location;
@@ -812,27 +904,44 @@ var RoomBaseModel = class extends import_pixi_vn6.StoredClassModel {
812
904
  this.defaultActivityIds = ((_a = props.defaultActivities) == null ? void 0 : _a.map((activity) => activity.id)) || [];
813
905
  this.defaultDisabled = props.disabled || false;
814
906
  this.defaultHidden = props.hidden || false;
815
- this._iconElement = props.iconElement;
907
+ this._icon = props.icon;
816
908
  this._isEntrance = props.isEntrance;
817
909
  }
910
+ /**
911
+ * The location where the room is.
912
+ */
818
913
  get location() {
819
914
  return this._location;
820
915
  }
916
+ /**
917
+ * Whether is an entrance room, so when the player enters in the location, it will be the first room to be shown.
918
+ */
821
919
  get isEntrance() {
822
920
  return this._isEntrance || false;
823
921
  }
922
+ /**
923
+ * The name.
924
+ * If you set undefined, it will return the default name.
925
+ */
824
926
  get name() {
825
927
  return this.getStorageProperty("name") || this.defaultName;
826
928
  }
827
929
  set name(value) {
828
930
  this.setStorageProperty("name", value);
829
931
  }
932
+ /**
933
+ * The image. It can be a string, an Element or a Pixi'VN Canvas Item.
934
+ * If you set undefined, it will return the default image.
935
+ */
830
936
  get image() {
831
937
  return this.getStorageProperty("image") || this.defaultImage;
832
938
  }
833
939
  set image(value) {
834
940
  this.setStorageProperty("image", value);
835
941
  }
942
+ /**
943
+ * The activities that are available in this room.
944
+ */
836
945
  get defaultActivities() {
837
946
  let roomMemories = this.getStorageProperty("activities_memory") || {};
838
947
  let activities = this.defaultActivityIds.map((id) => {
@@ -853,17 +962,30 @@ var RoomBaseModel = class extends import_pixi_vn6.StoredClassModel {
853
962
  let addedActivityIds = this.getStorageProperty(`addedActivityIds`) || [];
854
963
  return this.defaultActivityIds.concat(addedActivityIds);
855
964
  }
965
+ /**
966
+ * The activities that are available in this room.
967
+ */
856
968
  get activities() {
857
969
  let activities = this.activityIds.map((id) => {
858
970
  return this.getActivity(id);
859
971
  }).filter((activity) => activity !== void 0);
860
972
  return activities;
861
973
  }
974
+ /**
975
+ * Get the memory of an activity. This function can be used into olther libraries to get the memory of the activity.
976
+ * @param id The id of the activity.
977
+ * @returns The memory of the activity.
978
+ */
862
979
  getActivityMemory(id) {
863
980
  let roomMemories = this.getStorageProperty("activities_memory") || {};
864
981
  let roomMemory = roomMemories[id] || {};
865
982
  return roomMemory;
866
983
  }
984
+ /**
985
+ * Get the activity by id.
986
+ * @param id The id of the activity.
987
+ * @returns The room activity.
988
+ */
867
989
  getActivity(id) {
868
990
  if (!this.activityIds.includes(id)) {
869
991
  console.error(`[NQTR] Activity with id ${id} not found in room ${this.id}`);
@@ -879,11 +1001,20 @@ var RoomBaseModel = class extends import_pixi_vn6.StoredClassModel {
879
1001
  roomMemory = __spreadValues(__spreadValues({}, activity.export()), roomMemory);
880
1002
  return new ActivityRoom(id, this, activity.onRun, roomMemory);
881
1003
  }
1004
+ /**
1005
+ * Set the memory of an activity. This function can be used into olther libraries to set the memory of the activity.
1006
+ * @param id The id of the activity.
1007
+ * @param memory The memory of the activity.
1008
+ */
882
1009
  setActivity(activity) {
883
1010
  let roomMemories = this.getStorageProperty("activities_memory") || {};
884
1011
  roomMemories[activity.id] = activity.export();
885
1012
  this.setStorageProperty("activities_memory", roomMemories);
886
1013
  }
1014
+ /**
1015
+ * Add an activity to the room.
1016
+ * @param activity The activity to add.
1017
+ */
887
1018
  addActivity(activity) {
888
1019
  if (this.activityIds.includes(activity.id)) {
889
1020
  let currentActivity = this.getActivity(activity.id);
@@ -899,6 +1030,10 @@ var RoomBaseModel = class extends import_pixi_vn6.StoredClassModel {
899
1030
  addedActivityIds.push(activity.id);
900
1031
  this.setStorageProperty("addedActivityIds", addedActivityIds);
901
1032
  }
1033
+ /**
1034
+ * Remove an activity from the room.
1035
+ * @param activity The activity to remove.
1036
+ */
902
1037
  removeActivity(activity) {
903
1038
  let activityId = typeof activity === "string" ? activity : activity.id;
904
1039
  if (this.defaultActivityIds.includes(activityId)) {
@@ -923,6 +1058,9 @@ var RoomBaseModel = class extends import_pixi_vn6.StoredClassModel {
923
1058
  delete roomMemories[activityId];
924
1059
  this.setStorageProperty("activities_memory", roomMemories);
925
1060
  }
1061
+ /**
1062
+ * Clear all expired activities.
1063
+ */
926
1064
  clearExpiredActivities() {
927
1065
  this.activities.forEach((activity) => {
928
1066
  if (activity.isExpired()) {
@@ -930,6 +1068,9 @@ var RoomBaseModel = class extends import_pixi_vn6.StoredClassModel {
930
1068
  }
931
1069
  });
932
1070
  }
1071
+ /**
1072
+ * Whether is disabled. If it is a string, it is a Pixi'VN flag name.
1073
+ */
933
1074
  get disabled() {
934
1075
  let value = this.getStorageProperty("disabled") || this.defaultDisabled;
935
1076
  if (typeof value === "string") {
@@ -940,6 +1081,9 @@ var RoomBaseModel = class extends import_pixi_vn6.StoredClassModel {
940
1081
  set disabled(value) {
941
1082
  this.setStorageProperty("disabled", value);
942
1083
  }
1084
+ /**
1085
+ * Whether is hidden. If it is a string, it is a Pixi'VN flag name.
1086
+ */
943
1087
  get hidden() {
944
1088
  let value = this.getStorageProperty("hidden") || this.defaultHidden;
945
1089
  if (typeof value === "string") {
@@ -950,9 +1094,13 @@ var RoomBaseModel = class extends import_pixi_vn6.StoredClassModel {
950
1094
  set hidden(value) {
951
1095
  this.setStorageProperty("hidden", value);
952
1096
  }
953
- get iconElement() {
954
- return this._iconElement;
1097
+ get icon() {
1098
+ return this._icon;
955
1099
  }
1100
+ /**
1101
+ * Get the character commitments of the room.
1102
+ * @returns The character commitments of the room.
1103
+ */
956
1104
  getRoutine() {
957
1105
  let commitments = getCurrentCommitments();
958
1106
  return commitments.filter((c) => c.room.id === this.id);
@@ -1100,10 +1248,19 @@ var ExecutionTypeEnum = /* @__PURE__ */ ((ExecutionTypeEnum2) => {
1100
1248
  var import_pixi_vn9 = require("@drincs/pixi-vn");
1101
1249
  var CURRENT_ROOM_MEMORY_KEY = "___nqtr-current_room_memory___";
1102
1250
  function setCurrentRoom(room) {
1103
- let roomRegistrated = getRoomById(room.id);
1104
- if (!roomRegistrated) {
1105
- console.error(`[NQTR] The room ${room.id} is not registered, so it can't be set as current room`);
1106
- return;
1251
+ if (room instanceof LocationBaseModel) {
1252
+ let entrance = room.getEntrance();
1253
+ if (!entrance) {
1254
+ console.error(`[NQTR] The location ${room.id} has no entrance room`);
1255
+ return;
1256
+ }
1257
+ room = entrance;
1258
+ } else {
1259
+ let roomRegistrated = getRoomById(room.id);
1260
+ if (!roomRegistrated) {
1261
+ console.error(`[NQTR] The room ${room.id} is not registered, so it can't be set as current room`);
1262
+ return;
1263
+ }
1107
1264
  }
1108
1265
  localStorage.setItem(CURRENT_ROOM_MEMORY_KEY, room.id);
1109
1266
  }
@@ -1164,6 +1321,8 @@ function currentActivities() {
1164
1321
  clearExpiredRoutine,
1165
1322
  currentActivities,
1166
1323
  getActivityById,
1324
+ getAllLocations,
1325
+ getAllMaps,
1167
1326
  getCommitmentByCharacter,
1168
1327
  getCommitmentById,
1169
1328
  getCueerntMap,