@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.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,7 +427,7 @@ 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
  };
@@ -460,34 +460,56 @@ function getRoomById(id) {
460
460
  return;
461
461
  }
462
462
  }
463
- function getRoomByLocation(location) {
464
- return Object.values(registeredRooms).filter((room) => room.location === location);
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);
465
482
  }
466
483
 
467
484
  // src/classes/navigation/Location.ts
468
485
  var LOCATION_CATEGORY = "__nqtr-location__";
469
486
  var LocationBaseModel = class extends StoredClassModel {
470
- constructor(id, map, 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 = {}) {
471
493
  super(LOCATION_CATEGORY, id);
472
494
  this.defaultName = props.name || "";
473
495
  this.defaultDisabled = props.disabled || false;
474
496
  this.defaultHidden = props.hidden || false;
475
- this._iconElement = props.iconElement;
497
+ this._icon = props.icon;
476
498
  this._map = map;
477
499
  }
478
- getEntrance() {
479
- let rooms = getRoomByLocation(this);
480
- if (rooms.length === 0) {
481
- return;
482
- }
483
- return rooms.find((room) => room.isEntrance) || rooms[0];
484
- }
500
+ /**
501
+ * The name of the location.
502
+ * If you set undefined, it will return the default name.
503
+ */
485
504
  get name() {
486
505
  return this.getStorageProperty("name") || this.defaultName;
487
506
  }
488
507
  set name(value) {
489
508
  this.setStorageProperty("name", value);
490
509
  }
510
+ /**
511
+ * Whether is disabled. If it is a string, it is a Pixi'VN flag name.
512
+ */
491
513
  get disabled() {
492
514
  let value = this.getStorageProperty("disabled") || this.defaultDisabled;
493
515
  if (typeof value === "string") {
@@ -498,6 +520,9 @@ var LocationBaseModel = class extends StoredClassModel {
498
520
  set disabled(value) {
499
521
  this.setStorageProperty("disabled", value);
500
522
  }
523
+ /**
524
+ * Whether is hidden. If it is a string, it is a Pixi'VN flag name.
525
+ */
501
526
  get hidden() {
502
527
  let value = this.getStorageProperty("hidden") || this.defaultHidden;
503
528
  if (typeof value === "string") {
@@ -508,37 +533,87 @@ var LocationBaseModel = class extends StoredClassModel {
508
533
  set hidden(value) {
509
534
  this.setStorageProperty("hidden", value);
510
535
  }
511
- get iconElement() {
512
- 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;
513
541
  }
542
+ /**
543
+ * The map where the location is.
544
+ */
514
545
  get map() {
515
546
  return this._map;
516
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
+ }
517
577
  };
518
578
 
519
579
  // src/classes/navigation/Map.ts
520
580
  import { getFlag as getFlag3, StoredClassModel as StoredClassModel2 } from "@drincs/pixi-vn";
521
581
  var MAP_CATEGORY = "__nqtr-map__";
522
582
  var MapBaseModel = class extends StoredClassModel2 {
523
- 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 = {}) {
524
588
  super(MAP_CATEGORY, id);
525
589
  this.defaultName = props.name || "";
526
590
  this.defaultImage = props.image;
527
591
  this.defaultDisabled = props.disabled || false;
528
592
  this.defaultHidden = props.hidden || false;
529
593
  }
594
+ /**
595
+ * The name of the map.
596
+ * If you set undefined, it will return the default name.
597
+ */
530
598
  get name() {
531
599
  return this.getStorageProperty("name") || this.defaultName;
532
600
  }
533
601
  set name(value) {
534
602
  this.setStorageProperty("name", value);
535
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
+ */
536
608
  get image() {
537
609
  return this.getStorageProperty("image") || this.defaultImage;
538
610
  }
539
611
  set image(value) {
540
612
  this.setStorageProperty("image", value);
541
613
  }
614
+ /**
615
+ * Whether is disabled. If it is a string, it is a Pixi'VN flag name.
616
+ */
542
617
  get disabled() {
543
618
  let value = this.getStorageProperty("disabled") || this.defaultDisabled;
544
619
  if (typeof value === "string") {
@@ -549,6 +624,9 @@ var MapBaseModel = class extends StoredClassModel2 {
549
624
  set disabled(value) {
550
625
  this.setStorageProperty("disabled", value);
551
626
  }
627
+ /**
628
+ * Whether is hidden. If it is a string, it is a Pixi'VN flag name.
629
+ */
552
630
  get hidden() {
553
631
  let value = this.getStorageProperty("hidden") || this.defaultHidden;
554
632
  if (typeof value === "string") {
@@ -559,6 +637,13 @@ var MapBaseModel = class extends StoredClassModel2 {
559
637
  set hidden(value) {
560
638
  this.setStorageProperty("hidden", value);
561
639
  }
640
+ /**
641
+ * Get all locations in the map.
642
+ * @returns The locations in the map.
643
+ */
644
+ getLocations() {
645
+ return getLocationsByMap(this);
646
+ }
562
647
  };
563
648
 
564
649
  // src/classes/navigation/Room.ts
@@ -753,7 +838,12 @@ var ActivityRoom = class extends ActivityStoredAbstract {
753
838
  // src/classes/navigation/Room.ts
754
839
  var ROOM_CATEGORY = "__nqtr-room__";
755
840
  var RoomBaseModel = class extends StoredClassModel3 {
756
- 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 = {}) {
757
847
  var _a;
758
848
  super(ROOM_CATEGORY, id);
759
849
  this._location = location;
@@ -762,27 +852,44 @@ var RoomBaseModel = class extends StoredClassModel3 {
762
852
  this.defaultActivityIds = ((_a = props.defaultActivities) == null ? void 0 : _a.map((activity) => activity.id)) || [];
763
853
  this.defaultDisabled = props.disabled || false;
764
854
  this.defaultHidden = props.hidden || false;
765
- this._iconElement = props.iconElement;
855
+ this._icon = props.icon;
766
856
  this._isEntrance = props.isEntrance;
767
857
  }
858
+ /**
859
+ * The location where the room is.
860
+ */
768
861
  get location() {
769
862
  return this._location;
770
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
+ */
771
867
  get isEntrance() {
772
868
  return this._isEntrance || false;
773
869
  }
870
+ /**
871
+ * The name.
872
+ * If you set undefined, it will return the default name.
873
+ */
774
874
  get name() {
775
875
  return this.getStorageProperty("name") || this.defaultName;
776
876
  }
777
877
  set name(value) {
778
878
  this.setStorageProperty("name", value);
779
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
+ */
780
884
  get image() {
781
885
  return this.getStorageProperty("image") || this.defaultImage;
782
886
  }
783
887
  set image(value) {
784
888
  this.setStorageProperty("image", value);
785
889
  }
890
+ /**
891
+ * The activities that are available in this room.
892
+ */
786
893
  get defaultActivities() {
787
894
  let roomMemories = this.getStorageProperty("activities_memory") || {};
788
895
  let activities = this.defaultActivityIds.map((id) => {
@@ -803,17 +910,30 @@ var RoomBaseModel = class extends StoredClassModel3 {
803
910
  let addedActivityIds = this.getStorageProperty(`addedActivityIds`) || [];
804
911
  return this.defaultActivityIds.concat(addedActivityIds);
805
912
  }
913
+ /**
914
+ * The activities that are available in this room.
915
+ */
806
916
  get activities() {
807
917
  let activities = this.activityIds.map((id) => {
808
918
  return this.getActivity(id);
809
919
  }).filter((activity) => activity !== void 0);
810
920
  return activities;
811
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
+ */
812
927
  getActivityMemory(id) {
813
928
  let roomMemories = this.getStorageProperty("activities_memory") || {};
814
929
  let roomMemory = roomMemories[id] || {};
815
930
  return roomMemory;
816
931
  }
932
+ /**
933
+ * Get the activity by id.
934
+ * @param id The id of the activity.
935
+ * @returns The room activity.
936
+ */
817
937
  getActivity(id) {
818
938
  if (!this.activityIds.includes(id)) {
819
939
  console.error(`[NQTR] Activity with id ${id} not found in room ${this.id}`);
@@ -829,11 +949,20 @@ var RoomBaseModel = class extends StoredClassModel3 {
829
949
  roomMemory = __spreadValues(__spreadValues({}, activity.export()), roomMemory);
830
950
  return new ActivityRoom(id, this, activity.onRun, roomMemory);
831
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
+ */
832
957
  setActivity(activity) {
833
958
  let roomMemories = this.getStorageProperty("activities_memory") || {};
834
959
  roomMemories[activity.id] = activity.export();
835
960
  this.setStorageProperty("activities_memory", roomMemories);
836
961
  }
962
+ /**
963
+ * Add an activity to the room.
964
+ * @param activity The activity to add.
965
+ */
837
966
  addActivity(activity) {
838
967
  if (this.activityIds.includes(activity.id)) {
839
968
  let currentActivity = this.getActivity(activity.id);
@@ -849,6 +978,10 @@ var RoomBaseModel = class extends StoredClassModel3 {
849
978
  addedActivityIds.push(activity.id);
850
979
  this.setStorageProperty("addedActivityIds", addedActivityIds);
851
980
  }
981
+ /**
982
+ * Remove an activity from the room.
983
+ * @param activity The activity to remove.
984
+ */
852
985
  removeActivity(activity) {
853
986
  let activityId = typeof activity === "string" ? activity : activity.id;
854
987
  if (this.defaultActivityIds.includes(activityId)) {
@@ -873,6 +1006,9 @@ var RoomBaseModel = class extends StoredClassModel3 {
873
1006
  delete roomMemories[activityId];
874
1007
  this.setStorageProperty("activities_memory", roomMemories);
875
1008
  }
1009
+ /**
1010
+ * Clear all expired activities.
1011
+ */
876
1012
  clearExpiredActivities() {
877
1013
  this.activities.forEach((activity) => {
878
1014
  if (activity.isExpired()) {
@@ -880,6 +1016,9 @@ var RoomBaseModel = class extends StoredClassModel3 {
880
1016
  }
881
1017
  });
882
1018
  }
1019
+ /**
1020
+ * Whether is disabled. If it is a string, it is a Pixi'VN flag name.
1021
+ */
883
1022
  get disabled() {
884
1023
  let value = this.getStorageProperty("disabled") || this.defaultDisabled;
885
1024
  if (typeof value === "string") {
@@ -890,6 +1029,9 @@ var RoomBaseModel = class extends StoredClassModel3 {
890
1029
  set disabled(value) {
891
1030
  this.setStorageProperty("disabled", value);
892
1031
  }
1032
+ /**
1033
+ * Whether is hidden. If it is a string, it is a Pixi'VN flag name.
1034
+ */
893
1035
  get hidden() {
894
1036
  let value = this.getStorageProperty("hidden") || this.defaultHidden;
895
1037
  if (typeof value === "string") {
@@ -900,9 +1042,13 @@ var RoomBaseModel = class extends StoredClassModel3 {
900
1042
  set hidden(value) {
901
1043
  this.setStorageProperty("hidden", value);
902
1044
  }
903
- get iconElement() {
904
- return this._iconElement;
1045
+ get icon() {
1046
+ return this._icon;
905
1047
  }
1048
+ /**
1049
+ * Get the character commitments of the room.
1050
+ * @returns The character commitments of the room.
1051
+ */
906
1052
  getRoutine() {
907
1053
  let commitments = getCurrentCommitments();
908
1054
  return commitments.filter((c) => c.room.id === this.id);
@@ -1050,10 +1196,19 @@ var ExecutionTypeEnum = /* @__PURE__ */ ((ExecutionTypeEnum2) => {
1050
1196
  import { GameStorageManager as GameStorageManager3 } from "@drincs/pixi-vn";
1051
1197
  var CURRENT_ROOM_MEMORY_KEY = "___nqtr-current_room_memory___";
1052
1198
  function setCurrentRoom(room) {
1053
- let roomRegistrated = getRoomById(room.id);
1054
- if (!roomRegistrated) {
1055
- console.error(`[NQTR] The room ${room.id} is not registered, so it can't be set as current room`);
1056
- 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
+ }
1057
1212
  }
1058
1213
  localStorage.setItem(CURRENT_ROOM_MEMORY_KEY, room.id);
1059
1214
  }
@@ -1113,6 +1268,8 @@ export {
1113
1268
  clearExpiredRoutine,
1114
1269
  currentActivities,
1115
1270
  getActivityById,
1271
+ getAllLocations,
1272
+ getAllMaps,
1116
1273
  getCommitmentByCharacter,
1117
1274
  getCommitmentById,
1118
1275
  getCueerntMap,