@colyseus/schema 3.0.2 → 3.0.3
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/README.md +8 -7
- package/build/cjs/index.js +21 -2
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +21 -2
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +21 -2
- package/lib/decoder/DecodeOperation.js +1 -1
- package/lib/decoder/DecodeOperation.js.map +1 -1
- package/lib/decoder/strategy/StateCallbacks.d.ts +9 -0
- package/lib/decoder/strategy/StateCallbacks.js +20 -1
- package/lib/decoder/strategy/StateCallbacks.js.map +1 -1
- package/package.json +1 -1
- package/src/decoder/DecodeOperation.ts +1 -1
- package/src/decoder/strategy/StateCallbacks.ts +35 -8
package/README.md
CHANGED
|
@@ -9,13 +9,14 @@
|
|
|
9
9
|
|
|
10
10
|
# Features
|
|
11
11
|
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
12
|
+
- **Incremental State Synchronization**: Send only the properties that have changed.
|
|
13
|
+
- **Trigger Callbacks at Decoding**: [Bring your own](https://docs.colyseus.io/state/callbacks/custom) callback system at decoding, or use the built-in one.
|
|
14
|
+
- **Instance Reference Tracking**: Share references of the same instance across the state.
|
|
15
|
+
- **State Views**: Filter properties that should be sent only to specific clients.
|
|
16
|
+
- **Reflection**: Encode/Decode schema definitions.
|
|
17
|
+
- **Schema Generation**: Generate client-side schema files for strictly typed languages.
|
|
18
|
+
- **Type Safety**: Strictly typed schema definitions.
|
|
19
|
+
- **Multiple Language Support**: Decoders available for multiple languages ([C#](https://github.com/colyseus/colyseus-unity-sdk/tree/master/Assets/Colyseus/Runtime/Colyseus/Serializer/Schema), [Lua](https://github.com/colyseus/colyseus-defold/tree/master/colyseus/serializer/schema), [Haxe](https://github.com/colyseus/colyseus-haxe/tree/master/src/io/colyseus/serializer/schema)).
|
|
19
20
|
|
|
20
21
|
## Schema definition
|
|
21
22
|
|
package/build/cjs/index.js
CHANGED
|
@@ -1547,7 +1547,7 @@ function decodeValue(decoder, operation, ref, index, type, bytes, it, allChanges
|
|
|
1547
1547
|
// previousValue,
|
|
1548
1548
|
// });
|
|
1549
1549
|
}
|
|
1550
|
-
value =
|
|
1550
|
+
value = undefined;
|
|
1551
1551
|
}
|
|
1552
1552
|
if (operation === exports.OPERATION.DELETE) ;
|
|
1553
1553
|
else if (Schema.is(type)) {
|
|
@@ -4485,7 +4485,10 @@ function getDecoderStateCallbacks(decoder) {
|
|
|
4485
4485
|
}
|
|
4486
4486
|
}
|
|
4487
4487
|
// trigger onChange
|
|
4488
|
-
if (change.value !== change.previousValue
|
|
4488
|
+
if (change.value !== change.previousValue &&
|
|
4489
|
+
// FIXME: see "should not encode item if added and removed at the same patch" test case.
|
|
4490
|
+
// some "ADD" + "DELETE" operations on same patch are being encoded as "DELETE"
|
|
4491
|
+
(change.value !== undefined || change.previousValue !== undefined)) {
|
|
4489
4492
|
const replaceCallbacks = $callbacks[exports.OPERATION.REPLACE];
|
|
4490
4493
|
for (let i = replaceCallbacks?.length - 1; i >= 0; i--) {
|
|
4491
4494
|
replaceCallbacks[i](change.value, change.dynamicIndex ?? change.field);
|
|
@@ -4598,6 +4601,9 @@ function getDecoderStateCallbacks(decoder) {
|
|
|
4598
4601
|
const onRemove = function (ref, callback) {
|
|
4599
4602
|
return $root.addCallback($root.refIds.get(ref), exports.OPERATION.DELETE, callback);
|
|
4600
4603
|
};
|
|
4604
|
+
const onChange = function (ref, callback) {
|
|
4605
|
+
return $root.addCallback($root.refIds.get(ref), exports.OPERATION.REPLACE, callback);
|
|
4606
|
+
};
|
|
4601
4607
|
return new Proxy({
|
|
4602
4608
|
onAdd: function (callback, immediate = true) {
|
|
4603
4609
|
//
|
|
@@ -4629,6 +4635,19 @@ function getDecoderStateCallbacks(decoder) {
|
|
|
4629
4635
|
return onRemove(context.instance, callback);
|
|
4630
4636
|
}
|
|
4631
4637
|
},
|
|
4638
|
+
onChange: function (callback) {
|
|
4639
|
+
if (context.onInstanceAvailable) {
|
|
4640
|
+
// collection instance not received yet
|
|
4641
|
+
let detachCallback = () => { };
|
|
4642
|
+
context.onInstanceAvailable((ref) => {
|
|
4643
|
+
detachCallback = onChange(ref, callback);
|
|
4644
|
+
});
|
|
4645
|
+
return () => detachCallback();
|
|
4646
|
+
}
|
|
4647
|
+
else if (context.instance) {
|
|
4648
|
+
return onChange(context.instance, callback);
|
|
4649
|
+
}
|
|
4650
|
+
},
|
|
4632
4651
|
}, {
|
|
4633
4652
|
get(target, prop) {
|
|
4634
4653
|
if (!target[prop]) {
|