@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.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,36 +479,89 @@ 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
  };
484
486
 
485
487
  // src/classes/navigation/Location.ts
486
488
  var import_pixi_vn3 = require("@drincs/pixi-vn");
489
+
490
+ // src/decorators/RoomDecorator.ts
491
+ var registeredRooms = {};
492
+ function saveRoom(room) {
493
+ if (Array.isArray(room)) {
494
+ room.forEach((c) => saveRoom(c));
495
+ return;
496
+ }
497
+ if (registeredRooms[room.id]) {
498
+ console.warn(`[NQTR] Room id ${room.id} already exists, it will be overwritten`);
499
+ }
500
+ registeredRooms[room.id] = room;
501
+ }
502
+ function getRoomById(id) {
503
+ try {
504
+ let room = registeredRooms[id];
505
+ if (!room) {
506
+ console.error(`[NQTR] Room ${id} not found`);
507
+ return;
508
+ }
509
+ return room;
510
+ } catch (e) {
511
+ console.error(`[NQTR] Error while getting Room ${id}`, e);
512
+ return;
513
+ }
514
+ }
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);
534
+ }
535
+
536
+ // src/classes/navigation/Location.ts
487
537
  var LOCATION_CATEGORY = "__nqtr-location__";
488
538
  var LocationBaseModel = class extends import_pixi_vn3.StoredClassModel {
489
- constructor(id, map, entrance, 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 = {}) {
490
545
  super(LOCATION_CATEGORY, id);
491
- if (entrance.location.id !== id) {
492
- throw new Error(`[NQTR] Entrance room ${entrance.id} is not in location ${id}`);
493
- }
494
- this._entrance = entrance;
495
546
  this.defaultName = props.name || "";
496
547
  this.defaultDisabled = props.disabled || false;
497
548
  this.defaultHidden = props.hidden || false;
498
- this._iconElement = props.iconElement;
549
+ this._icon = props.icon;
499
550
  this._map = map;
500
551
  }
501
- get entrance() {
502
- return this._entrance;
503
- }
552
+ /**
553
+ * The name of the location.
554
+ * If you set undefined, it will return the default name.
555
+ */
504
556
  get name() {
505
557
  return this.getStorageProperty("name") || this.defaultName;
506
558
  }
507
559
  set name(value) {
508
560
  this.setStorageProperty("name", value);
509
561
  }
562
+ /**
563
+ * Whether is disabled. If it is a string, it is a Pixi'VN flag name.
564
+ */
510
565
  get disabled() {
511
566
  let value = this.getStorageProperty("disabled") || this.defaultDisabled;
512
567
  if (typeof value === "string") {
@@ -517,6 +572,9 @@ var LocationBaseModel = class extends import_pixi_vn3.StoredClassModel {
517
572
  set disabled(value) {
518
573
  this.setStorageProperty("disabled", value);
519
574
  }
575
+ /**
576
+ * Whether is hidden. If it is a string, it is a Pixi'VN flag name.
577
+ */
520
578
  get hidden() {
521
579
  let value = this.getStorageProperty("hidden") || this.defaultHidden;
522
580
  if (typeof value === "string") {
@@ -527,37 +585,87 @@ var LocationBaseModel = class extends import_pixi_vn3.StoredClassModel {
527
585
  set hidden(value) {
528
586
  this.setStorageProperty("hidden", value);
529
587
  }
530
- get iconElement() {
531
- 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;
532
593
  }
594
+ /**
595
+ * The map where the location is.
596
+ */
533
597
  get map() {
534
598
  return this._map;
535
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
+ }
536
629
  };
537
630
 
538
631
  // src/classes/navigation/Map.ts
539
632
  var import_pixi_vn4 = require("@drincs/pixi-vn");
540
633
  var MAP_CATEGORY = "__nqtr-map__";
541
634
  var MapBaseModel = class extends import_pixi_vn4.StoredClassModel {
542
- 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 = {}) {
543
640
  super(MAP_CATEGORY, id);
544
641
  this.defaultName = props.name || "";
545
642
  this.defaultImage = props.image;
546
643
  this.defaultDisabled = props.disabled || false;
547
644
  this.defaultHidden = props.hidden || false;
548
645
  }
646
+ /**
647
+ * The name of the map.
648
+ * If you set undefined, it will return the default name.
649
+ */
549
650
  get name() {
550
651
  return this.getStorageProperty("name") || this.defaultName;
551
652
  }
552
653
  set name(value) {
553
654
  this.setStorageProperty("name", value);
554
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
+ */
555
660
  get image() {
556
661
  return this.getStorageProperty("image") || this.defaultImage;
557
662
  }
558
663
  set image(value) {
559
664
  this.setStorageProperty("image", value);
560
665
  }
666
+ /**
667
+ * Whether is disabled. If it is a string, it is a Pixi'VN flag name.
668
+ */
561
669
  get disabled() {
562
670
  let value = this.getStorageProperty("disabled") || this.defaultDisabled;
563
671
  if (typeof value === "string") {
@@ -568,6 +676,9 @@ var MapBaseModel = class extends import_pixi_vn4.StoredClassModel {
568
676
  set disabled(value) {
569
677
  this.setStorageProperty("disabled", value);
570
678
  }
679
+ /**
680
+ * Whether is hidden. If it is a string, it is a Pixi'VN flag name.
681
+ */
571
682
  get hidden() {
572
683
  let value = this.getStorageProperty("hidden") || this.defaultHidden;
573
684
  if (typeof value === "string") {
@@ -578,6 +689,13 @@ var MapBaseModel = class extends import_pixi_vn4.StoredClassModel {
578
689
  set hidden(value) {
579
690
  this.setStorageProperty("hidden", value);
580
691
  }
692
+ /**
693
+ * Get all locations in the map.
694
+ * @returns The locations in the map.
695
+ */
696
+ getLocations() {
697
+ return getLocationsByMap(this);
698
+ }
581
699
  };
582
700
 
583
701
  // src/classes/navigation/Room.ts
@@ -673,32 +791,6 @@ function getTemporaryCommitments() {
673
791
  return commitments;
674
792
  }
675
793
 
676
- // src/decorators/RoomDecorator.ts
677
- var registeredRooms = {};
678
- function saveRoom(room) {
679
- if (Array.isArray(room)) {
680
- room.forEach((c) => saveRoom(c));
681
- return;
682
- }
683
- if (registeredRooms[room.id]) {
684
- console.warn(`[NQTR] Room id ${room.id} already exists, it will be overwritten`);
685
- }
686
- registeredRooms[room.id] = room;
687
- }
688
- function getRoomById(id) {
689
- try {
690
- let room = registeredRooms[id];
691
- if (!room) {
692
- console.error(`[NQTR] Room ${id} not found`);
693
- return;
694
- }
695
- return room;
696
- } catch (e) {
697
- console.error(`[NQTR] Error while getting Room ${id}`, e);
698
- return;
699
- }
700
- }
701
-
702
794
  // src/functions/RoutineFunctions.ts
703
795
  function clearExpiredRoutine() {
704
796
  Object.entries(registeredCommitments).forEach(([_, commitment]) => {
@@ -798,7 +890,12 @@ var ActivityRoom = class extends ActivityStoredAbstract {
798
890
  // src/classes/navigation/Room.ts
799
891
  var ROOM_CATEGORY = "__nqtr-room__";
800
892
  var RoomBaseModel = class extends import_pixi_vn6.StoredClassModel {
801
- 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 = {}) {
802
899
  var _a;
803
900
  super(ROOM_CATEGORY, id);
804
901
  this._location = location;
@@ -807,23 +904,44 @@ var RoomBaseModel = class extends import_pixi_vn6.StoredClassModel {
807
904
  this.defaultActivityIds = ((_a = props.defaultActivities) == null ? void 0 : _a.map((activity) => activity.id)) || [];
808
905
  this.defaultDisabled = props.disabled || false;
809
906
  this.defaultHidden = props.hidden || false;
810
- this._iconElement = props.iconElement;
907
+ this._icon = props.icon;
908
+ this._isEntrance = props.isEntrance;
811
909
  }
910
+ /**
911
+ * The location where the room is.
912
+ */
812
913
  get location() {
813
914
  return this._location;
814
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
+ */
919
+ get isEntrance() {
920
+ return this._isEntrance || false;
921
+ }
922
+ /**
923
+ * The name.
924
+ * If you set undefined, it will return the default name.
925
+ */
815
926
  get name() {
816
927
  return this.getStorageProperty("name") || this.defaultName;
817
928
  }
818
929
  set name(value) {
819
930
  this.setStorageProperty("name", value);
820
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
+ */
821
936
  get image() {
822
937
  return this.getStorageProperty("image") || this.defaultImage;
823
938
  }
824
939
  set image(value) {
825
940
  this.setStorageProperty("image", value);
826
941
  }
942
+ /**
943
+ * The activities that are available in this room.
944
+ */
827
945
  get defaultActivities() {
828
946
  let roomMemories = this.getStorageProperty("activities_memory") || {};
829
947
  let activities = this.defaultActivityIds.map((id) => {
@@ -844,17 +962,30 @@ var RoomBaseModel = class extends import_pixi_vn6.StoredClassModel {
844
962
  let addedActivityIds = this.getStorageProperty(`addedActivityIds`) || [];
845
963
  return this.defaultActivityIds.concat(addedActivityIds);
846
964
  }
965
+ /**
966
+ * The activities that are available in this room.
967
+ */
847
968
  get activities() {
848
969
  let activities = this.activityIds.map((id) => {
849
970
  return this.getActivity(id);
850
971
  }).filter((activity) => activity !== void 0);
851
972
  return activities;
852
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
+ */
853
979
  getActivityMemory(id) {
854
980
  let roomMemories = this.getStorageProperty("activities_memory") || {};
855
981
  let roomMemory = roomMemories[id] || {};
856
982
  return roomMemory;
857
983
  }
984
+ /**
985
+ * Get the activity by id.
986
+ * @param id The id of the activity.
987
+ * @returns The room activity.
988
+ */
858
989
  getActivity(id) {
859
990
  if (!this.activityIds.includes(id)) {
860
991
  console.error(`[NQTR] Activity with id ${id} not found in room ${this.id}`);
@@ -870,11 +1001,20 @@ var RoomBaseModel = class extends import_pixi_vn6.StoredClassModel {
870
1001
  roomMemory = __spreadValues(__spreadValues({}, activity.export()), roomMemory);
871
1002
  return new ActivityRoom(id, this, activity.onRun, roomMemory);
872
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
+ */
873
1009
  setActivity(activity) {
874
1010
  let roomMemories = this.getStorageProperty("activities_memory") || {};
875
1011
  roomMemories[activity.id] = activity.export();
876
1012
  this.setStorageProperty("activities_memory", roomMemories);
877
1013
  }
1014
+ /**
1015
+ * Add an activity to the room.
1016
+ * @param activity The activity to add.
1017
+ */
878
1018
  addActivity(activity) {
879
1019
  if (this.activityIds.includes(activity.id)) {
880
1020
  let currentActivity = this.getActivity(activity.id);
@@ -890,6 +1030,10 @@ var RoomBaseModel = class extends import_pixi_vn6.StoredClassModel {
890
1030
  addedActivityIds.push(activity.id);
891
1031
  this.setStorageProperty("addedActivityIds", addedActivityIds);
892
1032
  }
1033
+ /**
1034
+ * Remove an activity from the room.
1035
+ * @param activity The activity to remove.
1036
+ */
893
1037
  removeActivity(activity) {
894
1038
  let activityId = typeof activity === "string" ? activity : activity.id;
895
1039
  if (this.defaultActivityIds.includes(activityId)) {
@@ -914,6 +1058,9 @@ var RoomBaseModel = class extends import_pixi_vn6.StoredClassModel {
914
1058
  delete roomMemories[activityId];
915
1059
  this.setStorageProperty("activities_memory", roomMemories);
916
1060
  }
1061
+ /**
1062
+ * Clear all expired activities.
1063
+ */
917
1064
  clearExpiredActivities() {
918
1065
  this.activities.forEach((activity) => {
919
1066
  if (activity.isExpired()) {
@@ -921,6 +1068,9 @@ var RoomBaseModel = class extends import_pixi_vn6.StoredClassModel {
921
1068
  }
922
1069
  });
923
1070
  }
1071
+ /**
1072
+ * Whether is disabled. If it is a string, it is a Pixi'VN flag name.
1073
+ */
924
1074
  get disabled() {
925
1075
  let value = this.getStorageProperty("disabled") || this.defaultDisabled;
926
1076
  if (typeof value === "string") {
@@ -931,6 +1081,9 @@ var RoomBaseModel = class extends import_pixi_vn6.StoredClassModel {
931
1081
  set disabled(value) {
932
1082
  this.setStorageProperty("disabled", value);
933
1083
  }
1084
+ /**
1085
+ * Whether is hidden. If it is a string, it is a Pixi'VN flag name.
1086
+ */
934
1087
  get hidden() {
935
1088
  let value = this.getStorageProperty("hidden") || this.defaultHidden;
936
1089
  if (typeof value === "string") {
@@ -941,9 +1094,13 @@ var RoomBaseModel = class extends import_pixi_vn6.StoredClassModel {
941
1094
  set hidden(value) {
942
1095
  this.setStorageProperty("hidden", value);
943
1096
  }
944
- get iconElement() {
945
- return this._iconElement;
1097
+ get icon() {
1098
+ return this._icon;
946
1099
  }
1100
+ /**
1101
+ * Get the character commitments of the room.
1102
+ * @returns The character commitments of the room.
1103
+ */
947
1104
  getRoutine() {
948
1105
  let commitments = getCurrentCommitments();
949
1106
  return commitments.filter((c) => c.room.id === this.id);
@@ -1091,10 +1248,19 @@ var ExecutionTypeEnum = /* @__PURE__ */ ((ExecutionTypeEnum2) => {
1091
1248
  var import_pixi_vn9 = require("@drincs/pixi-vn");
1092
1249
  var CURRENT_ROOM_MEMORY_KEY = "___nqtr-current_room_memory___";
1093
1250
  function setCurrentRoom(room) {
1094
- let roomRegistrated = getRoomById(room.id);
1095
- if (!roomRegistrated) {
1096
- console.error(`[NQTR] The room ${room.id} is not registered, so it can't be set as current room`);
1097
- 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
+ }
1098
1264
  }
1099
1265
  localStorage.setItem(CURRENT_ROOM_MEMORY_KEY, room.id);
1100
1266
  }
@@ -1155,6 +1321,8 @@ function currentActivities() {
1155
1321
  clearExpiredRoutine,
1156
1322
  currentActivities,
1157
1323
  getActivityById,
1324
+ getAllLocations,
1325
+ getAllMaps,
1158
1326
  getCommitmentByCharacter,
1159
1327
  getCommitmentById,
1160
1328
  getCueerntMap,