@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,567 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local ecs = TS.import(script, TS.getModule(script, "@rbxts", "jecs").jecs)
|
|
4
|
+
local createSignal = TS.import(script, script.Parent, "signal").createSignal
|
|
5
|
+
local components = {}
|
|
6
|
+
local IdTocomponents = {}
|
|
7
|
+
local scheduleComponent = {}
|
|
8
|
+
local worldSignals = {}
|
|
9
|
+
--[[
|
|
10
|
+
*
|
|
11
|
+
* Returns a signal that fires when a component is added to an entity.
|
|
12
|
+
*
|
|
13
|
+
* @template T - The type of the component.
|
|
14
|
+
* @param key - Flamework autogenerated key for the component.
|
|
15
|
+
* @returns A signal that fires when the component is added to any entity.
|
|
16
|
+
* @metadata macro
|
|
17
|
+
|
|
18
|
+
]]
|
|
19
|
+
local component
|
|
20
|
+
local function added(registery, key)
|
|
21
|
+
local id = component(registery, key)
|
|
22
|
+
local _registery = registery
|
|
23
|
+
return worldSignals[_registery].added[id]
|
|
24
|
+
end
|
|
25
|
+
--[[
|
|
26
|
+
*
|
|
27
|
+
* Returns a signal that fires when a component is removed from an entity.
|
|
28
|
+
*
|
|
29
|
+
* @template T - The type of the component.
|
|
30
|
+
* @param key - Flamework autogenerated key for the component.
|
|
31
|
+
* @returns A signal that fires when the component is removed from any entity.
|
|
32
|
+
* @metadata macro
|
|
33
|
+
|
|
34
|
+
]]
|
|
35
|
+
local function removed(registery, key)
|
|
36
|
+
local id = component(registery, key)
|
|
37
|
+
local _registery = registery
|
|
38
|
+
return worldSignals[_registery].removed[id]
|
|
39
|
+
end
|
|
40
|
+
--[[
|
|
41
|
+
*
|
|
42
|
+
* Returns a signal that fires when a component's value changes on an entity.
|
|
43
|
+
*
|
|
44
|
+
* @template T - The type of the component.
|
|
45
|
+
* @param key - Flamework autogenerated key for the component.
|
|
46
|
+
* @returns A signal that fires when the component's value changes on any
|
|
47
|
+
* entity.
|
|
48
|
+
* @metadata macro
|
|
49
|
+
|
|
50
|
+
]]
|
|
51
|
+
local function changed(registery, key)
|
|
52
|
+
local id = component(registery, key)
|
|
53
|
+
local _registery = registery
|
|
54
|
+
return worldSignals[_registery].changed[id]
|
|
55
|
+
end
|
|
56
|
+
local function hookListeners(registry, id)
|
|
57
|
+
local addedSignal = createSignal()
|
|
58
|
+
local removedSignal = createSignal()
|
|
59
|
+
local changedSignal = createSignal()
|
|
60
|
+
local _registry = registry
|
|
61
|
+
local _condition = worldSignals[_registry]
|
|
62
|
+
if _condition == nil then
|
|
63
|
+
_condition = {
|
|
64
|
+
added = {},
|
|
65
|
+
removed = {},
|
|
66
|
+
changed = {},
|
|
67
|
+
}
|
|
68
|
+
end
|
|
69
|
+
local signals = _condition
|
|
70
|
+
local _registry_1 = registry
|
|
71
|
+
worldSignals[_registry_1] = signals
|
|
72
|
+
local _added = signals.added
|
|
73
|
+
local _id = id
|
|
74
|
+
_added[_id] = addedSignal
|
|
75
|
+
local _removed = signals.removed
|
|
76
|
+
local _id_1 = id
|
|
77
|
+
_removed[_id_1] = removedSignal
|
|
78
|
+
local _changed = signals.changed
|
|
79
|
+
local _id_2 = id
|
|
80
|
+
_changed[_id_2] = changedSignal
|
|
81
|
+
registry:set(id, ecs.OnAdd, function(entity, _, data)
|
|
82
|
+
addedSignal:fire(entity, data)
|
|
83
|
+
end)
|
|
84
|
+
registry:set(id, ecs.OnRemove, function(entity)
|
|
85
|
+
removedSignal:fire(entity)
|
|
86
|
+
end)
|
|
87
|
+
registry:set(id, ecs.OnChange, function(entity, data)
|
|
88
|
+
changedSignal:fire(entity, data)
|
|
89
|
+
end)
|
|
90
|
+
end
|
|
91
|
+
--[[
|
|
92
|
+
*
|
|
93
|
+
* Registers an existing entity to the component registry.
|
|
94
|
+
*
|
|
95
|
+
* @template T - The type of the component.
|
|
96
|
+
* @param runtimeId - The runtime entity to be registered.
|
|
97
|
+
* @param key - Flamework autogenerated key.
|
|
98
|
+
* @metadata macro
|
|
99
|
+
|
|
100
|
+
]]
|
|
101
|
+
local function reserve(registry, runtimeId, key)
|
|
102
|
+
local _key = key
|
|
103
|
+
assert(_key ~= "" and _key)
|
|
104
|
+
local _key_1 = key
|
|
105
|
+
local _arg0 = not (components[_key_1] ~= nil)
|
|
106
|
+
local _arg1 = `A component with the key "{key}" already exists`
|
|
107
|
+
assert(_arg0, _arg1)
|
|
108
|
+
local _key_2 = key
|
|
109
|
+
local _runtimeId = runtimeId
|
|
110
|
+
components[_key_2] = _runtimeId
|
|
111
|
+
local _runtimeId_1 = runtimeId
|
|
112
|
+
local _key_3 = key
|
|
113
|
+
IdTocomponents[_runtimeId_1] = _key_3
|
|
114
|
+
if registry ~= nil then
|
|
115
|
+
hookListeners(registry, runtimeId)
|
|
116
|
+
return nil
|
|
117
|
+
end
|
|
118
|
+
local _runtimeId_2 = runtimeId
|
|
119
|
+
scheduleComponent[_runtimeId_2] = true
|
|
120
|
+
end
|
|
121
|
+
--[[
|
|
122
|
+
*
|
|
123
|
+
* Defines a component that can be added to an entity. Components can either tag
|
|
124
|
+
* an entity (e.g., "this entity is an NPC"), store data for an entity (e.g.,
|
|
125
|
+
* "this entity is located at Vector3.new(10, 20, 30)"), or represent
|
|
126
|
+
* relationships between entities <Pair<P, O>> (e.g., "bob Likes alice") that
|
|
127
|
+
* may also store additional data (e.g., "bob Eats 10 apples").
|
|
128
|
+
*
|
|
129
|
+
* @template T - The type of the component.
|
|
130
|
+
* @param key - Flamework autogenerated key.
|
|
131
|
+
* @returns The component entity ID.
|
|
132
|
+
* @metadata macro
|
|
133
|
+
|
|
134
|
+
]]
|
|
135
|
+
function component(registry, key)
|
|
136
|
+
local _key = key
|
|
137
|
+
assert(_key ~= "" and _key)
|
|
138
|
+
local _key_1 = key
|
|
139
|
+
local id = components[_key_1]
|
|
140
|
+
if id == nil then
|
|
141
|
+
id = ecs.component()
|
|
142
|
+
local _key_2 = key
|
|
143
|
+
local _id = id
|
|
144
|
+
components[_key_2] = _id
|
|
145
|
+
local _id_1 = id
|
|
146
|
+
local _key_3 = key
|
|
147
|
+
IdTocomponents[_id_1] = _key_3
|
|
148
|
+
if registry ~= nil then
|
|
149
|
+
hookListeners(registry, id)
|
|
150
|
+
return id
|
|
151
|
+
end
|
|
152
|
+
local _id_2 = id
|
|
153
|
+
scheduleComponent[_id_2] = true
|
|
154
|
+
end
|
|
155
|
+
return id
|
|
156
|
+
end
|
|
157
|
+
--[[
|
|
158
|
+
*
|
|
159
|
+
* Retrieves the ID of a component or a pair relationship.
|
|
160
|
+
*
|
|
161
|
+
* @template T - The type of the component.
|
|
162
|
+
* @param key - Flamework autogenerated key or pair key.
|
|
163
|
+
* @returns The component or pair ID.
|
|
164
|
+
* @metadata macro.
|
|
165
|
+
|
|
166
|
+
]]
|
|
167
|
+
local function getId(registry, key)
|
|
168
|
+
local _key = key
|
|
169
|
+
assert(_key ~= "" and _key)
|
|
170
|
+
local _key_1 = key
|
|
171
|
+
if type(_key_1) == "table" then
|
|
172
|
+
local pairKey = key
|
|
173
|
+
local object = component(registry, pairKey.obj)
|
|
174
|
+
local predicate = component(registry, pairKey.pred)
|
|
175
|
+
return ecs.pair(predicate, object)
|
|
176
|
+
end
|
|
177
|
+
return component(registry, key)
|
|
178
|
+
end
|
|
179
|
+
local function getKey(runtimeId)
|
|
180
|
+
local _runtimeId = runtimeId
|
|
181
|
+
return IdTocomponents[_runtimeId]
|
|
182
|
+
end
|
|
183
|
+
--[[
|
|
184
|
+
*
|
|
185
|
+
* Creates a new empty entity.
|
|
186
|
+
*
|
|
187
|
+
* @returns The created entity.
|
|
188
|
+
* @metadata macro
|
|
189
|
+
|
|
190
|
+
]]
|
|
191
|
+
--[[
|
|
192
|
+
*
|
|
193
|
+
* Creates a new entity with the specified tag components.
|
|
194
|
+
*
|
|
195
|
+
* @template T - The type of the components.
|
|
196
|
+
* @param keys - Flamework autogenerated keys.
|
|
197
|
+
* @returns The created entity.
|
|
198
|
+
* @metadata macro
|
|
199
|
+
|
|
200
|
+
]]
|
|
201
|
+
--[[
|
|
202
|
+
*
|
|
203
|
+
* Creates a new entity with the specified components and their values.
|
|
204
|
+
*
|
|
205
|
+
* @template T - The type of the components.
|
|
206
|
+
* @param values - The values to set for the components.
|
|
207
|
+
* @param keys - Flamework autogenerated keys.
|
|
208
|
+
* @returns The created entity.
|
|
209
|
+
* @metadata macro
|
|
210
|
+
|
|
211
|
+
]]
|
|
212
|
+
local function spawn(registry, argument1, argument2)
|
|
213
|
+
local entity = registry:entity()
|
|
214
|
+
if argument2 ~= nil then
|
|
215
|
+
-- Spawn with components: spawn(values, keys)
|
|
216
|
+
local values = argument1
|
|
217
|
+
local keys = argument2
|
|
218
|
+
for index = 0, #keys - 1 do
|
|
219
|
+
local id = getId(registry, keys[index + 1])
|
|
220
|
+
local value = values[index + 1]
|
|
221
|
+
if value ~= nil then
|
|
222
|
+
registry:set(entity, id, value)
|
|
223
|
+
else
|
|
224
|
+
registry:add(entity, id)
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
elseif argument1 ~= nil then
|
|
228
|
+
-- Spawn with tags only: spawn(keys)
|
|
229
|
+
local keys = argument1
|
|
230
|
+
for _, key in keys do
|
|
231
|
+
registry:add(entity, getId(registry, key))
|
|
232
|
+
end
|
|
233
|
+
end
|
|
234
|
+
return entity
|
|
235
|
+
end
|
|
236
|
+
--[[
|
|
237
|
+
*
|
|
238
|
+
* Deletes the specified entity and all associated components.
|
|
239
|
+
*
|
|
240
|
+
* @param entity - The entity to delete.
|
|
241
|
+
|
|
242
|
+
]]
|
|
243
|
+
local function despawn(registry, entity)
|
|
244
|
+
registry:delete(entity)
|
|
245
|
+
end
|
|
246
|
+
--[[
|
|
247
|
+
*
|
|
248
|
+
* Adds or updates multiple components for the specified entity.
|
|
249
|
+
*
|
|
250
|
+
* @template T - The type of the components.
|
|
251
|
+
* @param entity - The entity to modify.
|
|
252
|
+
* @param keys - Flamework autogenerated keys.
|
|
253
|
+
* @metadata macro
|
|
254
|
+
|
|
255
|
+
]]
|
|
256
|
+
--[[
|
|
257
|
+
*
|
|
258
|
+
* Adds or updates multiple components for the specified entity.
|
|
259
|
+
*
|
|
260
|
+
* @template T - The type of the components.
|
|
261
|
+
* @param entity - The entity to modify.
|
|
262
|
+
* @param values - The values to set for the components.
|
|
263
|
+
* @param keys - Flamework autogenerated keys.
|
|
264
|
+
* @metadata macro
|
|
265
|
+
|
|
266
|
+
]]
|
|
267
|
+
local function insert(registry, entity, argument1, argument2)
|
|
268
|
+
local _arg0 = argument1 ~= nil
|
|
269
|
+
assert(_arg0)
|
|
270
|
+
if argument2 ~= nil then
|
|
271
|
+
-- Insert components: insert(entity, values, keys)
|
|
272
|
+
local values = argument1
|
|
273
|
+
local keys = argument2
|
|
274
|
+
for index = 0, #keys - 1 do
|
|
275
|
+
local id = getId(registry, keys[index + 1])
|
|
276
|
+
local value = values[index + 1]
|
|
277
|
+
if value ~= nil then
|
|
278
|
+
registry:set(entity, id, value)
|
|
279
|
+
else
|
|
280
|
+
registry:add(entity, id)
|
|
281
|
+
end
|
|
282
|
+
end
|
|
283
|
+
else
|
|
284
|
+
-- Insert tags only: insert(entity, keys)
|
|
285
|
+
local keys = argument1
|
|
286
|
+
for _, key in keys do
|
|
287
|
+
registry:add(entity, getId(registry, key))
|
|
288
|
+
end
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
--[[
|
|
292
|
+
*
|
|
293
|
+
* Adds a pair relationship with a specific target entity.
|
|
294
|
+
*
|
|
295
|
+
* @template T - The type of the pair.
|
|
296
|
+
* @param entity - The entity to which the pair relationship is added.
|
|
297
|
+
* @param object - The target entity of the relationship (object of the pair).
|
|
298
|
+
* @param key - Flamework autogenerated key.
|
|
299
|
+
* @metadata macro
|
|
300
|
+
|
|
301
|
+
]]
|
|
302
|
+
--[[
|
|
303
|
+
*
|
|
304
|
+
* Adds a fully defined pair to an entity. This is used when both the predicate
|
|
305
|
+
* and object of the pair are known at compile-time.
|
|
306
|
+
*
|
|
307
|
+
* @template T - The type of the pair.
|
|
308
|
+
* @param entity - The entity to which the pair component is added.
|
|
309
|
+
* @param key - Flamework autogenerated key.
|
|
310
|
+
* @metadata macro
|
|
311
|
+
|
|
312
|
+
]]
|
|
313
|
+
--[[
|
|
314
|
+
*
|
|
315
|
+
* Adds a component to an entity.
|
|
316
|
+
*
|
|
317
|
+
* @template T - The type of the component.
|
|
318
|
+
* @param entity - The entity to which the component is added.
|
|
319
|
+
* @param key - Flamework autogenerated key.
|
|
320
|
+
* @metadata macro
|
|
321
|
+
|
|
322
|
+
]]
|
|
323
|
+
local function add(registry, entity, argument1, argument2)
|
|
324
|
+
if argument2 ~= nil then
|
|
325
|
+
-- Pair<P, _> case: add(entity, object, key)
|
|
326
|
+
local object = argument1
|
|
327
|
+
local key = argument2
|
|
328
|
+
registry:add(entity, ecs.pair(component(registry, key), object))
|
|
329
|
+
else
|
|
330
|
+
-- Known component case: add(entity, key)
|
|
331
|
+
local key = argument1
|
|
332
|
+
registry:add(entity, getId(registry, key))
|
|
333
|
+
end
|
|
334
|
+
end
|
|
335
|
+
--[[
|
|
336
|
+
*
|
|
337
|
+
* Removes a pair relationship with a specific target entity.
|
|
338
|
+
*
|
|
339
|
+
* @template T - The type of the pair.
|
|
340
|
+
* @param entity - The entity from which the pair relationship is removed.
|
|
341
|
+
* @param object - The target entity of the relationship (object of the pair).
|
|
342
|
+
* @param key - Flamework autogenerated key.
|
|
343
|
+
* @metadata macro
|
|
344
|
+
|
|
345
|
+
]]
|
|
346
|
+
--[[
|
|
347
|
+
*
|
|
348
|
+
* Removes a fully defined pair from an entity. This is used when both the
|
|
349
|
+
* predicate and object of the pair are known at compile-time.
|
|
350
|
+
*
|
|
351
|
+
* @template T - The type of the pair.
|
|
352
|
+
* @param entity - The entity from which the pair component is removed.
|
|
353
|
+
* @param key - Flamework autogenerated key.
|
|
354
|
+
* @metadata macro
|
|
355
|
+
|
|
356
|
+
]]
|
|
357
|
+
--[[
|
|
358
|
+
*
|
|
359
|
+
* Removes a component from an entity.
|
|
360
|
+
*
|
|
361
|
+
* @template T - The type of the component.
|
|
362
|
+
* @param entity - The entity from which the component is removed.
|
|
363
|
+
* @param key - Flamework autogenerated key.
|
|
364
|
+
* @metadata macro
|
|
365
|
+
|
|
366
|
+
]]
|
|
367
|
+
local function remove(registry, entity, argument1, argument2)
|
|
368
|
+
if argument2 ~= nil then
|
|
369
|
+
-- Pair<P, _> case: remove(entity, object, key)
|
|
370
|
+
local object = argument1
|
|
371
|
+
local key = argument2
|
|
372
|
+
registry:remove(entity, ecs.pair(component(registry, key), object))
|
|
373
|
+
else
|
|
374
|
+
-- Known component case: remove(entity, key)
|
|
375
|
+
local key = argument1
|
|
376
|
+
registry:remove(entity, getId(registry, key))
|
|
377
|
+
end
|
|
378
|
+
end
|
|
379
|
+
--[[
|
|
380
|
+
*
|
|
381
|
+
* Sets a value for a pair with a specific runtime target entity.
|
|
382
|
+
*
|
|
383
|
+
* @template T - The type of the pair.
|
|
384
|
+
* @param entity - The entity to which the pair relationship is added.
|
|
385
|
+
* @param object - The target entity of the relationship (object of the pair).
|
|
386
|
+
* @param value - The value associated with the pair relationship.
|
|
387
|
+
* @param key - Flamework autogenerated key.
|
|
388
|
+
* @metadata macro
|
|
389
|
+
|
|
390
|
+
]]
|
|
391
|
+
--[[
|
|
392
|
+
*
|
|
393
|
+
* Sets a value for a fully defined pair on an entity. This is used when both
|
|
394
|
+
* the predicate and object of the pair are known at compile-time.
|
|
395
|
+
*
|
|
396
|
+
* @template T - The type of the pair.
|
|
397
|
+
* @param entity - The entity to which the pair component is added.
|
|
398
|
+
* @param value - The value associated with the pair component.
|
|
399
|
+
* @param key - Flamework autogenerated key.
|
|
400
|
+
* @metadata macro
|
|
401
|
+
|
|
402
|
+
]]
|
|
403
|
+
--[[
|
|
404
|
+
*
|
|
405
|
+
* Sets a value for a component on an entity.
|
|
406
|
+
*
|
|
407
|
+
* @template T - The type of the component.
|
|
408
|
+
* @param entity - The entity to which the component is added or updated.
|
|
409
|
+
* @param value - The value associated with the component.
|
|
410
|
+
* @param key - Flamework autogenerated key.
|
|
411
|
+
* @metadata macro
|
|
412
|
+
|
|
413
|
+
]]
|
|
414
|
+
local function set(registry, entity, argument1, argument2, argument3)
|
|
415
|
+
if argument3 ~= nil then
|
|
416
|
+
-- Pair<P, _> case: set(entity, object, value, key)
|
|
417
|
+
local object = argument1
|
|
418
|
+
local value = argument2
|
|
419
|
+
local key = argument3
|
|
420
|
+
registry:set(entity, ecs.pair(component(registry, key), object), value)
|
|
421
|
+
else
|
|
422
|
+
-- Known component case: set(entity, value, key)
|
|
423
|
+
local value = argument1
|
|
424
|
+
local key = argument2
|
|
425
|
+
registry:set(entity, getId(registry, key), value)
|
|
426
|
+
end
|
|
427
|
+
end
|
|
428
|
+
--[[
|
|
429
|
+
*
|
|
430
|
+
* Retrieves the value of a pair relationship for a specific entity and target.
|
|
431
|
+
*
|
|
432
|
+
* @template T - The type of the pair.
|
|
433
|
+
* @param entity - The entity from which to retrieve the pair relationship.
|
|
434
|
+
* @param object - The target entity of the relationship (object of the pair).
|
|
435
|
+
* @param key - Flamework autogenerated key.
|
|
436
|
+
* @returns The value associated with the pair relationship.
|
|
437
|
+
* @metadata macro
|
|
438
|
+
|
|
439
|
+
]]
|
|
440
|
+
--[[
|
|
441
|
+
*
|
|
442
|
+
* Retrieves the value of a component or pair for a specific entity.
|
|
443
|
+
*
|
|
444
|
+
* @template T - The type of the component or pair.
|
|
445
|
+
* @param entity - The entity from which to retrieve the component or pair.
|
|
446
|
+
* @param key - Flamework autogenerated key.
|
|
447
|
+
* @returns The value associated with the component or pair.
|
|
448
|
+
* @metadata macro
|
|
449
|
+
|
|
450
|
+
]]
|
|
451
|
+
local function get(registry, entity, argument1, argument2)
|
|
452
|
+
if argument2 ~= nil then
|
|
453
|
+
-- Pair<P, _> case: get(entity, object, key)
|
|
454
|
+
local object = argument1
|
|
455
|
+
local key = argument2
|
|
456
|
+
return registry:get(entity, ecs.pair(component(registry, key), object))
|
|
457
|
+
end
|
|
458
|
+
-- Known component case: get(entity, key)
|
|
459
|
+
local key = argument1
|
|
460
|
+
return registry:get(entity, getId(registry, key))
|
|
461
|
+
end
|
|
462
|
+
--[[
|
|
463
|
+
*
|
|
464
|
+
* Checks if a pair relationship exists for a specific entity and target.
|
|
465
|
+
*
|
|
466
|
+
* @template T - The type of the pair.
|
|
467
|
+
* @param entity - The entity to check for the pair relationship.
|
|
468
|
+
* @param object - The target entity of the relationship (object of the pair).
|
|
469
|
+
* @param key - Flamework autogenerated key.
|
|
470
|
+
* @returns True if the pair relationship exists, false otherwise.
|
|
471
|
+
* @metadata macro
|
|
472
|
+
|
|
473
|
+
]]
|
|
474
|
+
--[[
|
|
475
|
+
*
|
|
476
|
+
* Checks if a component or pair exists for a specific entity.
|
|
477
|
+
*
|
|
478
|
+
* @template T - The type of the component or pair.
|
|
479
|
+
* @param entity - The entity to check for the component or pair.
|
|
480
|
+
* @param key - Flamework autogenerated key.
|
|
481
|
+
* @returns True if the component or pair exists, false otherwise.
|
|
482
|
+
* @metadata macro
|
|
483
|
+
|
|
484
|
+
]]
|
|
485
|
+
local function has(registry, entity, argument1, argument2)
|
|
486
|
+
if argument2 ~= nil then
|
|
487
|
+
-- Pair<P, _> case: has(entity, object, key)
|
|
488
|
+
local object = argument1
|
|
489
|
+
local key = argument2
|
|
490
|
+
return registry:has(entity, ecs.pair(component(registry, key), object))
|
|
491
|
+
end
|
|
492
|
+
-- Known component case: has(entity, key)
|
|
493
|
+
local key = argument1
|
|
494
|
+
return registry:has(entity, getId(registry, key))
|
|
495
|
+
end
|
|
496
|
+
--[[
|
|
497
|
+
*
|
|
498
|
+
* Retrieves the target entity of a relationship involving the specified entity
|
|
499
|
+
* and component.
|
|
500
|
+
*
|
|
501
|
+
* @template T - The type of the component.
|
|
502
|
+
* @param entity - The entity to get the target for.
|
|
503
|
+
* @param key - Flamework autogenerated key.
|
|
504
|
+
* @returns The target entity if a relationship exists, or undefined otherwise.
|
|
505
|
+
* @metadata macro
|
|
506
|
+
|
|
507
|
+
]]
|
|
508
|
+
local function target(registry, entity, key)
|
|
509
|
+
local id = component(registry, key)
|
|
510
|
+
return registry:target(entity, id)
|
|
511
|
+
end
|
|
512
|
+
--[[
|
|
513
|
+
*
|
|
514
|
+
* Retrieves the parent entity (target of the ChildOf relationship) for the
|
|
515
|
+
* given entity.
|
|
516
|
+
*
|
|
517
|
+
* @param entity - The entity for which to get the parent.
|
|
518
|
+
* @returns The parent entity, or undefined if no parent exists.
|
|
519
|
+
|
|
520
|
+
]]
|
|
521
|
+
local function parent(registry, entity)
|
|
522
|
+
return target(registry, entity, "$ecsframework:core:framework/flamecs/registry@ChildOf")
|
|
523
|
+
end
|
|
524
|
+
--[[
|
|
525
|
+
*
|
|
526
|
+
* Creates a pair relationship between a component and an entity.
|
|
527
|
+
*
|
|
528
|
+
* @template P - The type of the predicate component.
|
|
529
|
+
* @template O - The type of the object component.
|
|
530
|
+
* @param object - The object entity.
|
|
531
|
+
* @param predicate - The predicate component key.
|
|
532
|
+
* @returns The pair ID.
|
|
533
|
+
* @metadata macro
|
|
534
|
+
|
|
535
|
+
]]
|
|
536
|
+
local function pair(registry, object, predicate)
|
|
537
|
+
local predicateId = component(registry, predicate)
|
|
538
|
+
return ecs.pair(predicateId, object)
|
|
539
|
+
end
|
|
540
|
+
local function initWorld(registry)
|
|
541
|
+
reserve(registry, ecs.Wildcard, "$ecsframework:core:framework/flamecs/registry@Wildcard")
|
|
542
|
+
reserve(registry, ecs.ChildOf, "$ecsframework:core:framework/flamecs/registry@ChildOf")
|
|
543
|
+
end
|
|
544
|
+
return {
|
|
545
|
+
added = added,
|
|
546
|
+
removed = removed,
|
|
547
|
+
changed = changed,
|
|
548
|
+
hookListeners = hookListeners,
|
|
549
|
+
reserve = reserve,
|
|
550
|
+
component = component,
|
|
551
|
+
getId = getId,
|
|
552
|
+
getKey = getKey,
|
|
553
|
+
spawn = spawn,
|
|
554
|
+
despawn = despawn,
|
|
555
|
+
insert = insert,
|
|
556
|
+
add = add,
|
|
557
|
+
remove = remove,
|
|
558
|
+
set = set,
|
|
559
|
+
get = get,
|
|
560
|
+
has = has,
|
|
561
|
+
target = target,
|
|
562
|
+
parent = parent,
|
|
563
|
+
pair = pair,
|
|
564
|
+
initWorld = initWorld,
|
|
565
|
+
scheduleComponent = scheduleComponent,
|
|
566
|
+
worldSignals = worldSignals,
|
|
567
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local function createSignal()
|
|
3
|
+
local listeners = {}
|
|
4
|
+
return {
|
|
5
|
+
connect = function(self, func)
|
|
6
|
+
local _func = func
|
|
7
|
+
table.insert(listeners, _func)
|
|
8
|
+
return function()
|
|
9
|
+
local _func_1 = func
|
|
10
|
+
local index = (table.find(listeners, _func_1) or 0) - 1
|
|
11
|
+
local _ = index ~= -1 and table.remove(listeners, index + 1)
|
|
12
|
+
end
|
|
13
|
+
end,
|
|
14
|
+
fire = function(self, ...)
|
|
15
|
+
local args = { ... }
|
|
16
|
+
for _, listener in listeners do
|
|
17
|
+
listener(unpack(args))
|
|
18
|
+
end
|
|
19
|
+
end,
|
|
20
|
+
}
|
|
21
|
+
end
|
|
22
|
+
return {
|
|
23
|
+
createSignal = createSignal,
|
|
24
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { World } from "@rbxts/jecs";
|
|
2
|
+
import { BaseSystem } from "../base-system";
|
|
3
|
+
type Cleanup<T> = (state: T) => boolean;
|
|
4
|
+
interface HookStorage<T> {
|
|
5
|
+
cleanup?: Cleanup<T>;
|
|
6
|
+
states: Map<string, T>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Starts a new stack frame for a function, ensuring cleanup after execution.
|
|
10
|
+
* Intended to be used in systems.
|
|
11
|
+
*
|
|
12
|
+
* @param node - The node to store the state for the current function.
|
|
13
|
+
* @param callback - The function to execute within the new stack frame.
|
|
14
|
+
*/
|
|
15
|
+
export declare function start(node: Record<string, HookStorage<unknown>>, system: BaseSystem, world: World, callback: () => void): void;
|
|
16
|
+
export declare function useSystem(): BaseSystem;
|
|
17
|
+
export declare function useWorld(): World;
|
|
18
|
+
/**
|
|
19
|
+
* Creates or retrieves a state object for a hook, keyed by a unique identifier.
|
|
20
|
+
*
|
|
21
|
+
* @template T The type of the hook state.
|
|
22
|
+
* @param key - A unique string identifier for the hook state.
|
|
23
|
+
* @param discriminator - An optional value to further distinguish different
|
|
24
|
+
* states within the same key. Defaults to the key itself.
|
|
25
|
+
* @param cleanup - An optional function that determines whether the state
|
|
26
|
+
* should be cleaned up. It should return true if the state should be removed.
|
|
27
|
+
* If not provided, the state will be cleaned up when the hook was not
|
|
28
|
+
* accessed in the current context.
|
|
29
|
+
* @returns The state object of type T.
|
|
30
|
+
*/
|
|
31
|
+
export declare function useHookState<T>(key: string, discriminator: unknown, cleanup?: Cleanup<T>): T;
|
|
32
|
+
export {};
|