@colyseus/schema 3.0.0-alpha.32 → 3.0.0-alpha.34
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/bin/schema-debug +93 -0
- package/build/cjs/index.js +5 -7
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +5 -7
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +5 -7
- package/lib/encoder/ChangeTree.js +1 -7
- package/lib/encoder/ChangeTree.js.map +1 -1
- package/lib/encoder/Root.js +4 -0
- package/lib/encoder/Root.js.map +1 -1
- package/package.json +3 -2
- package/src/encoder/ChangeTree.ts +1 -8
- package/src/encoder/Root.ts +5 -0
package/bin/schema-debug
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const schema = require('@colyseus/schema');
|
|
5
|
+
|
|
6
|
+
const Reflection = schema.Reflection;
|
|
7
|
+
const Decoder = schema.Decoder;
|
|
8
|
+
|
|
9
|
+
if (!fs.existsSync(process.argv[2])) {
|
|
10
|
+
console.error("Error: File not found:", process.argv[2]);
|
|
11
|
+
console.log("");
|
|
12
|
+
console.log("Usage: schema-debug <schema-debug.txt>");
|
|
13
|
+
console.log("");
|
|
14
|
+
console.log(" From your server-side, you must use the SchemaSerializerDebug as serializer, in order to generate the schema-debug.txt file.");
|
|
15
|
+
console.log("");
|
|
16
|
+
console.log(" Example:");
|
|
17
|
+
console.log("");
|
|
18
|
+
console.log(" import { SchemaSerializerDebug } from '@colyseus/core';");
|
|
19
|
+
console.log(" // ...");
|
|
20
|
+
console.log(" onCreate() {");
|
|
21
|
+
console.log(" this.setState(new MyRoomState());");
|
|
22
|
+
console.log(" // Override serializer");
|
|
23
|
+
console.log(" this.serializer = new SchemaSerializerDebug();");
|
|
24
|
+
console.log(" this.serializer.reset(this.state);");
|
|
25
|
+
console.log(" // ...");
|
|
26
|
+
console.log("");
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const contents = fs.readFileSync(process.argv[2], { encoding: "utf8" }).toString();
|
|
31
|
+
|
|
32
|
+
let isCommentBlock = false;
|
|
33
|
+
let lastComment = "";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @type {Decoder}
|
|
37
|
+
*/
|
|
38
|
+
let decoder;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* @param line string
|
|
43
|
+
* @returns {Buffer}
|
|
44
|
+
*/
|
|
45
|
+
function getBuffer(line) {
|
|
46
|
+
const start = line.lastIndexOf(":");
|
|
47
|
+
const buffer = Buffer.from(new Uint8Array(line.substring(start + 1).split(",").map(n => Number(n))));
|
|
48
|
+
console.log(`(${buffer.byteLength}) ${Array.from(buffer).join(",")}`)
|
|
49
|
+
// console.log("");
|
|
50
|
+
// console.log("");
|
|
51
|
+
// console.log("> ", line);
|
|
52
|
+
// console.log("> substring:", line.substring(start + 1))
|
|
53
|
+
return buffer;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param buffer {Buffer}
|
|
58
|
+
*/
|
|
59
|
+
function decode(buffer) {
|
|
60
|
+
try {
|
|
61
|
+
decoder.decode(buffer);
|
|
62
|
+
} catch (e) {
|
|
63
|
+
console.error(e);
|
|
64
|
+
console.log("NOT OK. Last log:\n\n")
|
|
65
|
+
console.log(lastComment);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
contents.split("\n").forEach((line) => {
|
|
70
|
+
if (line.startsWith("#")) {
|
|
71
|
+
// reset last comment.
|
|
72
|
+
if (isCommentBlock === false) { lastComment = ""; }
|
|
73
|
+
|
|
74
|
+
isCommentBlock = true;
|
|
75
|
+
lastComment += line.substring(line.indexOf(":") + 1) + "\n";
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
isCommentBlock = false;
|
|
80
|
+
|
|
81
|
+
if (line.startsWith("handshake:") && !decoder) {
|
|
82
|
+
const state = Reflection.decode(getBuffer(line));
|
|
83
|
+
decoder = new Decoder(state);
|
|
84
|
+
|
|
85
|
+
} else if (line.startsWith("state:")) {
|
|
86
|
+
decode(getBuffer(line));
|
|
87
|
+
|
|
88
|
+
} else if (line.startsWith("patch:")) {
|
|
89
|
+
decode(getBuffer(line));
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
console.log("OK:", decoder.state.toJSON());
|
package/build/cjs/index.js
CHANGED
|
@@ -483,13 +483,7 @@ class ChangeTree {
|
|
|
483
483
|
//
|
|
484
484
|
// (the property descriptors should NOT be used at decoding time. only at encoding time.)
|
|
485
485
|
//
|
|
486
|
-
|
|
487
|
-
//
|
|
488
|
-
// Only remove "root" reference if it's the last reference
|
|
489
|
-
//
|
|
490
|
-
if (refCount <= 0) {
|
|
491
|
-
previousValue[$changes].root = undefined;
|
|
492
|
-
}
|
|
486
|
+
this.root?.remove(previousValue[$changes]);
|
|
493
487
|
}
|
|
494
488
|
//
|
|
495
489
|
// FIXME: this is looking a bit ugly (and repeated from `.change()`)
|
|
@@ -3469,6 +3463,10 @@ class Root {
|
|
|
3469
3463
|
remove(changeTree) {
|
|
3470
3464
|
const refCount = (this.refCount.get(changeTree)) - 1;
|
|
3471
3465
|
if (refCount <= 0) {
|
|
3466
|
+
//
|
|
3467
|
+
// Only remove "root" reference if it's the last reference
|
|
3468
|
+
//
|
|
3469
|
+
changeTree.root = undefined;
|
|
3472
3470
|
this.allChanges.delete(changeTree);
|
|
3473
3471
|
this.changes.delete(changeTree);
|
|
3474
3472
|
if (changeTree.isFiltered || changeTree.isPartiallyFiltered) {
|