@nativewrappers/common 0.0.58 → 0.0.59
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.d.ts +2 -1
- package/net/NetworkedMap.js +17 -4
- package/package.json +1 -1
package/net/NetworkedMap.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ export declare class NetworkedMap<K, V> extends Map<K, V> {
|
|
|
7
7
|
constructor(syncName: string, initialValue?: [K, V][]);
|
|
8
8
|
get SyncName(): string;
|
|
9
9
|
private onPlayerDropped;
|
|
10
|
-
|
|
10
|
+
resync(source: number): void;
|
|
11
|
+
addSubscriber(source: number): void;
|
|
11
12
|
removeSubscriber(sub: number): boolean;
|
|
12
13
|
hasSubscriber(sub: number): boolean;
|
|
13
14
|
private handleSync;
|
package/net/NetworkedMap.js
CHANGED
|
@@ -86,15 +86,23 @@ export class NetworkedMap extends Map {
|
|
|
86
86
|
this.removeSubscriber(source);
|
|
87
87
|
}
|
|
88
88
|
/*
|
|
89
|
-
*
|
|
89
|
+
* Resyncs the entire map to the client, useful for if there's a mismatch in the clients map (when multiple players change things, in cases like inventories)
|
|
90
|
+
*
|
|
91
|
+
* NOTE: This doesn't check that the player is already subscribed to the map, you should do your own due-diligence to only call this for players already subscribed
|
|
90
92
|
*/
|
|
91
|
-
|
|
92
|
-
this.#subscribers.add(sub);
|
|
93
|
+
resync(source) {
|
|
93
94
|
const packed_data = msgpack_pack([
|
|
94
95
|
this.#syncName,
|
|
95
96
|
[[MapChangeType.Init, this.size === 0 ? [] : Array.from(this)]],
|
|
96
97
|
]);
|
|
97
|
-
TriggerClientEventInternal(`${GlobalData.CurrentResource}:syncChanges`,
|
|
98
|
+
TriggerClientEventInternal(`${GlobalData.CurrentResource}:syncChanges`, source, packed_data, packed_data.length);
|
|
99
|
+
}
|
|
100
|
+
/*
|
|
101
|
+
* Adds a new subscriber to the map
|
|
102
|
+
*/
|
|
103
|
+
addSubscriber(source) {
|
|
104
|
+
this.#subscribers.add(source);
|
|
105
|
+
this.resync(source);
|
|
98
106
|
}
|
|
99
107
|
removeSubscriber(sub) {
|
|
100
108
|
return this.#subscribers.delete(sub);
|
|
@@ -118,6 +126,8 @@ export class NetworkedMap extends Map {
|
|
|
118
126
|
continue;
|
|
119
127
|
}
|
|
120
128
|
case MapChangeType.Init: {
|
|
129
|
+
// We also use this for whenever we want to resync a table
|
|
130
|
+
super.clear();
|
|
121
131
|
const key_value = key;
|
|
122
132
|
for (const [k, v] of key_value) {
|
|
123
133
|
this.set(k, v);
|
|
@@ -192,6 +202,9 @@ export class NetworkedMap extends Map {
|
|
|
192
202
|
}
|
|
193
203
|
return this;
|
|
194
204
|
}
|
|
205
|
+
/*
|
|
206
|
+
* Resets the map to its default state
|
|
207
|
+
*/
|
|
195
208
|
clear() {
|
|
196
209
|
CLIENT: throw new Error(`Cannot call 'clear' on client`);
|
|
197
210
|
// if we're clearing our map then we want to remove all queued changes and
|