@colyseus/schema 3.0.47 → 3.0.49

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.
@@ -2801,6 +2801,12 @@ class MapSchema {
2801
2801
  this.$indexes.delete(index);
2802
2802
  }
2803
2803
  [$onEncodeEnd]() {
2804
+ const changeTree = this[$changes];
2805
+ // cleanup changeTree.indexes of deleted keys
2806
+ for (const indexStr in this.deletedItems) {
2807
+ const key = this.$indexes.get(parseInt(indexStr));
2808
+ delete changeTree.indexes[key];
2809
+ }
2804
2810
  this.deletedItems = {};
2805
2811
  }
2806
2812
  toJSON() {
@@ -3174,20 +3180,29 @@ function defineTypes(target, fields, options) {
3174
3180
  }
3175
3181
  return target;
3176
3182
  }
3177
- function schema(fields, name, inherits = Schema) {
3183
+ function schema(fieldsAndMethods, name, inherits = Schema) {
3184
+ const fields = {};
3185
+ const methods = {};
3178
3186
  const defaultValues = {};
3179
3187
  const viewTagFields = {};
3180
- for (let fieldName in fields) {
3181
- const field = fields[fieldName];
3182
- if (typeof (field) === "object") {
3183
- if (field['default'] !== undefined) {
3184
- defaultValues[fieldName] = field['default'];
3188
+ for (let fieldName in fieldsAndMethods) {
3189
+ const value = fieldsAndMethods[fieldName];
3190
+ if (typeof (value) === "object") {
3191
+ if (value['default'] !== undefined) {
3192
+ defaultValues[fieldName] = value['default'];
3185
3193
  }
3186
- if (field['view'] !== undefined) {
3187
- viewTagFields[fieldName] = (typeof (field['view']) === "boolean")
3194
+ if (value['view'] !== undefined) {
3195
+ viewTagFields[fieldName] = (typeof (value['view']) === "boolean")
3188
3196
  ? DEFAULT_VIEW_TAG
3189
- : field['view'];
3197
+ : value['view'];
3190
3198
  }
3199
+ fields[fieldName] = value;
3200
+ }
3201
+ else if (typeof (value) === "function") {
3202
+ methods[fieldName] = value;
3203
+ }
3204
+ else {
3205
+ fields[fieldName] = value;
3191
3206
  }
3192
3207
  }
3193
3208
  const klass = Metadata.setFields(class extends inherits {
@@ -3199,6 +3214,9 @@ function schema(fields, name, inherits = Schema) {
3199
3214
  for (let fieldName in viewTagFields) {
3200
3215
  view(viewTagFields[fieldName])(klass.prototype, fieldName);
3201
3216
  }
3217
+ for (let methodName in methods) {
3218
+ klass.prototype[methodName] = methods[methodName];
3219
+ }
3202
3220
  if (name) {
3203
3221
  Object.defineProperty(klass, "name", { value: name });
3204
3222
  }