@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.
@@ -168,7 +168,6 @@ class Root {
168
168
  // pending changes to be encoded
169
169
  this.changes = new Map();
170
170
  this.filteredChanges = new Map();
171
- this.views = [];
172
171
  }
173
172
  getNextUniqueId() {
174
173
  return this.nextUniqueId++;
@@ -564,6 +563,26 @@ try {
564
563
  textEncoder = new TextEncoder();
565
564
  }
566
565
  catch (e) { }
566
+ function utf8Length(str) {
567
+ var c = 0, length = 0;
568
+ for (var i = 0, l = str.length; i < l; i++) {
569
+ c = str.charCodeAt(i);
570
+ if (c < 0x80) {
571
+ length += 1;
572
+ }
573
+ else if (c < 0x800) {
574
+ length += 2;
575
+ }
576
+ else if (c < 0xd800 || c >= 0xe000) {
577
+ length += 3;
578
+ }
579
+ else {
580
+ i++;
581
+ length += 4;
582
+ }
583
+ }
584
+ return length;
585
+ }
567
586
  function utf8Write(view, str, it) {
568
587
  var c = 0;
569
588
  for (var i = 0, l = str.length; i < l; i++) {
@@ -770,6 +789,7 @@ function number$1(bytes, value, it) {
770
789
 
771
790
  var encode = /*#__PURE__*/Object.freeze({
772
791
  __proto__: null,
792
+ utf8Length: utf8Length,
773
793
  utf8Write: utf8Write,
774
794
  int8: int8$1,
775
795
  uint8: uint8$1,
@@ -3362,13 +3382,13 @@ class Encoder {
3362
3382
  // });
3363
3383
  }
3364
3384
  setRoot(state) {
3365
- this.$root = new Root();
3385
+ this.root = new Root();
3366
3386
  this.state = state;
3367
- state[$changes].setRoot(this.$root);
3387
+ state[$changes].setRoot(this.root);
3368
3388
  }
3369
- encode(it = { offset: 0 }, view, bytes = this.sharedBuffer, changeTrees = this.$root.changes) {
3389
+ encode(it = { offset: 0 }, view, bytes = this.sharedBuffer, changeTrees = this.root.changes) {
3370
3390
  const initialOffset = it.offset; // cache current offset in case we need to resize the buffer
3371
- const isEncodeAll = this.$root.allChanges === changeTrees;
3391
+ const isEncodeAll = this.root.allChanges === changeTrees;
3372
3392
  const hasView = (view !== undefined);
3373
3393
  const rootChangeTree = this.state[$changes];
3374
3394
  const changeTreesIterator = changeTrees.entries();
@@ -3442,14 +3462,14 @@ class Encoder {
3442
3462
  // Array.from(this.$root.allChanges.entries()).map((item) => {
3443
3463
  // console.log("->", item[0].refId, item[0].ref.toJSON());
3444
3464
  // });
3445
- return this.encode(it, undefined, this.sharedBuffer, this.$root.allChanges);
3465
+ return this.encode(it, undefined, this.sharedBuffer, this.root.allChanges);
3446
3466
  }
3447
3467
  encodeAllView(view, sharedOffset, it, bytes = this.sharedBuffer) {
3448
3468
  const viewOffset = it.offset;
3449
3469
  // console.log(`encodeAllView(), this.$root.allFilteredChanges (${this.$root.allFilteredChanges.size})`);
3450
3470
  // this.debugAllFilteredChanges();
3451
3471
  // try to encode "filtered" changes
3452
- this.encode(it, view, bytes, this.$root.allFilteredChanges);
3472
+ this.encode(it, view, bytes, this.root.allFilteredChanges);
3453
3473
  return Buffer.concat([
3454
3474
  bytes.slice(0, sharedOffset),
3455
3475
  bytes.slice(viewOffset, it.offset)
@@ -3468,7 +3488,7 @@ class Encoder {
3468
3488
  encodeView(view, sharedOffset, it, bytes = this.sharedBuffer) {
3469
3489
  const viewOffset = it.offset;
3470
3490
  // try to encode "filtered" changes
3471
- this.encode(it, view, bytes, this.$root.filteredChanges);
3491
+ this.encode(it, view, bytes, this.root.filteredChanges);
3472
3492
  // encode visibility changes (add/remove for this view)
3473
3493
  const viewChangesIterator = view.changes.entries();
3474
3494
  for (const [changeTree, changes] of viewChangesIterator) {
@@ -3500,7 +3520,7 @@ class Encoder {
3500
3520
  bytes.slice(viewOffset, it.offset)
3501
3521
  ]);
3502
3522
  }
3503
- onEndEncode(changeTrees = this.$root.changes) {
3523
+ onEndEncode(changeTrees = this.root.changes) {
3504
3524
  const changeTreesIterator = changeTrees.entries();
3505
3525
  for (const [changeTree, _] of changeTreesIterator) {
3506
3526
  changeTree.endEncode();
@@ -3508,14 +3528,14 @@ class Encoder {
3508
3528
  }
3509
3529
  discardChanges() {
3510
3530
  // discard shared changes
3511
- if (this.$root.changes.size > 0) {
3512
- this.onEndEncode(this.$root.changes);
3513
- this.$root.changes.clear();
3531
+ if (this.root.changes.size > 0) {
3532
+ this.onEndEncode(this.root.changes);
3533
+ this.root.changes.clear();
3514
3534
  }
3515
3535
  // discard filtered changes
3516
- if (this.$root.filteredChanges.size > 0) {
3517
- this.onEndEncode(this.$root.filteredChanges);
3518
- this.$root.filteredChanges.clear();
3536
+ if (this.root.filteredChanges.size > 0) {
3537
+ this.onEndEncode(this.root.filteredChanges);
3538
+ this.root.filteredChanges.clear();
3519
3539
  }
3520
3540
  }
3521
3541
  tryEncodeTypeId(bytes, baseType, targetType, it) {