@colyseus/schema 3.0.10 → 3.0.11

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.
@@ -1238,6 +1238,7 @@ class ChangeTree {
1238
1238
  //
1239
1239
  this.root?.remove(previousValue[$changes]);
1240
1240
  }
1241
+ deleteOperationAtIndex(this.allChanges, allChangesIndex);
1241
1242
  //
1242
1243
  // FIXME: this is looking a ugly and repeated
1243
1244
  //
@@ -1246,7 +1247,6 @@ class ChangeTree {
1246
1247
  enqueueChangeTree(this.root, this, 'filteredChanges');
1247
1248
  }
1248
1249
  else {
1249
- deleteOperationAtIndex(this.allChanges, allChangesIndex);
1250
1250
  enqueueChangeTree(this.root, this, 'changes');
1251
1251
  }
1252
1252
  }
@@ -3747,15 +3747,31 @@ class Root {
3747
3747
  }
3748
3748
  else {
3749
3749
  this.refCount[changeTree.refId] = refCount;
3750
+ //
3751
+ // When losing a reference to an instance, it is best to move the
3752
+ // ChangeTree to the end of the encoding queue.
3753
+ //
3754
+ // This way, at decoding time, the instance that contains the
3755
+ // ChangeTree will be available before the ChangeTree itself. If the
3756
+ // containing instance is not available, the Decoder will throw
3757
+ // "refId not found" error.
3758
+ //
3759
+ if (changeTree.filteredChanges !== undefined) {
3760
+ this.removeChangeFromChangeSet("filteredChanges", changeTree);
3761
+ enqueueChangeTree(this, changeTree, "filteredChanges");
3762
+ }
3763
+ else {
3764
+ this.removeChangeFromChangeSet("changes", changeTree);
3765
+ enqueueChangeTree(this, changeTree, "changes");
3766
+ }
3750
3767
  }
3751
3768
  changeTree.forEachChild((child, _) => this.remove(child));
3752
3769
  return refCount;
3753
3770
  }
3754
3771
  removeChangeFromChangeSet(changeSetName, changeTree) {
3755
3772
  const changeSet = this[changeSetName];
3756
- const index = changeSet.indexOf(changeTree);
3757
- if (index !== -1) {
3758
- spliceOne(changeSet, index);
3773
+ if (spliceOne(changeSet, changeSet.indexOf(changeTree))) {
3774
+ changeTree[changeSetName].queueRootIndex = -1;
3759
3775
  // changeSet[index] = undefined;
3760
3776
  }
3761
3777
  }