@nativewrappers/common 0.0.54 → 0.0.55
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/net/NetworkedMap.js +7 -4
- package/package.json +1 -1
package/net/NetworkedMap.js
CHANGED
|
@@ -51,7 +51,9 @@ export class NetworkedMap extends Map {
|
|
|
51
51
|
*/
|
|
52
52
|
addSubscriber(sub) {
|
|
53
53
|
this.#subscribers.add(sub);
|
|
54
|
-
const packed_data = msgpack_pack([
|
|
54
|
+
const packed_data = msgpack_pack([
|
|
55
|
+
[MapChangeType.Init, this.size === 0 ? [] : Array.from(this)],
|
|
56
|
+
]);
|
|
55
57
|
TriggerClientEventInternal(`${this.#syncName}:syncChanges`, sub, packed_data, packed_data.length);
|
|
56
58
|
}
|
|
57
59
|
removeSubscriber(sub) {
|
|
@@ -62,8 +64,7 @@ export class NetworkedMap extends Map {
|
|
|
62
64
|
}
|
|
63
65
|
#handleSync(msgpack_data) {
|
|
64
66
|
const data = msgpack_unpack(msgpack_data);
|
|
65
|
-
for (const
|
|
66
|
-
const [change_type, key, value] = change_data;
|
|
67
|
+
for (const [change_type, key, value, possibly_undefined_subvalue] of data) {
|
|
67
68
|
switch (change_type) {
|
|
68
69
|
case MapChangeType.Add: {
|
|
69
70
|
this.set(key, value);
|
|
@@ -82,11 +83,13 @@ export class NetworkedMap extends Map {
|
|
|
82
83
|
for (const [k, v] of key_value) {
|
|
83
84
|
this.set(k, v);
|
|
84
85
|
}
|
|
86
|
+
continue;
|
|
85
87
|
}
|
|
86
88
|
case MapChangeType.SubValueChanged: {
|
|
87
89
|
const data = this.get(key);
|
|
88
90
|
// @ts-ignore
|
|
89
|
-
data[value] =
|
|
91
|
+
data[value] = possibly_undefined_subvalue;
|
|
92
|
+
continue;
|
|
90
93
|
}
|
|
91
94
|
}
|
|
92
95
|
}
|