@nativewrappers/common 0.0.53 → 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.
@@ -8,6 +8,7 @@ export declare class NetworkedMap<K, V> extends Map<K, V> {
8
8
  private onPlayerDropped;
9
9
  addSubscriber(sub: number): void;
10
10
  removeSubscriber(sub: number): boolean;
11
+ hasSubscriber(sub: number): boolean;
11
12
  listenForChange(key: K, fn: ChangeListener<V>): void;
12
13
  set(key: K, value: V): this;
13
14
  clear(): void;
@@ -51,16 +51,20 @@ export class NetworkedMap extends Map {
51
51
  */
52
52
  addSubscriber(sub) {
53
53
  this.#subscribers.add(sub);
54
- const packed_data = msgpack_pack([MapChangeType.Init, Array.from(this)]);
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) {
58
60
  return this.#subscribers.delete(sub);
59
61
  }
62
+ hasSubscriber(sub) {
63
+ return this.#subscribers.has(sub);
64
+ }
60
65
  #handleSync(msgpack_data) {
61
66
  const data = msgpack_unpack(msgpack_data);
62
- for (const change_data of data) {
63
- const [change_type, key, value] = change_data;
67
+ for (const [change_type, key, value, possibly_undefined_subvalue] of data) {
64
68
  switch (change_type) {
65
69
  case MapChangeType.Add: {
66
70
  this.set(key, value);
@@ -79,11 +83,13 @@ export class NetworkedMap extends Map {
79
83
  for (const [k, v] of key_value) {
80
84
  this.set(k, v);
81
85
  }
86
+ continue;
82
87
  }
83
88
  case MapChangeType.SubValueChanged: {
84
89
  const data = this.get(key);
85
90
  // @ts-ignore
86
- data[value] = change_data[3];
91
+ data[value] = possibly_undefined_subvalue;
92
+ continue;
87
93
  }
88
94
  }
89
95
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "author": "Remco Troost <d0p3t>",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
- "version": "0.0.53",
7
+ "version": "0.0.55",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "https://github.com/nativewrappers/nativewrappers.git"