@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,295 @@
|
|
|
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 world = TS.import(script, TS.getModule(script, "@rbxts", "jecs").jecs).world
|
|
7
|
+
local RunService = TS.import(script, TS.getModule(script, "@rbxts", "services")).RunService
|
|
8
|
+
local DependenciesContainer = TS.import(script, script, "dependencies-container").DependenciesContainer
|
|
9
|
+
local start = TS.import(script, script, "flamecs").start
|
|
10
|
+
local _registry = TS.import(script, script, "flamecs", "registry")
|
|
11
|
+
local hookListeners = _registry.hookListeners
|
|
12
|
+
local initWorld = _registry.initWorld
|
|
13
|
+
local reserve = _registry.reserve
|
|
14
|
+
local scheduleComponent = _registry.scheduleComponent
|
|
15
|
+
local _utilities = TS.import(script, script, "utilities")
|
|
16
|
+
local ApplyClassComponentMeta = _utilities.ApplyClassComponentMeta
|
|
17
|
+
local GetIdentifier = _utilities.GetIdentifier
|
|
18
|
+
local function getCachedMethod(instance, methodName)
|
|
19
|
+
return instance[methodName]
|
|
20
|
+
end
|
|
21
|
+
local ECSFramework
|
|
22
|
+
do
|
|
23
|
+
ECSFramework = setmetatable({}, {
|
|
24
|
+
__tostring = function()
|
|
25
|
+
return "ECSFramework"
|
|
26
|
+
end,
|
|
27
|
+
})
|
|
28
|
+
ECSFramework.__index = ECSFramework
|
|
29
|
+
function ECSFramework.new(...)
|
|
30
|
+
local self = setmetatable({}, ECSFramework)
|
|
31
|
+
return self:constructor(...) or self
|
|
32
|
+
end
|
|
33
|
+
function ECSFramework:constructor(container)
|
|
34
|
+
if container == nil then
|
|
35
|
+
container = DependenciesContainer.new()
|
|
36
|
+
end
|
|
37
|
+
self.container = container
|
|
38
|
+
self.systems = {}
|
|
39
|
+
self.canCallEffect = true
|
|
40
|
+
self.isStarted = false
|
|
41
|
+
self.componentsMap = {}
|
|
42
|
+
self.components = {}
|
|
43
|
+
self.signals = {
|
|
44
|
+
added = {},
|
|
45
|
+
changed = {},
|
|
46
|
+
removed = {},
|
|
47
|
+
}
|
|
48
|
+
self.baseSystemCtor = Modding.getObjectFromId("$ecsframework:core:framework/base-system@BaseSystem")
|
|
49
|
+
container:Register(function()
|
|
50
|
+
return self
|
|
51
|
+
end, "$ecsframework:core:framework/init@ECSFramework")
|
|
52
|
+
container:Register(function()
|
|
53
|
+
return container
|
|
54
|
+
end, "$ecsframework:core:framework/dependencies-container@DependenciesContainer")
|
|
55
|
+
self:initComponents()
|
|
56
|
+
self.world = world()
|
|
57
|
+
self:initComponentLifecycles()
|
|
58
|
+
container:Register(function()
|
|
59
|
+
return self.world
|
|
60
|
+
end, "@rbxts/jecs:jecs@World")
|
|
61
|
+
end
|
|
62
|
+
function ECSFramework:GetAllComponents()
|
|
63
|
+
-- ▼ ReadonlyMap.size ▼
|
|
64
|
+
local _size = 0
|
|
65
|
+
for _ in self.componentsMap do
|
|
66
|
+
_size += 1
|
|
67
|
+
end
|
|
68
|
+
-- ▲ ReadonlyMap.size ▲
|
|
69
|
+
if _size > 0 then
|
|
70
|
+
return self.components
|
|
71
|
+
end
|
|
72
|
+
local _result = Reflect.getOwnMetadata(self.baseSystemCtor, "ECSFramework:Components")
|
|
73
|
+
if _result ~= nil then
|
|
74
|
+
-- ▼ ReadonlyArray.map ▼
|
|
75
|
+
local _newValue = table.create(#_result)
|
|
76
|
+
local _callback = function(ctor)
|
|
77
|
+
local options = Reflect.getOwnMetadata(ctor, "ECSFramework:ComponentOptions")
|
|
78
|
+
if not options then
|
|
79
|
+
warn(`Component {ctor} is missing ECSComponentOptions.`)
|
|
80
|
+
return nil
|
|
81
|
+
end
|
|
82
|
+
if options.RunContext ~= nil and options.RunContext ~= 2 and (if RunService:IsServer() then 0 else 1) ~= options.RunContext then
|
|
83
|
+
return nil
|
|
84
|
+
end
|
|
85
|
+
local _exp = (self.componentsMap)
|
|
86
|
+
local _arg0 = GetIdentifier(ctor)
|
|
87
|
+
local _ctor = ctor
|
|
88
|
+
_exp[_arg0] = _ctor
|
|
89
|
+
return ctor
|
|
90
|
+
end
|
|
91
|
+
for _k, _v in _result do
|
|
92
|
+
_newValue[_k] = _callback(_v, _k - 1, _result)
|
|
93
|
+
end
|
|
94
|
+
-- ▲ ReadonlyArray.map ▲
|
|
95
|
+
-- ▼ ReadonlyArray.filterUndefined ▼
|
|
96
|
+
local _length = 0
|
|
97
|
+
for _i in _newValue do
|
|
98
|
+
if _i > _length then
|
|
99
|
+
_length = _i
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
local _result_1 = {}
|
|
103
|
+
local _resultLength = 0
|
|
104
|
+
for _i = 1, _length do
|
|
105
|
+
local _v = _newValue[_i]
|
|
106
|
+
if _v ~= nil then
|
|
107
|
+
_resultLength += 1
|
|
108
|
+
_result_1[_resultLength] = _v
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
-- ▲ ReadonlyArray.filterUndefined ▲
|
|
112
|
+
_result = _result_1
|
|
113
|
+
end
|
|
114
|
+
local _condition = _result
|
|
115
|
+
if _condition == nil then
|
|
116
|
+
_condition = {}
|
|
117
|
+
end
|
|
118
|
+
self.components = _condition
|
|
119
|
+
return self.components
|
|
120
|
+
end
|
|
121
|
+
function ECSFramework:initSystems()
|
|
122
|
+
local systems = Reflect.getMetadata(self.baseSystemCtor, "ECSFramework:Systems") or {}
|
|
123
|
+
local _exp = self.container:InstantiateGroup(systems, true)
|
|
124
|
+
-- ▼ ReadonlyArray.map ▼
|
|
125
|
+
local _newValue = table.create(#_exp)
|
|
126
|
+
local _callback = function(instance)
|
|
127
|
+
local options = Reflect.getOwnMetadata(getmetatable(instance), "ECSFramework:Options") or {}
|
|
128
|
+
if options.RunContext ~= nil and options.RunContext ~= 2 and (if RunService:IsServer() then 0 else 1) ~= options.RunContext then
|
|
129
|
+
return nil
|
|
130
|
+
end
|
|
131
|
+
return {
|
|
132
|
+
Instance = instance,
|
|
133
|
+
OnStartup = getCachedMethod(instance, "OnStartup"),
|
|
134
|
+
OnEffect = getCachedMethod(instance, "OnEffect"),
|
|
135
|
+
OnUpdate = getCachedMethod(instance, "OnUpdate"),
|
|
136
|
+
Options = options,
|
|
137
|
+
}
|
|
138
|
+
end
|
|
139
|
+
for _k, _v in _exp do
|
|
140
|
+
_newValue[_k] = _callback(_v, _k - 1, _exp)
|
|
141
|
+
end
|
|
142
|
+
-- ▲ ReadonlyArray.map ▲
|
|
143
|
+
-- ▼ ReadonlyArray.filterUndefined ▼
|
|
144
|
+
local _length = 0
|
|
145
|
+
for _i in _newValue do
|
|
146
|
+
if _i > _length then
|
|
147
|
+
_length = _i
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
local _result = {}
|
|
151
|
+
local _resultLength = 0
|
|
152
|
+
for _i = 1, _length do
|
|
153
|
+
local _v = _newValue[_i]
|
|
154
|
+
if _v ~= nil then
|
|
155
|
+
_resultLength += 1
|
|
156
|
+
_result[_resultLength] = _v
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
-- ▲ ReadonlyArray.filterUndefined ▲
|
|
160
|
+
table.sort(_result, function(a, b)
|
|
161
|
+
local _condition = a.Options.Priority
|
|
162
|
+
if _condition == nil then
|
|
163
|
+
_condition = 1
|
|
164
|
+
end
|
|
165
|
+
local _condition_1 = b.Options.Priority
|
|
166
|
+
if _condition_1 == nil then
|
|
167
|
+
_condition_1 = 1
|
|
168
|
+
end
|
|
169
|
+
return _condition > _condition_1
|
|
170
|
+
end)
|
|
171
|
+
self.systems = _result
|
|
172
|
+
end
|
|
173
|
+
function ECSFramework:invokeStartup()
|
|
174
|
+
local _exp = self.systems
|
|
175
|
+
-- ▼ ReadonlyArray.forEach ▼
|
|
176
|
+
local _callback = function(system)
|
|
177
|
+
start(system.Instance.__hookStates, system.Instance, self.world, function()
|
|
178
|
+
return system.OnStartup(system.Instance)
|
|
179
|
+
end)
|
|
180
|
+
end
|
|
181
|
+
for _k, _v in _exp do
|
|
182
|
+
_callback(_v, _k - 1, _exp)
|
|
183
|
+
end
|
|
184
|
+
-- ▲ ReadonlyArray.forEach ▲
|
|
185
|
+
end
|
|
186
|
+
function ECSFramework:initUpdate()
|
|
187
|
+
RunService.Heartbeat:Connect(function(dt)
|
|
188
|
+
for _, system in self.systems do
|
|
189
|
+
start(system.Instance.__hookStates, system.Instance, self.world, function()
|
|
190
|
+
return system.OnUpdate(system.Instance, dt)
|
|
191
|
+
end)
|
|
192
|
+
end
|
|
193
|
+
end)
|
|
194
|
+
end
|
|
195
|
+
function ECSFramework:initComponents()
|
|
196
|
+
local _exp = self:GetAllComponents()
|
|
197
|
+
-- ▼ ReadonlyArray.forEach ▼
|
|
198
|
+
local _callback = function(component)
|
|
199
|
+
local runtimeId = Reflect.getOwnMetadata(component, "ECSFramework:Id")
|
|
200
|
+
if runtimeId == nil then
|
|
201
|
+
error(`Component {component} does not have a runtime id.`)
|
|
202
|
+
end
|
|
203
|
+
reserve(self.world, runtimeId, GetIdentifier(component))
|
|
204
|
+
ApplyClassComponentMeta(component, runtimeId)
|
|
205
|
+
end
|
|
206
|
+
for _k, _v in _exp do
|
|
207
|
+
_callback(_v, _k - 1, _exp)
|
|
208
|
+
end
|
|
209
|
+
-- ▲ ReadonlyArray.forEach ▲
|
|
210
|
+
end
|
|
211
|
+
function ECSFramework:initComponentLifecycles()
|
|
212
|
+
-- ▼ ReadonlySet.forEach ▼
|
|
213
|
+
local _callback = function(component)
|
|
214
|
+
hookListeners(self.world, component)
|
|
215
|
+
end
|
|
216
|
+
for _v in scheduleComponent do
|
|
217
|
+
_callback(_v, _v, scheduleComponent)
|
|
218
|
+
end
|
|
219
|
+
-- ▲ ReadonlySet.forEach ▲
|
|
220
|
+
end
|
|
221
|
+
function ECSFramework:initEvents()
|
|
222
|
+
RunService.Heartbeat:Connect(function()
|
|
223
|
+
if not self.canCallEffect then
|
|
224
|
+
return nil
|
|
225
|
+
end
|
|
226
|
+
self.canCallEffect = false
|
|
227
|
+
for _, system in self.systems do
|
|
228
|
+
start(system.Instance.__hookStates, system.Instance, self.world, function()
|
|
229
|
+
return system.OnEffect(system.Instance)
|
|
230
|
+
end)
|
|
231
|
+
end
|
|
232
|
+
end)
|
|
233
|
+
local _exp = self:GetAllComponents()
|
|
234
|
+
-- ▼ ReadonlyArray.map ▼
|
|
235
|
+
local _newValue = table.create(#_exp)
|
|
236
|
+
local _callback = function(obj)
|
|
237
|
+
local _condition = Reflect.getOwnMetadata(obj, "ECSFramework:Unaffectable")
|
|
238
|
+
if _condition == nil then
|
|
239
|
+
_condition = false
|
|
240
|
+
end
|
|
241
|
+
local unaffectable = _condition
|
|
242
|
+
local id = Reflect.getOwnMetadata(obj, "ECSFramework:Id")
|
|
243
|
+
return if not unaffectable then id else nil
|
|
244
|
+
end
|
|
245
|
+
for _k, _v in _exp do
|
|
246
|
+
_newValue[_k] = _callback(_v, _k - 1, _exp)
|
|
247
|
+
end
|
|
248
|
+
-- ▲ ReadonlyArray.map ▲
|
|
249
|
+
-- ▼ ReadonlyArray.filterUndefined ▼
|
|
250
|
+
local _length = 0
|
|
251
|
+
for _i in _newValue do
|
|
252
|
+
if _i > _length then
|
|
253
|
+
_length = _i
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
local _result = {}
|
|
257
|
+
local _resultLength = 0
|
|
258
|
+
for _i = 1, _length do
|
|
259
|
+
local _v = _newValue[_i]
|
|
260
|
+
if _v ~= nil then
|
|
261
|
+
_resultLength += 1
|
|
262
|
+
_result[_resultLength] = _v
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
-- ▲ ReadonlyArray.filterUndefined ▲
|
|
266
|
+
local reactives = _result
|
|
267
|
+
for _, ct in reactives do
|
|
268
|
+
self.world:added(ct, function()
|
|
269
|
+
self.canCallEffect = true
|
|
270
|
+
end)
|
|
271
|
+
self.world:changed(ct, function()
|
|
272
|
+
self.canCallEffect = true
|
|
273
|
+
end)
|
|
274
|
+
self.world:removed(ct, function()
|
|
275
|
+
self.canCallEffect = true
|
|
276
|
+
end)
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
function ECSFramework:Start()
|
|
280
|
+
if self.isStarted then
|
|
281
|
+
return nil
|
|
282
|
+
end
|
|
283
|
+
self.isStarted = true
|
|
284
|
+
-- Init
|
|
285
|
+
initWorld(self.world)
|
|
286
|
+
self:initSystems()
|
|
287
|
+
self:initUpdate()
|
|
288
|
+
self:initEvents()
|
|
289
|
+
-- Call events
|
|
290
|
+
self:invokeStartup()
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
return {
|
|
294
|
+
ECSFramework = ECSFramework,
|
|
295
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
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 CollectionService = TS.import(script, TS.getModule(script, "@rbxts", "services")).CollectionService
|
|
5
|
+
local BaseSystem = TS.import(script, script.Parent.Parent, "base-system").BaseSystem
|
|
6
|
+
local ECSSystem = TS.import(script, script.Parent.Parent, "decorators", "system").ECSSystem
|
|
7
|
+
local INSTANCE_ATTRIBUTE_ENTITY_ID = TS.import(script, script.Parent.Parent, "utilities").INSTANCE_ATTRIBUTE_ENTITY_ID
|
|
8
|
+
local InjectType = TS.import(script, script.Parent.Parent, "decorators", "inject-type").InjectType
|
|
9
|
+
local RobloxInstanceSystem
|
|
10
|
+
do
|
|
11
|
+
local super = BaseSystem
|
|
12
|
+
RobloxInstanceSystem = setmetatable({}, {
|
|
13
|
+
__tostring = function()
|
|
14
|
+
return "RobloxInstanceSystem"
|
|
15
|
+
end,
|
|
16
|
+
__index = super,
|
|
17
|
+
})
|
|
18
|
+
RobloxInstanceSystem.__index = RobloxInstanceSystem
|
|
19
|
+
function RobloxInstanceSystem.new(...)
|
|
20
|
+
local self = setmetatable({}, RobloxInstanceSystem)
|
|
21
|
+
return self:constructor(...) or self
|
|
22
|
+
end
|
|
23
|
+
function RobloxInstanceSystem:constructor(...)
|
|
24
|
+
super.constructor(self, ...)
|
|
25
|
+
end
|
|
26
|
+
function RobloxInstanceSystem:GetEntityFromInstance(instance)
|
|
27
|
+
local id = instance:GetAttribute(INSTANCE_ATTRIBUTE_ENTITY_ID)
|
|
28
|
+
return id
|
|
29
|
+
end
|
|
30
|
+
function RobloxInstanceSystem:OnStartup()
|
|
31
|
+
self:Added("$ecsframework:core:framework/components/roblox-instance-component@RobloxInstanceComponent"):connect(function(entity, data)
|
|
32
|
+
data.Instance:SetAttribute(INSTANCE_ATTRIBUTE_ENTITY_ID, entity)
|
|
33
|
+
end)
|
|
34
|
+
self:Removed("$ecsframework:core:framework/components/roblox-instance-component@RobloxInstanceComponent"):connect(function(entity)
|
|
35
|
+
local _result = self:GetComponent(entity, "$ecsframework:core:framework/components/roblox-instance-component@RobloxInstanceComponent")
|
|
36
|
+
if _result ~= nil then
|
|
37
|
+
_result = _result.Instance:Destroy()
|
|
38
|
+
end
|
|
39
|
+
end)
|
|
40
|
+
for component in self:Each("$ecsframework:core:framework/decorators/tagged@TaggedInstance") do
|
|
41
|
+
local options = self:GetComponent(component, "$ecsframework:core:framework/decorators/tagged@TaggedInstance")
|
|
42
|
+
local key = self:GetComponentKey(component)
|
|
43
|
+
local _exp = CollectionService:GetTagged(options.Tag)
|
|
44
|
+
-- ▼ ReadonlyArray.forEach ▼
|
|
45
|
+
local _callback = function(instance)
|
|
46
|
+
local _condition = self:GetEntityFromInstance(instance)
|
|
47
|
+
if _condition == nil then
|
|
48
|
+
_condition = self.world:entity()
|
|
49
|
+
end
|
|
50
|
+
local entity = _condition
|
|
51
|
+
self:SetComponent(entity, options.OnCreateData(instance, self.world, self.container), key)
|
|
52
|
+
self:SetComponent(entity, {
|
|
53
|
+
Instance = instance,
|
|
54
|
+
}, "$ecsframework:core:framework/components/roblox-instance-component@RobloxInstanceComponent")
|
|
55
|
+
instance.AncestryChanged:Once(function(_, parent)
|
|
56
|
+
if parent ~= nil then
|
|
57
|
+
return nil
|
|
58
|
+
end
|
|
59
|
+
if not self:ExistEntity(entity) then
|
|
60
|
+
return nil
|
|
61
|
+
end
|
|
62
|
+
self:DespawnEntity(entity)
|
|
63
|
+
end)
|
|
64
|
+
end
|
|
65
|
+
for _k, _v in _exp do
|
|
66
|
+
_callback(_v, _k - 1, _exp)
|
|
67
|
+
end
|
|
68
|
+
-- ▲ ReadonlyArray.forEach ▲
|
|
69
|
+
CollectionService:GetInstanceAddedSignal(options.Tag):Connect(function(instance)
|
|
70
|
+
local _condition = self:GetEntityFromInstance(instance)
|
|
71
|
+
if _condition == nil then
|
|
72
|
+
_condition = self.world:entity()
|
|
73
|
+
end
|
|
74
|
+
local entity = _condition
|
|
75
|
+
self:SetComponent(entity, options.OnCreateData(instance, self.world, self.container), key)
|
|
76
|
+
self:SetComponent(entity, {
|
|
77
|
+
Instance = instance,
|
|
78
|
+
}, "$ecsframework:core:framework/components/roblox-instance-component@RobloxInstanceComponent")
|
|
79
|
+
instance.AncestryChanged:Once(function(_, parent)
|
|
80
|
+
if parent ~= nil then
|
|
81
|
+
return nil
|
|
82
|
+
end
|
|
83
|
+
if not self:ExistEntity(entity) then
|
|
84
|
+
return nil
|
|
85
|
+
end
|
|
86
|
+
self:DespawnEntity(entity)
|
|
87
|
+
end)
|
|
88
|
+
end)
|
|
89
|
+
CollectionService:GetInstanceRemovedSignal(options.Tag):Connect(function(instance)
|
|
90
|
+
local entity = self:GetEntityFromInstance(instance)
|
|
91
|
+
if entity == nil then
|
|
92
|
+
return nil
|
|
93
|
+
end
|
|
94
|
+
self:RemoveComponent(entity, key)
|
|
95
|
+
end)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
do
|
|
99
|
+
-- (Flamework) RobloxInstanceSystem metadata
|
|
100
|
+
Reflect.defineMetadata(RobloxInstanceSystem, "identifier", "$ecsframework:core:framework/systems/roblox-instance-system@RobloxInstanceSystem")
|
|
101
|
+
-- (Flamework) RobloxInstanceSystem.container metadata
|
|
102
|
+
Reflect.defineMetadata(RobloxInstanceSystem, "flamework:type", "$ecsframework:core:framework/dependencies-container@DependenciesContainer", "container")
|
|
103
|
+
end
|
|
104
|
+
RobloxInstanceSystem = ECSSystem({
|
|
105
|
+
Priority = -math.huge,
|
|
106
|
+
})(RobloxInstanceSystem) or RobloxInstanceSystem
|
|
107
|
+
end
|
|
108
|
+
-- (Flamework) RobloxInstanceSystem.container decorators
|
|
109
|
+
Reflect.decorate(RobloxInstanceSystem, "$ecsframework:core:framework/decorators/inject-type@InjectType", InjectType, {}, "container", false)
|
|
110
|
+
return {
|
|
111
|
+
RobloxInstanceSystem = RobloxInstanceSystem,
|
|
112
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Constructor } from "@flamework/core/out/utility";
|
|
2
|
+
import { Entity } from "./flamecs";
|
|
3
|
+
import { ResolveKey } from "./flamecs/registry";
|
|
4
|
+
export declare function GetIdentifier(obj: object, suffix?: string): string;
|
|
5
|
+
export declare const GetClassName: (object: object) => string;
|
|
6
|
+
export declare function getDeferredConstructor<T extends object>(ctor: Constructor<T>): readonly [InstanceType<T>, (...args: ConstructorParameters<Constructor<T>>) => void];
|
|
7
|
+
export type VoidCallback = () => void;
|
|
8
|
+
export declare const enum RunContext {
|
|
9
|
+
Server = 0,
|
|
10
|
+
Client = 1,
|
|
11
|
+
Shared = 2
|
|
12
|
+
}
|
|
13
|
+
export declare const INSTANCE_ATTRIBUTE_ENTITY_ID: string;
|
|
14
|
+
export declare const SERVER_ATTRIBUTE_ENTITY_ID = "__Server_EntityId";
|
|
15
|
+
/** @metadata macro */
|
|
16
|
+
export declare function DefineClassComponentMeta<T>(ctor: Constructor, value?: unknown, key?: ResolveKey<T>): void;
|
|
17
|
+
export declare function ApplyClassComponentMeta(ctor: Constructor, componentRuntimeId: Entity): void;
|
|
@@ -0,0 +1,69 @@
|
|
|
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 meta = TS.import(script, TS.getModule(script, "@rbxts", "jecs").jecs).meta
|
|
5
|
+
local getId = TS.import(script, script.Parent, "flamecs", "registry").getId
|
|
6
|
+
local RunService = TS.import(script, TS.getModule(script, "@rbxts", "services")).RunService
|
|
7
|
+
local function GetIdentifier(obj, suffix)
|
|
8
|
+
if suffix == nil then
|
|
9
|
+
suffix = ""
|
|
10
|
+
end
|
|
11
|
+
local _condition = Reflect.getMetadata(obj, "identifier")
|
|
12
|
+
if _condition == nil then
|
|
13
|
+
_condition = `UnidentifiedFlameworkListener{suffix}`
|
|
14
|
+
end
|
|
15
|
+
return _condition
|
|
16
|
+
end
|
|
17
|
+
local GetClassName = function(object)
|
|
18
|
+
return `{getmetatable(object)}`
|
|
19
|
+
end
|
|
20
|
+
local function getDeferredConstructor(ctor)
|
|
21
|
+
local obj = setmetatable({}, ctor)
|
|
22
|
+
return { obj, function(...)
|
|
23
|
+
local args = { ... }
|
|
24
|
+
local result = obj:constructor(unpack(args))
|
|
25
|
+
local _arg0 = result == nil or result == obj
|
|
26
|
+
local _arg1 = `Deferred constructors are not allowed to return values.`
|
|
27
|
+
assert(_arg0, _arg1)
|
|
28
|
+
end }
|
|
29
|
+
end
|
|
30
|
+
local INSTANCE_ATTRIBUTE_ENTITY_ID = `__{if RunService:IsServer() then "Server" else "Client"}_EntityId`
|
|
31
|
+
local SERVER_ATTRIBUTE_ENTITY_ID = `__Server_EntityId`
|
|
32
|
+
--* @metadata macro
|
|
33
|
+
local function DefineClassComponentMeta(ctor, value, key)
|
|
34
|
+
local metadata = { key, value }
|
|
35
|
+
local datas = Reflect.getOwnMetadata(ctor, "ECSFramework:Meta") or {}
|
|
36
|
+
local _exp = ctor
|
|
37
|
+
local _array = {}
|
|
38
|
+
local _length = #_array
|
|
39
|
+
local _datasLength = #datas
|
|
40
|
+
table.move(datas, 1, _datasLength, _length + 1, _array)
|
|
41
|
+
_length += _datasLength
|
|
42
|
+
_array[_length + 1] = metadata
|
|
43
|
+
Reflect.defineMetadata(_exp, "ECSFramework:Meta", _array)
|
|
44
|
+
end
|
|
45
|
+
local function ApplyClassComponentMeta(ctor, componentRuntimeId)
|
|
46
|
+
local datas = Reflect.getOwnMetadata(ctor, "ECSFramework:Meta")
|
|
47
|
+
if datas == nil then
|
|
48
|
+
return nil
|
|
49
|
+
end
|
|
50
|
+
-- ▼ ReadonlyArray.forEach ▼
|
|
51
|
+
local _callback = function(_param)
|
|
52
|
+
local key = _param[1]
|
|
53
|
+
local value = _param[2]
|
|
54
|
+
meta(componentRuntimeId, getId(nil, key), value)
|
|
55
|
+
end
|
|
56
|
+
for _k, _v in datas do
|
|
57
|
+
_callback(_v, _k - 1, datas)
|
|
58
|
+
end
|
|
59
|
+
-- ▲ ReadonlyArray.forEach ▲
|
|
60
|
+
end
|
|
61
|
+
return {
|
|
62
|
+
GetIdentifier = GetIdentifier,
|
|
63
|
+
getDeferredConstructor = getDeferredConstructor,
|
|
64
|
+
DefineClassComponentMeta = DefineClassComponentMeta,
|
|
65
|
+
ApplyClassComponentMeta = ApplyClassComponentMeta,
|
|
66
|
+
GetClassName = GetClassName,
|
|
67
|
+
INSTANCE_ATTRIBUTE_ENTITY_ID = INSTANCE_ATTRIBUTE_ENTITY_ID,
|
|
68
|
+
SERVER_ATTRIBUTE_ENTITY_ID = SERVER_ATTRIBUTE_ENTITY_ID,
|
|
69
|
+
}
|
package/out/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { ECSFramework } from "./framework";
|
|
2
|
+
export { Flamework } from "@flamework/core";
|
|
3
|
+
export { ECSComponent } from "./framework/decorators/component";
|
|
4
|
+
export { ECSSystem } from "./framework/decorators/system";
|
|
5
|
+
export { InjectType } from "./framework/decorators/inject-type";
|
|
6
|
+
export { Unaffectable } from "./framework/decorators/unaffectable";
|
|
7
|
+
export { Tagged } from "./framework/decorators/tagged";
|
|
8
|
+
export { BaseSystem } from "./framework/base-system";
|
|
9
|
+
export { DestroyComponent } from "./framework/components/destroyed-component";
|
|
10
|
+
export { RobloxInstanceComponent } from "./framework/components/roblox-instance-component";
|
|
11
|
+
export { RobloxInstanceSystem } from "./framework/systems/roblox-instance-system";
|
|
12
|
+
export { RunContext, DefineClassComponentMeta, ApplyClassComponentMeta, INSTANCE_ATTRIBUTE_ENTITY_ID, SERVER_ATTRIBUTE_ENTITY_ID } from "./framework/utilities";
|
|
13
|
+
export * from "./framework/hooks/query-change";
|
|
14
|
+
export { useAdded } from "./framework/hooks/use-added";
|
|
15
|
+
export { useRemoved } from "./framework/hooks/use-removed";
|
|
16
|
+
export { useChanged } from "./framework/hooks/use-changed";
|
|
17
|
+
export { useEvent } from "./framework/hooks/use-event";
|
|
18
|
+
export { useThrottle } from "./framework/hooks/use-throttle";
|
|
19
|
+
export * from "./framework/flamecs";
|
package/out/init.luau
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local exports = {}
|
|
4
|
+
exports.ECSFramework = TS.import(script, script, "framework").ECSFramework
|
|
5
|
+
exports.Flamework = TS.import(script, TS.getModule(script, "@flamework", "core").out).Flamework
|
|
6
|
+
exports.ECSComponent = TS.import(script, script, "framework", "decorators", "component").ECSComponent
|
|
7
|
+
exports.ECSSystem = TS.import(script, script, "framework", "decorators", "system").ECSSystem
|
|
8
|
+
exports.InjectType = TS.import(script, script, "framework", "decorators", "inject-type").InjectType
|
|
9
|
+
exports.Unaffectable = TS.import(script, script, "framework", "decorators", "unaffectable").Unaffectable
|
|
10
|
+
exports.Tagged = TS.import(script, script, "framework", "decorators", "tagged").Tagged
|
|
11
|
+
exports.BaseSystem = TS.import(script, script, "framework", "base-system").BaseSystem
|
|
12
|
+
exports.RobloxInstanceComponent = TS.import(script, script, "framework", "components", "roblox-instance-component").RobloxInstanceComponent
|
|
13
|
+
exports.RobloxInstanceSystem = TS.import(script, script, "framework", "systems", "roblox-instance-system").RobloxInstanceSystem
|
|
14
|
+
local _utilities = TS.import(script, script, "framework", "utilities")
|
|
15
|
+
exports.DefineClassComponentMeta = _utilities.DefineClassComponentMeta
|
|
16
|
+
exports.ApplyClassComponentMeta = _utilities.ApplyClassComponentMeta
|
|
17
|
+
exports.INSTANCE_ATTRIBUTE_ENTITY_ID = _utilities.INSTANCE_ATTRIBUTE_ENTITY_ID
|
|
18
|
+
exports.SERVER_ATTRIBUTE_ENTITY_ID = _utilities.SERVER_ATTRIBUTE_ENTITY_ID
|
|
19
|
+
for _k, _v in TS.import(script, script, "framework", "hooks", "query-change") or {} do
|
|
20
|
+
exports[_k] = _v
|
|
21
|
+
end
|
|
22
|
+
exports.useAdded = TS.import(script, script, "framework", "hooks", "use-added").useAdded
|
|
23
|
+
exports.useRemoved = TS.import(script, script, "framework", "hooks", "use-removed").useRemoved
|
|
24
|
+
exports.useChanged = TS.import(script, script, "framework", "hooks", "use-changed").useChanged
|
|
25
|
+
exports.useEvent = TS.import(script, script, "framework", "hooks", "use-event").useEvent
|
|
26
|
+
exports.useThrottle = TS.import(script, script, "framework", "hooks", "use-throttle").useThrottle
|
|
27
|
+
for _k, _v in TS.import(script, script, "framework", "flamecs") or {} do
|
|
28
|
+
exports[_k] = _v
|
|
29
|
+
end
|
|
30
|
+
return exports
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ecsframework/core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "out/init.lua",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "rbxtsc",
|
|
8
|
+
"watch": "rbxtsc -w",
|
|
9
|
+
"test:watch": "rbxtsc -w --type=game -p test -i test/include",
|
|
10
|
+
"serve": "rojo serve test/default.project.json",
|
|
11
|
+
"prepublishOnly": "npm run build"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [],
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"types": "out/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"out",
|
|
19
|
+
"!**/*.tsbuildinfo",
|
|
20
|
+
"!**/*.spec.lua"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@rbxts/compiler-types": "^3.0.0-types.0",
|
|
27
|
+
"@rbxts/types": "^1.0.876",
|
|
28
|
+
"@typescript-eslint/eslint-plugin": "^8.39.1",
|
|
29
|
+
"@typescript-eslint/parser": "^8.39.1",
|
|
30
|
+
"eslint": "^8.57.1",
|
|
31
|
+
"eslint-config-prettier": "^10.1.8",
|
|
32
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
33
|
+
"eslint-plugin-roblox-ts": "^1.1.0",
|
|
34
|
+
"prettier": "^3.6.2",
|
|
35
|
+
"roblox-ts": "^3.0.0",
|
|
36
|
+
"typescript": "^5.5.3"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@rbxts/immut": "^0.4.4-ts.0",
|
|
40
|
+
"@rbxts/jecs": "^0.9.0-rc.10",
|
|
41
|
+
"@rbxts/services": "^1.5.5",
|
|
42
|
+
"@rbxts/signal": "^1.1.1"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"@flamework/core": "*",
|
|
46
|
+
"rbxts-transformer-flamework": "*"
|
|
47
|
+
}
|
|
48
|
+
}
|