@colyseus/schema 5.0.3 → 5.0.5
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/decoder/strategy/Callbacks.d.ts +6 -6
- package/build/encoder/StateView.d.ts +17 -0
- package/build/index.cjs +184 -37
- package/build/index.cjs.map +1 -1
- package/build/index.js +184 -37
- package/build/index.mjs +184 -37
- package/build/index.mjs.map +1 -1
- package/build/input/index.cjs +28 -4
- package/build/input/index.cjs.map +1 -1
- package/build/input/index.mjs +28 -4
- package/build/input/index.mjs.map +1 -1
- package/build/types/builder.d.ts +83 -29
- package/package.json +6 -5
- package/src/annotations.ts +48 -18
- package/src/codegen/languages/csharp.ts +24 -0
- package/src/decoder/strategy/Callbacks.ts +16 -14
- package/src/encoder/Encoder.ts +13 -2
- package/src/encoder/StateView.ts +63 -2
- package/src/encoder/changeTree/inheritedFlags.ts +16 -2
- package/src/types/builder.ts +82 -20
package/build/codegen/cli.cjs
CHANGED
|
@@ -683,10 +683,33 @@ ${generateClassBody$8(klass, indent)}
|
|
|
683
683
|
${namespace ? "}" : ""}
|
|
684
684
|
`;
|
|
685
685
|
}
|
|
686
|
+
/**
|
|
687
|
+
* Check if all enum members resolve to non-negative integers,
|
|
688
|
+
* allowing emission as a native C# `enum` (which only supports integral types).
|
|
689
|
+
*/
|
|
690
|
+
function canUseNativeEnum(_enum) {
|
|
691
|
+
return _enum.properties.every((prop) => {
|
|
692
|
+
if (!prop.type)
|
|
693
|
+
return true;
|
|
694
|
+
const n = Number(prop.type);
|
|
695
|
+
return Number.isInteger(n) && n >= 0;
|
|
696
|
+
});
|
|
697
|
+
}
|
|
686
698
|
/**
|
|
687
699
|
* Generate just the enum body (without imports/namespace) for bundling
|
|
688
700
|
*/
|
|
689
701
|
function generateEnumBody$1(_enum, indent = "") {
|
|
702
|
+
if (canUseNativeEnum(_enum)) {
|
|
703
|
+
const members = _enum.properties
|
|
704
|
+
.map((prop, i) => {
|
|
705
|
+
const value = prop.type ? Number(prop.type) : i;
|
|
706
|
+
return `${indent}\t${prop.name} = ${value},`;
|
|
707
|
+
})
|
|
708
|
+
.join("\n");
|
|
709
|
+
return `${indent}public enum ${_enum.name} : int {
|
|
710
|
+
${members}
|
|
711
|
+
${indent}}`;
|
|
712
|
+
}
|
|
690
713
|
return `${indent}public struct ${_enum.name} {
|
|
691
714
|
|
|
692
715
|
${_enum.properties
|