@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colyseus/schema",
3
- "version": "4.0.19",
3
+ "version": "4.0.21",
4
4
  "description": "Binary state serializer with delta encoding for games",
5
5
  "type": "module",
6
6
  "bin": {
@@ -25,7 +25,7 @@
25
25
  "generate-test-10": "bin/schema-codegen test-external/Callbacks.ts --namespace SchemaTest.Callbacks --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/Callbacks",
26
26
  "generate-test-11": "bin/schema-codegen test-external/MapSchemaMoveNullifyType.ts --namespace SchemaTest.MapSchemaMoveNullifyType --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/MapSchemaMoveNullifyType",
27
27
  "generate-test-12": "bin/schema-codegen test-external/ArraySchemaClear --namespace SchemaTest.ArraySchemaClear --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/ArraySchemaClear",
28
- "prepublishOnly": "npm run build"
28
+ "prepare": "npm run build"
29
29
  },
30
30
  "files": [
31
31
  "src",
@@ -82,7 +82,7 @@
82
82
  "typescript": "^5.9.3"
83
83
  },
84
84
  "peerDependencies": {
85
- "typescript": "^5.9.3"
85
+ "typescript": "^5.0.0 || ^6.0.0"
86
86
  },
87
87
  "c8": {
88
88
  "include": [
@@ -122,10 +122,34 @@ ${namespace ? "}" : ""}
122
122
  `;
123
123
  }
124
124
 
125
+ /**
126
+ * Check if all enum members resolve to non-negative integers,
127
+ * allowing emission as a native C# `enum` (which only supports integral types).
128
+ */
129
+ function canUseNativeEnum(_enum: Enum): boolean {
130
+ return _enum.properties.every((prop) => {
131
+ if (!prop.type) return true;
132
+ const n = Number(prop.type);
133
+ return Number.isInteger(n) && n >= 0;
134
+ });
135
+ }
136
+
125
137
  /**
126
138
  * Generate just the enum body (without imports/namespace) for bundling
127
139
  */
128
140
  function generateEnumBody(_enum: Enum, indent: string = ""): string {
141
+ if (canUseNativeEnum(_enum)) {
142
+ const members = _enum.properties
143
+ .map((prop, i) => {
144
+ const value = prop.type ? Number(prop.type) : i;
145
+ return `${indent}\t${prop.name} = ${value},`;
146
+ })
147
+ .join("\n");
148
+ return `${indent}public enum ${_enum.name} : int {
149
+ ${members}
150
+ ${indent}}`;
151
+ }
152
+
129
153
  return `${indent}public struct ${_enum.name} {
130
154
 
131
155
  ${_enum.properties
@@ -568,7 +568,7 @@ export class ChangeTree<T extends Ref = any> {
568
568
  || fieldHasViewTag;
569
569
 
570
570
  //
571
- // "isFiltered" may not be imedialely available during `change()` due to the instance not being attached to the root yet.
571
+ // "isFiltered" may not be immediately available during `change()` due to the instance not being attached to the root yet.
572
572
  // when it's available, we need to enqueue the "changes" changeset into the "filteredChanges" changeset.
573
573
  //
574
574
  if (this.isFiltered) {
@@ -576,8 +576,7 @@ export class ChangeTree<T extends Ref = any> {
576
576
  this.isVisibilitySharedWithParent = (
577
577
  parentChangeTree.isFiltered &&
578
578
  typeof (refType) !== "string" &&
579
- !fieldHasViewTag &&
580
- parentIsCollection
579
+ !fieldHasViewTag
581
580
  );
582
581
 
583
582
  if (!this.filteredChanges) {