@colyseus/schema 4.0.19 → 4.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/codegen/cli.cjs +23 -0
- package/build/codegen/cli.cjs.map +1 -1
- package/build/index.cjs +2 -3
- package/build/index.cjs.map +1 -1
- package/build/index.js +2 -3
- package/build/index.mjs +2 -3
- package/build/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/codegen/languages/csharp.ts +24 -0
- package/src/encoder/ChangeTree.ts +2 -3
package/build/codegen/cli.cjs
CHANGED
|
@@ -643,10 +643,33 @@ ${generateClassBody$8(klass, indent)}
|
|
|
643
643
|
${namespace ? "}" : ""}
|
|
644
644
|
`;
|
|
645
645
|
}
|
|
646
|
+
/**
|
|
647
|
+
* Check if all enum members resolve to non-negative integers,
|
|
648
|
+
* allowing emission as a native C# `enum` (which only supports integral types).
|
|
649
|
+
*/
|
|
650
|
+
function canUseNativeEnum(_enum) {
|
|
651
|
+
return _enum.properties.every((prop) => {
|
|
652
|
+
if (!prop.type)
|
|
653
|
+
return true;
|
|
654
|
+
const n = Number(prop.type);
|
|
655
|
+
return Number.isInteger(n) && n >= 0;
|
|
656
|
+
});
|
|
657
|
+
}
|
|
646
658
|
/**
|
|
647
659
|
* Generate just the enum body (without imports/namespace) for bundling
|
|
648
660
|
*/
|
|
649
661
|
function generateEnumBody$1(_enum, indent = "") {
|
|
662
|
+
if (canUseNativeEnum(_enum)) {
|
|
663
|
+
const members = _enum.properties
|
|
664
|
+
.map((prop, i) => {
|
|
665
|
+
const value = prop.type ? Number(prop.type) : i;
|
|
666
|
+
return `${indent}\t${prop.name} = ${value},`;
|
|
667
|
+
})
|
|
668
|
+
.join("\n");
|
|
669
|
+
return `${indent}public enum ${_enum.name} : int {
|
|
670
|
+
${members}
|
|
671
|
+
${indent}}`;
|
|
672
|
+
}
|
|
650
673
|
return `${indent}public struct ${_enum.name} {
|
|
651
674
|
|
|
652
675
|
${_enum.properties
|