@m2c2kit/core 0.3.19 → 0.3.21

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
@@ -499,32 +499,534 @@ const _Timer = class _Timer {
499
499
  _Timer._timers = new Array();
500
500
  let Timer = _Timer;
501
501
 
502
+ class WebColors {
503
+ }
504
+ WebColors.Transparent = [0, 0, 0, 0];
505
+ WebColors.MediumVioletRed = [199, 21, 133, 1];
506
+ WebColors.DeepPink = [255, 20, 147, 1];
507
+ WebColors.PaleVioletRed = [219, 112, 147, 1];
508
+ WebColors.HotPink = [255, 105, 180, 1];
509
+ WebColors.LightPink = [255, 182, 193, 1];
510
+ WebColors.Pink = [255, 192, 203, 1];
511
+ WebColors.DarkRed = [139, 0, 0, 1];
512
+ WebColors.Red = [255, 0, 0, 1];
513
+ WebColors.Firebrick = [178, 34, 34, 1];
514
+ WebColors.Crimson = [220, 20, 60, 1];
515
+ WebColors.IndianRed = [205, 92, 92, 1];
516
+ WebColors.LightCoral = [240, 128, 128, 1];
517
+ WebColors.Salmon = [250, 128, 114, 1];
518
+ WebColors.DarkSalmon = [233, 150, 122, 1];
519
+ WebColors.LightSalmon = [255, 160, 122, 1];
520
+ WebColors.OrangeRed = [255, 69, 0, 1];
521
+ WebColors.Tomato = [255, 99, 71, 1];
522
+ WebColors.DarkOrange = [255, 140, 0, 1];
523
+ WebColors.Coral = [255, 127, 80, 1];
524
+ WebColors.Orange = [255, 165, 0, 1];
525
+ WebColors.DarkKhaki = [189, 183, 107, 1];
526
+ WebColors.Gold = [255, 215, 0, 1];
527
+ WebColors.Khaki = [240, 230, 140, 1];
528
+ WebColors.PeachPuff = [255, 218, 185, 1];
529
+ WebColors.Yellow = [255, 255, 0, 1];
530
+ WebColors.PaleGoldenrod = [238, 232, 170, 1];
531
+ WebColors.Moccasin = [255, 228, 181, 1];
532
+ WebColors.PapayaWhip = [255, 239, 213, 1];
533
+ WebColors.LightGoldenrodYellow = [250, 250, 210, 1];
534
+ WebColors.LemonChiffon = [255, 250, 205, 1];
535
+ WebColors.LightYellow = [255, 255, 224, 1];
536
+ WebColors.Maroon = [128, 0, 0, 1];
537
+ WebColors.Brown = [165, 42, 42, 1];
538
+ WebColors.SaddleBrown = [139, 69, 19, 1];
539
+ WebColors.Sienna = [160, 82, 45, 1];
540
+ WebColors.Chocolate = [210, 105, 30, 1];
541
+ WebColors.DarkGoldenrod = [184, 134, 11, 1];
542
+ WebColors.Peru = [205, 133, 63, 1];
543
+ WebColors.RosyBrown = [188, 143, 143, 1];
544
+ WebColors.Goldenrod = [218, 165, 32, 1];
545
+ WebColors.SandyBrown = [244, 164, 96, 1];
546
+ WebColors.Tan = [210, 180, 140, 1];
547
+ WebColors.Burlywood = [222, 184, 135, 1];
548
+ WebColors.Wheat = [245, 222, 179, 1];
549
+ WebColors.NavajoWhite = [255, 222, 173, 1];
550
+ WebColors.Bisque = [255, 228, 196, 1];
551
+ WebColors.BlanchedAlmond = [255, 235, 205, 1];
552
+ WebColors.Cornsilk = [255, 248, 220, 1];
553
+ WebColors.DarkGreen = [0, 100, 0, 1];
554
+ WebColors.Green = [0, 128, 0, 1];
555
+ WebColors.DarkOliveGreen = [85, 107, 47, 1];
556
+ WebColors.ForestGreen = [34, 139, 34, 1];
557
+ WebColors.SeaGreen = [46, 139, 87, 1];
558
+ WebColors.Olive = [128, 128, 0, 1];
559
+ WebColors.OliveDrab = [107, 142, 35, 1];
560
+ WebColors.MediumSeaGreen = [60, 179, 113, 1];
561
+ WebColors.LimeGreen = [50, 205, 50, 1];
562
+ WebColors.Lime = [0, 255, 0, 1];
563
+ WebColors.SpringGreen = [0, 255, 127, 1];
564
+ WebColors.MediumSpringGreen = [0, 250, 154, 1];
565
+ WebColors.DarkSeaGreen = [143, 188, 143, 1];
566
+ WebColors.MediumAquamarine = [102, 205, 170, 1];
567
+ WebColors.YellowGreen = [154, 205, 50, 1];
568
+ WebColors.LawnGreen = [124, 252, 0, 1];
569
+ WebColors.Chartreuse = [127, 255, 0, 1];
570
+ WebColors.LightGreen = [144, 238, 144, 1];
571
+ WebColors.GreenYellow = [173, 255, 47, 1];
572
+ WebColors.PaleGreen = [152, 251, 152, 1];
573
+ WebColors.Teal = [0, 128, 128, 1];
574
+ WebColors.DarkCyan = [0, 139, 139, 1];
575
+ WebColors.LightSeaGreen = [32, 178, 170, 1];
576
+ WebColors.CadetBlue = [95, 158, 160, 1];
577
+ WebColors.DarkTurquoise = [0, 206, 209, 1];
578
+ WebColors.MediumTurquoise = [72, 209, 204, 1];
579
+ WebColors.Turquoise = [64, 224, 208, 1];
580
+ WebColors.Aqua = [0, 255, 255, 1];
581
+ WebColors.Cyan = [0, 255, 255, 1];
582
+ WebColors.Aquamarine = [127, 255, 212, 1];
583
+ WebColors.PaleTurquoise = [175, 238, 238, 1];
584
+ WebColors.LightCyan = [224, 255, 255, 1];
585
+ WebColors.Navy = [0, 0, 128, 1];
586
+ WebColors.DarkBlue = [0, 0, 139, 1];
587
+ WebColors.MediumBlue = [0, 0, 205, 1];
588
+ WebColors.Blue = [0, 0, 255, 1];
589
+ WebColors.MidnightBlue = [25, 25, 112, 1];
590
+ WebColors.RoyalBlue = [65, 105, 225, 1];
591
+ WebColors.SteelBlue = [70, 130, 180, 1];
592
+ WebColors.DodgerBlue = [30, 144, 255, 1];
593
+ WebColors.DeepSkyBlue = [0, 191, 255, 1];
594
+ WebColors.CornflowerBlue = [100, 149, 237, 1];
595
+ WebColors.SkyBlue = [135, 206, 235, 1];
596
+ WebColors.LightSkyBlue = [135, 206, 250, 1];
597
+ WebColors.LightSteelBlue = [176, 196, 222, 1];
598
+ WebColors.LightBlue = [173, 216, 230, 1];
599
+ WebColors.PowderBlue = [176, 224, 230, 1];
600
+ WebColors.Indigo = [75, 0, 130, 1];
601
+ WebColors.Purple = [128, 0, 128, 1];
602
+ WebColors.DarkMagenta = [139, 0, 139, 1];
603
+ WebColors.DarkViolet = [148, 0, 211, 1];
604
+ WebColors.DarkSlateBlue = [72, 61, 139, 1];
605
+ WebColors.BlueViolet = [138, 43, 226, 1];
606
+ WebColors.DarkOrchid = [153, 50, 204, 1];
607
+ WebColors.Fuchsia = [255, 0, 255, 1];
608
+ WebColors.Magenta = [255, 0, 255, 1];
609
+ WebColors.SlateBlue = [106, 90, 205, 1];
610
+ WebColors.MediumSlateBlue = [123, 104, 238, 1];
611
+ WebColors.MediumOrchid = [186, 85, 211, 1];
612
+ WebColors.MediumPurple = [147, 112, 219, 1];
613
+ WebColors.Orchid = [218, 112, 214, 1];
614
+ WebColors.Violet = [238, 130, 238, 1];
615
+ WebColors.Plum = [221, 160, 221, 1];
616
+ WebColors.Thistle = [216, 191, 216, 1];
617
+ WebColors.Lavender = [230, 230, 250, 1];
618
+ WebColors.MistyRose = [255, 228, 225, 1];
619
+ WebColors.AntiqueWhite = [250, 235, 215, 1];
620
+ WebColors.Linen = [250, 240, 230, 1];
621
+ WebColors.Beige = [245, 245, 220, 1];
622
+ WebColors.WhiteSmoke = [245, 245, 245, 1];
623
+ WebColors.LavenderBlush = [255, 240, 245, 1];
624
+ WebColors.OldLace = [253, 245, 230, 1];
625
+ WebColors.AliceBlue = [240, 248, 255, 1];
626
+ WebColors.Seashell = [255, 245, 238, 1];
627
+ WebColors.GhostWhite = [248, 248, 255, 1];
628
+ WebColors.Honeydew = [240, 255, 240, 1];
629
+ WebColors.FloralWhite = [255, 250, 240, 1];
630
+ WebColors.Azure = [240, 255, 255, 1];
631
+ WebColors.MintCream = [245, 255, 250, 1];
632
+ WebColors.Snow = [255, 250, 250, 1];
633
+ WebColors.Ivory = [255, 255, 240, 1];
634
+ WebColors.White = [255, 255, 255, 1];
635
+ WebColors.Black = [0, 0, 0, 1];
636
+ WebColors.DarkSlateGray = [47, 79, 79, 1];
637
+ WebColors.DimGray = [105, 105, 105, 1];
638
+ WebColors.SlateGray = [112, 128, 144, 1];
639
+ WebColors.Gray = [128, 128, 128, 1];
640
+ WebColors.LightSlateGray = [119, 136, 153, 1];
641
+ WebColors.DarkGray = [169, 169, 169, 1];
642
+ WebColors.Silver = [192, 192, 192, 1];
643
+ WebColors.LightGray = [211, 211, 211, 1];
644
+ WebColors.Gainsboro = [220, 220, 220, 1];
645
+ WebColors.RebeccaPurple = [102, 51, 153, 1];
646
+
647
+ class Constants {
648
+ }
649
+ /** Size of the font showing frames per second */
650
+ Constants.FPS_DISPLAY_TEXT_FONT_SIZE = 12;
651
+ /** Color of the font showing frames per second */
652
+ Constants.FPS_DISPLAY_TEXT_COLOR = [0, 0, 0, 0.5];
653
+ /** Frequency, in milliseconds, at which to update frames per second metric shown on the screen */
654
+ Constants.FPS_DISPLAY_UPDATE_INTERVAL = 1e3;
655
+ /** Maximum number of activity metrics to log. */
656
+ Constants.MAXIMUM_RECORDED_ACTIVITY_METRICS = 32;
657
+ /** The frames per second will be logged in game metrics if the FPS is lower than this value */
658
+ Constants.FPS_METRIC_REPORT_THRESHOLD = 59;
659
+ /** Scene color, if none is specified. */
660
+ Constants.DEFAULT_SCENE_BACKGROUND_COLOR = WebColors.White;
661
+ /** Shape fill color, if none is specified. */
662
+ Constants.DEFAULT_SHAPE_FILL_COLOR = WebColors.Red;
663
+ /** Color of paths in a shape, if none is specified. */
664
+ Constants.DEFAULT_PATH_STROKE_COLOR = WebColors.Red;
665
+ /** Line width of paths in a shape, if none is specified. */
666
+ Constants.DEFAULT_PATH_LINE_WIDTH = 2;
667
+ /** Color of text in Label and TextLine, if none is specified. */
668
+ Constants.DEFAULT_FONT_COLOR = WebColors.Black;
669
+ /** Font size in Label and TextLine, if none is specified. */
670
+ Constants.DEFAULT_FONT_SIZE = 16;
671
+ Constants.LIMITED_FPS_RATE = 5;
672
+ Constants.FREE_NODES_SCENE_NAME = "__freeNodesScene";
673
+ Constants.OUTGOING_SCENE_NAME = "__outgoingScene";
674
+ Constants.OUTGOING_SCENE_SPRITE_NAME = "__outgoingSceneSprite";
675
+ Constants.OUTGOING_SCENE_IMAGE_NAME = "__outgoingSceneSnapshot";
676
+ Constants.SESSION_INITIALIZATION_POLLING_INTERVAL_MS = 50;
677
+ /** Placeholder that will be populated during the build process. */
678
+ Constants.MODULE_METADATA_PLACEHOLDER = {
679
+ name: "",
680
+ version: "",
681
+ dependencies: {}
682
+ };
683
+ Constants.DEFAULT_ROOT_ELEMENT_ID = "m2c2kit";
684
+ Constants.ERUDA_URL = "https://cdn.jsdelivr.net/npm/eruda@3.2.3/eruda.js";
685
+ Constants.ERUDA_SRI = "sha384-KlRzgy/c+nZSV+eiFqoTkkbZ5pUqToho7HsNuebTbOsYTh4m0m/PAqkGsTMLXK14";
686
+
502
687
  class M2c2KitHelpers {
503
688
  /**
504
- * Returns the URL as it appears in the game's manifest.json file.
689
+ * Returns the URL as it appears in the game's manifest.json file.
690
+ *
691
+ * @remarks This is used to return the hashed URL.
692
+ *
693
+ * @param game - game object
694
+ * @param url - the URL
695
+ * @returns the hashed URL from the manifest, or the original URL if there is no manifest or the URL is not in the manifest.
696
+ */
697
+ static getUrlFromManifest(game, url) {
698
+ const manifest = game.manifest;
699
+ if (manifest && manifest[url]) {
700
+ return manifest[url];
701
+ }
702
+ return url;
703
+ }
704
+ /**
705
+ * Does the URL have a scheme?
706
+ *
707
+ * @param url - the URL to test
708
+ * @returns true if the url begins with a scheme (e.g., "http://",
709
+ * "https://", "file://", etc.)
710
+ */
711
+ static urlHasScheme(url) {
712
+ return /^[a-z]+:\/\//i.test(url);
713
+ }
714
+ /**
715
+ * Converts a value to a JSON schema type or one of types.
716
+ *
717
+ * @remarks The value can be of the target type, or a string that can be
718
+ * parsed into the target type. For example, a string `"3"` can be converted
719
+ * to a number, and a string `'{ "color" : "red" }'` can be converted to an
720
+ * object. If the target type if an object or array, the value can be a
721
+ * string parsable into the target type: this string can be the string
722
+ * representation of the object or array, or the URI encoded string.
723
+ * Throws an error if the value cannot be converted to the type or one of the
724
+ * types. Converting an object, null, or array to a string is often not the
725
+ * desired behavior, so a warning is logged if this occurs.
726
+ *
727
+ * @param value - the value to convert
728
+ * @param type - A JSON Schema type or types to convert the value to, e.g.,
729
+ * "string" or ["string", "null"]
730
+ * @returns the converted value
731
+ */
732
+ static convertValueToType(value, type) {
733
+ function canBeString(value2) {
734
+ if (typeof value2 === "string") {
735
+ return true;
736
+ }
737
+ if (typeof value2 === "object") {
738
+ return true;
739
+ }
740
+ if (!Number.isNaN(parseFloat(value2))) {
741
+ return true;
742
+ }
743
+ if (typeof value2 === "boolean") {
744
+ return true;
745
+ }
746
+ return false;
747
+ }
748
+ function asString(value2) {
749
+ if (typeof value2 === "string") {
750
+ return value2;
751
+ }
752
+ if (typeof value2 === "object") {
753
+ console.warn(
754
+ `convertValueToType() converted an object to a string. This may not be the desired behavior. The object was: ${JSON.stringify(value2)}`
755
+ );
756
+ return JSON.stringify(value2);
757
+ }
758
+ if (!Number.isNaN(parseFloat(value2))) {
759
+ return value2;
760
+ }
761
+ if (typeof value2 === "boolean") {
762
+ return value2.toString();
763
+ }
764
+ throw new Error(`Error parsing "${value2}" as a string.`);
765
+ }
766
+ function canBeNumber(value2) {
767
+ if (typeof value2 === "number") {
768
+ return true;
769
+ }
770
+ if (typeof value2 !== "string") {
771
+ return false;
772
+ }
773
+ const n = parseFloat(value2);
774
+ if (Number.isNaN(n)) {
775
+ return false;
776
+ }
777
+ return true;
778
+ }
779
+ function asNumber(value2) {
780
+ if (typeof value2 === "number") {
781
+ return value2;
782
+ }
783
+ if (typeof value2 !== "string") {
784
+ throw new Error(`Error parsing "${value2}" as a number.`);
785
+ }
786
+ const n = parseFloat(value2);
787
+ if (Number.isNaN(n)) {
788
+ throw new Error(`Error parsing "${value2}" as a number.`);
789
+ }
790
+ return n;
791
+ }
792
+ function canBeInteger(value2) {
793
+ if (typeof value2 === "number") {
794
+ return true;
795
+ }
796
+ if (typeof value2 !== "string") {
797
+ return false;
798
+ }
799
+ const n = parseInt(value2);
800
+ if (Number.isNaN(n)) {
801
+ return false;
802
+ }
803
+ return true;
804
+ }
805
+ function asInteger(value2) {
806
+ if (typeof value2 === "number") {
807
+ return value2;
808
+ }
809
+ if (typeof value2 !== "string") {
810
+ throw new Error(`Error parsing "${value2}" as an integer.`);
811
+ }
812
+ const n = parseInt(value2);
813
+ if (Number.isNaN(n)) {
814
+ throw new Error(`Error parsing "${value2}" as an integer.`);
815
+ }
816
+ return n;
817
+ }
818
+ function canBeBoolean(value2) {
819
+ if (typeof value2 === "boolean") {
820
+ return true;
821
+ }
822
+ if (value2 !== "true" && value2 !== "false") {
823
+ return false;
824
+ }
825
+ return true;
826
+ }
827
+ function asBoolean(value2) {
828
+ if (typeof value2 === "boolean") {
829
+ return value2;
830
+ }
831
+ if (value2 !== "true" && value2 !== "false") {
832
+ throw new Error(`Error parsing "${value2}" as a boolean.`);
833
+ }
834
+ return value2 === "true";
835
+ }
836
+ function canBeArray(value2) {
837
+ if (Array.isArray(value2)) {
838
+ return true;
839
+ }
840
+ if (typeof value2 !== "string") {
841
+ return false;
842
+ }
843
+ try {
844
+ const a = JSON.parse(value2);
845
+ if (Array.isArray(a)) {
846
+ return true;
847
+ }
848
+ } catch {
849
+ const a = JSON.parse(decodeURIComponent(value2));
850
+ if (Array.isArray(a)) {
851
+ return true;
852
+ }
853
+ }
854
+ return false;
855
+ }
856
+ function asArray(value2) {
857
+ if (Array.isArray(value2)) {
858
+ return value2;
859
+ }
860
+ if (typeof value2 !== "string") {
861
+ throw new Error(`Error parsing "${value2}" as an array.`);
862
+ }
863
+ try {
864
+ const a = JSON.parse(value2);
865
+ if (Array.isArray(a)) {
866
+ return a;
867
+ }
868
+ } catch {
869
+ const a = JSON.parse(decodeURIComponent(value2));
870
+ if (Array.isArray(a)) {
871
+ return a;
872
+ }
873
+ }
874
+ throw new Error(`Error parsing "${value2}" as an array.`);
875
+ }
876
+ function canBeObject(value2) {
877
+ if (typeof value2 === "object" && !Array.isArray(value2) && value2 !== null) {
878
+ return true;
879
+ }
880
+ if (typeof value2 !== "string") {
881
+ return false;
882
+ }
883
+ try {
884
+ const o = JSON.parse(value2);
885
+ if (typeof o === "object" && !Array.isArray(o) && o !== null) {
886
+ return true;
887
+ }
888
+ } catch {
889
+ const o = JSON.parse(decodeURIComponent(value2));
890
+ if (typeof o === "object" && !Array.isArray(o) && o !== null) {
891
+ return true;
892
+ }
893
+ }
894
+ return false;
895
+ }
896
+ function asObject(value2) {
897
+ if (typeof value2 === "object" && !Array.isArray(value2) && value2 !== null) {
898
+ return value2;
899
+ }
900
+ if (typeof value2 !== "string") {
901
+ throw new Error(`Error parsing "${value2}" as an object.`);
902
+ }
903
+ try {
904
+ const o = JSON.parse(value2);
905
+ if (typeof o === "object" && !Array.isArray(o) && o !== null) {
906
+ return o;
907
+ }
908
+ } catch {
909
+ const o = JSON.parse(decodeURIComponent(value2));
910
+ if (typeof o === "object" && !Array.isArray(o) && o !== null) {
911
+ return o;
912
+ }
913
+ }
914
+ throw new Error(`Error parsing "${value2}" as an object.`);
915
+ }
916
+ function canBeNull(value2) {
917
+ if (value2 === null || value2 === "null") {
918
+ return true;
919
+ }
920
+ return false;
921
+ }
922
+ function asNull(value2) {
923
+ if (value2 !== "null" && value2 !== null) {
924
+ throw new Error(`Error parsing "${value2}" as null.`);
925
+ }
926
+ return null;
927
+ }
928
+ const typeCheckers = {
929
+ string: canBeString,
930
+ number: canBeNumber,
931
+ integer: canBeInteger,
932
+ boolean: canBeBoolean,
933
+ array: canBeArray,
934
+ object: canBeObject,
935
+ null: canBeNull
936
+ };
937
+ const typeConverters = {
938
+ string: asString,
939
+ number: asNumber,
940
+ integer: asInteger,
941
+ boolean: asBoolean,
942
+ array: asArray,
943
+ object: asObject,
944
+ null: asNull
945
+ };
946
+ if (type === void 0) {
947
+ throw new Error(`Error with "${value}" as a target type.`);
948
+ }
949
+ if (!Array.isArray(type)) {
950
+ if (typeCheckers[type](value)) {
951
+ return typeConverters[type](value);
952
+ }
953
+ throw new Error(`Error parsing "${value}" as a ${type}.`);
954
+ }
955
+ for (const t of type) {
956
+ if (typeCheckers[t](value)) {
957
+ return typeConverters[t](value);
958
+ }
959
+ }
960
+ throw new Error(`Error parsing "${value}" as one of ${type}.`);
961
+ }
962
+ /**
963
+ * Load scripts from URLs.
505
964
  *
506
- * @remarks This is used to return the hashed URL.
965
+ * @remarks This is for debugging purposes only. If this is unwanted, it
966
+ * can be disabled on the server side with an appropriate Content
967
+ * Security Policy (CSP) header.
507
968
  *
508
- * @param game - game object
509
- * @param url - the URL
510
- * @returns the hashed URL from the manifest, or the original URL if there is no manifest or the URL is not in the manifest.
969
+ * @param urls - URLs with scripts to load
511
970
  */
512
- static getUrlFromManifest(game, url) {
513
- const manifest = game.manifest;
514
- if (manifest && manifest[url]) {
515
- return manifest[url];
971
+ static loadScriptUrls(urls) {
972
+ if (!Array.isArray(urls) || !urls.every((s) => typeof s === "string")) {
973
+ console.warn(
974
+ `Error parsing "scripts" parameter. "scripts" must be an array of URL strings, and it is recommended to be URI encoded.`
975
+ );
976
+ return;
516
977
  }
517
- return url;
978
+ urls.forEach((url) => {
979
+ if (!m2c2Globals.addedScriptUrls.includes(url)) {
980
+ const script = document.createElement("script");
981
+ script.src = url;
982
+ script.async = true;
983
+ document.head.appendChild(script);
984
+ console.log(`\u26AA added script: ${url}`);
985
+ m2c2Globals.addedScriptUrls.push(url);
986
+ }
987
+ });
518
988
  }
519
989
  /**
520
- * Does the URL have a scheme?
990
+ * Loads eruda from a CDN and initializes it.
521
991
  *
522
- * @param url - the URL to test
523
- * @returns true if the url begins with a scheme (e.g., "http://",
524
- * "https://", "file://", etc.)
992
+ * @remarks This is for debugging purposes only. If this is unwanted, it
993
+ * can be disabled on the server side with an appropriate Content
994
+ * Security Policy (CSP) header.
995
+ * eruda is a dev console overlay for mobile web browsers and web views.
996
+ * see https://github.com/liriliri/eruda
997
+ *
998
+ * @param pollingIntervalMs - milliseconds between each attempt
999
+ * @param maxAttempts - how many attempts to make
525
1000
  */
526
- static urlHasScheme(url) {
527
- return /^[a-z]+:\/\//i.test(url);
1001
+ static loadEruda(pollingIntervalMs = 100, maxAttempts = 50) {
1002
+ if (m2c2Globals.erudaRequested === true) {
1003
+ return;
1004
+ }
1005
+ console.log(`\u26AA added eruda script: ${Constants.ERUDA_URL}`);
1006
+ const script = document.createElement("script");
1007
+ script.src = Constants.ERUDA_URL;
1008
+ script.integrity = Constants.ERUDA_SRI;
1009
+ script.crossOrigin = "anonymous";
1010
+ script.async = true;
1011
+ document.head.appendChild(script);
1012
+ m2c2Globals.erudaRequested = true;
1013
+ let attempts = 0;
1014
+ const waitForEruda = () => {
1015
+ const eruda = window?.eruda;
1016
+ if (typeof eruda !== "undefined") {
1017
+ console.log("\u26AA eruda ready");
1018
+ eruda.init();
1019
+ m2c2Globals.erudaInitialized = true;
1020
+ } else if (attempts < maxAttempts) {
1021
+ attempts++;
1022
+ setTimeout(waitForEruda, pollingIntervalMs);
1023
+ } else {
1024
+ console.log(
1025
+ `eruda was requested, but could not be loaded after ${pollingIntervalMs * maxAttempts} milliseconds.`
1026
+ );
1027
+ }
1028
+ };
1029
+ waitForEruda();
528
1030
  }
529
1031
  /**
530
1032
  * Registers a `M2Node` class with the global class registry.
@@ -2026,189 +2528,6 @@ class MutablePath {
2026
2528
  }
2027
2529
  }
2028
2530
 
2029
- class WebColors {
2030
- }
2031
- WebColors.Transparent = [0, 0, 0, 0];
2032
- WebColors.MediumVioletRed = [199, 21, 133, 1];
2033
- WebColors.DeepPink = [255, 20, 147, 1];
2034
- WebColors.PaleVioletRed = [219, 112, 147, 1];
2035
- WebColors.HotPink = [255, 105, 180, 1];
2036
- WebColors.LightPink = [255, 182, 193, 1];
2037
- WebColors.Pink = [255, 192, 203, 1];
2038
- WebColors.DarkRed = [139, 0, 0, 1];
2039
- WebColors.Red = [255, 0, 0, 1];
2040
- WebColors.Firebrick = [178, 34, 34, 1];
2041
- WebColors.Crimson = [220, 20, 60, 1];
2042
- WebColors.IndianRed = [205, 92, 92, 1];
2043
- WebColors.LightCoral = [240, 128, 128, 1];
2044
- WebColors.Salmon = [250, 128, 114, 1];
2045
- WebColors.DarkSalmon = [233, 150, 122, 1];
2046
- WebColors.LightSalmon = [255, 160, 122, 1];
2047
- WebColors.OrangeRed = [255, 69, 0, 1];
2048
- WebColors.Tomato = [255, 99, 71, 1];
2049
- WebColors.DarkOrange = [255, 140, 0, 1];
2050
- WebColors.Coral = [255, 127, 80, 1];
2051
- WebColors.Orange = [255, 165, 0, 1];
2052
- WebColors.DarkKhaki = [189, 183, 107, 1];
2053
- WebColors.Gold = [255, 215, 0, 1];
2054
- WebColors.Khaki = [240, 230, 140, 1];
2055
- WebColors.PeachPuff = [255, 218, 185, 1];
2056
- WebColors.Yellow = [255, 255, 0, 1];
2057
- WebColors.PaleGoldenrod = [238, 232, 170, 1];
2058
- WebColors.Moccasin = [255, 228, 181, 1];
2059
- WebColors.PapayaWhip = [255, 239, 213, 1];
2060
- WebColors.LightGoldenrodYellow = [250, 250, 210, 1];
2061
- WebColors.LemonChiffon = [255, 250, 205, 1];
2062
- WebColors.LightYellow = [255, 255, 224, 1];
2063
- WebColors.Maroon = [128, 0, 0, 1];
2064
- WebColors.Brown = [165, 42, 42, 1];
2065
- WebColors.SaddleBrown = [139, 69, 19, 1];
2066
- WebColors.Sienna = [160, 82, 45, 1];
2067
- WebColors.Chocolate = [210, 105, 30, 1];
2068
- WebColors.DarkGoldenrod = [184, 134, 11, 1];
2069
- WebColors.Peru = [205, 133, 63, 1];
2070
- WebColors.RosyBrown = [188, 143, 143, 1];
2071
- WebColors.Goldenrod = [218, 165, 32, 1];
2072
- WebColors.SandyBrown = [244, 164, 96, 1];
2073
- WebColors.Tan = [210, 180, 140, 1];
2074
- WebColors.Burlywood = [222, 184, 135, 1];
2075
- WebColors.Wheat = [245, 222, 179, 1];
2076
- WebColors.NavajoWhite = [255, 222, 173, 1];
2077
- WebColors.Bisque = [255, 228, 196, 1];
2078
- WebColors.BlanchedAlmond = [255, 235, 205, 1];
2079
- WebColors.Cornsilk = [255, 248, 220, 1];
2080
- WebColors.DarkGreen = [0, 100, 0, 1];
2081
- WebColors.Green = [0, 128, 0, 1];
2082
- WebColors.DarkOliveGreen = [85, 107, 47, 1];
2083
- WebColors.ForestGreen = [34, 139, 34, 1];
2084
- WebColors.SeaGreen = [46, 139, 87, 1];
2085
- WebColors.Olive = [128, 128, 0, 1];
2086
- WebColors.OliveDrab = [107, 142, 35, 1];
2087
- WebColors.MediumSeaGreen = [60, 179, 113, 1];
2088
- WebColors.LimeGreen = [50, 205, 50, 1];
2089
- WebColors.Lime = [0, 255, 0, 1];
2090
- WebColors.SpringGreen = [0, 255, 127, 1];
2091
- WebColors.MediumSpringGreen = [0, 250, 154, 1];
2092
- WebColors.DarkSeaGreen = [143, 188, 143, 1];
2093
- WebColors.MediumAquamarine = [102, 205, 170, 1];
2094
- WebColors.YellowGreen = [154, 205, 50, 1];
2095
- WebColors.LawnGreen = [124, 252, 0, 1];
2096
- WebColors.Chartreuse = [127, 255, 0, 1];
2097
- WebColors.LightGreen = [144, 238, 144, 1];
2098
- WebColors.GreenYellow = [173, 255, 47, 1];
2099
- WebColors.PaleGreen = [152, 251, 152, 1];
2100
- WebColors.Teal = [0, 128, 128, 1];
2101
- WebColors.DarkCyan = [0, 139, 139, 1];
2102
- WebColors.LightSeaGreen = [32, 178, 170, 1];
2103
- WebColors.CadetBlue = [95, 158, 160, 1];
2104
- WebColors.DarkTurquoise = [0, 206, 209, 1];
2105
- WebColors.MediumTurquoise = [72, 209, 204, 1];
2106
- WebColors.Turquoise = [64, 224, 208, 1];
2107
- WebColors.Aqua = [0, 255, 255, 1];
2108
- WebColors.Cyan = [0, 255, 255, 1];
2109
- WebColors.Aquamarine = [127, 255, 212, 1];
2110
- WebColors.PaleTurquoise = [175, 238, 238, 1];
2111
- WebColors.LightCyan = [224, 255, 255, 1];
2112
- WebColors.Navy = [0, 0, 128, 1];
2113
- WebColors.DarkBlue = [0, 0, 139, 1];
2114
- WebColors.MediumBlue = [0, 0, 205, 1];
2115
- WebColors.Blue = [0, 0, 255, 1];
2116
- WebColors.MidnightBlue = [25, 25, 112, 1];
2117
- WebColors.RoyalBlue = [65, 105, 225, 1];
2118
- WebColors.SteelBlue = [70, 130, 180, 1];
2119
- WebColors.DodgerBlue = [30, 144, 255, 1];
2120
- WebColors.DeepSkyBlue = [0, 191, 255, 1];
2121
- WebColors.CornflowerBlue = [100, 149, 237, 1];
2122
- WebColors.SkyBlue = [135, 206, 235, 1];
2123
- WebColors.LightSkyBlue = [135, 206, 250, 1];
2124
- WebColors.LightSteelBlue = [176, 196, 222, 1];
2125
- WebColors.LightBlue = [173, 216, 230, 1];
2126
- WebColors.PowderBlue = [176, 224, 230, 1];
2127
- WebColors.Indigo = [75, 0, 130, 1];
2128
- WebColors.Purple = [128, 0, 128, 1];
2129
- WebColors.DarkMagenta = [139, 0, 139, 1];
2130
- WebColors.DarkViolet = [148, 0, 211, 1];
2131
- WebColors.DarkSlateBlue = [72, 61, 139, 1];
2132
- WebColors.BlueViolet = [138, 43, 226, 1];
2133
- WebColors.DarkOrchid = [153, 50, 204, 1];
2134
- WebColors.Fuchsia = [255, 0, 255, 1];
2135
- WebColors.Magenta = [255, 0, 255, 1];
2136
- WebColors.SlateBlue = [106, 90, 205, 1];
2137
- WebColors.MediumSlateBlue = [123, 104, 238, 1];
2138
- WebColors.MediumOrchid = [186, 85, 211, 1];
2139
- WebColors.MediumPurple = [147, 112, 219, 1];
2140
- WebColors.Orchid = [218, 112, 214, 1];
2141
- WebColors.Violet = [238, 130, 238, 1];
2142
- WebColors.Plum = [221, 160, 221, 1];
2143
- WebColors.Thistle = [216, 191, 216, 1];
2144
- WebColors.Lavender = [230, 230, 250, 1];
2145
- WebColors.MistyRose = [255, 228, 225, 1];
2146
- WebColors.AntiqueWhite = [250, 235, 215, 1];
2147
- WebColors.Linen = [250, 240, 230, 1];
2148
- WebColors.Beige = [245, 245, 220, 1];
2149
- WebColors.WhiteSmoke = [245, 245, 245, 1];
2150
- WebColors.LavenderBlush = [255, 240, 245, 1];
2151
- WebColors.OldLace = [253, 245, 230, 1];
2152
- WebColors.AliceBlue = [240, 248, 255, 1];
2153
- WebColors.Seashell = [255, 245, 238, 1];
2154
- WebColors.GhostWhite = [248, 248, 255, 1];
2155
- WebColors.Honeydew = [240, 255, 240, 1];
2156
- WebColors.FloralWhite = [255, 250, 240, 1];
2157
- WebColors.Azure = [240, 255, 255, 1];
2158
- WebColors.MintCream = [245, 255, 250, 1];
2159
- WebColors.Snow = [255, 250, 250, 1];
2160
- WebColors.Ivory = [255, 255, 240, 1];
2161
- WebColors.White = [255, 255, 255, 1];
2162
- WebColors.Black = [0, 0, 0, 1];
2163
- WebColors.DarkSlateGray = [47, 79, 79, 1];
2164
- WebColors.DimGray = [105, 105, 105, 1];
2165
- WebColors.SlateGray = [112, 128, 144, 1];
2166
- WebColors.Gray = [128, 128, 128, 1];
2167
- WebColors.LightSlateGray = [119, 136, 153, 1];
2168
- WebColors.DarkGray = [169, 169, 169, 1];
2169
- WebColors.Silver = [192, 192, 192, 1];
2170
- WebColors.LightGray = [211, 211, 211, 1];
2171
- WebColors.Gainsboro = [220, 220, 220, 1];
2172
- WebColors.RebeccaPurple = [102, 51, 153, 1];
2173
-
2174
- class Constants {
2175
- }
2176
- /** Size of the font showing frames per second */
2177
- Constants.FPS_DISPLAY_TEXT_FONT_SIZE = 12;
2178
- /** Color of the font showing frames per second */
2179
- Constants.FPS_DISPLAY_TEXT_COLOR = [0, 0, 0, 0.5];
2180
- /** Frequency, in milliseconds, at which to update frames per second metric shown on the screen */
2181
- Constants.FPS_DISPLAY_UPDATE_INTERVAL = 1e3;
2182
- /** Maximum number of activity metrics to log. */
2183
- Constants.MAXIMUM_RECORDED_ACTIVITY_METRICS = 32;
2184
- /** The frames per second will be logged in game metrics if the FPS is lower than this value */
2185
- Constants.FPS_METRIC_REPORT_THRESHOLD = 59;
2186
- /** Scene color, if none is specified. */
2187
- Constants.DEFAULT_SCENE_BACKGROUND_COLOR = WebColors.White;
2188
- /** Shape fill color, if none is specified. */
2189
- Constants.DEFAULT_SHAPE_FILL_COLOR = WebColors.Red;
2190
- /** Color of paths in a shape, if none is specified. */
2191
- Constants.DEFAULT_PATH_STROKE_COLOR = WebColors.Red;
2192
- /** Line width of paths in a shape, if none is specified. */
2193
- Constants.DEFAULT_PATH_LINE_WIDTH = 2;
2194
- /** Color of text in Label and TextLine, if none is specified. */
2195
- Constants.DEFAULT_FONT_COLOR = WebColors.Black;
2196
- /** Font size in Label and TextLine, if none is specified. */
2197
- Constants.DEFAULT_FONT_SIZE = 16;
2198
- Constants.LIMITED_FPS_RATE = 5;
2199
- Constants.FREE_NODES_SCENE_NAME = "__freeNodesScene";
2200
- Constants.OUTGOING_SCENE_NAME = "__outgoingScene";
2201
- Constants.OUTGOING_SCENE_SPRITE_NAME = "__outgoingSceneSprite";
2202
- Constants.OUTGOING_SCENE_IMAGE_NAME = "__outgoingSceneSnapshot";
2203
- Constants.SESSION_INITIALIZATION_POLLING_INTERVAL_MS = 50;
2204
- /** Placeholder that will be populated during the build process. */
2205
- Constants.MODULE_METADATA_PLACEHOLDER = {
2206
- name: "",
2207
- version: "",
2208
- dependencies: {}
2209
- };
2210
- Constants.DEFAULT_ROOT_ELEMENT_ID = "m2c2kit";
2211
-
2212
2531
  class ColorfulMutablePath extends MutablePath {
2213
2532
  constructor() {
2214
2533
  super(...arguments);
@@ -7942,7 +8261,6 @@ class EventMaterializer {
7942
8261
  `EventMaterializer: composite node of type ${event.compositeType} with uuid ${event.target} not found when handling CompositeEvent ${event.compositeEventType}`
7943
8262
  );
7944
8263
  } else {
7945
- console.log(`calling handleCompositeEvent on composite node`);
7946
8264
  if (node.type === M2NodeType.Composite) {
7947
8265
  node.handleCompositeEvent(event);
7948
8266
  } else {
@@ -8278,6 +8596,11 @@ class Game {
8278
8596
  dependencies: {}
8279
8597
  };
8280
8598
  }
8599
+ if (options.moduleMetadata?.name && options.version) {
8600
+ console.log(
8601
+ `\u26AA ${options.moduleMetadata.name} version ${options.version}`
8602
+ );
8603
+ }
8281
8604
  }
8282
8605
  createFreeNodesScene() {
8283
8606
  this.freeNodesScene.game = this;
@@ -8384,7 +8707,29 @@ class Game {
8384
8707
  ...M2c2KitHelpers.createFrameUpdateTimestamps()
8385
8708
  });
8386
8709
  }
8710
+ async waitForErudaInitialization(maxWaitDurationMs = 5e3) {
8711
+ await new Promise((resolve) => {
8712
+ let cumulativeWaitTime = 0;
8713
+ const intervalId = setInterval(() => {
8714
+ if (m2c2Globals.erudaInitialized === true) {
8715
+ clearInterval(intervalId);
8716
+ resolve(void 0);
8717
+ }
8718
+ cumulativeWaitTime = cumulativeWaitTime + 100;
8719
+ if (cumulativeWaitTime > maxWaitDurationMs) {
8720
+ console.warn(
8721
+ `Could not initialize eruda within ${maxWaitDurationMs} milliseconds.`
8722
+ );
8723
+ clearInterval(intervalId);
8724
+ resolve(void 0);
8725
+ }
8726
+ }, 100);
8727
+ });
8728
+ }
8387
8729
  async initialize() {
8730
+ if (m2c2Globals.erudaRequested === true) {
8731
+ await this.waitForErudaInitialization();
8732
+ }
8388
8733
  if (this.options.recordEvents === true) {
8389
8734
  this.eventStore.mode = EventStoreMode.Record;
8390
8735
  }
@@ -8694,17 +9039,50 @@ class Game {
8694
9039
  setParameters(additionalParameters) {
8695
9040
  const { parameters } = this.options;
8696
9041
  Object.keys(additionalParameters).forEach((key) => {
9042
+ if (key === "eruda") {
9043
+ const erudaRequested = additionalParameters[key] === true;
9044
+ if (erudaRequested) {
9045
+ M2c2KitHelpers.loadEruda();
9046
+ }
9047
+ return;
9048
+ }
9049
+ if (key === "scripts") {
9050
+ const scriptUrls = additionalParameters[key];
9051
+ if (scriptUrls) {
9052
+ M2c2KitHelpers.loadScriptUrls(scriptUrls);
9053
+ }
9054
+ return;
9055
+ }
8697
9056
  if (!parameters || !(key in parameters)) {
8698
9057
  console.warn(
8699
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8700
9058
  `game ${this.options.name} does not have a parameter named ${key}. attempt to set parameter ${key} to value ${// eslint-disable-next-line @typescript-eslint/no-explicit-any
8701
9059
  additionalParameters[key]} will be ignored`
8702
9060
  );
8703
9061
  } else if (this.options.parameters && this.options.parameters[key]) {
8704
- this.options.parameters[key].default = additionalParameters[key];
9062
+ const providedValue = additionalParameters[key];
9063
+ let value;
9064
+ if (this.options.parameters[key].type !== void 0 && providedValue !== void 0) {
9065
+ try {
9066
+ value = M2c2KitHelpers.convertValueToType(
9067
+ providedValue,
9068
+ this.options.parameters[key].type
9069
+ );
9070
+ } catch (e) {
9071
+ throw new Error(
9072
+ "Error setting parameter " + key + ": " + e.message
9073
+ );
9074
+ }
9075
+ } else {
9076
+ value = providedValue;
9077
+ }
9078
+ this.options.parameters[key].default = value;
9079
+ }
9080
+ if (this.additionalParameters === void 0) {
9081
+ this.additionalParameters = {};
8705
9082
  }
9083
+ this.additionalParameters[key] = // eslint-disable-next-line @typescript-eslint/no-explicit-any
9084
+ additionalParameters[key];
8706
9085
  });
8707
- this.additionalParameters = additionalParameters;
8708
9086
  }
8709
9087
  get canvasKit() {
8710
9088
  if (!this._canvasKit) {
@@ -10507,8 +10885,8 @@ class Game {
10507
10885
  handled: false,
10508
10886
  ...M2c2KitHelpers.createTimestamps()
10509
10887
  };
10510
- this.processDomPointerDown(scene, nodeEvent, domPointerEvent);
10511
10888
  this.processDomPointerDown(this.freeNodesScene, nodeEvent, domPointerEvent);
10889
+ this.processDomPointerDown(scene, nodeEvent, domPointerEvent);
10512
10890
  }
10513
10891
  htmlCanvasPointerUpHandler(domPointerEvent) {
10514
10892
  domPointerEvent.preventDefault();
@@ -10522,8 +10900,8 @@ class Game {
10522
10900
  handled: false,
10523
10901
  ...M2c2KitHelpers.createTimestamps()
10524
10902
  };
10525
- this.processDomPointerUp(scene, nodeEvent, domPointerEvent);
10526
10903
  this.processDomPointerUp(this.freeNodesScene, nodeEvent, domPointerEvent);
10904
+ this.processDomPointerUp(scene, nodeEvent, domPointerEvent);
10527
10905
  }
10528
10906
  htmlCanvasPointerMoveHandler(domPointerEvent) {
10529
10907
  domPointerEvent.preventDefault();
@@ -10537,8 +10915,8 @@ class Game {
10537
10915
  handled: false,
10538
10916
  ...M2c2KitHelpers.createTimestamps()
10539
10917
  };
10540
- this.processDomPointerMove(scene, nodeEvent, domPointerEvent);
10541
10918
  this.processDomPointerMove(this.freeNodesScene, nodeEvent, domPointerEvent);
10919
+ this.processDomPointerMove(scene, nodeEvent, domPointerEvent);
10542
10920
  }
10543
10921
  htmlCanvasPointerLeaveHandler(domPointerEvent) {
10544
10922
  if (!this.currentScene) {
@@ -10555,12 +10933,12 @@ class Game {
10555
10933
  handled: false,
10556
10934
  ...M2c2KitHelpers.createTimestamps()
10557
10935
  };
10558
- this.processDomPointerLeave(scene, nodeEvent, domPointerEvent);
10559
10936
  this.processDomPointerLeave(
10560
10937
  this.freeNodesScene,
10561
10938
  nodeEvent,
10562
10939
  domPointerEvent
10563
10940
  );
10941
+ this.processDomPointerLeave(scene, nodeEvent, domPointerEvent);
10564
10942
  }
10565
10943
  /**
10566
10944
  * Determines if/how m2c2kit nodes respond to the DOM PointerDown event
@@ -11052,7 +11430,8 @@ function initializeGlobalVariables() {
11052
11430
  get eventSequence() {
11053
11431
  m2c2Globals.__sequence++;
11054
11432
  return m2c2Globals.__sequence - 1;
11055
- }
11433
+ },
11434
+ addedScriptUrls: []
11056
11435
  };
11057
11436
  }
11058
11437
  initializeGlobalVariables();
@@ -11651,7 +12030,7 @@ class Story {
11651
12030
  }
11652
12031
  }
11653
12032
 
11654
- console.log("\u26AA @m2c2kit/core version 0.3.19 (0679492d)");
12033
+ console.log("\u26AA @m2c2kit/core version 0.3.21 (05ed0dd2)");
11655
12034
 
11656
12035
  export { Action, ActivityType, CanvasKitHelpers, ColorfulMutablePath, Composite, Constants, ConstraintType, CustomAction, Dimensions, Easings, Equal, Equals, EventStore, EventStoreMode, FadeAlphaAction, FontManager, Game, GroupAction, I18n, ImageManager, Label, LabelHorizontalAlignmentMode, LayoutConstraint, LegacyTimer, M2EventType, M2ImageStatus, M2Node, M2NodeFactory, M2NodeType, M2SoundStatus, M2c2KitHelpers, MoveAction, MutablePath, NoneTransition, PlayAction, RandomDraws, RepeatAction, RepeatForeverAction, RotateAction, ScaleAction, Scene, SceneTransition, SequenceAction, Shape, ShapeType, SlideTransition, SoundManager, SoundPlayer, SoundRecorder, Sprite, Story, TextLine, Timer, Transition, TransitionDirection, TransitionType, Uuid, WaitAction, WebColors, WebGlInfo, handleInterfaceOptions };
11657
12036
  //# sourceMappingURL=index.js.map