@rbxts/replecs 0.2.4 → 0.3.0

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.
@@ -70,8 +70,8 @@ type DeletedHookEntry = {
70
70
  type CustomIdMap = { [Entity]: CustomId | Entity }
71
71
 
72
72
  export type ClientImp = {
73
- set_serdes: <T>(client: Client, id: Component<T>, serdes: types.Serdes<T>) -> (),
74
- remove_serdes: (client: Client, id: Component) -> (),
73
+ set_serdes: <T>(self: Client, id: Component<T>, serdes: types.Serdes<T>) -> (),
74
+ remove_serdes: (self: Client, id: Component) -> (),
75
75
  }
76
76
 
77
77
  export type Client = ClientImp & {
@@ -158,6 +158,7 @@ local WORLD_ADD = common.world_add
158
158
  local WORLD_SET = common.world_set
159
159
  local WORLD_REMOVE = common.world_remove
160
160
  local WORLD_GET = common.world_get
161
+ local WORLD_HAS = common.world_has
161
162
  local WORLD_DELETE = common.world_delete
162
163
 
163
164
  local HOOK_ADDED = common.hook_added
@@ -269,7 +270,9 @@ function client_replicator.entity_set_unreliable(
269
270
  local command_buffer = get_or_create_command_buffer(client, entity)
270
271
  command_buffer.unreliable_components[id] = { value = value }
271
272
  else
272
- client_replicator.entity_set(client, entity, id, value, changed_hooks)
273
+ if WORLD_HAS(client.world, entity, id) then
274
+ client_replicator.entity_set(client, entity, id, value, changed_hooks)
275
+ end
273
276
  end
274
277
  end
275
278
 
@@ -1371,6 +1374,7 @@ function client_replicator.apply_unreliable(client: Client, buf: buffer, all_var
1371
1374
  for _ = 1, total_unreliable do
1372
1375
  local component = client_replicator.read_component_id(client, c)
1373
1376
  local value = client_replicator.read_component_value(client, component, c, variants)
1377
+
1374
1378
  local unreliable_hooks = changed_hooks[PAIR(components.unreliable, component)]
1375
1379
  client_replicator.entity_set_unreliable(client, entity, component, value, unreliable_hooks)
1376
1380
  end
@@ -1,18 +1,18 @@
1
- import type { Entity, Id, Pair, Tag, World } from "@rbxts/jecs";
1
+ import type { Entity, Id, InferComponent, Pair, Tag, World } from "@rbxts/jecs";
2
2
 
3
3
  declare namespace Replecs {
4
- export type SerdesTable =
4
+ export type SerdesTable<T = any> =
5
5
  | {
6
6
  bytespan?: number;
7
7
  includes_variants?: false;
8
- serialize: (value: any) => buffer;
9
- deserialize: (buffer: buffer) => any;
8
+ serialize: (value: T) => buffer;
9
+ deserialize: (buffer: buffer) => T;
10
10
  }
11
11
  | {
12
12
  bytespan?: number;
13
13
  includes_variants: true;
14
- serialize: (value: any) => LuaTuple<[buffer, defined[] | undefined]>;
15
- deserialize: (buffer: buffer, blobs: defined[] | undefined) => any;
14
+ serialize: (value: T) => LuaTuple<[buffer, defined[] | undefined]>;
15
+ deserialize: (buffer: buffer, blobs: defined[] | undefined) => T;
16
16
  };
17
17
 
18
18
  type MemberFilterMap = Map<Player, boolean>;
@@ -80,6 +80,14 @@ declare namespace Replecs {
80
80
  Global: Entity<number>;
81
81
  }
82
82
 
83
+ export interface ClientImp {
84
+ set_serdes<T extends Id>(
85
+ component: InferComponent<T>,
86
+ serdes: SerdesTable<T>,
87
+ ): void;
88
+ remove_serdes(component: Id): void;
89
+ }
90
+
83
91
  export interface Client {
84
92
  world: World;
85
93
  inited?: boolean;
@@ -91,9 +99,7 @@ declare namespace Replecs {
91
99
 
92
100
  init(world?: World): void;
93
101
  destroy(): void;
94
-
95
102
  handle_global(handler: (id: number) => Entity): void;
96
-
97
103
  get_server_entity(client_entity: Entity): number | undefined;
98
104
  get_client_entity(server_entity: number): Entity | undefined;
99
105
 
@@ -137,6 +143,8 @@ declare namespace Replecs {
137
143
 
138
144
  encode_component(component: Entity): number;
139
145
  decode_component(encoded: number): Entity;
146
+ get_shared_count(): number;
147
+
140
148
  register_custom_id(custom_id: CustomId): void;
141
149
 
142
150
  apply_updates(buf: buffer, all_variants?: defined[][]): void;
@@ -161,15 +169,23 @@ declare namespace Replecs {
161
169
  component: Entity,
162
170
  filter?: MemberFilter,
163
171
  ): void;
172
+ set_pair(entity: Entity, id: Pair, filter?: MemberFilter): void;
164
173
  set_relation(entity: Entity, relation: Entity, filter?: MemberFilter): void;
165
174
 
166
175
  stop_networked(entity: Entity, keep?: boolean): void;
167
176
  stop_reliable(entity: Entity, component: Entity, keep?: boolean): void;
168
177
  stop_unreliable(entity: Entity, component: Entity, keep?: boolean): void;
178
+ stop_pair(entity: Entity, id: Pair): void;
169
179
  stop_relation(entity: Entity, relation: Entity, keep?: boolean): void;
170
180
 
171
181
  set_custom(entity: Entity, handler: Entity | CustomId): void;
172
182
  remove_custom(entity: Entity): void;
183
+
184
+ set_serdes<T extends Id>(
185
+ component: InferComponent<T>,
186
+ serdes: SerdesTable<T>,
187
+ ): void;
188
+ remove_serdes(component: Id): void;
173
189
  }
174
190
 
175
191
  export interface Server extends ServerImp {
@@ -180,15 +196,20 @@ declare namespace Replecs {
180
196
  destroy(): void;
181
197
 
182
198
  encode_component(component: Entity): number;
183
- decode_component(encoded: number): Entity;
199
+ decode_component(encoded: number): Entity | undefined;
200
+ get_shared_count(): number;
201
+
184
202
  register_custom_id(custom_id: CustomId): void;
185
203
 
186
- get_full(player: Player): LuaTuple<[buffer, defined[][]?]>;
204
+ get_full(player: Player): LuaTuple<[buffer, defined[][] | undefined]>;
205
+ collect_entity(
206
+ entity: Entity,
207
+ ): IterableFunction<LuaTuple<[Player, buffer, defined[][] | undefined]>>;
187
208
  collect_updates(): IterableFunction<
188
- LuaTuple<[Player, buffer, defined[][]?]>
209
+ LuaTuple<[Player, buffer, defined[][] | undefined]>
189
210
  >;
190
211
  collect_unreliable(): IterableFunction<
191
- LuaTuple<[Player, buffer, defined[][]?]>
212
+ LuaTuple<[Player, buffer, defined[][] | undefined]>
192
213
  >;
193
214
 
194
215
  mark_player_ready(player: Player): void;
@@ -209,6 +230,12 @@ declare namespace Replecs {
209
230
 
210
231
  after_replication(callback: () => void): void;
211
232
  register_custom_id(custom_id: CustomId): void;
233
+
234
+ set_serdes<T extends Id>(
235
+ component: InferComponent<T>,
236
+ serdes: SerdesTable<T>,
237
+ ): void;
238
+ remove_serdes(component: Id): void;
212
239
  }
213
240
 
214
241
  export interface Replecs extends Components {
@@ -13,6 +13,7 @@ export type Client = client.Client
13
13
 
14
14
  type Entity = common.Entity
15
15
  type World = common.World
16
+ type Component<T = any> = common.Component<T>
16
17
 
17
18
  export type HandleContext = customid.HandleContext
18
19
  export type CustomId = customid.CustomId
@@ -26,6 +27,9 @@ export type ReplecsLib = {
26
27
 
27
28
  after_replication: (self: ReplecsLib, callback: () -> ()) -> (),
28
29
  register_custom_id: (self: ReplecsLib, custom_id: CustomId) -> (),
30
+
31
+ set_serdes: <T>(self: ReplecsLib, id: Component<T>, serdes: types.Serdes<T>) -> (),
32
+ remove_serdes: (self: ReplecsLib, id: Component) -> (),
29
33
  }
30
34
 
31
35
  type Replecs = types.Components & {
@@ -109,4 +113,22 @@ function replecs.register_custom_id(lib: ReplecsLib, custom_id: CustomId)
109
113
  end
110
114
  end
111
115
 
116
+ function replecs.set_serdes(lib: ReplecsLib, id: Component, serdes: Serdes)
117
+ if lib.server then
118
+ lib.server:set_serdes(id, serdes)
119
+ end
120
+ if lib.client then
121
+ lib.client:set_serdes(id, serdes)
122
+ end
123
+ end
124
+
125
+ function replecs.remove_serdes(lib: ReplecsLib, id: Component)
126
+ if lib.server then
127
+ lib.server:remove_serdes(id)
128
+ end
129
+ if lib.client then
130
+ lib.client:remove_serdes(id)
131
+ end
132
+ end
133
+
112
134
  return replecs :: Replecs