@colyseus/schema 3.0.0-alpha.1 → 3.0.0-alpha.2

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.
@@ -164,7 +164,6 @@ class Root {
164
164
  // pending changes to be encoded
165
165
  this.changes = new Map();
166
166
  this.filteredChanges = new Map();
167
- this.views = [];
168
167
  }
169
168
  getNextUniqueId() {
170
169
  return this.nextUniqueId++;
@@ -560,6 +559,26 @@ try {
560
559
  textEncoder = new TextEncoder();
561
560
  }
562
561
  catch (e) { }
562
+ function utf8Length(str) {
563
+ var c = 0, length = 0;
564
+ for (var i = 0, l = str.length; i < l; i++) {
565
+ c = str.charCodeAt(i);
566
+ if (c < 0x80) {
567
+ length += 1;
568
+ }
569
+ else if (c < 0x800) {
570
+ length += 2;
571
+ }
572
+ else if (c < 0xd800 || c >= 0xe000) {
573
+ length += 3;
574
+ }
575
+ else {
576
+ i++;
577
+ length += 4;
578
+ }
579
+ }
580
+ return length;
581
+ }
563
582
  function utf8Write(view, str, it) {
564
583
  var c = 0;
565
584
  for (var i = 0, l = str.length; i < l; i++) {
@@ -766,6 +785,7 @@ function number$1(bytes, value, it) {
766
785
 
767
786
  var encode = /*#__PURE__*/Object.freeze({
768
787
  __proto__: null,
788
+ utf8Length: utf8Length,
769
789
  utf8Write: utf8Write,
770
790
  int8: int8$1,
771
791
  uint8: uint8$1,
@@ -3358,13 +3378,13 @@ class Encoder {
3358
3378
  // });
3359
3379
  }
3360
3380
  setRoot(state) {
3361
- this.$root = new Root();
3381
+ this.root = new Root();
3362
3382
  this.state = state;
3363
- state[$changes].setRoot(this.$root);
3383
+ state[$changes].setRoot(this.root);
3364
3384
  }
3365
- encode(it = { offset: 0 }, view, bytes = this.sharedBuffer, changeTrees = this.$root.changes) {
3385
+ encode(it = { offset: 0 }, view, bytes = this.sharedBuffer, changeTrees = this.root.changes) {
3366
3386
  const initialOffset = it.offset; // cache current offset in case we need to resize the buffer
3367
- const isEncodeAll = this.$root.allChanges === changeTrees;
3387
+ const isEncodeAll = this.root.allChanges === changeTrees;
3368
3388
  const hasView = (view !== undefined);
3369
3389
  const rootChangeTree = this.state[$changes];
3370
3390
  const changeTreesIterator = changeTrees.entries();
@@ -3438,14 +3458,14 @@ class Encoder {
3438
3458
  // Array.from(this.$root.allChanges.entries()).map((item) => {
3439
3459
  // console.log("->", item[0].refId, item[0].ref.toJSON());
3440
3460
  // });
3441
- return this.encode(it, undefined, this.sharedBuffer, this.$root.allChanges);
3461
+ return this.encode(it, undefined, this.sharedBuffer, this.root.allChanges);
3442
3462
  }
3443
3463
  encodeAllView(view, sharedOffset, it, bytes = this.sharedBuffer) {
3444
3464
  const viewOffset = it.offset;
3445
3465
  // console.log(`encodeAllView(), this.$root.allFilteredChanges (${this.$root.allFilteredChanges.size})`);
3446
3466
  // this.debugAllFilteredChanges();
3447
3467
  // try to encode "filtered" changes
3448
- this.encode(it, view, bytes, this.$root.allFilteredChanges);
3468
+ this.encode(it, view, bytes, this.root.allFilteredChanges);
3449
3469
  return Buffer.concat([
3450
3470
  bytes.slice(0, sharedOffset),
3451
3471
  bytes.slice(viewOffset, it.offset)
@@ -3464,7 +3484,7 @@ class Encoder {
3464
3484
  encodeView(view, sharedOffset, it, bytes = this.sharedBuffer) {
3465
3485
  const viewOffset = it.offset;
3466
3486
  // try to encode "filtered" changes
3467
- this.encode(it, view, bytes, this.$root.filteredChanges);
3487
+ this.encode(it, view, bytes, this.root.filteredChanges);
3468
3488
  // encode visibility changes (add/remove for this view)
3469
3489
  const viewChangesIterator = view.changes.entries();
3470
3490
  for (const [changeTree, changes] of viewChangesIterator) {
@@ -3496,7 +3516,7 @@ class Encoder {
3496
3516
  bytes.slice(viewOffset, it.offset)
3497
3517
  ]);
3498
3518
  }
3499
- onEndEncode(changeTrees = this.$root.changes) {
3519
+ onEndEncode(changeTrees = this.root.changes) {
3500
3520
  const changeTreesIterator = changeTrees.entries();
3501
3521
  for (const [changeTree, _] of changeTreesIterator) {
3502
3522
  changeTree.endEncode();
@@ -3504,14 +3524,14 @@ class Encoder {
3504
3524
  }
3505
3525
  discardChanges() {
3506
3526
  // discard shared changes
3507
- if (this.$root.changes.size > 0) {
3508
- this.onEndEncode(this.$root.changes);
3509
- this.$root.changes.clear();
3527
+ if (this.root.changes.size > 0) {
3528
+ this.onEndEncode(this.root.changes);
3529
+ this.root.changes.clear();
3510
3530
  }
3511
3531
  // discard filtered changes
3512
- if (this.$root.filteredChanges.size > 0) {
3513
- this.onEndEncode(this.$root.filteredChanges);
3514
- this.$root.filteredChanges.clear();
3532
+ if (this.root.filteredChanges.size > 0) {
3533
+ this.onEndEncode(this.root.filteredChanges);
3534
+ this.root.filteredChanges.clear();
3515
3535
  }
3516
3536
  }
3517
3537
  tryEncodeTypeId(bytes, baseType, targetType, it) {