@colyseus/schema 4.0.13 → 4.0.14

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.
@@ -3,7 +3,7 @@
3
3
 
4
4
  var fs = require('fs');
5
5
  var path = require('path');
6
- var ts = require('typescript');
6
+ var ts$1 = require('typescript');
7
7
 
8
8
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
9
9
  function _interopNamespaceDefault(e) {
@@ -25,7 +25,7 @@ function _interopNamespaceDefault(e) {
25
25
 
26
26
  var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
27
27
  var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
28
- var ts__namespace = /*#__PURE__*/_interopNamespaceDefault(ts);
28
+ var ts__namespace = /*#__PURE__*/_interopNamespaceDefault(ts$1);
29
29
 
30
30
  /**
31
31
  * @author Ethan Davis
@@ -538,7 +538,8 @@ function getDecorators(node) {
538
538
  return node.modifiers?.filter(ts__namespace.isDecorator);
539
539
  }
540
540
 
541
- const typeMaps$6 = {
541
+ const name$8 = "Unity/C#";
542
+ const typeMaps$8 = {
542
543
  "string": "string",
543
544
  "number": "float",
544
545
  "boolean": "bool",
@@ -553,6 +554,10 @@ const typeMaps$6 = {
553
554
  "float32": "float",
554
555
  "float64": "double",
555
556
  };
557
+ const COMMON_IMPORTS$5 = `using Colyseus.Schema;
558
+ #if UNITY_5_3_OR_NEWER
559
+ using UnityEngine.Scripting;
560
+ #endif`;
556
561
  /**
557
562
  * C# Code Generator
558
563
  */
@@ -561,15 +566,18 @@ const capitalize$1 = (s) => {
561
566
  return '';
562
567
  return s.charAt(0).toUpperCase() + s.slice(1);
563
568
  };
564
- function generate$7(context, options) {
569
+ /**
570
+ * Generate individual files for each class/interface/enum
571
+ */
572
+ function generate$9(context, options) {
565
573
  // enrich typeMaps with enums
566
574
  context.enums.forEach((structure) => {
567
- typeMaps$6[structure.name] = structure.name;
575
+ typeMaps$8[structure.name] = structure.name;
568
576
  });
569
577
  return [
570
578
  ...context.classes.map(structure => ({
571
579
  name: `${structure.name}.cs`,
572
- content: generateClass$6(structure, options.namespace)
580
+ content: generateClass$8(structure, options.namespace)
573
581
  })),
574
582
  ...context.interfaces.map(structure => ({
575
583
  name: `${structure.name}.cs`,
@@ -577,34 +585,65 @@ function generate$7(context, options) {
577
585
  })),
578
586
  ...context.enums.filter(structure => structure.name !== 'OPERATION').map((structure) => ({
579
587
  name: `${structure.name}.cs`,
580
- content: generateEnum(structure, options.namespace),
588
+ content: generateEnum$1(structure, options.namespace),
581
589
  })),
582
590
  ];
583
591
  }
584
- function generateClass$6(klass, namespace) {
585
- const indent = (namespace) ? "\t" : "";
586
- return `${getCommentHeader()}
592
+ /**
593
+ * Generate a single bundled file containing all classes, interfaces, and enums
594
+ */
595
+ function renderBundle$8(context, options) {
596
+ const fileName = options.namespace ? `${options.namespace}.cs` : "Schema.cs";
597
+ const indent = options.namespace ? "\t" : "";
598
+ // enrich typeMaps with enums
599
+ context.enums.forEach((structure) => {
600
+ typeMaps$8[structure.name] = structure.name;
601
+ });
602
+ // Collect all bodies
603
+ const classBodies = context.classes.map(klass => generateClassBody$8(klass, indent));
604
+ const interfaceBodies = context.interfaces.map(iface => generateInterfaceBody$1(iface, indent));
605
+ const enumBodies = context.enums
606
+ .filter(structure => structure.name !== 'OPERATION')
607
+ .map(e => generateEnumBody$1(e, indent));
608
+ const allBodies = [...classBodies, ...interfaceBodies, ...enumBodies].join("\n\n");
609
+ const content = `${getCommentHeader()}
587
610
 
588
- using Colyseus.Schema;
589
- #if UNITY_5_3_OR_NEWER
590
- using UnityEngine.Scripting;
591
- #endif
592
- ${namespace ? `\nnamespace ${namespace} {` : ""}
593
- ${indent}public partial class ${klass.name} : ${klass.extends} {
611
+ ${COMMON_IMPORTS$5}
612
+ ${options.namespace ? `\nnamespace ${options.namespace} {\n` : ""}
613
+ ${allBodies}
614
+ ${options.namespace ? "}" : ""}`;
615
+ return { name: fileName, content };
616
+ }
617
+ /**
618
+ * Generate just the class body (without imports/namespace) for bundling
619
+ */
620
+ function generateClassBody$8(klass, indent = "") {
621
+ return `${indent}public partial class ${klass.name} : ${klass.extends} {
594
622
  #if UNITY_5_3_OR_NEWER
595
623
  [Preserve]
596
624
  #endif
597
625
  public ${klass.name}() { }
598
626
  ${klass.properties.map((prop) => generateProperty$4(prop, indent)).join("\n\n")}
599
- ${indent}}
600
- ${namespace ? "}" : ""}
601
- `;
627
+ ${indent}}`;
602
628
  }
603
- function generateEnum(_enum, namespace) {
604
- const indent = namespace ? "\t" : "";
629
+ /**
630
+ * Generate a complete class file with imports/namespace (for individual file mode)
631
+ */
632
+ function generateClass$8(klass, namespace) {
633
+ const indent = (namespace) ? "\t" : "";
605
634
  return `${getCommentHeader()}
635
+
636
+ ${COMMON_IMPORTS$5}
606
637
  ${namespace ? `\nnamespace ${namespace} {` : ""}
607
- ${indent}public struct ${_enum.name} {
638
+ ${generateClassBody$8(klass, indent)}
639
+ ${namespace ? "}" : ""}
640
+ `;
641
+ }
642
+ /**
643
+ * Generate just the enum body (without imports/namespace) for bundling
644
+ */
645
+ function generateEnumBody$1(_enum, indent = "") {
646
+ return `${indent}public struct ${_enum.name} {
608
647
 
609
648
  ${_enum.properties
610
649
  .map((prop) => {
@@ -626,7 +665,16 @@ ${_enum.properties
626
665
  return `${indent}\tpublic const ${dataType} ${prop.name} = ${value};`;
627
666
  })
628
667
  .join("\n")}
629
- ${indent}}
668
+ ${indent}}`;
669
+ }
670
+ /**
671
+ * Generate a complete enum file with imports/namespace (for individual file mode)
672
+ */
673
+ function generateEnum$1(_enum, namespace) {
674
+ const indent = namespace ? "\t" : "";
675
+ return `${getCommentHeader()}
676
+ ${namespace ? `\nnamespace ${namespace} {` : ""}
677
+ ${generateEnumBody$1(_enum, indent)}
630
678
  ${namespace ? "}" : ""}`;
631
679
  }
632
680
  function generateProperty$4(prop, indent = "") {
@@ -652,20 +700,29 @@ function generateProperty$4(prop, indent = "") {
652
700
  return ret + `\t${indent}[Type(${prop.index}, ${typeArgs})]
653
701
  \t${indent}${property} = ${initializer};`;
654
702
  }
703
+ /**
704
+ * Generate just the interface body (without imports/namespace) for bundling
705
+ */
706
+ function generateInterfaceBody$1(struct, indent = "") {
707
+ return `${indent}public class ${struct.name} {
708
+ ${struct.properties.map(prop => `\t${indent}public ${getType(prop)} ${prop.name};`).join("\n")}
709
+ ${indent}}`;
710
+ }
711
+ /**
712
+ * Generate a complete interface file with imports/namespace (for individual file mode)
713
+ */
655
714
  function generateInterface$1(struct, namespace) {
656
715
  const indent = (namespace) ? "\t" : "";
657
716
  return `${getCommentHeader()}
658
717
 
659
718
  using Colyseus.Schema;
660
719
  ${namespace ? `\nnamespace ${namespace} {` : ""}
661
- ${indent}public class ${struct.name} {
662
- ${struct.properties.map(prop => `\t${indent}public ${getType(prop)} ${prop.name};`).join("\n")}
663
- ${indent}}
720
+ ${generateInterfaceBody$1(struct, indent)}
664
721
  ${namespace ? "}" : ""}
665
722
  `;
666
723
  }
667
724
  function getChildType(prop) {
668
- return typeMaps$6[prop.childType];
725
+ return typeMaps$8[prop.childType];
669
726
  }
670
727
  function getType(prop) {
671
728
  if (prop.childType) {
@@ -686,12 +743,20 @@ function getType(prop) {
686
743
  }
687
744
  else {
688
745
  return (prop.type === "array")
689
- ? `${typeMaps$6[prop.childType] || prop.childType}[]`
690
- : typeMaps$6[prop.type];
746
+ ? `${typeMaps$8[prop.childType] || prop.childType}[]`
747
+ : typeMaps$8[prop.type];
691
748
  }
692
749
  }
693
750
 
694
- const typeMaps$5 = {
751
+ var csharp = /*#__PURE__*/Object.freeze({
752
+ __proto__: null,
753
+ generate: generate$9,
754
+ name: name$8,
755
+ renderBundle: renderBundle$8
756
+ });
757
+
758
+ const name$7 = "C++";
759
+ const typeMaps$7 = {
695
760
  "string": "string",
696
761
  "number": "varint_t",
697
762
  "boolean": "bool",
@@ -721,6 +786,11 @@ const typeInitializer$2 = {
721
786
  "float32": "0",
722
787
  "float64": "0",
723
788
  };
789
+ const COMMON_INCLUDES$1 = `#include "schema.h"
790
+ #include <typeinfo>
791
+ #include <typeindex>
792
+
793
+ using namespace colyseus::schema;`;
724
794
  /**
725
795
  * C++ Code Generator
726
796
  */
@@ -729,14 +799,41 @@ const capitalize = (s) => {
729
799
  return '';
730
800
  return s.charAt(0).toUpperCase() + s.slice(1);
731
801
  };
732
- const distinct$3 = (value, index, self) => self.indexOf(value) === index;
733
- function generate$6(context, options) {
802
+ const distinct$5 = (value, index, self) => self.indexOf(value) === index;
803
+ /**
804
+ * Generate individual files for each class
805
+ */
806
+ function generate$8(context, options) {
734
807
  return context.classes.map(klass => ({
735
808
  name: klass.name + ".hpp",
736
- content: generateClass$5(klass, options.namespace, context.classes)
809
+ content: generateClass$7(klass, options.namespace, context.classes)
737
810
  }));
738
811
  }
739
- function generateClass$5(klass, namespace, allClasses) {
812
+ /**
813
+ * Generate a single bundled header file containing all classes
814
+ */
815
+ function renderBundle$7(context, options) {
816
+ const fileName = options.namespace ? `${options.namespace}.hpp` : "schema.hpp";
817
+ const guardName = `__SCHEMA_CODEGEN_${(options.namespace || "SCHEMA").toUpperCase()}_H__`;
818
+ const classBodies = context.classes.map(klass => generateClassBody$7(klass, context.classes, options.namespace));
819
+ const content = `${getCommentHeader()}
820
+ #ifndef ${guardName}
821
+ #define ${guardName} 1
822
+
823
+ ${COMMON_INCLUDES$1}
824
+
825
+ ${options.namespace ? `namespace ${options.namespace} {\n` : ""}
826
+ ${classBodies.join("\n\n")}
827
+ ${options.namespace ? "}" : ""}
828
+
829
+ #endif
830
+ `;
831
+ return { name: fileName, content };
832
+ }
833
+ /**
834
+ * Generate just the class body (without includes/guards) for bundling
835
+ */
836
+ function generateClassBody$7(klass, allClasses, namespace) {
740
837
  const propertiesPerType = {};
741
838
  const allRefs = [];
742
839
  klass.properties.forEach(property => {
@@ -750,32 +847,13 @@ function generateClass$5(klass, namespace, allClasses) {
750
847
  allRefs.push(property);
751
848
  }
752
849
  });
753
- const allProperties = getAllProperties(klass, allClasses);
850
+ const allProperties = getAllProperties$1(klass, allClasses);
754
851
  const createInstanceMethod = (allRefs.length === 0) ? "" :
755
852
  `\tinline Schema* createInstance(std::type_index type) {
756
- \t\t${generateFieldIfElseChain(allRefs, (property) => `type == typeid(${property.childType})`, (property) => `return new ${property.childType}();`, (property) => typeMaps$5[property.childType] === undefined)}
853
+ \t\t${generateFieldIfElseChain(allRefs, (property) => `type == typeid(${property.childType})`, (property) => `return new ${property.childType}();`, (property) => typeMaps$7[property.childType] === undefined)}
757
854
  \t\treturn ${klass.extends}::createInstance(type);
758
855
  \t}`;
759
- return `${getCommentHeader()}
760
- #ifndef __SCHEMA_CODEGEN_${klass.name.toUpperCase()}_H__
761
- #define __SCHEMA_CODEGEN_${klass.name.toUpperCase()}_H__ 1
762
-
763
- #include "schema.h"
764
- #include <typeinfo>
765
- #include <typeindex>
766
-
767
- ${allRefs.
768
- filter(ref => ref.childType && typeMaps$5[ref.childType] === undefined).
769
- map(ref => ref.childType).
770
- concat(getInheritanceTree(klass, allClasses, false).map(klass => klass.name)).
771
- filter(distinct$3).
772
- map(childType => `#include "${childType}.hpp"`).
773
- join("\n")}
774
-
775
- using namespace colyseus::schema;
776
-
777
- ${namespace ? `namespace ${namespace} {` : ""}
778
- class ${klass.name} : public ${klass.extends} {
856
+ return `class ${klass.name} : public ${klass.extends} {
779
857
  public:
780
858
  ${klass.properties.map(prop => generateProperty$3(prop)).join("\n")}
781
859
 
@@ -795,7 +873,36 @@ ${Object.keys(propertiesPerType).map(type => generateGettersAndSetters(klass, ty
795
873
  join("\n")}
796
874
 
797
875
  ${createInstanceMethod}
798
- };
876
+ };`;
877
+ }
878
+ /**
879
+ * Generate a complete class file with includes/guards (for individual file mode)
880
+ */
881
+ function generateClass$7(klass, namespace, allClasses) {
882
+ const allRefs = [];
883
+ klass.properties.forEach(property => {
884
+ let type = property.type;
885
+ // keep all refs list
886
+ if ((type === "ref" || type === "array" || type === "map")) {
887
+ allRefs.push(property);
888
+ }
889
+ });
890
+ const localIncludes = allRefs.
891
+ filter(ref => ref.childType && typeMaps$7[ref.childType] === undefined).
892
+ map(ref => ref.childType).
893
+ concat(getInheritanceTree(klass, allClasses, false).map(klass => klass.name)).
894
+ filter(distinct$5).
895
+ map(childType => `#include "${childType}.hpp"`).
896
+ join("\n");
897
+ return `${getCommentHeader()}
898
+ #ifndef __SCHEMA_CODEGEN_${klass.name.toUpperCase()}_H__
899
+ #define __SCHEMA_CODEGEN_${klass.name.toUpperCase()}_H__ 1
900
+
901
+ ${COMMON_INCLUDES$1}
902
+ ${localIncludes}
903
+
904
+ ${namespace ? `namespace ${namespace} {` : ""}
905
+ ${generateClassBody$7(klass, allClasses)}
799
906
  ${namespace ? "}" : ""}
800
907
 
801
908
  #endif
@@ -815,26 +922,26 @@ function generateProperty$3(prop) {
815
922
  else if (prop.type === "array") {
816
923
  langType = (isUpcaseFirst)
817
924
  ? `ArraySchema<${prop.childType}*>`
818
- : `ArraySchema<${typeMaps$5[prop.childType]}>`;
925
+ : `ArraySchema<${typeMaps$7[prop.childType]}>`;
819
926
  initializer = `new ${langType}()`;
820
927
  }
821
928
  else if (prop.type === "map") {
822
929
  langType = (isUpcaseFirst)
823
930
  ? `MapSchema<${prop.childType}*>`
824
- : `MapSchema<${typeMaps$5[prop.childType]}>`;
931
+ : `MapSchema<${typeMaps$7[prop.childType]}>`;
825
932
  initializer = `new ${langType}()`;
826
933
  }
827
934
  isPropPointer = "*";
828
935
  }
829
936
  else {
830
- langType = typeMaps$5[prop.type];
937
+ langType = typeMaps$7[prop.type];
831
938
  initializer = typeInitializer$2[prop.type];
832
939
  }
833
940
  property += ` ${langType} ${isPropPointer}${prop.name}`;
834
941
  return `\t${property} = ${initializer};`;
835
942
  }
836
943
  function generateGettersAndSetters(klass, type, properties) {
837
- let langType = typeMaps$5[type];
944
+ let langType = typeMaps$7[type];
838
945
  let typeCast = "";
839
946
  const getMethodName = `get${capitalize(type)}`;
840
947
  const setMethodName = `set${capitalize(type)}`;
@@ -858,7 +965,7 @@ function generateGettersAndSetters(klass, type, properties) {
858
965
  \tinline void ${setMethodName}(const string &field, ${langType} value)
859
966
  \t{
860
967
  \t\t${generateFieldIfElseChain(properties, (property) => `field == "${property.name}"`, (property) => {
861
- const isSchemaType = (typeMaps$5[property.childType] === undefined);
968
+ const isSchemaType = (typeMaps$7[property.childType] === undefined);
862
969
  if (type === "ref") {
863
970
  langType = `${property.childType}*`;
864
971
  typeCast = (isSchemaType)
@@ -868,12 +975,12 @@ function generateGettersAndSetters(klass, type, properties) {
868
975
  else if (type === "array") {
869
976
  typeCast = (isSchemaType)
870
977
  ? `(ArraySchema<${property.childType}*> *)`
871
- : `(ArraySchema<${typeMaps$5[property.childType]}> *)`;
978
+ : `(ArraySchema<${typeMaps$7[property.childType]}> *)`;
872
979
  }
873
980
  else if (type === "map") {
874
981
  typeCast = (isSchemaType)
875
982
  ? `(MapSchema<${property.childType}*> *)`
876
- : `(MapSchema<${typeMaps$5[property.childType]}> *)`;
983
+ : `(MapSchema<${typeMaps$7[property.childType]}> *)`;
877
984
  }
878
985
  return `this->${property.name} = ${typeCast}value;\n\t\t\treturn;`;
879
986
  })}
@@ -912,7 +1019,7 @@ function generateAllTypes(properties) {
912
1019
  }
913
1020
  function generateAllChildSchemaTypes(properties) {
914
1021
  return `{${properties.map((property, i) => {
915
- if (property.childType && typeMaps$5[property.childType] === undefined) {
1022
+ if (property.childType && typeMaps$7[property.childType] === undefined) {
916
1023
  return `{${i}, typeid(${property.childType})}`;
917
1024
  }
918
1025
  else {
@@ -922,7 +1029,7 @@ function generateAllChildSchemaTypes(properties) {
922
1029
  }
923
1030
  function generateAllChildPrimitiveTypes(properties) {
924
1031
  return `{${properties.map((property, i) => {
925
- if (typeMaps$5[property.childType] !== undefined) {
1032
+ if (typeMaps$7[property.childType] !== undefined) {
926
1033
  return `{${i}, "${property.childType}"}`;
927
1034
  }
928
1035
  else {
@@ -940,7 +1047,7 @@ function generateDestructors(properties) {
940
1047
  }
941
1048
  }).filter(r => r !== null);
942
1049
  }
943
- function getAllProperties(klass, allClasses) {
1050
+ function getAllProperties$1(klass, allClasses) {
944
1051
  let properties = [];
945
1052
  getInheritanceTree(klass, allClasses).reverse().forEach((klass) => {
946
1053
  properties = properties.concat(klass.properties);
@@ -948,7 +1055,15 @@ function getAllProperties(klass, allClasses) {
948
1055
  return properties;
949
1056
  }
950
1057
 
951
- const typeMaps$4 = {
1058
+ var cpp = /*#__PURE__*/Object.freeze({
1059
+ __proto__: null,
1060
+ generate: generate$8,
1061
+ name: name$7,
1062
+ renderBundle: renderBundle$7
1063
+ });
1064
+
1065
+ const name$6 = "Haxe";
1066
+ const typeMaps$6 = {
952
1067
  "string": "String",
953
1068
  "number": "Dynamic",
954
1069
  "boolean": "Bool",
@@ -978,22 +1093,50 @@ const typeInitializer$1 = {
978
1093
  "float32": "0",
979
1094
  "float64": "0",
980
1095
  };
981
- function generate$5(context, options) {
1096
+ const COMMON_IMPORTS$4 = `import io.colyseus.serializer.schema.Schema;
1097
+ import io.colyseus.serializer.schema.types.*;`;
1098
+ /**
1099
+ * Generate individual files for each class
1100
+ */
1101
+ function generate$7(context, options) {
982
1102
  return context.classes.map(klass => ({
983
1103
  name: klass.name + ".hx",
984
- content: generateClass$4(klass, options.namespace, context.classes)
1104
+ content: generateClass$6(klass, options.namespace, context.classes)
985
1105
  }));
986
1106
  }
987
- function generateClass$4(klass, namespace, allClasses) {
988
- return `${getCommentHeader()}
1107
+ /**
1108
+ * Generate a single bundled file containing all classes
1109
+ */
1110
+ function renderBundle$6(context, options) {
1111
+ const fileName = options.namespace ? `${options.namespace}.hx` : "Schema.hx";
1112
+ const classBodies = context.classes.map(klass => generateClassBody$6(klass));
1113
+ const content = `${getCommentHeader()}
989
1114
 
990
- ${namespace ? `package ${namespace};` : ""}
991
- import io.colyseus.serializer.schema.Schema;
992
- import io.colyseus.serializer.schema.types.*;
1115
+ ${options.namespace ? `package ${options.namespace};` : ""}
1116
+ ${COMMON_IMPORTS$4}
993
1117
 
994
- class ${klass.name} extends ${klass.extends} {
1118
+ ${classBodies.join("\n\n")}
1119
+ `;
1120
+ return { name: fileName, content };
1121
+ }
1122
+ /**
1123
+ * Generate just the class body (without package/imports) for bundling
1124
+ */
1125
+ function generateClassBody$6(klass) {
1126
+ return `class ${klass.name} extends ${klass.extends} {
995
1127
  ${klass.properties.map(prop => generateProperty$2(prop)).join("\n")}
1128
+ }`;
996
1129
  }
1130
+ /**
1131
+ * Generate a complete class file with package/imports (for individual file mode)
1132
+ */
1133
+ function generateClass$6(klass, namespace, allClasses) {
1134
+ return `${getCommentHeader()}
1135
+
1136
+ ${namespace ? `package ${namespace};` : ""}
1137
+ ${COMMON_IMPORTS$4}
1138
+
1139
+ ${generateClassBody$6(klass)}
997
1140
  `;
998
1141
  }
999
1142
  function generateProperty$2(prop) {
@@ -1015,18 +1158,18 @@ function generateProperty$2(prop) {
1015
1158
  else if (prop.type === "array") {
1016
1159
  langType = (isUpcaseFirst)
1017
1160
  ? `ArraySchema<${prop.childType}>`
1018
- : `ArraySchema<${typeMaps$4[prop.childType]}>`;
1161
+ : `ArraySchema<${typeMaps$6[prop.childType]}>`;
1019
1162
  initializer = `new ${langType}()`;
1020
1163
  }
1021
1164
  else if (prop.type === "map") {
1022
1165
  langType = (isUpcaseFirst)
1023
1166
  ? `MapSchema<${prop.childType}>`
1024
- : `MapSchema<${typeMaps$4[prop.childType]}>`;
1167
+ : `MapSchema<${typeMaps$6[prop.childType]}>`;
1025
1168
  initializer = `new ${langType}()`;
1026
1169
  }
1027
1170
  }
1028
1171
  else {
1029
- langType = typeMaps$4[prop.type];
1172
+ langType = typeMaps$6[prop.type];
1030
1173
  initializer = typeInitializer$1[prop.type];
1031
1174
  }
1032
1175
  // TODO: remove initializer. The callbacks at the Haxe decoder side have a
@@ -1035,7 +1178,15 @@ function generateProperty$2(prop) {
1035
1178
  // return `\t@:type(${typeArgs})\n\tpublic var ${prop.name}: ${langType};\n`
1036
1179
  }
1037
1180
 
1038
- const typeMaps$3 = {
1181
+ var haxe = /*#__PURE__*/Object.freeze({
1182
+ __proto__: null,
1183
+ generate: generate$7,
1184
+ name: name$6,
1185
+ renderBundle: renderBundle$6
1186
+ });
1187
+
1188
+ const name$5 = "TypeScript";
1189
+ const typeMaps$5 = {
1039
1190
  "string": "string",
1040
1191
  "number": "number",
1041
1192
  "boolean": "boolean",
@@ -1050,12 +1201,16 @@ const typeMaps$3 = {
1050
1201
  "float32": "number",
1051
1202
  "float64": "number",
1052
1203
  };
1053
- const distinct$2 = (value, index, self) => self.indexOf(value) === index;
1054
- function generate$4(context, options) {
1204
+ const COMMON_IMPORTS$3 = `import { Schema, type, ArraySchema, MapSchema, SetSchema, DataChange } from '@colyseus/schema';`;
1205
+ const distinct$4 = (value, index, self) => self.indexOf(value) === index;
1206
+ /**
1207
+ * Generate individual files for each class/interface
1208
+ */
1209
+ function generate$6(context, options) {
1055
1210
  return [
1056
1211
  ...context.classes.map(structure => ({
1057
1212
  name: structure.name + ".ts",
1058
- content: generateClass$3(structure, options.namespace, context.classes)
1213
+ content: generateClass$5(structure, options.namespace, context.classes)
1059
1214
  })),
1060
1215
  ...context.interfaces.map(structure => ({
1061
1216
  name: structure.name + ".ts",
@@ -1063,7 +1218,43 @@ function generate$4(context, options) {
1063
1218
  }))
1064
1219
  ];
1065
1220
  }
1066
- function generateClass$3(klass, namespace, allClasses) {
1221
+ /**
1222
+ * Generate a single bundled file containing all classes and interfaces
1223
+ */
1224
+ function renderBundle$5(context, options) {
1225
+ const fileName = options.namespace ? `${options.namespace}.ts` : "schema.ts";
1226
+ // Collect all class bodies
1227
+ const classBodies = context.classes.map(klass => generateClassBody$5(klass));
1228
+ // Collect all interface bodies
1229
+ const interfaceBodies = context.interfaces.map(iface => generateInterfaceBody(iface));
1230
+ const content = `${getCommentHeader()}
1231
+
1232
+ ${COMMON_IMPORTS$3}
1233
+
1234
+ ${classBodies.join("\n\n")}
1235
+ ${interfaceBodies.length > 0 ? "\n" + interfaceBodies.join("\n\n") : ""}`;
1236
+ return { name: fileName, content };
1237
+ }
1238
+ /**
1239
+ * Generate just the class body (without imports) for bundling
1240
+ */
1241
+ function generateClassBody$5(klass) {
1242
+ return `export class ${klass.name} extends ${klass.extends} {
1243
+ ${klass.properties.map(prop => ` ${generateProperty$1(prop)}`).join("\n")}
1244
+ }`;
1245
+ }
1246
+ /**
1247
+ * Generate just the interface body (without imports) for bundling
1248
+ */
1249
+ function generateInterfaceBody(iface) {
1250
+ return `export interface ${iface.name} {
1251
+ ${iface.properties.map(prop => ` ${prop.name}: ${prop.type};`).join("\n")}
1252
+ }`;
1253
+ }
1254
+ /**
1255
+ * Generate a complete class file with imports (for individual file mode)
1256
+ */
1257
+ function generateClass$5(klass, namespace, allClasses) {
1067
1258
  const allRefs = [];
1068
1259
  klass.properties.forEach(property => {
1069
1260
  let type = property.type;
@@ -1072,20 +1263,19 @@ function generateClass$3(klass, namespace, allClasses) {
1072
1263
  allRefs.push(property);
1073
1264
  }
1074
1265
  });
1075
- return `${getCommentHeader()}
1076
-
1077
- import { Schema, type, ArraySchema, MapSchema, SetSchema, DataChange } from '@colyseus/schema';
1078
- ${allRefs.
1079
- filter(ref => ref.childType && typeMaps$3[ref.childType] === undefined).
1266
+ const localImports = allRefs.
1267
+ filter(ref => ref.childType && typeMaps$5[ref.childType] === undefined).
1080
1268
  map(ref => ref.childType).
1081
1269
  concat(getInheritanceTree(klass, allClasses, false).map(klass => klass.name)).
1082
- filter(distinct$2).
1270
+ filter(distinct$4).
1083
1271
  map(childType => `import { ${childType} } from './${childType}'`).
1084
- join("\n")}
1272
+ join("\n");
1273
+ return `${getCommentHeader()}
1085
1274
 
1086
- export class ${klass.name} extends ${klass.extends} {
1087
- ${klass.properties.map(prop => ` ${generateProperty$1(prop)}`).join("\n")}
1088
- }
1275
+ ${COMMON_IMPORTS$3}
1276
+ ${localImports}
1277
+
1278
+ ${generateClassBody$5(klass)}
1089
1279
  `;
1090
1280
  }
1091
1281
  function generateProperty$1(prop) {
@@ -1108,7 +1298,7 @@ function generateProperty$1(prop) {
1108
1298
  else if (prop.type === "array") {
1109
1299
  langType = (isUpcaseFirst)
1110
1300
  ? `ArraySchema<${prop.childType}>`
1111
- : `ArraySchema<${typeMaps$3[prop.childType]}>`;
1301
+ : `ArraySchema<${typeMaps$5[prop.childType]}>`;
1112
1302
  initializer = `new ${langType}()`;
1113
1303
  typeArgs = (isUpcaseFirst)
1114
1304
  ? `[ ${prop.childType} ]`
@@ -1117,7 +1307,7 @@ function generateProperty$1(prop) {
1117
1307
  else if (prop.type === "map") {
1118
1308
  langType = (isUpcaseFirst)
1119
1309
  ? `MapSchema<${prop.childType}>`
1120
- : `MapSchema<${typeMaps$3[prop.childType]}>`;
1310
+ : `MapSchema<${typeMaps$5[prop.childType]}>`;
1121
1311
  initializer = `new ${langType}()`;
1122
1312
  typeArgs = (isUpcaseFirst)
1123
1313
  ? `{ map: ${prop.childType} }`
@@ -1126,7 +1316,7 @@ function generateProperty$1(prop) {
1126
1316
  else if (prop.type === "set") {
1127
1317
  langType = (isUpcaseFirst)
1128
1318
  ? `SetSchema<${prop.childType}>`
1129
- : `SetSchema<${typeMaps$3[prop.childType]}>`;
1319
+ : `SetSchema<${typeMaps$5[prop.childType]}>`;
1130
1320
  initializer = `new ${langType}()`;
1131
1321
  typeArgs = (isUpcaseFirst)
1132
1322
  ? `{ set: ${prop.childType} }`
@@ -1134,23 +1324,32 @@ function generateProperty$1(prop) {
1134
1324
  }
1135
1325
  }
1136
1326
  else {
1137
- langType = typeMaps$3[prop.type];
1327
+ langType = typeMaps$5[prop.type];
1138
1328
  typeArgs = `"${prop.type}"`;
1139
1329
  }
1140
1330
  // TS1263: "Declarations with initializers cannot also have definite assignment assertions"
1141
1331
  const definiteAssertion = initializer ? "" : "!";
1142
1332
  return `@type(${typeArgs}) public ${prop.name}${definiteAssertion}: ${langType}${(initializer) ? ` = ${initializer}` : ""};`;
1143
1333
  }
1334
+ /**
1335
+ * Generate a complete interface file with header (for individual file mode)
1336
+ */
1144
1337
  function generateInterface(structure, namespace, allClasses) {
1145
1338
  return `${getCommentHeader()}
1146
1339
 
1147
- export interface ${structure.name} {
1148
- ${structure.properties.map(prop => ` ${prop.name}: ${prop.type};`).join("\n")}
1149
- }
1340
+ ${generateInterfaceBody(structure)}
1150
1341
  `;
1151
1342
  }
1152
1343
 
1153
- const typeMaps$2 = {
1344
+ var ts = /*#__PURE__*/Object.freeze({
1345
+ __proto__: null,
1346
+ generate: generate$6,
1347
+ name: name$5,
1348
+ renderBundle: renderBundle$5
1349
+ });
1350
+
1351
+ const name$4 = "JavaScript";
1352
+ const typeMaps$4 = {
1154
1353
  "string": "string",
1155
1354
  "number": "number",
1156
1355
  "boolean": "boolean",
@@ -1165,14 +1364,56 @@ const typeMaps$2 = {
1165
1364
  "float32": "number",
1166
1365
  "float64": "number",
1167
1366
  };
1168
- const distinct$1 = (value, index, self) => self.indexOf(value) === index;
1169
- function generate$3(context, options) {
1367
+ const COMMON_IMPORTS$2 = `const schema = require("@colyseus/schema");
1368
+ const Schema = schema.Schema;
1369
+ const type = schema.type;`;
1370
+ const distinct$3 = (value, index, self) => self.indexOf(value) === index;
1371
+ /**
1372
+ * Generate individual files for each class
1373
+ */
1374
+ function generate$5(context, options) {
1170
1375
  return context.classes.map(klass => ({
1171
1376
  name: klass.name + ".js",
1172
- content: generateClass$2(klass, options.namespace, context.classes)
1377
+ content: generateClass$4(klass, options.namespace, context.classes)
1173
1378
  }));
1174
1379
  }
1175
- function generateClass$2(klass, namespace, allClasses) {
1380
+ /**
1381
+ * Generate a single bundled file containing all classes
1382
+ */
1383
+ function renderBundle$4(context, options) {
1384
+ const fileName = options.namespace ? `${options.namespace}.js` : "schema.js";
1385
+ const classBodies = context.classes.map(klass => generateClassBody$4(klass));
1386
+ const classExports = context.classes.map(klass => ` ${klass.name},`).join("\n");
1387
+ const content = `${getCommentHeader()}
1388
+
1389
+ ${COMMON_IMPORTS$2}
1390
+
1391
+ ${classBodies.join("\n\n")}
1392
+
1393
+ module.exports = {
1394
+ ${classExports}
1395
+ };
1396
+ `;
1397
+ return { name: fileName, content };
1398
+ }
1399
+ /**
1400
+ * Generate just the class body (without imports) for bundling
1401
+ */
1402
+ function generateClassBody$4(klass) {
1403
+ return `class ${klass.name} extends ${klass.extends} {
1404
+ constructor () {
1405
+ super();
1406
+ ${klass.properties.
1407
+ filter(prop => prop.childType !== undefined).
1408
+ map(prop => " " + generatePropertyInitializer(prop)).join("\n")}
1409
+ }
1410
+ }
1411
+ ${klass.properties.map(prop => generatePropertyDeclaration$1(klass.name, prop)).join("\n")}`;
1412
+ }
1413
+ /**
1414
+ * Generate a complete class file with imports (for individual file mode)
1415
+ */
1416
+ function generateClass$4(klass, namespace, allClasses) {
1176
1417
  const allRefs = [];
1177
1418
  klass.properties.forEach(property => {
1178
1419
  let type = property.type;
@@ -1181,28 +1422,19 @@ function generateClass$2(klass, namespace, allClasses) {
1181
1422
  allRefs.push(property);
1182
1423
  }
1183
1424
  });
1184
- return `${getCommentHeader()}
1185
-
1186
- const schema = require("@colyseus/schema");
1187
- const Schema = schema.Schema;
1188
- const type = schema.type;
1189
- ${allRefs.
1190
- filter(ref => ref.childType && typeMaps$2[ref.childType] === undefined).
1425
+ const localImports = allRefs.
1426
+ filter(ref => ref.childType && typeMaps$4[ref.childType] === undefined).
1191
1427
  map(ref => ref.childType).
1192
1428
  concat(getInheritanceTree(klass, allClasses, false).map(klass => klass.name)).
1193
- filter(distinct$1).
1429
+ filter(distinct$3).
1194
1430
  map(childType => `const ${childType} = require("./${childType}");`).
1195
- join("\n")}
1431
+ join("\n");
1432
+ return `${getCommentHeader()}
1196
1433
 
1197
- class ${klass.name} extends ${klass.extends} {
1198
- constructor () {
1199
- super();
1200
- ${klass.properties.
1201
- filter(prop => prop.childType !== undefined).
1202
- map(prop => " " + generatePropertyInitializer(prop)).join("\n")}
1203
- }
1204
- }
1205
- ${klass.properties.map(prop => generatePropertyDeclaration$1(klass.name, prop)).join("\n")}
1434
+ ${COMMON_IMPORTS$2}
1435
+ ${localImports}
1436
+
1437
+ ${generateClassBody$4(klass)}
1206
1438
 
1207
1439
  export default ${klass.name};
1208
1440
  `;
@@ -1250,7 +1482,15 @@ function generatePropertyInitializer(prop) {
1250
1482
  return `this.${prop.name} = ${initializer}`;
1251
1483
  }
1252
1484
 
1253
- const typeMaps$1 = {
1485
+ var js = /*#__PURE__*/Object.freeze({
1486
+ __proto__: null,
1487
+ generate: generate$5,
1488
+ name: name$4,
1489
+ renderBundle: renderBundle$4
1490
+ });
1491
+
1492
+ const name$3 = "Java";
1493
+ const typeMaps$3 = {
1254
1494
  "string": "String",
1255
1495
  "number": "float",
1256
1496
  "boolean": "boolean",
@@ -1280,23 +1520,56 @@ const typeInitializer = {
1280
1520
  "float32": "0",
1281
1521
  "float64": "0",
1282
1522
  };
1523
+ const COMMON_IMPORTS$1 = `import io.colyseus.serializer.schema.Schema;
1524
+ import io.colyseus.serializer.schema.annotations.SchemaClass;
1525
+ import io.colyseus.serializer.schema.annotations.SchemaField;`;
1283
1526
  /**
1284
- * C# Code Generator
1527
+ * Java Code Generator
1285
1528
  */
1286
- function generate$2(context, options) {
1529
+ /**
1530
+ * Generate individual files for each class
1531
+ */
1532
+ function generate$4(context, options) {
1287
1533
  return context.classes.map(klass => ({
1288
1534
  name: klass.name + ".java",
1289
- content: generateClass$1(klass, options.namespace)
1535
+ content: generateClass$3(klass, options.namespace)
1290
1536
  }));
1291
1537
  }
1292
- function generateClass$1(klass, namespace) {
1538
+ /**
1539
+ * Generate a single bundled file containing all classes
1540
+ * Note: Java typically requires one public class per file, so bundled mode
1541
+ * generates all classes in a single file with package-private visibility
1542
+ */
1543
+ function renderBundle$3(context, options) {
1544
+ const fileName = options.namespace ? `Schema.java` : "Schema.java";
1545
+ const classBodies = context.classes.map(klass => generateClassBody$3(klass));
1546
+ const content = `${getCommentHeader()}
1547
+ ${options.namespace ? `\npackage ${options.namespace};` : ""}
1548
+
1549
+ ${COMMON_IMPORTS$1}
1550
+
1551
+ ${classBodies.join("\n\n")}
1552
+ `;
1553
+ return { name: fileName, content };
1554
+ }
1555
+ /**
1556
+ * Generate just the class body (without package/imports) for bundling
1557
+ */
1558
+ function generateClassBody$3(klass) {
1559
+ return `@SchemaClass
1560
+ class ${klass.name} extends ${klass.extends} {
1561
+ ${klass.properties.map(prop => generateProperty(prop, "")).join("\n\n")}
1562
+ }`;
1563
+ }
1564
+ /**
1565
+ * Generate a complete class file with package/imports (for individual file mode)
1566
+ */
1567
+ function generateClass$3(klass, namespace) {
1293
1568
  const indent = (namespace) ? "\t" : "";
1294
1569
  return `${getCommentHeader()}
1295
1570
  ${namespace ? `\npackage ${namespace};` : ""}
1296
1571
 
1297
- import io.colyseus.serializer.schema.Schema;
1298
- import io.colyseus.serializer.schema.annotations.SchemaClass;
1299
- import io.colyseus.serializer.schema.annotations.SchemaField;
1572
+ ${COMMON_IMPORTS$1}
1300
1573
 
1301
1574
  @SchemaClass
1302
1575
  ${indent}public class ${klass.name} extends ${klass.extends} {
@@ -1319,7 +1592,7 @@ function generateProperty(prop, indent = "") {
1319
1592
  if (prop.type === "ref") {
1320
1593
  langType = (isUpcaseFirst)
1321
1594
  ? prop.childType
1322
- : typeMaps$1[prop.childType];
1595
+ : typeMaps$3[prop.childType];
1323
1596
  initializer = `new ${langType}${(prop.type !== "ref" && isUpcaseFirst) ? "<>" : ""}(${ctorArgs})`;
1324
1597
  }
1325
1598
  else if (prop.type === "array") {
@@ -1341,7 +1614,7 @@ function generateProperty(prop, indent = "") {
1341
1614
  }
1342
1615
  }
1343
1616
  else {
1344
- langType = typeMaps$1[prop.type];
1617
+ langType = typeMaps$3[prop.type];
1345
1618
  initializer = typeInitializer[prop.type];
1346
1619
  }
1347
1620
  property += ` ${langType} ${prop.name}`;
@@ -1349,12 +1622,20 @@ function generateProperty(prop, indent = "") {
1349
1622
  \t${indent}${property} = ${initializer};`;
1350
1623
  }
1351
1624
 
1625
+ var java = /*#__PURE__*/Object.freeze({
1626
+ __proto__: null,
1627
+ generate: generate$4,
1628
+ name: name$3,
1629
+ renderBundle: renderBundle$3
1630
+ });
1631
+
1632
+ const name$2 = "LUA";
1352
1633
  /**
1353
1634
  TODO:
1354
1635
  - Support inheritance
1355
1636
  - Support importing Schema dependencies
1356
1637
  */
1357
- const typeMaps = {
1638
+ const typeMaps$2 = {
1358
1639
  "string": "string",
1359
1640
  "number": "number",
1360
1641
  "boolean": "boolean",
@@ -1369,14 +1650,55 @@ const typeMaps = {
1369
1650
  "float32": "number",
1370
1651
  "float64": "number",
1371
1652
  };
1372
- const distinct = (value, index, self) => self.indexOf(value) === index;
1373
- function generate$1(context, options) {
1653
+ const COMMON_IMPORTS = `local schema = require 'colyseus.serializer.schema.schema'`;
1654
+ const distinct$2 = (value, index, self) => self.indexOf(value) === index;
1655
+ /**
1656
+ * Generate individual files for each class
1657
+ */
1658
+ function generate$3(context, options) {
1374
1659
  return context.classes.map(klass => ({
1375
1660
  name: klass.name + ".lua",
1376
- content: generateClass(klass, options.namespace, context.classes)
1661
+ content: generateClass$2(klass, options.namespace, context.classes)
1377
1662
  }));
1378
1663
  }
1379
- function generateClass(klass, namespace, allClasses) {
1664
+ /**
1665
+ * Generate a single bundled file containing all classes
1666
+ */
1667
+ function renderBundle$2(context, options) {
1668
+ const fileName = options.namespace ? `${options.namespace}.lua` : "schema.lua";
1669
+ const classBodies = context.classes.map(klass => generateClassBody$2(klass));
1670
+ const classNames = context.classes.map(klass => ` ${klass.name} = ${klass.name},`).join("\n");
1671
+ const content = `${getCommentHeader().replace(/\/\//mg, "--")}
1672
+
1673
+ ${COMMON_IMPORTS}
1674
+
1675
+ ${classBodies.join("\n\n")}
1676
+
1677
+ return {
1678
+ ${classNames}
1679
+ }
1680
+ `;
1681
+ return { name: fileName, content };
1682
+ }
1683
+ /**
1684
+ * Generate just the class body (without requires) for bundling
1685
+ */
1686
+ function generateClassBody$2(klass) {
1687
+ // Inheritance support
1688
+ const inherits = (klass.extends !== "Schema")
1689
+ ? `, ${klass.extends}`
1690
+ : "";
1691
+ return `---@class ${klass.name}: ${klass.extends}
1692
+ ${klass.properties.map(prop => `---@field ${prop.name} ${getLUATypeAnnotation(prop)}`).join("\n")}
1693
+ local ${klass.name} = schema.define({
1694
+ ${klass.properties.map(prop => generatePropertyDeclaration(prop)).join(",\n")},
1695
+ ["_fields_by_index"] = { ${klass.properties.map(prop => `"${prop.name}"`).join(", ")} },
1696
+ }${inherits})`;
1697
+ }
1698
+ /**
1699
+ * Generate a complete class file with requires (for individual file mode)
1700
+ */
1701
+ function generateClass$2(klass, namespace, allClasses) {
1380
1702
  const allRefs = [];
1381
1703
  klass.properties.forEach(property => {
1382
1704
  let type = property.type;
@@ -1385,27 +1707,19 @@ function generateClass(klass, namespace, allClasses) {
1385
1707
  allRefs.push(property);
1386
1708
  }
1387
1709
  });
1388
- // Inheritance support
1389
- const inherits = (klass.extends !== "Schema")
1390
- ? `, ${klass.extends}`
1391
- : "";
1392
- return `${getCommentHeader().replace(/\/\//mg, "--")}
1393
-
1394
- local schema = require 'colyseus.serializer.schema.schema'
1395
- ${allRefs.
1396
- filter(ref => ref.childType && typeMaps[ref.childType] === undefined).
1710
+ const localRequires = allRefs.
1711
+ filter(ref => ref.childType && typeMaps$2[ref.childType] === undefined).
1397
1712
  map(ref => ref.childType).
1398
1713
  concat(getInheritanceTree(klass, allClasses, false).map(klass => klass.name)).
1399
- filter(distinct).
1714
+ filter(distinct$2).
1400
1715
  map(childType => `local ${childType} = require '${(namespace ? `${namespace}.` : '')}${childType}'`).
1401
- join("\n")}
1716
+ join("\n");
1717
+ return `${getCommentHeader().replace(/\/\//mg, "--")}
1402
1718
 
1403
- ---@class ${klass.name}: ${klass.extends}
1404
- ${klass.properties.map(prop => `---@field ${prop.name} ${getLUATypeAnnotation(prop)}`).join("\n")}
1405
- local ${klass.name} = schema.define({
1406
- ${klass.properties.map(prop => generatePropertyDeclaration(prop)).join(",\n")},
1407
- ["_fields_by_index"] = { ${klass.properties.map(prop => `"${prop.name}"`).join(", ")} },
1408
- }${inherits})
1719
+ ${COMMON_IMPORTS}
1720
+ ${localRequires}
1721
+
1722
+ ${generateClassBody$2(klass)}
1409
1723
 
1410
1724
  return ${klass.name}
1411
1725
  `;
@@ -1447,11 +1761,449 @@ function getLUATypeAnnotation(prop) {
1447
1761
  return "MapSchema";
1448
1762
  }
1449
1763
  else {
1450
- return typeMaps[prop.type];
1764
+ return typeMaps$2[prop.type];
1451
1765
  }
1452
1766
  }
1453
1767
 
1454
- const generators = { csharp: generate$7, cpp: generate$6, haxe: generate$5, ts: generate$4, js: generate$3, java: generate$2, lua: generate$1, };
1768
+ var lua = /*#__PURE__*/Object.freeze({
1769
+ __proto__: null,
1770
+ generate: generate$3,
1771
+ name: name$2,
1772
+ renderBundle: renderBundle$2
1773
+ });
1774
+
1775
+ const name$1 = "C";
1776
+ /**
1777
+ * Type mappings for C
1778
+ */
1779
+ const typeMaps$1 = {
1780
+ "string": "char*",
1781
+ "number": "double",
1782
+ "boolean": "bool",
1783
+ "int8": "int8_t",
1784
+ "uint8": "uint8_t",
1785
+ "int16": "int16_t",
1786
+ "uint16": "uint16_t",
1787
+ "int32": "int32_t",
1788
+ "uint32": "uint32_t",
1789
+ "int64": "int64_t",
1790
+ "uint64": "uint64_t",
1791
+ "float32": "float",
1792
+ "float64": "double",
1793
+ };
1794
+ /**
1795
+ * Colyseus field type enum mappings
1796
+ */
1797
+ const fieldTypeMaps = {
1798
+ "string": "COLYSEUS_FIELD_STRING",
1799
+ "number": "COLYSEUS_FIELD_NUMBER",
1800
+ "boolean": "COLYSEUS_FIELD_BOOLEAN",
1801
+ "int8": "COLYSEUS_FIELD_INT8",
1802
+ "uint8": "COLYSEUS_FIELD_UINT8",
1803
+ "int16": "COLYSEUS_FIELD_INT16",
1804
+ "uint16": "COLYSEUS_FIELD_UINT16",
1805
+ "int32": "COLYSEUS_FIELD_INT32",
1806
+ "uint32": "COLYSEUS_FIELD_UINT32",
1807
+ "int64": "COLYSEUS_FIELD_INT64",
1808
+ "uint64": "COLYSEUS_FIELD_UINT64",
1809
+ "float32": "COLYSEUS_FIELD_FLOAT32",
1810
+ "float64": "COLYSEUS_FIELD_FLOAT64",
1811
+ "ref": "COLYSEUS_FIELD_REF",
1812
+ "array": "COLYSEUS_FIELD_ARRAY",
1813
+ "map": "COLYSEUS_FIELD_MAP",
1814
+ };
1815
+ const COMMON_INCLUDES = `#include "colyseus/schema/types.h"
1816
+ #include "colyseus/schema/collections.h"
1817
+ #include <stdlib.h>
1818
+ #include <stddef.h>
1819
+ #include <stdbool.h>`;
1820
+ /**
1821
+ * Native C Code Generator
1822
+ */
1823
+ const toSnakeCase = (s) => {
1824
+ return s.replace(/([A-Z])/g, (match, p1, offset) => (offset > 0 ? '_' : '') + p1.toLowerCase());
1825
+ };
1826
+ const distinct$1 = (value, index, self) => self.indexOf(value) === index;
1827
+ /**
1828
+ * Generate individual files for each class
1829
+ */
1830
+ function generate$2(context, options) {
1831
+ return context.classes.map(klass => ({
1832
+ name: toSnakeCase(klass.name) + ".h",
1833
+ content: generateClass$1(klass, options.namespace, context.classes)
1834
+ }));
1835
+ }
1836
+ /**
1837
+ * Generate a single bundled header file containing all classes
1838
+ */
1839
+ function renderBundle$1(context, options) {
1840
+ const fileName = options.namespace ? `${toSnakeCase(options.namespace)}.h` : "schema.h";
1841
+ const guardName = `__SCHEMA_CODEGEN_${(options.namespace || "SCHEMA").toUpperCase()}_H__`;
1842
+ const classBodies = context.classes.map(klass => generateClassBody$1(klass, context.classes)).join("\n\n");
1843
+ const content = `${getCommentHeader()}
1844
+ #ifndef ${guardName}
1845
+ #define ${guardName} 1
1846
+
1847
+ ${COMMON_INCLUDES}
1848
+
1849
+ ${classBodies}
1850
+
1851
+ #endif
1852
+ `;
1853
+ return { name: fileName, content };
1854
+ }
1855
+ /**
1856
+ * Generate just the class body (without guards/includes) for bundling
1857
+ */
1858
+ function generateClassBody$1(klass, allClasses) {
1859
+ const snakeName = toSnakeCase(klass.name);
1860
+ const typeName = `${snakeName}_t`;
1861
+ const allProperties = getAllProperties(klass, allClasses);
1862
+ return `${generateTypedef(klass, typeName, allClasses)}
1863
+
1864
+ ${generateFieldsArray(klass, typeName, snakeName, allProperties)}
1865
+
1866
+ ${generateCreateFunction(snakeName, typeName)}
1867
+
1868
+ ${generateDestroyFunction(klass, snakeName, typeName, allProperties)}
1869
+
1870
+ ${generateVtable(klass, snakeName, typeName, allProperties)}`;
1871
+ }
1872
+ /**
1873
+ * Generate a complete class file with guards/includes (for individual file mode)
1874
+ */
1875
+ function generateClass$1(klass, namespace, allClasses) {
1876
+ toSnakeCase(klass.name);
1877
+ const guardName = `__SCHEMA_CODEGEN_${klass.name.toUpperCase()}_H__`;
1878
+ const allRefs = [];
1879
+ klass.properties.forEach(property => {
1880
+ if (property.type === "ref" || property.type === "array" || property.type === "map") {
1881
+ allRefs.push(property);
1882
+ }
1883
+ });
1884
+ // Generate includes for referenced schema types
1885
+ const refIncludes = allRefs
1886
+ .filter(ref => ref.childType && typeMaps$1[ref.childType] === undefined)
1887
+ .map(ref => ref.childType)
1888
+ .concat(getInheritanceTree(klass, allClasses, false).map(k => k.name))
1889
+ .filter(distinct$1)
1890
+ .map(childType => `#include "${toSnakeCase(childType)}.h"`)
1891
+ .join("\n");
1892
+ return `${getCommentHeader()}
1893
+ #ifndef ${guardName}
1894
+ #define ${guardName} 1
1895
+
1896
+ ${COMMON_INCLUDES}
1897
+ ${refIncludes ? `\n${refIncludes}\n` : ""}
1898
+ ${generateClassBody$1(klass, allClasses)}
1899
+
1900
+ #endif
1901
+ `;
1902
+ }
1903
+ function generateTypedef(klass, typeName, allClasses) {
1904
+ const allProperties = getAllProperties(klass, allClasses);
1905
+ const fields = allProperties.map(prop => {
1906
+ const cType = getCType(prop);
1907
+ return ` ${cType} ${prop.name};`;
1908
+ }).join("\n");
1909
+ return `typedef struct {
1910
+ colyseus_schema_t __base;
1911
+ ${fields}
1912
+ } ${typeName};`;
1913
+ }
1914
+ function getCType(prop) {
1915
+ if (prop.type === "ref") {
1916
+ return `${toSnakeCase(prop.childType)}_t*`;
1917
+ }
1918
+ else if (prop.type === "array") {
1919
+ if (typeMaps$1[prop.childType]) {
1920
+ return `colyseus_array_schema_t*`;
1921
+ }
1922
+ else {
1923
+ return `colyseus_array_schema_t*`;
1924
+ }
1925
+ }
1926
+ else if (prop.type === "map") {
1927
+ if (typeMaps$1[prop.childType]) {
1928
+ return `colyseus_map_schema_t*`;
1929
+ }
1930
+ else {
1931
+ return `colyseus_map_schema_t*`;
1932
+ }
1933
+ }
1934
+ else {
1935
+ return typeMaps$1[prop.type] || `${toSnakeCase(prop.type)}_t*`;
1936
+ }
1937
+ }
1938
+ function getFieldType(prop) {
1939
+ return fieldTypeMaps[prop.type] || "COLYSEUS_FIELD_REF";
1940
+ }
1941
+ function getFieldTypeString(prop) {
1942
+ // Always return the type itself (ref, array, map, string, number, etc.)
1943
+ return prop.type;
1944
+ }
1945
+ function generateFieldsArray(klass, typeName, snakeName, allProperties) {
1946
+ if (allProperties.length === 0) {
1947
+ return `static const colyseus_field_t ${snakeName}_fields[] = {};`;
1948
+ }
1949
+ const fields = allProperties.map((prop, i) => {
1950
+ const fieldType = getFieldType(prop);
1951
+ const typeString = getFieldTypeString(prop);
1952
+ let vtableRef = "NULL";
1953
+ if (prop.type === "ref" && prop.childType && !typeMaps$1[prop.childType]) {
1954
+ const childSnake = toSnakeCase(prop.childType);
1955
+ vtableRef = `&${childSnake}_vtable`;
1956
+ }
1957
+ else if ((prop.type === "array" || prop.type === "map") && prop.childType && !typeMaps$1[prop.childType]) {
1958
+ const childSnake = toSnakeCase(prop.childType);
1959
+ vtableRef = `&${childSnake}_vtable`;
1960
+ }
1961
+ return ` {${prop.index}, "${prop.name}", ${fieldType}, "${typeString}", offsetof(${typeName}, ${prop.name}), ${vtableRef}, NULL}`;
1962
+ }).join(",\n");
1963
+ return `static const colyseus_field_t ${snakeName}_fields[] = {
1964
+ ${fields}
1965
+ };`;
1966
+ }
1967
+ function generateCreateFunction(snakeName, typeName) {
1968
+ return `static ${typeName}* ${snakeName}_create(void) {
1969
+ ${typeName}* instance = calloc(1, sizeof(${typeName}));
1970
+ return instance;
1971
+ }`;
1972
+ }
1973
+ function generateDestroyFunction(klass, snakeName, typeName, allProperties) {
1974
+ const freeStatements = [];
1975
+ allProperties.forEach(prop => {
1976
+ if (prop.type === "string") {
1977
+ freeStatements.push(` if (instance->${prop.name}) free(instance->${prop.name});`);
1978
+ }
1979
+ else if (prop.type === "ref") {
1980
+ if (typeMaps$1[prop.childType]) {
1981
+ freeStatements.push(` if (instance->${prop.name}) free(instance->${prop.name});`);
1982
+ }
1983
+ else {
1984
+ const childSnake = toSnakeCase(prop.childType);
1985
+ freeStatements.push(` if (instance->${prop.name}) ${childSnake}_destroy((colyseus_schema_t*)instance->${prop.name});`);
1986
+ }
1987
+ }
1988
+ else if (prop.type === "array" || prop.type === "map") ;
1989
+ });
1990
+ const freeCode = freeStatements.length > 0 ? freeStatements.join("\n") + "\n" : "";
1991
+ return `static void ${snakeName}_destroy(colyseus_schema_t* schema) {
1992
+ ${typeName}* instance = (${typeName}*)schema;
1993
+ ${freeCode} free(instance);
1994
+ }`;
1995
+ }
1996
+ function generateVtable(klass, snakeName, typeName, allProperties) {
1997
+ const fieldCount = allProperties.length;
1998
+ return `static const colyseus_schema_vtable_t ${snakeName}_vtable = {
1999
+ "${klass.name}",
2000
+ sizeof(${typeName}),
2001
+ (colyseus_schema_t* (*)(void))${snakeName}_create,
2002
+ ${snakeName}_destroy,
2003
+ ${snakeName}_fields,
2004
+ ${fieldCount}
2005
+ };`;
2006
+ }
2007
+ function getAllProperties(klass, allClasses) {
2008
+ let properties = [];
2009
+ getInheritanceTree(klass, allClasses).reverse().forEach((k) => {
2010
+ properties = properties.concat(k.properties);
2011
+ });
2012
+ return properties;
2013
+ }
2014
+
2015
+ var c = /*#__PURE__*/Object.freeze({
2016
+ __proto__: null,
2017
+ generate: generate$2,
2018
+ name: name$1,
2019
+ renderBundle: renderBundle$1
2020
+ });
2021
+
2022
+ const name = "GDScript";
2023
+ /**
2024
+ * Type mappings from schema types to GDScript Colyseus.Schema type constants
2025
+ */
2026
+ const typeMaps = {
2027
+ "string": "Colyseus.Schema.STRING",
2028
+ "number": "Colyseus.Schema.NUMBER",
2029
+ "boolean": "Colyseus.Schema.BOOLEAN",
2030
+ "int8": "Colyseus.Schema.INT8",
2031
+ "uint8": "Colyseus.Schema.UINT8",
2032
+ "int16": "Colyseus.Schema.INT16",
2033
+ "uint16": "Colyseus.Schema.UINT16",
2034
+ "int32": "Colyseus.Schema.INT32",
2035
+ "uint32": "Colyseus.Schema.UINT32",
2036
+ "int64": "Colyseus.Schema.INT64",
2037
+ "uint64": "Colyseus.Schema.UINT64",
2038
+ "float32": "Colyseus.Schema.FLOAT32",
2039
+ "float64": "Colyseus.Schema.FLOAT64",
2040
+ };
2041
+ const containerMaps = {
2042
+ "array": "Colyseus.Schema.ARRAY",
2043
+ "map": "Colyseus.Schema.MAP",
2044
+ "ref": "Colyseus.Schema.REF",
2045
+ };
2046
+ const distinct = (value, index, self) => self.indexOf(value) === index;
2047
+ /**
2048
+ * GDScript Code Generator
2049
+ */
2050
+ /**
2051
+ * Generate individual files for each class
2052
+ */
2053
+ function generate$1(context, options) {
2054
+ // Enrich typeMaps with enums
2055
+ context.enums.forEach((structure) => {
2056
+ typeMaps[structure.name] = structure.name;
2057
+ });
2058
+ return [
2059
+ ...context.classes.map(klass => ({
2060
+ name: `${klass.name}.gd`,
2061
+ content: generateClass(klass, options.namespace, context.classes)
2062
+ })),
2063
+ ...context.enums.filter(structure => structure.name !== 'OPERATION').map((structure) => ({
2064
+ name: `${structure.name}.gd`,
2065
+ content: generateEnum(structure, options.namespace),
2066
+ })),
2067
+ ];
2068
+ }
2069
+ /**
2070
+ * Generate a single bundled file containing all classes and enums
2071
+ */
2072
+ function renderBundle(context, options) {
2073
+ const fileName = options.namespace ? `${options.namespace}.gd` : "schema.gd";
2074
+ // Enrich typeMaps with enums
2075
+ context.enums.forEach((structure) => {
2076
+ typeMaps[structure.name] = structure.name;
2077
+ });
2078
+ const enumBodies = context.enums
2079
+ .filter(structure => structure.name !== 'OPERATION')
2080
+ .map(e => generateEnumBody(e));
2081
+ const classBodies = context.classes.map(klass => generateClassBody(klass));
2082
+ const content = `${getCommentHeader("#")}
2083
+
2084
+ ${enumBodies.length > 0 ? enumBodies.join("\n\n") + "\n\n" : ""}${classBodies.join("\n\n")}
2085
+ `;
2086
+ return { name: fileName, content };
2087
+ }
2088
+ /**
2089
+ * Generate just the class body (without preload) for bundling
2090
+ */
2091
+ function generateClassBody(klass) {
2092
+ // Determine parent class
2093
+ const parentClass = (klass.extends !== "Schema")
2094
+ ? klass.extends
2095
+ : "Colyseus.Schema";
2096
+ const properties = klass.properties;
2097
+ const fieldsContent = properties.length > 0
2098
+ ? properties.map(prop => generateFieldDefinition(prop)).join(",\n") + ","
2099
+ : "";
2100
+ // Generate _to_string() method
2101
+ const toStringMethod = generateToStringMethod(klass.name, properties);
2102
+ return `class ${klass.name} extends ${parentClass}:
2103
+ static func definition():
2104
+ return [
2105
+ ${fieldsContent}
2106
+ ]
2107
+
2108
+ ${toStringMethod}`;
2109
+ }
2110
+ /**
2111
+ * Generate _to_string() method for the class
2112
+ */
2113
+ function generateToStringMethod(className, properties) {
2114
+ const fieldNames = properties.map(prop => prop.name);
2115
+ const allFields = ["__ref_id", ...fieldNames];
2116
+ const formatParts = allFields.map(name => `${name}: %s`).join(", ");
2117
+ const formatString = `${className}(${formatParts})`;
2118
+ const selfReferences = allFields.map(name => `self.${name}`).join(", ");
2119
+ return `\tfunc _to_string() -> String:
2120
+ return "${formatString}" % [${selfReferences}]`;
2121
+ }
2122
+ /**
2123
+ * Generate a complete class file with preload (for individual file mode)
2124
+ */
2125
+ function generateClass(klass, namespace, allClasses) {
2126
+ const allRefs = [];
2127
+ klass.properties.forEach(property => {
2128
+ let type = property.type;
2129
+ // Keep all refs list
2130
+ if ((type === "ref" || type === "array" || type === "map")) {
2131
+ allRefs.push(property);
2132
+ }
2133
+ });
2134
+ // Get required preloads for referenced types
2135
+ const preloads = allRefs
2136
+ .filter(ref => ref.childType && typeMaps[ref.childType] === undefined)
2137
+ .map(ref => ref.childType)
2138
+ .concat(getInheritanceTree(klass, allClasses, false).map(klass => klass.name))
2139
+ .filter(distinct)
2140
+ .map(childType => `const ${childType} = preload("${childType}.gd")`)
2141
+ .join("\n");
2142
+ return `${getCommentHeader("#")}
2143
+
2144
+ ${preloads ? preloads + "\n\n" : ""}${generateClassBody(klass)}
2145
+ `;
2146
+ }
2147
+ /**
2148
+ * Generate a field definition for the definition() array
2149
+ */
2150
+ function generateFieldDefinition(prop) {
2151
+ let args;
2152
+ if (prop.childType) {
2153
+ const isUpcaseFirst = prop.childType.match(/^[A-Z]/);
2154
+ // Array or Map container
2155
+ const containerType = containerMaps[prop.type];
2156
+ const childTypeRef = isUpcaseFirst ? prop.childType : typeMaps[prop.childType] || `"${prop.childType}"`;
2157
+ args = [`"${prop.name}"`, containerType, childTypeRef];
2158
+ }
2159
+ else {
2160
+ // Primitive type
2161
+ const typeRef = typeMaps[prop.type] || `"${prop.type}"`;
2162
+ args = [`"${prop.name}"`, typeRef];
2163
+ }
2164
+ return `\t\t\tColyseus.Schema.Field.new(${args.join(", ")})`;
2165
+ }
2166
+ /**
2167
+ * Generate just the enum body for bundling
2168
+ */
2169
+ function generateEnumBody(_enum) {
2170
+ const enumValues = _enum.properties.map((prop, index) => {
2171
+ let value;
2172
+ if (prop.type) {
2173
+ if (isNaN(Number(prop.type))) {
2174
+ value = `"${prop.type}"`;
2175
+ }
2176
+ else {
2177
+ value = Number(prop.type);
2178
+ }
2179
+ }
2180
+ else {
2181
+ value = index;
2182
+ }
2183
+ return `\t"${prop.name}": ${value},`;
2184
+ }).join("\n");
2185
+ return `const ${_enum.name} = {
2186
+ ${enumValues}
2187
+ }`;
2188
+ }
2189
+ /**
2190
+ * Generate a complete enum file (for individual file mode)
2191
+ */
2192
+ function generateEnum(_enum, _namespace) {
2193
+ return `${getCommentHeader("#")}
2194
+
2195
+ ${generateEnumBody(_enum)}
2196
+ `;
2197
+ }
2198
+
2199
+ var gdscript = /*#__PURE__*/Object.freeze({
2200
+ __proto__: null,
2201
+ generate: generate$1,
2202
+ name: name,
2203
+ renderBundle: renderBundle
2204
+ });
2205
+
2206
+ const generators = { csharp, cpp, haxe, ts, js, java, lua, c, gdscript, };
1455
2207
  function generate(targetId, options) {
1456
2208
  const generator = generators[targetId];
1457
2209
  if (!generator) {
@@ -1480,12 +2232,22 @@ function generate(targetId, options) {
1480
2232
  const structures = parseFiles(options.files, options.decorator);
1481
2233
  // Post-process classes before generating
1482
2234
  structures.classes.forEach(klass => klass.postProcessing());
1483
- const files = generator(structures, options);
1484
- files.forEach((file) => {
1485
- const outputPath = path__namespace.resolve(options.output, file.name);
1486
- fs__namespace.writeFileSync(outputPath, file.content);
1487
- console.log("generated:", file.name);
1488
- });
2235
+ if (options.bundle && generator.renderBundle) {
2236
+ // Bundle mode: generate all classes/interfaces/enums into a single file
2237
+ const bundled = generator.renderBundle(structures, options);
2238
+ const outputPath = path__namespace.resolve(options.output, bundled.name);
2239
+ fs__namespace.writeFileSync(outputPath, bundled.content);
2240
+ console.log("generated (bundled):", bundled.name);
2241
+ }
2242
+ else {
2243
+ // Standard mode: write individual files
2244
+ const generatedFiles = generator.generate(structures, options);
2245
+ generatedFiles.forEach((file) => {
2246
+ const outputPath = path__namespace.resolve(options.output, file.name);
2247
+ fs__namespace.writeFileSync(outputPath, file.content);
2248
+ console.log("generated:", file.name);
2249
+ });
2250
+ }
1489
2251
  }
1490
2252
  function recursiveFiles(dir) {
1491
2253
  const files = fs__namespace.readdirSync(dir, { withFileTypes: true });
@@ -1497,15 +2259,6 @@ function recursiveFiles(dir) {
1497
2259
  return collect;
1498
2260
  }
1499
2261
 
1500
- const supportedTargets = {
1501
- csharp: 'generate for C#/Unity',
1502
- cpp: 'generate for C++',
1503
- haxe: 'generate for Haxe',
1504
- ts: 'generate for TypeScript',
1505
- js: 'generate for JavaScript',
1506
- java: 'generate for Java',
1507
- lua: 'generate for LUA',
1508
- };
1509
2262
  function displayHelp() {
1510
2263
  console.log(`\nschema-codegen [path/to/Schema.ts]
1511
2264
 
@@ -1514,9 +2267,12 @@ Usage (C#/Unity)
1514
2267
 
1515
2268
  Valid options:
1516
2269
  --output: the output directory for generated client-side schema files
2270
+ --bundle: bundle all generated files into a single file
2271
+
2272
+ Generators:
1517
2273
  ${Object.
1518
- keys(supportedTargets).
1519
- map((targetId) => (` --${targetId}: ${supportedTargets[targetId]}`)).
2274
+ keys(generators).
2275
+ map((targetId) => (` --${targetId}: generate for ${generators[targetId].name}`)).
1520
2276
  join("\n")}
1521
2277
 
1522
2278
  Optional:
@@ -1529,7 +2285,7 @@ if (args.help) {
1529
2285
  displayHelp();
1530
2286
  }
1531
2287
  let targetId;
1532
- for (let target in supportedTargets) {
2288
+ for (let target in generators) {
1533
2289
  if (args[target]) {
1534
2290
  targetId = target;
1535
2291
  }
@@ -1544,7 +2300,8 @@ try {
1544
2300
  files: args._,
1545
2301
  decorator: args.decorator,
1546
2302
  output: args.output,
1547
- namespace: args.namespace
2303
+ namespace: args.namespace,
2304
+ bundle: args.bundle
1548
2305
  });
1549
2306
  }
1550
2307
  catch (e) {