@ecsframework/core 0.0.1

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.
Files changed (49) hide show
  1. package/out/framework/base-system.d.ts +279 -0
  2. package/out/framework/base-system.luau +170 -0
  3. package/out/framework/components/destroyed-component.d.ts +3 -0
  4. package/out/framework/components/destroyed-component.luau +2 -0
  5. package/out/framework/components/roblox-instance-component.d.ts +3 -0
  6. package/out/framework/components/roblox-instance-component.luau +27 -0
  7. package/out/framework/decorators/component.d.ts +6 -0
  8. package/out/framework/decorators/component.luau +28 -0
  9. package/out/framework/decorators/inject-type.d.ts +15 -0
  10. package/out/framework/decorators/inject-type.luau +48 -0
  11. package/out/framework/decorators/system.d.ts +9 -0
  12. package/out/framework/decorators/system.luau +20 -0
  13. package/out/framework/decorators/tagged.d.ts +11 -0
  14. package/out/framework/decorators/tagged.luau +11 -0
  15. package/out/framework/decorators/unaffectable.d.ts +1 -0
  16. package/out/framework/decorators/unaffectable.luau +11 -0
  17. package/out/framework/dependencies-container.d.ts +21 -0
  18. package/out/framework/dependencies-container.luau +169 -0
  19. package/out/framework/flamecs/index.d.ts +4 -0
  20. package/out/framework/flamecs/init.luau +13 -0
  21. package/out/framework/flamecs/query.d.ts +55 -0
  22. package/out/framework/flamecs/query.luau +114 -0
  23. package/out/framework/flamecs/registry.d.ts +315 -0
  24. package/out/framework/flamecs/registry.luau +567 -0
  25. package/out/framework/flamecs/signal.d.ts +5 -0
  26. package/out/framework/flamecs/signal.luau +24 -0
  27. package/out/framework/flamecs/topo.d.ts +32 -0
  28. package/out/framework/flamecs/topo.luau +96 -0
  29. package/out/framework/hooks/query-change.d.ts +11 -0
  30. package/out/framework/hooks/query-change.luau +109 -0
  31. package/out/framework/hooks/use-added.d.ts +17 -0
  32. package/out/framework/hooks/use-added.luau +54 -0
  33. package/out/framework/hooks/use-changed.d.ts +17 -0
  34. package/out/framework/hooks/use-changed.luau +54 -0
  35. package/out/framework/hooks/use-event.d.ts +30 -0
  36. package/out/framework/hooks/use-event.luau +92 -0
  37. package/out/framework/hooks/use-removed.d.ts +13 -0
  38. package/out/framework/hooks/use-removed.luau +52 -0
  39. package/out/framework/hooks/use-throttle.d.ts +14 -0
  40. package/out/framework/hooks/use-throttle.luau +33 -0
  41. package/out/framework/index.d.ts +28 -0
  42. package/out/framework/init.luau +295 -0
  43. package/out/framework/systems/roblox-instance-system.d.ts +7 -0
  44. package/out/framework/systems/roblox-instance-system.luau +112 -0
  45. package/out/framework/utilities.d.ts +17 -0
  46. package/out/framework/utilities.luau +69 -0
  47. package/out/index.d.ts +19 -0
  48. package/out/init.luau +30 -0
  49. package/package.json +48 -0
@@ -0,0 +1,315 @@
1
+ import type { Modding } from "@flamework/core";
2
+ import * as ecs from "@rbxts/jecs";
3
+ import type { Signal } from "./signal";
4
+ export interface Wrap<T> {
5
+ readonly _flamecs_type: T;
6
+ }
7
+ export interface Tag extends Wrap<undefined> {
8
+ }
9
+ export interface ChildOf extends Tag {
10
+ }
11
+ export interface Wildcard extends Tag {
12
+ }
13
+ export interface Name extends Wrap<string> {
14
+ }
15
+ export type Id<T = unknown> = ecs.Id<T>;
16
+ export type Entity<T = unknown> = ecs.Entity<T>;
17
+ export type Pair<P = undefined, O = undefined> = ecs.Pair<P, O>;
18
+ export type ExtractPredicate<T> = T extends Pair<infer P, unknown> ? P : T;
19
+ export type Unwrap<T> = T extends Wrap<infer Inner> ? Inner : T;
20
+ export type ResolveValue<T> = Unwrap<ExtractPredicate<T>>;
21
+ export type ResolveValues<T> = {
22
+ [K in keyof T]: ResolveValue<T[K]>;
23
+ };
24
+ export type ComponentKey<T> = Modding.Generic<T, "id">;
25
+ export type PairKey<P, O> = Modding.Many<{
26
+ obj: ComponentKey<O extends defined ? O : Wildcard>;
27
+ pred: ComponentKey<P extends defined ? P : Wildcard>;
28
+ }>;
29
+ export type ResolveKey<T> = T extends Pair<infer P, infer O> ? PairKey<P, O> : ComponentKey<T>;
30
+ export type ResolveKeys<T> = Modding.Many<{
31
+ [K in keyof T]: ResolveKey<T[K]>;
32
+ }>;
33
+ type TrailingUndefined<T extends Array<unknown>> = T extends [...infer Rest, undefined] ? [...TrailingUndefined<Rest>, undefined?] : T;
34
+ export declare const scheduleComponent: Set<ecs.Entity<unknown>>;
35
+ export declare const worldSignals: Map<ecs.World, {
36
+ added: Map<Entity, Signal<[Entity, unknown]>>;
37
+ changed: Map<Entity, Signal<[Entity, unknown]>>;
38
+ removed: Map<Entity, Signal<[Entity]>>;
39
+ }>;
40
+ /**
41
+ * Returns a signal that fires when a component is added to an entity.
42
+ *
43
+ * @template T - The type of the component.
44
+ * @param key - Flamework autogenerated key for the component.
45
+ * @returns A signal that fires when the component is added to any entity.
46
+ * @metadata macro
47
+ */
48
+ export declare function added<T>(registery: ecs.World, key?: ComponentKey<T>): Signal<[Entity<T>, T]>;
49
+ /**
50
+ * Returns a signal that fires when a component is removed from an entity.
51
+ *
52
+ * @template T - The type of the component.
53
+ * @param key - Flamework autogenerated key for the component.
54
+ * @returns A signal that fires when the component is removed from any entity.
55
+ * @metadata macro
56
+ */
57
+ export declare function removed<T>(registery: ecs.World, key?: ComponentKey<T>): Signal<[Entity<T>]>;
58
+ /**
59
+ * Returns a signal that fires when a component's value changes on an entity.
60
+ *
61
+ * @template T - The type of the component.
62
+ * @param key - Flamework autogenerated key for the component.
63
+ * @returns A signal that fires when the component's value changes on any
64
+ * entity.
65
+ * @metadata macro
66
+ */
67
+ export declare function changed<T>(registery: ecs.World, key?: ComponentKey<T>): Signal<[Entity<T>, T]>;
68
+ export declare function hookListeners(registry: ecs.World, id: Entity): void;
69
+ /**
70
+ * Registers an existing entity to the component registry.
71
+ *
72
+ * @template T - The type of the component.
73
+ * @param runtimeId - The runtime entity to be registered.
74
+ * @param key - Flamework autogenerated key.
75
+ * @metadata macro
76
+ */
77
+ export declare function reserve<T>(registry: ecs.World | undefined, runtimeId: Entity<Unwrap<T>>, key?: ComponentKey<T>): void;
78
+ /**
79
+ * Defines a component that can be added to an entity. Components can either tag
80
+ * an entity (e.g., "this entity is an NPC"), store data for an entity (e.g.,
81
+ * "this entity is located at Vector3.new(10, 20, 30)"), or represent
82
+ * relationships between entities <Pair<P, O>> (e.g., "bob Likes alice") that
83
+ * may also store additional data (e.g., "bob Eats 10 apples").
84
+ *
85
+ * @template T - The type of the component.
86
+ * @param key - Flamework autogenerated key.
87
+ * @returns The component entity ID.
88
+ * @metadata macro
89
+ */
90
+ export declare function component<T>(registry?: ecs.World, key?: ComponentKey<T>): Entity<Unwrap<T>>;
91
+ /**
92
+ * Retrieves the ID of a component or a pair relationship.
93
+ *
94
+ * @template T - The type of the component.
95
+ * @param key - Flamework autogenerated key or pair key.
96
+ * @returns The component or pair ID.
97
+ * @metadata macro.
98
+ */
99
+ export declare function getId<T>(registry?: ecs.World, key?: ResolveKey<T>): Id<ResolveValue<T>>;
100
+ export declare function getKey<T>(runtimeId: Entity): T | undefined;
101
+ /**
102
+ * Creates a new empty entity.
103
+ *
104
+ * @returns The created entity.
105
+ * @metadata macro
106
+ */
107
+ export declare function spawn(registry: ecs.World): ecs.Tag;
108
+ /**
109
+ * Creates a new entity with the specified tag components.
110
+ *
111
+ * @template T - The type of the components.
112
+ * @param keys - Flamework autogenerated keys.
113
+ * @returns The created entity.
114
+ * @metadata macro
115
+ */
116
+ export declare function spawn<T extends Array<Tag>>(registry: ecs.World, keys?: ResolveKeys<T>): ecs.Tag;
117
+ /**
118
+ * Creates a new entity with the specified components and their values.
119
+ *
120
+ * @template T - The type of the components.
121
+ * @param values - The values to set for the components.
122
+ * @param keys - Flamework autogenerated keys.
123
+ * @returns The created entity.
124
+ * @metadata macro
125
+ */
126
+ export declare function spawn<T extends Array<unknown>>(registry: ecs.World, values: TrailingUndefined<ResolveValues<T>>, keys?: ResolveKeys<T>): ecs.Tag;
127
+ /**
128
+ * Deletes the specified entity and all associated components.
129
+ *
130
+ * @param entity - The entity to delete.
131
+ */
132
+ export declare function despawn(registry: ecs.World, entity: Entity): void;
133
+ /**
134
+ * Adds or updates multiple components for the specified entity.
135
+ *
136
+ * @template T - The type of the components.
137
+ * @param entity - The entity to modify.
138
+ * @param keys - Flamework autogenerated keys.
139
+ * @metadata macro
140
+ */
141
+ export declare function insert<T extends Array<Tag>>(registry: ecs.World, entity: Entity, keys?: ResolveKeys<T>): void;
142
+ /**
143
+ * Adds or updates multiple components for the specified entity.
144
+ *
145
+ * @template T - The type of the components.
146
+ * @param entity - The entity to modify.
147
+ * @param values - The values to set for the components.
148
+ * @param keys - Flamework autogenerated keys.
149
+ * @metadata macro
150
+ */
151
+ export declare function insert<T extends Array<unknown>>(registry: ecs.World, entity: Entity, values: TrailingUndefined<ResolveValues<T>>, keys?: ResolveKeys<T>): void;
152
+ /**
153
+ * Adds a pair relationship with a specific target entity.
154
+ *
155
+ * @template T - The type of the pair.
156
+ * @param entity - The entity to which the pair relationship is added.
157
+ * @param object - The target entity of the relationship (object of the pair).
158
+ * @param key - Flamework autogenerated key.
159
+ * @metadata macro
160
+ */
161
+ export declare function add<T extends Pair<Tag>>(registry: ecs.World, entity: Entity, object: Entity, key?: ComponentKey<ExtractPredicate<T>>): void;
162
+ /**
163
+ * Adds a fully defined pair to an entity. This is used when both the predicate
164
+ * and object of the pair are known at compile-time.
165
+ *
166
+ * @template T - The type of the pair.
167
+ * @param entity - The entity to which the pair component is added.
168
+ * @param key - Flamework autogenerated key.
169
+ * @metadata macro
170
+ */
171
+ export declare function add<T extends Pair<Tag, defined>>(registry: ecs.World, entity: Entity, key?: ResolveKey<T>): void;
172
+ /**
173
+ * Adds a component to an entity.
174
+ *
175
+ * @template T - The type of the component.
176
+ * @param entity - The entity to which the component is added.
177
+ * @param key - Flamework autogenerated key.
178
+ * @metadata macro
179
+ */
180
+ export declare function add<T extends Tag>(registry: ecs.World, entity: Entity, key?: ComponentKey<T>): void;
181
+ /**
182
+ * Removes a pair relationship with a specific target entity.
183
+ *
184
+ * @template T - The type of the pair.
185
+ * @param entity - The entity from which the pair relationship is removed.
186
+ * @param object - The target entity of the relationship (object of the pair).
187
+ * @param key - Flamework autogenerated key.
188
+ * @metadata macro
189
+ */
190
+ export declare function remove<T extends Pair<defined>>(registry: ecs.World, entity: Entity, object: Entity, key?: ComponentKey<ExtractPredicate<T>>): void;
191
+ /**
192
+ * Removes a fully defined pair from an entity. This is used when both the
193
+ * predicate and object of the pair are known at compile-time.
194
+ *
195
+ * @template T - The type of the pair.
196
+ * @param entity - The entity from which the pair component is removed.
197
+ * @param key - Flamework autogenerated key.
198
+ * @metadata macro
199
+ */
200
+ export declare function remove<T extends Pair<defined, defined>>(registry: ecs.World, entity: Entity, key?: ResolveKey<T>): void;
201
+ /**
202
+ * Removes a component from an entity.
203
+ *
204
+ * @template T - The type of the component.
205
+ * @param entity - The entity from which the component is removed.
206
+ * @param key - Flamework autogenerated key.
207
+ * @metadata macro
208
+ */
209
+ export declare function remove<T>(registry: ecs.World, entity: Entity, key?: ComponentKey<T>): void;
210
+ /**
211
+ * Sets a value for a pair with a specific runtime target entity.
212
+ *
213
+ * @template T - The type of the pair.
214
+ * @param entity - The entity to which the pair relationship is added.
215
+ * @param object - The target entity of the relationship (object of the pair).
216
+ * @param value - The value associated with the pair relationship.
217
+ * @param key - Flamework autogenerated key.
218
+ * @metadata macro
219
+ */
220
+ export declare function set<T extends Pair<defined>>(registry: ecs.World, entity: Entity, object: Entity, value: ResolveValue<T>, key?: ComponentKey<ExtractPredicate<T>>): void;
221
+ /**
222
+ * Sets a value for a fully defined pair on an entity. This is used when both
223
+ * the predicate and object of the pair are known at compile-time.
224
+ *
225
+ * @template T - The type of the pair.
226
+ * @param entity - The entity to which the pair component is added.
227
+ * @param value - The value associated with the pair component.
228
+ * @param key - Flamework autogenerated key.
229
+ * @metadata macro
230
+ */
231
+ export declare function set<T extends Pair<defined, defined>>(registry: ecs.World, entity: Entity, value: ResolveValue<T>, key?: ResolveKey<T>): void;
232
+ /**
233
+ * Sets a value for a component on an entity.
234
+ *
235
+ * @template T - The type of the component.
236
+ * @param entity - The entity to which the component is added or updated.
237
+ * @param value - The value associated with the component.
238
+ * @param key - Flamework autogenerated key.
239
+ * @metadata macro
240
+ */
241
+ export declare function set<T>(registry: ecs.World, entity: Entity, value: Unwrap<T>, key?: ComponentKey<T>): void;
242
+ /**
243
+ * Retrieves the value of a pair relationship for a specific entity and target.
244
+ *
245
+ * @template T - The type of the pair.
246
+ * @param entity - The entity from which to retrieve the pair relationship.
247
+ * @param object - The target entity of the relationship (object of the pair).
248
+ * @param key - Flamework autogenerated key.
249
+ * @returns The value associated with the pair relationship.
250
+ * @metadata macro
251
+ */
252
+ export declare function get<T extends Pair<defined>>(registry: ecs.World, entity: Entity, object: Entity, key?: ComponentKey<ExtractPredicate<T>>): ResolveValue<T> | undefined;
253
+ /**
254
+ * Retrieves the value of a component or pair for a specific entity.
255
+ *
256
+ * @template T - The type of the component or pair.
257
+ * @param entity - The entity from which to retrieve the component or pair.
258
+ * @param key - Flamework autogenerated key.
259
+ * @returns The value associated with the component or pair.
260
+ * @metadata macro
261
+ */
262
+ export declare function get<T>(registry: ecs.World, entity: Entity, key?: ResolveKey<T>): ResolveValue<T> | undefined;
263
+ /**
264
+ * Checks if a pair relationship exists for a specific entity and target.
265
+ *
266
+ * @template T - The type of the pair.
267
+ * @param entity - The entity to check for the pair relationship.
268
+ * @param object - The target entity of the relationship (object of the pair).
269
+ * @param key - Flamework autogenerated key.
270
+ * @returns True if the pair relationship exists, false otherwise.
271
+ * @metadata macro
272
+ */
273
+ export declare function has<T extends Pair<defined>>(registry: ecs.World, entity: Entity, object: Entity, key?: ComponentKey<ExtractPredicate<T>>): boolean;
274
+ /**
275
+ * Checks if a component or pair exists for a specific entity.
276
+ *
277
+ * @template T - The type of the component or pair.
278
+ * @param entity - The entity to check for the component or pair.
279
+ * @param key - Flamework autogenerated key.
280
+ * @returns True if the component or pair exists, false otherwise.
281
+ * @metadata macro
282
+ */
283
+ export declare function has<T>(registry: ecs.World, entity: Entity, key?: ResolveKey<T>): boolean;
284
+ /**
285
+ * Retrieves the target entity of a relationship involving the specified entity
286
+ * and component.
287
+ *
288
+ * @template T - The type of the component.
289
+ * @param entity - The entity to get the target for.
290
+ * @param key - Flamework autogenerated key.
291
+ * @returns The target entity if a relationship exists, or undefined otherwise.
292
+ * @metadata macro
293
+ */
294
+ export declare function target<T>(registry: ecs.World, entity: Entity, key?: ComponentKey<T>): Entity | undefined;
295
+ /**
296
+ * Retrieves the parent entity (target of the ChildOf relationship) for the
297
+ * given entity.
298
+ *
299
+ * @param entity - The entity for which to get the parent.
300
+ * @returns The parent entity, or undefined if no parent exists.
301
+ */
302
+ export declare function parent(registry: ecs.World, entity: Entity): Entity | undefined;
303
+ /**
304
+ * Creates a pair relationship between a component and an entity.
305
+ *
306
+ * @template P - The type of the predicate component.
307
+ * @template O - The type of the object component.
308
+ * @param object - The object entity.
309
+ * @param predicate - The predicate component key.
310
+ * @returns The pair ID.
311
+ * @metadata macro
312
+ */
313
+ export declare function pair<P>(registry: ecs.World, object: Entity, predicate?: ComponentKey<P>): Pair<Unwrap<P>, unknown>;
314
+ export declare function initWorld(registry: ecs.World): void;
315
+ export {};