@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.
- package/out/framework/base-system.d.ts +279 -0
- package/out/framework/base-system.luau +170 -0
- package/out/framework/components/destroyed-component.d.ts +3 -0
- package/out/framework/components/destroyed-component.luau +2 -0
- package/out/framework/components/roblox-instance-component.d.ts +3 -0
- package/out/framework/components/roblox-instance-component.luau +27 -0
- package/out/framework/decorators/component.d.ts +6 -0
- package/out/framework/decorators/component.luau +28 -0
- package/out/framework/decorators/inject-type.d.ts +15 -0
- package/out/framework/decorators/inject-type.luau +48 -0
- package/out/framework/decorators/system.d.ts +9 -0
- package/out/framework/decorators/system.luau +20 -0
- package/out/framework/decorators/tagged.d.ts +11 -0
- package/out/framework/decorators/tagged.luau +11 -0
- package/out/framework/decorators/unaffectable.d.ts +1 -0
- package/out/framework/decorators/unaffectable.luau +11 -0
- package/out/framework/dependencies-container.d.ts +21 -0
- package/out/framework/dependencies-container.luau +169 -0
- package/out/framework/flamecs/index.d.ts +4 -0
- package/out/framework/flamecs/init.luau +13 -0
- package/out/framework/flamecs/query.d.ts +55 -0
- package/out/framework/flamecs/query.luau +114 -0
- package/out/framework/flamecs/registry.d.ts +315 -0
- package/out/framework/flamecs/registry.luau +567 -0
- package/out/framework/flamecs/signal.d.ts +5 -0
- package/out/framework/flamecs/signal.luau +24 -0
- package/out/framework/flamecs/topo.d.ts +32 -0
- package/out/framework/flamecs/topo.luau +96 -0
- package/out/framework/hooks/query-change.d.ts +11 -0
- package/out/framework/hooks/query-change.luau +109 -0
- package/out/framework/hooks/use-added.d.ts +17 -0
- package/out/framework/hooks/use-added.luau +54 -0
- package/out/framework/hooks/use-changed.d.ts +17 -0
- package/out/framework/hooks/use-changed.luau +54 -0
- package/out/framework/hooks/use-event.d.ts +30 -0
- package/out/framework/hooks/use-event.luau +92 -0
- package/out/framework/hooks/use-removed.d.ts +13 -0
- package/out/framework/hooks/use-removed.luau +52 -0
- package/out/framework/hooks/use-throttle.d.ts +14 -0
- package/out/framework/hooks/use-throttle.luau +33 -0
- package/out/framework/index.d.ts +28 -0
- package/out/framework/init.luau +295 -0
- package/out/framework/systems/roblox-instance-system.d.ts +7 -0
- package/out/framework/systems/roblox-instance-system.luau +112 -0
- package/out/framework/utilities.d.ts +17 -0
- package/out/framework/utilities.luau +69 -0
- package/out/index.d.ts +19 -0
- package/out/init.luau +30 -0
- package/package.json +48 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { Modding } from "@flamework/core";
|
|
2
|
+
import { Constructor } from "@flamework/core/out/utility";
|
|
3
|
+
import jecs, { Entity, Id } from "@rbxts/jecs";
|
|
4
|
+
import { Calculate, ExtractQueryTypes, QueryHandle, ToIds } from "./flamecs";
|
|
5
|
+
import { ComponentKey, ExtractPredicate, Pair, ResolveKey, ResolveKeys, ResolveValue, ResolveValues, Tag, Unwrap } from "./flamecs/registry";
|
|
6
|
+
import { Signal } from "./flamecs/signal";
|
|
7
|
+
import { WritableDraft } from "@rbxts/immut/src/types-external";
|
|
8
|
+
type TrailingUndefined<T extends Array<unknown>> = T extends [...infer Rest, undefined] ? [...TrailingUndefined<Rest>, undefined?] : T;
|
|
9
|
+
/** @metadata reflect identifier */
|
|
10
|
+
export declare abstract class BaseSystem {
|
|
11
|
+
protected readonly world: jecs.World;
|
|
12
|
+
private framework;
|
|
13
|
+
/** @hidden */
|
|
14
|
+
__hookStates: {};
|
|
15
|
+
constructor();
|
|
16
|
+
/**
|
|
17
|
+
* Adds a pair relationship with a specific target entity.
|
|
18
|
+
*
|
|
19
|
+
* @template T - The type of the pair.
|
|
20
|
+
* @param entity - The entity to which the pair relationship is added.
|
|
21
|
+
* @param object - The target entity of the relationship (object of the pair).
|
|
22
|
+
* @param key - Flamework autogenerated key.
|
|
23
|
+
* @metadata macro
|
|
24
|
+
*/
|
|
25
|
+
AddComponent<T extends Pair<Tag>>(entity: Entity, object: Entity, key?: ComponentKey<ExtractPredicate<T>>): void;
|
|
26
|
+
/**
|
|
27
|
+
* Adds a fully defined pair to an entity. This is used when both the predicate
|
|
28
|
+
* and object of the pair are known at compile-time.
|
|
29
|
+
*
|
|
30
|
+
* @template T - The type of the pair.
|
|
31
|
+
* @param entity - The entity to which the pair component is added.
|
|
32
|
+
* @param key - Flamework autogenerated key.
|
|
33
|
+
* @metadata macro
|
|
34
|
+
*/
|
|
35
|
+
AddComponent<T extends Pair<Tag, defined>>(entity: Entity, key?: ResolveKey<T>): void;
|
|
36
|
+
/**
|
|
37
|
+
* Adds a component to an entity.
|
|
38
|
+
*
|
|
39
|
+
* @template T - The type of the component.
|
|
40
|
+
* @param entity - The entity to which the component is added.
|
|
41
|
+
* @param key - Flamework autogenerated key.
|
|
42
|
+
* @metadata macro
|
|
43
|
+
*/
|
|
44
|
+
AddComponent<T extends Tag>(entity: Entity, key?: ComponentKey<T>): void;
|
|
45
|
+
/**
|
|
46
|
+
* Sets a value for a pair with a specific runtime target entity.
|
|
47
|
+
*
|
|
48
|
+
* @template T - The type of the pair.
|
|
49
|
+
* @param entity - The entity to which the pair relationship is added.
|
|
50
|
+
* @param object - The target entity of the relationship (object of the pair).
|
|
51
|
+
* @param value - The value associated with the pair relationship.
|
|
52
|
+
* @param key - Flamework autogenerated key.
|
|
53
|
+
* @metadata macro
|
|
54
|
+
*/
|
|
55
|
+
SetComponent<T extends Pair<defined>>(entity: Entity, object: Entity, value: ResolveValue<T>, key?: ComponentKey<ExtractPredicate<T>>): void;
|
|
56
|
+
/**
|
|
57
|
+
* Sets a value for a fully defined pair on an entity. This is used when both
|
|
58
|
+
* the predicate and object of the pair are known at compile-time.
|
|
59
|
+
*
|
|
60
|
+
* @template T - The type of the pair.
|
|
61
|
+
* @param entity - The entity to which the pair component is added.
|
|
62
|
+
* @param value - The value associated with the pair component.
|
|
63
|
+
* @param key - Flamework autogenerated key.
|
|
64
|
+
* @metadata macro
|
|
65
|
+
*/
|
|
66
|
+
SetComponent<T extends Pair<defined, defined>>(entity: Entity, value: ResolveValue<T>, key?: ResolveKey<T>): void;
|
|
67
|
+
/**
|
|
68
|
+
* Sets a value for a component on an entity.
|
|
69
|
+
*
|
|
70
|
+
* @template T - The type of the component.
|
|
71
|
+
* @param entity - The entity to which the component is added or updated.
|
|
72
|
+
* @param value - The value associated with the component.
|
|
73
|
+
* @param key - Flamework autogenerated key.
|
|
74
|
+
* @metadata macro
|
|
75
|
+
*/
|
|
76
|
+
SetComponent<T>(entity: Entity, value: Unwrap<T>, key?: ComponentKey<T>): void;
|
|
77
|
+
/**
|
|
78
|
+
* Sets a value for a component on an entity.
|
|
79
|
+
*
|
|
80
|
+
* @template T - The type of the component.
|
|
81
|
+
* @param entity - The entity to which the component is added or updated.
|
|
82
|
+
* @param value - The value associated with the component.
|
|
83
|
+
* @param key - Flamework autogenerated key.
|
|
84
|
+
* @metadata macro
|
|
85
|
+
*/
|
|
86
|
+
SetComponent<T>(entity: Entity, value: Partial<T>, key?: ComponentKey<T>): void;
|
|
87
|
+
/** @metadata macro */
|
|
88
|
+
MutateComponent<T>(entity: Entity, onMutate: (darft: WritableDraft<Unwrap<T>>, original: Unwrap<T>) => void, key?: ComponentKey<T>): void;
|
|
89
|
+
/**
|
|
90
|
+
* Adds or updates multiple components for the specified entity.
|
|
91
|
+
*
|
|
92
|
+
* @template T - The type of the components.
|
|
93
|
+
* @param entity - The entity to modify.
|
|
94
|
+
* @param keys - Flamework autogenerated keys.
|
|
95
|
+
* @metadata macro
|
|
96
|
+
*/
|
|
97
|
+
InsertComponents<T extends Array<Tag>>(entity: Entity, keys?: ResolveKeys<T>): void;
|
|
98
|
+
/**
|
|
99
|
+
* Adds or updates multiple components for the specified entity.
|
|
100
|
+
*
|
|
101
|
+
* @template T - The type of the components.
|
|
102
|
+
* @param entity - The entity to modify.
|
|
103
|
+
* @param values - The values to set for the components.
|
|
104
|
+
* @param keys - Flamework autogenerated keys.
|
|
105
|
+
* @metadata macro
|
|
106
|
+
*/
|
|
107
|
+
InsertComponents<T extends Array<unknown>>(entity: Entity, values: TrailingUndefined<ResolveValues<T>>, keys?: ResolveKeys<T>): void;
|
|
108
|
+
/**
|
|
109
|
+
* Removes a pair relationship with a specific target entity.
|
|
110
|
+
*
|
|
111
|
+
* @template T - The type of the pair.
|
|
112
|
+
* @param entity - The entity from which the pair relationship is removed.
|
|
113
|
+
* @param object - The target entity of the relationship (object of the pair).
|
|
114
|
+
* @param key - Flamework autogenerated key.
|
|
115
|
+
* @metadata macro
|
|
116
|
+
*/
|
|
117
|
+
RemoveComponent<T extends Pair<defined>>(entity: Entity, object: Entity, key?: ComponentKey<ExtractPredicate<T>>): void;
|
|
118
|
+
/**
|
|
119
|
+
* Removes a fully defined pair from an entity. This is used when both the
|
|
120
|
+
* predicate and object of the pair are known at compile-time.
|
|
121
|
+
*
|
|
122
|
+
* @template T - The type of the pair.
|
|
123
|
+
* @param entity - The entity from which the pair component is removed.
|
|
124
|
+
* @param key - Flamework autogenerated key.
|
|
125
|
+
* @metadata macro
|
|
126
|
+
*/
|
|
127
|
+
RemoveComponent<T extends Pair<defined, defined>>(entity: Entity, key?: ResolveKey<T>): void;
|
|
128
|
+
/**
|
|
129
|
+
* Removes a component from an entity.
|
|
130
|
+
*
|
|
131
|
+
* @template T - The type of the component.
|
|
132
|
+
* @param entity - The entity from which the component is removed.
|
|
133
|
+
* @param key - Flamework autogenerated key.
|
|
134
|
+
* @metadata macro
|
|
135
|
+
*/
|
|
136
|
+
RemoveComponent<T>(entity: Entity, key?: ComponentKey<T>): void;
|
|
137
|
+
/**
|
|
138
|
+
* Retrieves the value of a pair relationship for a specific entity and target.
|
|
139
|
+
*
|
|
140
|
+
* @template T - The type of the pair.
|
|
141
|
+
* @param entity - The entity from which to retrieve the pair relationship.
|
|
142
|
+
* @param object - The target entity of the relationship (object of the pair).
|
|
143
|
+
* @param key - Flamework autogenerated key.
|
|
144
|
+
* @returns The value associated with the pair relationship.
|
|
145
|
+
* @metadata macro
|
|
146
|
+
*/
|
|
147
|
+
GetComponent<T extends Pair<defined>>(entity: Entity, object: Entity, key?: ComponentKey<ExtractPredicate<T>>): ResolveValue<T> | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* Retrieves the value of a component or pair for a specific entity.
|
|
150
|
+
*
|
|
151
|
+
* @template T - The type of the component or pair.
|
|
152
|
+
* @param entity - The entity from which to retrieve the component or pair.
|
|
153
|
+
* @param key - Flamework autogenerated key.
|
|
154
|
+
* @returns The value associated with the component or pair.
|
|
155
|
+
* @metadata macro
|
|
156
|
+
*/
|
|
157
|
+
GetComponent<T>(entity: Entity, key?: ResolveKey<T>): ResolveValue<T> | undefined;
|
|
158
|
+
/**
|
|
159
|
+
* Checks if a pair relationship exists for a specific entity and target.
|
|
160
|
+
*
|
|
161
|
+
* @template T - The type of the pair.
|
|
162
|
+
* @param entity - The entity to check for the pair relationship.
|
|
163
|
+
* @param object - The target entity of the relationship (object of the pair).
|
|
164
|
+
* @param key - Flamework autogenerated key.
|
|
165
|
+
* @returns True if the pair relationship exists, false otherwise.
|
|
166
|
+
* @metadata macro
|
|
167
|
+
*/
|
|
168
|
+
HasComponent<T extends Pair<defined>>(entity: Entity, object: Entity, key?: ComponentKey<ExtractPredicate<T>>): boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Checks if a component or pair exists for a specific entity.
|
|
171
|
+
*
|
|
172
|
+
* @template T - The type of the component or pair.
|
|
173
|
+
* @param entity - The entity to check for the component or pair.
|
|
174
|
+
* @param key - Flamework autogenerated key.
|
|
175
|
+
* @returns True if the component or pair exists, false otherwise.
|
|
176
|
+
* @metadata macro
|
|
177
|
+
*/
|
|
178
|
+
HasComponent<T>(entity: Entity, key?: ResolveKey<T>): boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Retrieves the target entity of a relationship involving the specified entity
|
|
181
|
+
* and component.
|
|
182
|
+
*
|
|
183
|
+
* @template T - The type of the component.
|
|
184
|
+
* @param entity - The entity to get the target for.
|
|
185
|
+
* @param key - Flamework autogenerated key.
|
|
186
|
+
* @returns The target entity if a relationship exists, or undefined otherwise.
|
|
187
|
+
* @metadata macro
|
|
188
|
+
*/
|
|
189
|
+
TargetComponent<T>(entity: Entity, key?: ComponentKey<T>): Entity | undefined;
|
|
190
|
+
/**
|
|
191
|
+
* Retrieves the parent entity (target of the ChildOf relationship) for the
|
|
192
|
+
* given entity.
|
|
193
|
+
*
|
|
194
|
+
* @param entity - The entity for which to get the parent.
|
|
195
|
+
* @returns The parent entity, or undefined if no parent exists.
|
|
196
|
+
*/
|
|
197
|
+
ParentComponent(entity: Entity): Entity | undefined;
|
|
198
|
+
GetAllClassComponents(): Constructor[];
|
|
199
|
+
/** @metadata macro */
|
|
200
|
+
GetClassComponent<T>(key?: ComponentKey<T>): Constructor;
|
|
201
|
+
/**
|
|
202
|
+
* Retrieves the ID of a component or a pair relationship.
|
|
203
|
+
*
|
|
204
|
+
* @template T - The type of the component.
|
|
205
|
+
* @param key - Flamework autogenerated key or pair key.
|
|
206
|
+
* @returns The component or pair ID.
|
|
207
|
+
* @metadata macro.
|
|
208
|
+
*/
|
|
209
|
+
GetComponentId<T>(key?: ResolveKey<T>): Id<ResolveValue<T>>;
|
|
210
|
+
ClearAllComponents(entity: jecs.Entity): void;
|
|
211
|
+
/**
|
|
212
|
+
* Returns a signal that fires when a component is added to an entity.
|
|
213
|
+
*
|
|
214
|
+
* @template T - The type of the component.
|
|
215
|
+
* @param key - Flamework autogenerated key for the component.
|
|
216
|
+
* @returns A signal that fires when the component is added to any entity.
|
|
217
|
+
* @metadata macro
|
|
218
|
+
*/
|
|
219
|
+
Added<T>(key?: ComponentKey<T>): Signal<[entity: Entity<T>, data: T]>;
|
|
220
|
+
/**
|
|
221
|
+
* Returns a signal that fires when a component is removed from an entity.
|
|
222
|
+
*
|
|
223
|
+
* @template T - The type of the component.
|
|
224
|
+
* @param key - Flamework autogenerated key for the component.
|
|
225
|
+
* @returns A signal that fires when the component is removed from any entity.
|
|
226
|
+
* @metadata macro
|
|
227
|
+
*/
|
|
228
|
+
Removed<T>(key?: ComponentKey<T>): Signal<[Entity<T>]>;
|
|
229
|
+
/**
|
|
230
|
+
* Returns a signal that fires when a component's value changes on an entity.
|
|
231
|
+
*
|
|
232
|
+
* @template T - The type of the component.
|
|
233
|
+
* @param key - Flamework autogenerated key for the component.
|
|
234
|
+
* @returns A signal that fires when the component's value changes on any
|
|
235
|
+
* entity.
|
|
236
|
+
* @metadata macro
|
|
237
|
+
*/
|
|
238
|
+
Changed<T>(key?: ComponentKey<T>): Signal<[Entity<T>, T]>;
|
|
239
|
+
GetComponentKey<T>(runtimeId: Entity): T | undefined;
|
|
240
|
+
private createComponentData;
|
|
241
|
+
/**
|
|
242
|
+
* Creates a new empty entity.
|
|
243
|
+
*
|
|
244
|
+
* @returns The created entity.
|
|
245
|
+
* @metadata macro
|
|
246
|
+
*/
|
|
247
|
+
SpawnEntity(): jecs.Tag;
|
|
248
|
+
/**
|
|
249
|
+
* Creates a new entity with the specified tag components.
|
|
250
|
+
*
|
|
251
|
+
* @template T - The type of the components.
|
|
252
|
+
* @param keys - Flamework autogenerated keys.
|
|
253
|
+
* @returns The created entity.
|
|
254
|
+
* @metadata macro
|
|
255
|
+
*/
|
|
256
|
+
SpawnEntity<T extends Array<Tag>>(keys?: ResolveKeys<T>): jecs.Tag;
|
|
257
|
+
/**
|
|
258
|
+
* Creates a new entity with the specified components and their values.
|
|
259
|
+
*
|
|
260
|
+
* @template T - The type of the components.
|
|
261
|
+
* @param values - The values to set for the components.
|
|
262
|
+
* @param keys - Flamework autogenerated keys.
|
|
263
|
+
* @returns The created entity.
|
|
264
|
+
* @metadata macro
|
|
265
|
+
*/
|
|
266
|
+
SpawnEntity<T extends Array<unknown>>(values: TrailingUndefined<Partial<ResolveValues<T>>>, keys?: ResolveKeys<T>): jecs.Tag;
|
|
267
|
+
ExistEntity(entity: jecs.Entity): boolean;
|
|
268
|
+
DespawnEntity(entity: jecs.Entity): void;
|
|
269
|
+
/** @metadata macro */
|
|
270
|
+
Query<T extends Array<unknown> = []>(terms?: ToIds<Calculate<T>["query"]>, filterWithout?: ToIds<Calculate<T>["without"]>, filterWith?: ToIds<Calculate<T>["with"]>): QueryHandle<ExtractQueryTypes<T>>;
|
|
271
|
+
/** @metadata macro */
|
|
272
|
+
QueryChange<T>(componentTypeId?: ComponentKey<T>, key?: Modding.Caller<"uuid">): IterableFunction<[entity: jecs.Entity, record: import("./hooks/query-change").QueryRecord<T>, isDestroyedEntity: boolean]>;
|
|
273
|
+
/** @metadata macro */
|
|
274
|
+
Each<T>(key?: ResolveKey<T>): IterableFunction<jecs.Entity<unknown>>;
|
|
275
|
+
OnStartup(): void;
|
|
276
|
+
OnUpdate(): void;
|
|
277
|
+
OnEffect(): void;
|
|
278
|
+
}
|
|
279
|
+
export {};
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local Reflect = TS.import(script, TS.getModule(script, "@flamework", "core").out).Reflect
|
|
4
|
+
local query = TS.import(script, script.Parent, "flamecs").query
|
|
5
|
+
local _registry = TS.import(script, script.Parent, "flamecs", "registry")
|
|
6
|
+
local add = _registry.add
|
|
7
|
+
local added = _registry.added
|
|
8
|
+
local changed = _registry.changed
|
|
9
|
+
local get = _registry.get
|
|
10
|
+
local getId = _registry.getId
|
|
11
|
+
local getKey = _registry.getKey
|
|
12
|
+
local has = _registry.has
|
|
13
|
+
local insert = _registry.insert
|
|
14
|
+
local remove = _registry.remove
|
|
15
|
+
local removed = _registry.removed
|
|
16
|
+
local set = _registry.set
|
|
17
|
+
local target = _registry.target
|
|
18
|
+
local InjectType = TS.import(script, script.Parent, "decorators", "inject-type").InjectType
|
|
19
|
+
local QueryChange = TS.import(script, script.Parent, "hooks", "query-change").QueryChange
|
|
20
|
+
local produce = TS.import(script, TS.getModule(script, "@rbxts", "immut").src).produce
|
|
21
|
+
--* @metadata reflect identifier
|
|
22
|
+
local BaseSystem
|
|
23
|
+
do
|
|
24
|
+
BaseSystem = {}
|
|
25
|
+
function BaseSystem:constructor()
|
|
26
|
+
self.__hookStates = {}
|
|
27
|
+
end
|
|
28
|
+
function BaseSystem:AddComponent(entity, argument1, argument2)
|
|
29
|
+
return add(self.world, entity, argument1, argument2)
|
|
30
|
+
end
|
|
31
|
+
function BaseSystem:SetComponent(entity, argument1, argument2, argument3)
|
|
32
|
+
local classComponent = self:GetClassComponent(argument2)
|
|
33
|
+
if argument3 == nil and classComponent ~= nil then
|
|
34
|
+
-- Case class component
|
|
35
|
+
local value = self:createComponentData(classComponent, argument1)
|
|
36
|
+
return set(self.world, entity, value, argument2)
|
|
37
|
+
end
|
|
38
|
+
return set(self.world, entity, argument1, argument2, argument3)
|
|
39
|
+
end
|
|
40
|
+
function BaseSystem:MutateComponent(entity, onMutate, key)
|
|
41
|
+
local data = self:GetComponent(entity, key)
|
|
42
|
+
if not (data ~= 0 and data == data and data ~= "" and data) then
|
|
43
|
+
error(`Component {key} does not exist on entity {entity}.`)
|
|
44
|
+
end
|
|
45
|
+
self:SetComponent(entity, produce(data, function(draft)
|
|
46
|
+
return onMutate(draft, data)
|
|
47
|
+
end), key)
|
|
48
|
+
end
|
|
49
|
+
function BaseSystem:InsertComponents(entity, argument1, argument2)
|
|
50
|
+
local _arg0 = argument1 ~= nil
|
|
51
|
+
assert(_arg0)
|
|
52
|
+
if argument2 ~= nil then
|
|
53
|
+
-- Insert components: insert(entity, values, keys)
|
|
54
|
+
local values = argument1
|
|
55
|
+
local keys = argument2
|
|
56
|
+
local newValues = {}
|
|
57
|
+
for index = 0, #keys - 1 do
|
|
58
|
+
local componentClass = self:GetClassComponent(keys[index + 1])
|
|
59
|
+
if componentClass == nil then
|
|
60
|
+
newValues[index + 1] = values[index + 1]
|
|
61
|
+
continue
|
|
62
|
+
end
|
|
63
|
+
local newData = self:createComponentData(componentClass, values[index + 1])
|
|
64
|
+
newValues[index + 1] = newData
|
|
65
|
+
end
|
|
66
|
+
return insert(self.world, entity, newValues, keys)
|
|
67
|
+
end
|
|
68
|
+
return insert(self.world, entity, argument1, argument2)
|
|
69
|
+
end
|
|
70
|
+
function BaseSystem:RemoveComponent(entity, argument1, argument2)
|
|
71
|
+
return remove(self.world, entity, argument1, argument2)
|
|
72
|
+
end
|
|
73
|
+
function BaseSystem:GetComponent(entity, argument1, argument2)
|
|
74
|
+
return get(self.world, entity, argument1, argument2)
|
|
75
|
+
end
|
|
76
|
+
function BaseSystem:HasComponent(entity, argument1, argument2)
|
|
77
|
+
return has(self.world, entity, argument1, argument2)
|
|
78
|
+
end
|
|
79
|
+
function BaseSystem:TargetComponent(entity, key)
|
|
80
|
+
return target(self.world, entity, key)
|
|
81
|
+
end
|
|
82
|
+
function BaseSystem:ParentComponent(entity)
|
|
83
|
+
return target(self.world, entity, "$ecsframework:core:framework/flamecs/registry@ChildOf")
|
|
84
|
+
end
|
|
85
|
+
function BaseSystem:GetAllClassComponents()
|
|
86
|
+
return Reflect.getOwnMetadata(getmetatable(self), "ECSFramework:Components") or ({})
|
|
87
|
+
end
|
|
88
|
+
function BaseSystem:GetClassComponent(key)
|
|
89
|
+
local _componentsMap = self.framework.componentsMap
|
|
90
|
+
local _key = key
|
|
91
|
+
local ctor = _componentsMap[_key]
|
|
92
|
+
if not ctor then
|
|
93
|
+
error(`Component {key} does not exist.`)
|
|
94
|
+
end
|
|
95
|
+
return ctor
|
|
96
|
+
end
|
|
97
|
+
function BaseSystem:GetComponentId(key)
|
|
98
|
+
return getId(self.world, key)
|
|
99
|
+
end
|
|
100
|
+
function BaseSystem:ClearAllComponents(entity)
|
|
101
|
+
self.world:clear(entity)
|
|
102
|
+
end
|
|
103
|
+
function BaseSystem:Added(key)
|
|
104
|
+
return added(self.world, key)
|
|
105
|
+
end
|
|
106
|
+
function BaseSystem:Removed(key)
|
|
107
|
+
return removed(self.world, key)
|
|
108
|
+
end
|
|
109
|
+
function BaseSystem:Changed(key)
|
|
110
|
+
return changed(self.world, key)
|
|
111
|
+
end
|
|
112
|
+
function BaseSystem:GetComponentKey(runtimeId)
|
|
113
|
+
return getKey(runtimeId)
|
|
114
|
+
end
|
|
115
|
+
function BaseSystem:createComponentData(ctor, addtitionalData)
|
|
116
|
+
local finalData = {}
|
|
117
|
+
ctor.constructor(finalData)
|
|
118
|
+
if addtitionalData ~= nil then
|
|
119
|
+
for key, _ in pairs(addtitionalData) do
|
|
120
|
+
finalData[key] = addtitionalData[key]
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
return finalData
|
|
124
|
+
end
|
|
125
|
+
function BaseSystem:SpawnEntity(argument1, argument2)
|
|
126
|
+
local entity = self.world:entity()
|
|
127
|
+
if argument1 == nil and argument2 == nil then
|
|
128
|
+
return entity
|
|
129
|
+
end
|
|
130
|
+
self:InsertComponents(entity, argument1, argument2)
|
|
131
|
+
return entity
|
|
132
|
+
end
|
|
133
|
+
function BaseSystem:ExistEntity(entity)
|
|
134
|
+
return self.world:exists(entity)
|
|
135
|
+
end
|
|
136
|
+
function BaseSystem:DespawnEntity(entity)
|
|
137
|
+
self:AddComponent(entity, "$ecsframework:core:framework/components/destroyed-component@DestroyComponent")
|
|
138
|
+
self.world:delete(entity)
|
|
139
|
+
end
|
|
140
|
+
function BaseSystem:Query(terms, filterWithout, filterWith)
|
|
141
|
+
return query(self.world, terms, filterWithout, filterWith)
|
|
142
|
+
end
|
|
143
|
+
function BaseSystem:QueryChange(componentTypeId, key)
|
|
144
|
+
return QueryChange(componentTypeId, key)
|
|
145
|
+
end
|
|
146
|
+
function BaseSystem:Each(key)
|
|
147
|
+
return self.world:each(getId(self.world, key))
|
|
148
|
+
end
|
|
149
|
+
function BaseSystem:OnStartup()
|
|
150
|
+
end
|
|
151
|
+
function BaseSystem:OnUpdate()
|
|
152
|
+
end
|
|
153
|
+
function BaseSystem:OnEffect()
|
|
154
|
+
end
|
|
155
|
+
do
|
|
156
|
+
-- (Flamework) BaseSystem metadata
|
|
157
|
+
Reflect.defineMetadata(BaseSystem, "identifier", "$ecsframework:core:framework/base-system@BaseSystem")
|
|
158
|
+
-- (Flamework) BaseSystem.world metadata
|
|
159
|
+
Reflect.defineMetadata(BaseSystem, "flamework:type", "@rbxts/jecs:jecs@World", "world")
|
|
160
|
+
-- (Flamework) BaseSystem.framework metadata
|
|
161
|
+
Reflect.defineMetadata(BaseSystem, "flamework:type", "$ecsframework:core:framework/init@ECSFramework", "framework")
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
-- (Flamework) BaseSystem.world decorators
|
|
165
|
+
Reflect.decorate(BaseSystem, "$ecsframework:core:framework/decorators/inject-type@InjectType", InjectType, {}, "world", false)
|
|
166
|
+
-- (Flamework) BaseSystem.framework decorators
|
|
167
|
+
Reflect.decorate(BaseSystem, "$ecsframework:core:framework/decorators/inject-type@InjectType", InjectType, {}, "framework", false)
|
|
168
|
+
return {
|
|
169
|
+
BaseSystem = BaseSystem,
|
|
170
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local Reflect = TS.import(script, TS.getModule(script, "@flamework", "core").out).Reflect
|
|
4
|
+
local ECSComponent = TS.import(script, script.Parent.Parent, "decorators", "component").ECSComponent
|
|
5
|
+
local RobloxInstanceComponent
|
|
6
|
+
do
|
|
7
|
+
RobloxInstanceComponent = setmetatable({}, {
|
|
8
|
+
__tostring = function()
|
|
9
|
+
return "RobloxInstanceComponent"
|
|
10
|
+
end,
|
|
11
|
+
})
|
|
12
|
+
RobloxInstanceComponent.__index = RobloxInstanceComponent
|
|
13
|
+
function RobloxInstanceComponent.new(...)
|
|
14
|
+
local self = setmetatable({}, RobloxInstanceComponent)
|
|
15
|
+
return self:constructor(...) or self
|
|
16
|
+
end
|
|
17
|
+
function RobloxInstanceComponent:constructor()
|
|
18
|
+
end
|
|
19
|
+
do
|
|
20
|
+
-- (Flamework) RobloxInstanceComponent metadata
|
|
21
|
+
Reflect.defineMetadata(RobloxInstanceComponent, "identifier", "$ecsframework:core:framework/components/roblox-instance-component@RobloxInstanceComponent")
|
|
22
|
+
end
|
|
23
|
+
RobloxInstanceComponent = ECSComponent()(RobloxInstanceComponent) or RobloxInstanceComponent
|
|
24
|
+
end
|
|
25
|
+
return {
|
|
26
|
+
RobloxInstanceComponent = RobloxInstanceComponent,
|
|
27
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local Reflect = TS.import(script, TS.getModule(script, "@flamework", "core").out).Reflect
|
|
4
|
+
local component = TS.import(script, TS.getModule(script, "@rbxts", "jecs").jecs).component
|
|
5
|
+
local BaseSystem = TS.import(script, script.Parent.Parent, "base-system").BaseSystem
|
|
6
|
+
local GetIdentifier = TS.import(script, script.Parent.Parent, "utilities").GetIdentifier
|
|
7
|
+
--* @metadata reflect identifier
|
|
8
|
+
local function ECSComponent(options)
|
|
9
|
+
if options == nil then
|
|
10
|
+
options = {}
|
|
11
|
+
end
|
|
12
|
+
return function(target)
|
|
13
|
+
local components = Reflect.getMetadata(BaseSystem, "ECSFramework:Components") or {}
|
|
14
|
+
local componentId = component()
|
|
15
|
+
local _target = target
|
|
16
|
+
table.insert(components, _target)
|
|
17
|
+
Reflect.defineMetadata(target, "ECSFramework:Id", componentId)
|
|
18
|
+
Reflect.defineMetadata(target, "ECSFramework:ComponentOptions", options)
|
|
19
|
+
Reflect.defineMetadata(BaseSystem, "ECSFramework:Components", components)
|
|
20
|
+
local componentsId = Reflect.getOwnMetadata(BaseSystem, "ECSFramework:ComponentsId") or {}
|
|
21
|
+
local _arg1 = GetIdentifier(target)
|
|
22
|
+
componentsId[componentId] = _arg1
|
|
23
|
+
Reflect.defineMetadata(BaseSystem, "ECSFramework:ComponentsId", componentsId)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
return {
|
|
27
|
+
ECSComponent = ECSComponent,
|
|
28
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const INJECT_TYPE_KEY = "Inject-type";
|
|
2
|
+
export declare const ObjectWithInjectTypes: Map<string, object[]>;
|
|
3
|
+
/**
|
|
4
|
+
* Inject dependency.
|
|
5
|
+
*
|
|
6
|
+
* @metadata flamework:type
|
|
7
|
+
*/
|
|
8
|
+
export declare const InjectType: (() => ((target: defined, propertyKey: string) => never) & {
|
|
9
|
+
_flamework_Decorator: never;
|
|
10
|
+
}) & ((target: defined, propertyKey: string) => never) & {
|
|
11
|
+
_flamework_Decorator: never;
|
|
12
|
+
} & {
|
|
13
|
+
_flamework_Parameters: [];
|
|
14
|
+
};
|
|
15
|
+
export declare const GetInjectTypes: (obj: {}) => Map<string, string>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local _core = TS.import(script, TS.getModule(script, "@flamework", "core").out)
|
|
4
|
+
local Modding = _core.Modding
|
|
5
|
+
local Reflect = _core.Reflect
|
|
6
|
+
local t = TS.import(script, TS.getModule(script, "@rbxts", "t").lib.ts).t
|
|
7
|
+
local INJECT_TYPE_KEY = "Inject-type"
|
|
8
|
+
local ObjectWithInjectTypes = {}
|
|
9
|
+
--[[
|
|
10
|
+
*
|
|
11
|
+
* Inject dependency.
|
|
12
|
+
*
|
|
13
|
+
* @metadata flamework:type
|
|
14
|
+
|
|
15
|
+
]]
|
|
16
|
+
local InjectType = Modding.createDecorator("Property", function(descriptor)
|
|
17
|
+
local typeSpecifier = Reflect.getMetadata(descriptor.object, "flamework:type", descriptor.property)
|
|
18
|
+
if typeSpecifier == nil then
|
|
19
|
+
error("Injected type not found")
|
|
20
|
+
end
|
|
21
|
+
Reflect.defineMetadata(descriptor.object, descriptor.property, typeSpecifier, INJECT_TYPE_KEY)
|
|
22
|
+
end)
|
|
23
|
+
local GetInjectTypes = function(obj)
|
|
24
|
+
local injectProperties = Reflect.getMetadataKeys(obj, INJECT_TYPE_KEY)
|
|
25
|
+
local injectTypes = {}
|
|
26
|
+
-- ▼ ReadonlyArray.forEach ▼
|
|
27
|
+
local _callback = function(prop)
|
|
28
|
+
local typeSpec = Reflect.getMetadata(obj, prop, INJECT_TYPE_KEY)
|
|
29
|
+
local _arg0 = typeSpec ~= nil
|
|
30
|
+
local _arg1 = `Injected type not found for {prop}`
|
|
31
|
+
assert(_arg0, _arg1)
|
|
32
|
+
local _prop = prop
|
|
33
|
+
injectTypes[_prop] = typeSpec
|
|
34
|
+
end
|
|
35
|
+
for _k, _v in injectProperties do
|
|
36
|
+
_callback(_v, _k - 1, injectProperties)
|
|
37
|
+
end
|
|
38
|
+
-- ▲ ReadonlyArray.forEach ▲
|
|
39
|
+
local _arg0 = t.map(t.string, t.string)(injectTypes)
|
|
40
|
+
assert(_arg0, "Invalid inject types")
|
|
41
|
+
return injectTypes
|
|
42
|
+
end
|
|
43
|
+
return {
|
|
44
|
+
INJECT_TYPE_KEY = INJECT_TYPE_KEY,
|
|
45
|
+
ObjectWithInjectTypes = ObjectWithInjectTypes,
|
|
46
|
+
InjectType = InjectType,
|
|
47
|
+
GetInjectTypes = GetInjectTypes,
|
|
48
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Constructor } from "@flamework/core/out/utility";
|
|
2
|
+
import { BaseSystem } from "../base-system";
|
|
3
|
+
import { RunContext } from "../utilities";
|
|
4
|
+
export interface SystemOptions {
|
|
5
|
+
Priority?: number;
|
|
6
|
+
RunContext?: RunContext;
|
|
7
|
+
}
|
|
8
|
+
/** @metadata reflect identifier */
|
|
9
|
+
export declare function ECSSystem(options?: SystemOptions): (target: Constructor<BaseSystem>) => void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local Reflect = TS.import(script, TS.getModule(script, "@flamework", "core").out).Reflect
|
|
4
|
+
local BaseSystem = TS.import(script, script.Parent.Parent, "base-system").BaseSystem
|
|
5
|
+
--* @metadata reflect identifier
|
|
6
|
+
local function ECSSystem(options)
|
|
7
|
+
if options == nil then
|
|
8
|
+
options = {}
|
|
9
|
+
end
|
|
10
|
+
return function(target)
|
|
11
|
+
local systems = Reflect.getOwnMetadata(BaseSystem, "ECSFramework:Systems") or {}
|
|
12
|
+
local _target = target
|
|
13
|
+
table.insert(systems, _target)
|
|
14
|
+
Reflect.defineMetadata(BaseSystem, "ECSFramework:Systems", systems)
|
|
15
|
+
Reflect.defineMetadata(target, "ECSFramework:Options", options)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
return {
|
|
19
|
+
ECSSystem = ECSSystem,
|
|
20
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Constructor } from "@flamework/core/out/utility";
|
|
2
|
+
import { World } from "@rbxts/jecs";
|
|
3
|
+
import { DependenciesContainer } from "../dependencies-container";
|
|
4
|
+
import { Tag } from "../flamecs";
|
|
5
|
+
export interface TaggedOptions<T> {
|
|
6
|
+
Tag: string;
|
|
7
|
+
OnCreateData: (instance: Instance, world: World, container: DependenciesContainer) => Partial<T>;
|
|
8
|
+
}
|
|
9
|
+
export interface TaggedInstance extends Tag {
|
|
10
|
+
}
|
|
11
|
+
export declare function Tagged<T>(options: TaggedOptions<T>): (target: Constructor<T>) => void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local DefineClassComponentMeta = TS.import(script, script.Parent.Parent, "utilities").DefineClassComponentMeta
|
|
4
|
+
local function Tagged(options)
|
|
5
|
+
return function(target)
|
|
6
|
+
DefineClassComponentMeta(target, options, "$ecsframework:core:framework/decorators/tagged@TaggedInstance")
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
return {
|
|
10
|
+
Tagged = Tagged,
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Unaffectable(): (target: object) => void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local Reflect = TS.import(script, TS.getModule(script, "@flamework", "core").out).Reflect
|
|
4
|
+
local function Unaffectable()
|
|
5
|
+
return function(target)
|
|
6
|
+
Reflect.defineMetadata(target, "ECSFramework:Unaffectable", true)
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
return {
|
|
10
|
+
Unaffectable = Unaffectable,
|
|
11
|
+
}
|