@colyseus/schema 4.0.13 → 4.0.15

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