@zthun/romulator-client 1.10.0 → 1.12.0

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.
@@ -67,6 +67,17 @@ export declare class ZRomulatorGameBuilder {
67
67
  * This instance.
68
68
  */
69
69
  system(system: ZRomulatorSystemId): this;
70
+ /**
71
+ * Attempts to parse a game from a game entry in a system.json game
72
+ * list.
73
+ *
74
+ * @param candidate -
75
+ * The candidate to parse.
76
+ *
77
+ * @returns
78
+ * This object.
79
+ */
80
+ parse(candidate: unknown): this;
70
81
  /**
71
82
  * Copies an existing game into this builder.
72
83
  *
package/dist/index.cjs CHANGED
@@ -18,8 +18,20 @@ class ZRomulatorConfigGamesMetadata {
18
18
  }
19
19
  }
20
20
 
21
+ function _define_property$4(obj, key, value) {
22
+ if (key in obj) {
23
+ Object.defineProperty(obj, key, {
24
+ value: value,
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true
28
+ });
29
+ } else {
30
+ obj[key] = value;
31
+ }
32
+ return obj;
33
+ }
21
34
  class ZRomulatorConfigGamesBuilder {
22
- _config = {};
23
35
  gamesFolder(games) {
24
36
  this._config.gamesFolder = games;
25
37
  return this;
@@ -38,8 +50,24 @@ class ZRomulatorConfigGamesBuilder {
38
50
  build() {
39
51
  return structuredClone(this._config);
40
52
  }
53
+ constructor(){
54
+ _define_property$4(this, "_config", {});
55
+ }
41
56
  }
42
57
 
58
+ function _define_property$3(obj, key, value) {
59
+ if (key in obj) {
60
+ Object.defineProperty(obj, key, {
61
+ value: value,
62
+ enumerable: true,
63
+ configurable: true,
64
+ writable: true
65
+ });
66
+ } else {
67
+ obj[key] = value;
68
+ }
69
+ return obj;
70
+ }
43
71
  /**
44
72
  * Represents a list of known config ids
45
73
  */ var ZRomulatorConfigId = /*#__PURE__*/ function(ZRomulatorConfigId) {
@@ -52,11 +80,6 @@ class ZRomulatorConfigGamesBuilder {
52
80
  return ZRomulatorConfigId;
53
81
  }({});
54
82
  class ZRomulatorConfigBuilder {
55
- _config = {
56
- id: "games",
57
- name: "",
58
- file: ""
59
- };
60
83
  id(id) {
61
84
  this._config.id = id;
62
85
  return this;
@@ -93,14 +116,31 @@ class ZRomulatorConfigBuilder {
93
116
  build() {
94
117
  return structuredClone(this._config);
95
118
  }
119
+ constructor(){
120
+ _define_property$3(this, "_config", {
121
+ id: "games",
122
+ name: "",
123
+ file: ""
124
+ });
125
+ }
96
126
  }
97
127
 
128
+ function _define_property$2(obj, key, value) {
129
+ if (key in obj) {
130
+ Object.defineProperty(obj, key, {
131
+ value: value,
132
+ enumerable: true,
133
+ configurable: true,
134
+ writable: true
135
+ });
136
+ } else {
137
+ obj[key] = value;
138
+ }
139
+ return obj;
140
+ }
98
141
  /**
99
142
  * A builder for the IZRomulatorGame model.
100
143
  */ class ZRomulatorGameBuilder {
101
- _game = {
102
- id: ""
103
- };
104
144
  /**
105
145
  * Sets the unique id for the game.
106
146
  *
@@ -146,6 +186,25 @@ class ZRomulatorConfigBuilder {
146
186
  return this;
147
187
  }
148
188
  /**
189
+ * Attempts to parse a game from a game entry in a system.json game
190
+ * list.
191
+ *
192
+ * @param candidate -
193
+ * The candidate to parse.
194
+ *
195
+ * @returns
196
+ * This object.
197
+ */ parse(candidate) {
198
+ if (candidate == null || typeof candidate !== "object") {
199
+ return this;
200
+ }
201
+ const name = lodashEs.get(candidate, "name");
202
+ if (name != null && typeof name === "string") {
203
+ this.name(name);
204
+ }
205
+ return this;
206
+ }
207
+ /**
149
208
  * Copies an existing game into this builder.
150
209
  *
151
210
  * @param other -
@@ -165,6 +224,11 @@ class ZRomulatorConfigBuilder {
165
224
  const clone = structuredClone(this._game);
166
225
  return lodashEs.omitBy(clone, lodashEs.isUndefined);
167
226
  }
227
+ constructor(){
228
+ _define_property$2(this, "_game", {
229
+ id: ""
230
+ });
231
+ }
168
232
  }
169
233
 
170
234
  var ZRomulatorGameMediaType = /*#__PURE__*/ function(ZRomulatorGameMediaType) {
@@ -413,14 +477,34 @@ function isMediaType(candidate) {
413
477
  const ZRomulatorSystemIdMap = lodashEs.keyBy(Object.values(ZRomulatorSystemId));
414
478
  /**
415
479
  * Gets whether a candidate string represents a system id.
480
+ *
481
+ * This check is case sensitive.
482
+ *
483
+ * @param candidate -
484
+ * The candidate to check.
485
+ *
486
+ * @returns
487
+ * True if candidate is a string that represents a system id.
416
488
  */ function isSystemId(candidate) {
417
489
  return typeof candidate === "string" && Object.prototype.hasOwnProperty.call(ZRomulatorSystemIdMap, candidate);
418
490
  }
419
491
 
492
+ function _define_property$1(obj, key, value) {
493
+ if (key in obj) {
494
+ Object.defineProperty(obj, key, {
495
+ value: value,
496
+ enumerable: true,
497
+ configurable: true,
498
+ writable: true
499
+ });
500
+ } else {
501
+ obj[key] = value;
502
+ }
503
+ return obj;
504
+ }
420
505
  /**
421
506
  * A builder for the media object.
422
507
  */ class ZRomulatorMediaBuilder {
423
- _media = {};
424
508
  id(id) {
425
509
  this._media.id = id;
426
510
  return this;
@@ -482,12 +566,18 @@ const ZRomulatorSystemIdMap = lodashEs.keyBy(Object.values(ZRomulatorSystemId));
482
566
  const clone = structuredClone(this._media);
483
567
  return lodashEs.omitBy(clone, lodashEs.isUndefined);
484
568
  }
569
+ constructor(){
570
+ _define_property$1(this, "_media", {});
571
+ }
485
572
  }
486
573
 
487
574
  /**
488
575
  * The type of media content for a system.
489
576
  */ var ZRomulatorSystemContentType = /*#__PURE__*/ function(ZRomulatorSystemContentType) {
490
577
  /**
578
+ * No idea
579
+ */ ZRomulatorSystemContentType["Unknown"] = "unknown";
580
+ /**
491
581
  * Uses memory roms.
492
582
  */ ZRomulatorSystemContentType["ReadOnlyMemory"] = "rom";
493
583
  /**
@@ -501,11 +591,28 @@ const ZRomulatorSystemIdMap = lodashEs.keyBy(Object.values(ZRomulatorSystemId));
501
591
  */ ZRomulatorSystemContentType["Disk"] = "iso";
502
592
  return ZRomulatorSystemContentType;
503
593
  }({});
594
+ const ZRomulatorSystemContentTypeMap = lodashEs.keyBy(Object.values(ZRomulatorSystemContentType));
595
+ /**
596
+ * Gets whether a candidate string represents a system content type.
597
+ *
598
+ * This check is case sensitive.
599
+ *
600
+ * @param candidate -
601
+ * The candidate to check.
602
+ *
603
+ * @returns
604
+ * True if candidate is a string that represents a system content type.
605
+ */ function isSystemContentType(candidate) {
606
+ return typeof candidate === "string" && Object.prototype.hasOwnProperty.call(ZRomulatorSystemContentTypeMap, candidate);
607
+ }
504
608
 
505
609
  /**
506
610
  * Describes the type of hardware a system is.
507
611
  */ var ZRomulatorSystemHardwareType = /*#__PURE__*/ function(ZRomulatorSystemHardwareType) {
508
612
  /**
613
+ * No idea what this is.
614
+ */ ZRomulatorSystemHardwareType["Unknown"] = "unknown";
615
+ /**
509
616
  * An accessory that attaches to another system.
510
617
  */ ZRomulatorSystemHardwareType["Accessory"] = "accessory";
511
618
  /**
@@ -534,37 +641,74 @@ const ZRomulatorSystemIdMap = lodashEs.keyBy(Object.values(ZRomulatorSystemId));
534
641
  */ ZRomulatorSystemHardwareType["VirtualMachine"] = "virtual-machine";
535
642
  return ZRomulatorSystemHardwareType;
536
643
  }({});
644
+ const ZRomulatorSystemHardwareTypeMap = lodashEs.keyBy(Object.values(ZRomulatorSystemHardwareType));
645
+ /**
646
+ * Gets whether a candidate string represents a system hardware type.
647
+ *
648
+ * This check is case sensitive.
649
+ *
650
+ * @param candidate -
651
+ * The candidate to check.
652
+ *
653
+ * @returns
654
+ * True if candidate is a string that represents a system hardware type.
655
+ */ function isSystemHardwareType(candidate) {
656
+ return typeof candidate === "string" && Object.prototype.hasOwnProperty.call(ZRomulatorSystemHardwareTypeMap, candidate);
657
+ }
537
658
 
538
659
  /**
539
660
  * The type of media a system supports.
540
- */ var ZRomulatorSystemMediaFormatType = /*#__PURE__*/ function(ZRomulatorSystemMediaFormatType) {
661
+ */ var ZRomulatorSystemMediaFormat = /*#__PURE__*/ function(ZRomulatorSystemMediaFormat) {
662
+ /**
663
+ * No idea
664
+ */ ZRomulatorSystemMediaFormat["Unknown"] = "unknown";
541
665
  /**
542
666
  * Cartridge based systems.
543
- */ ZRomulatorSystemMediaFormatType["Cartridge"] = "cartridge";
667
+ */ ZRomulatorSystemMediaFormat["Cartridge"] = "cartridge";
544
668
  /**
545
669
  * Motherboard based systems.
546
670
  *
547
671
  * Usually for arcades.
548
- */ ZRomulatorSystemMediaFormatType["Pcb"] = "pcb";
672
+ */ ZRomulatorSystemMediaFormat["Pcb"] = "pcb";
549
673
  /**
550
674
  * CD/DVD based systems.
551
- */ ZRomulatorSystemMediaFormatType["Cd"] = "cd";
675
+ */ ZRomulatorSystemMediaFormat["Cd"] = "cd";
552
676
  /**
553
677
  * Floppy disk based systems.
554
- */ ZRomulatorSystemMediaFormatType["FloppyDisk"] = "floppy-disk";
555
- return ZRomulatorSystemMediaFormatType;
678
+ */ ZRomulatorSystemMediaFormat["FloppyDisk"] = "floppy-disk";
679
+ return ZRomulatorSystemMediaFormat;
556
680
  }({});
681
+ const ZRomulatorSystemMediaFormatMap = lodashEs.keyBy(Object.values(ZRomulatorSystemMediaFormat));
682
+ /**
683
+ * Gets whether a candidate string represents a system media format.
684
+ *
685
+ * This check is case sensitive.
686
+ *
687
+ * @param candidate -
688
+ * The candidate to check.
689
+ *
690
+ * @returns
691
+ * True if candidate is a string that represents a system media format.
692
+ */ function isSystemMediaFormat(candidate) {
693
+ return typeof candidate === "string" && Object.prototype.hasOwnProperty.call(ZRomulatorSystemMediaFormatMap, candidate);
694
+ }
557
695
 
696
+ function _define_property(obj, key, value) {
697
+ if (key in obj) {
698
+ Object.defineProperty(obj, key, {
699
+ value: value,
700
+ enumerable: true,
701
+ configurable: true,
702
+ writable: true
703
+ });
704
+ } else {
705
+ obj[key] = value;
706
+ }
707
+ return obj;
708
+ }
558
709
  /**
559
710
  * A builder for creating an IZRomulatorSystem.
560
711
  */ class ZRomulatorSystemBuilder {
561
- _system = {
562
- id: ZRomulatorSystemId.Nintendo,
563
- extensions: [
564
- "zip",
565
- "7z"
566
- ]
567
- };
568
712
  /**
569
713
  * Sets the id (slug) of the system.
570
714
  *
@@ -610,7 +754,6 @@ const ZRomulatorSystemIdMap = lodashEs.keyBy(Object.values(ZRomulatorSystemId));
610
754
  * @returns
611
755
  * This instance.
612
756
  */ hardware(type) {
613
- this._system.classification = helpfulFn.firstDefined({}, this._system.classification);
614
757
  this._system.classification.hardwareType = type;
615
758
  return this;
616
759
  }
@@ -623,7 +766,6 @@ const ZRomulatorSystemIdMap = lodashEs.keyBy(Object.values(ZRomulatorSystemId));
623
766
  * @returns
624
767
  * This instance.
625
768
  */ mediaFormat(type) {
626
- this._system.classification = helpfulFn.firstDefined({}, this._system.classification);
627
769
  this._system.classification.mediaFormat = type;
628
770
  return this;
629
771
  }
@@ -636,12 +778,37 @@ const ZRomulatorSystemIdMap = lodashEs.keyBy(Object.values(ZRomulatorSystemId));
636
778
  * @returns
637
779
  * This instance.
638
780
  */ contentType(type) {
639
- this._system.classification = helpfulFn.firstDefined({}, this._system.classification);
640
781
  this._system.classification.contentType = type;
641
782
  return this;
642
783
  }
643
784
  /**
644
- * Sets the production run.
785
+ * Sets the production start value.
786
+ *
787
+ * @param start -
788
+ * The year the system was released into production.
789
+ * Use '?' if you do not know this information.
790
+ *
791
+ * @returns
792
+ * This object.
793
+ */ productionStart(start) {
794
+ this._system.productionYears.start = start;
795
+ return this;
796
+ }
797
+ /**
798
+ * Sets the production end of life value.
799
+ *
800
+ * @param end -
801
+ * The end of life year. Set to current
802
+ * to mark no end of life.
803
+ *
804
+ * @returns
805
+ * This object.
806
+ */ productionEnd(end) {
807
+ this._system.productionYears.end = end;
808
+ return this;
809
+ }
810
+ /**
811
+ * Sets the full production run.
645
812
  *
646
813
  * @param start -
647
814
  * The starting year of production.
@@ -650,14 +817,8 @@ const ZRomulatorSystemIdMap = lodashEs.keyBy(Object.values(ZRomulatorSystemId));
650
817
  *
651
818
  * @returns
652
819
  * This object.
653
- */ production(start, end) {
654
- delete this._system.productionYears;
655
- this._system.productionYears = {
656
- start,
657
- end
658
- };
659
- this._system.productionYears = lodashEs.omitBy(this._system.productionYears, lodashEs.isUndefined);
660
- return this;
820
+ */ production(start = "?", end = "current") {
821
+ return this.productionStart(start).productionEnd(end);
661
822
  }
662
823
  /**
663
824
  * Adds to the extension list.
@@ -672,6 +833,50 @@ const ZRomulatorSystemIdMap = lodashEs.keyBy(Object.values(ZRomulatorSystemId));
672
833
  this._system.extensions = lodashEs.uniqBy(extensions.concat(extension), lodashEs.upperCase).map((e)=>e.toLowerCase());
673
834
  return this;
674
835
  }
836
+ parseId(candidate) {
837
+ const id = lodashEs.get(candidate, "id");
838
+ return isSystemId(id) ? this.id(id) : this;
839
+ }
840
+ parseName(candidate) {
841
+ const name = lodashEs.get(candidate, "name");
842
+ return name != null && typeof name === "string" ? this.name(name) : this;
843
+ }
844
+ parseCompany(candidate) {
845
+ const company = lodashEs.get(candidate, "company");
846
+ return company != null && typeof company === "string" ? this.company(company) : this;
847
+ }
848
+ parseExtensions(candidate) {
849
+ const extensions = lodashEs.castArray(lodashEs.get(candidate, "extensions")).filter((ext)=>ext != null).filter((ext)=>typeof ext === "string");
850
+ return this.extension(extensions);
851
+ }
852
+ parseHardwareType(classification) {
853
+ const hardwareType = lodashEs.get(classification, "hardwareType");
854
+ return isSystemHardwareType(hardwareType) ? this.hardware(hardwareType) : this;
855
+ }
856
+ parseMediaFormat(classification) {
857
+ const mediaFormat = lodashEs.get(classification, "mediaFormat");
858
+ return isSystemMediaFormat(mediaFormat) ? this.mediaFormat(mediaFormat) : this;
859
+ }
860
+ parseContentType(classification) {
861
+ const contentType = lodashEs.get(classification, "contentType");
862
+ return isSystemContentType(contentType) ? this.contentType(contentType) : this;
863
+ }
864
+ parseClassification(candidate) {
865
+ const classification = lodashEs.get(candidate, "classification");
866
+ return classification != null && typeof classification === "object" ? this.parseHardwareType(classification).parseMediaFormat(classification).parseContentType(classification) : this;
867
+ }
868
+ parseProductionStart(productionYears) {
869
+ const start = lodashEs.get(productionYears, "start");
870
+ return typeof start === "number" || start === "?" ? this.productionStart(start) : this;
871
+ }
872
+ parseProductionEnd(productionYears) {
873
+ const end = lodashEs.get(productionYears, "end");
874
+ return typeof end === "number" || end === "current" ? this.productionEnd(end) : this;
875
+ }
876
+ parseProductionYears(candidate) {
877
+ const production = lodashEs.get(candidate, "productionYears");
878
+ return production != null && typeof production === "object" ? this.parseProductionStart(production).parseProductionEnd(production) : this;
879
+ }
675
880
  /**
676
881
  * Parses an unknown object to try and build a system from it.
677
882
  *
@@ -684,20 +889,8 @@ const ZRomulatorSystemIdMap = lodashEs.keyBy(Object.values(ZRomulatorSystemId));
684
889
  if (candidate == null || typeof candidate !== "object") {
685
890
  return this;
686
891
  }
687
- const id = lodashEs.get(candidate, "id");
688
- const name = lodashEs.get(candidate, "name");
689
- const company = lodashEs.get(candidate, "company");
690
- const extensions = lodashEs.castArray(lodashEs.get(candidate, "extensions")).filter((ext)=>ext != null).filter((ext)=>typeof ext === "string");
691
- if (isSystemId(id)) {
692
- this.id(id);
693
- }
694
- if (name != null && typeof name === "string") {
695
- this.name(name);
696
- }
697
- if (company != null && typeof company === "string") {
698
- this.company(company);
699
- }
700
- return this.extension(extensions);
892
+ this.parseId(candidate).parseName(candidate).parseCompany(candidate).parseExtensions(candidate).parseClassification(candidate).parseProductionYears(candidate);
893
+ return this;
701
894
  }
702
895
  /**
703
896
  * Builds the system instance.
@@ -708,6 +901,26 @@ const ZRomulatorSystemIdMap = lodashEs.keyBy(Object.values(ZRomulatorSystemId));
708
901
  */ build() {
709
902
  return structuredClone(this._system);
710
903
  }
904
+ constructor(){
905
+ _define_property(this, "_system", {
906
+ id: ZRomulatorSystemId.Nintendo,
907
+ name: "",
908
+ classification: {
909
+ hardwareType: ZRomulatorSystemHardwareType.Unknown,
910
+ mediaFormat: ZRomulatorSystemMediaFormat.Unknown,
911
+ contentType: ZRomulatorSystemContentType.Unknown
912
+ },
913
+ company: "",
914
+ productionYears: {
915
+ start: "?",
916
+ end: "current"
917
+ },
918
+ extensions: [
919
+ "zip",
920
+ "7z"
921
+ ]
922
+ });
923
+ }
711
924
  }
712
925
 
713
926
  exports.ZRomulatorConfigBuilder = ZRomulatorConfigBuilder;
@@ -721,10 +934,13 @@ exports.ZRomulatorSystemBuilder = ZRomulatorSystemBuilder;
721
934
  exports.ZRomulatorSystemContentType = ZRomulatorSystemContentType;
722
935
  exports.ZRomulatorSystemHardwareType = ZRomulatorSystemHardwareType;
723
936
  exports.ZRomulatorSystemId = ZRomulatorSystemId;
724
- exports.ZRomulatorSystemMediaFormatType = ZRomulatorSystemMediaFormatType;
937
+ exports.ZRomulatorSystemMediaFormat = ZRomulatorSystemMediaFormat;
725
938
  exports.ZRomulatorSystemMediaType = ZRomulatorSystemMediaType;
726
939
  exports.isGameMediaType = isGameMediaType;
727
940
  exports.isMediaType = isMediaType;
941
+ exports.isSystemContentType = isSystemContentType;
942
+ exports.isSystemHardwareType = isSystemHardwareType;
728
943
  exports.isSystemId = isSystemId;
944
+ exports.isSystemMediaFormat = isSystemMediaFormat;
729
945
  exports.isSystemMediaType = isSystemMediaType;
730
946
  //# sourceMappingURL=index.cjs.map