@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,96 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local stack = {}
|
|
3
|
+
local function cleanupUnused()
|
|
4
|
+
-- ▼ Array.pop ▼
|
|
5
|
+
local _length = #stack
|
|
6
|
+
local _result = stack[_length]
|
|
7
|
+
stack[_length] = nil
|
|
8
|
+
-- ▲ Array.pop ▲
|
|
9
|
+
local context = _result
|
|
10
|
+
assert(context, "No context to cleanup.")
|
|
11
|
+
for _, storage in pairs(context.node) do
|
|
12
|
+
for key, state in storage.states do
|
|
13
|
+
if not (context.activeKeys[key] ~= nil) and (not storage.cleanup or storage.cleanup(state)) then
|
|
14
|
+
storage.states[key] = nil
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
--[[
|
|
20
|
+
*
|
|
21
|
+
* Starts a new stack frame for a function, ensuring cleanup after execution.
|
|
22
|
+
* Intended to be used in systems.
|
|
23
|
+
*
|
|
24
|
+
* @param node - The node to store the state for the current function.
|
|
25
|
+
* @param callback - The function to execute within the new stack frame.
|
|
26
|
+
|
|
27
|
+
]]
|
|
28
|
+
local function start(node, system, world, callback)
|
|
29
|
+
local _arg0 = {
|
|
30
|
+
activeKeys = {},
|
|
31
|
+
node = node,
|
|
32
|
+
world = world,
|
|
33
|
+
system = system,
|
|
34
|
+
}
|
|
35
|
+
table.insert(stack, _arg0)
|
|
36
|
+
callback()
|
|
37
|
+
cleanupUnused()
|
|
38
|
+
stack[#stack] = nil
|
|
39
|
+
end
|
|
40
|
+
local function useSystem()
|
|
41
|
+
local context = stack[#stack]
|
|
42
|
+
assert(context, "Hooks can only be used within a `start` function.")
|
|
43
|
+
return context.system
|
|
44
|
+
end
|
|
45
|
+
local function useWorld()
|
|
46
|
+
local context = stack[#stack]
|
|
47
|
+
assert(context, "Hooks can only be used within a `start` function.")
|
|
48
|
+
return context.world
|
|
49
|
+
end
|
|
50
|
+
--[[
|
|
51
|
+
*
|
|
52
|
+
* Creates or retrieves a state object for a hook, keyed by a unique identifier.
|
|
53
|
+
*
|
|
54
|
+
* @template T The type of the hook state.
|
|
55
|
+
* @param key - A unique string identifier for the hook state.
|
|
56
|
+
* @param discriminator - An optional value to further distinguish different
|
|
57
|
+
* states within the same key. Defaults to the key itself.
|
|
58
|
+
* @param cleanup - An optional function that determines whether the state
|
|
59
|
+
* should be cleaned up. It should return true if the state should be removed.
|
|
60
|
+
* If not provided, the state will be cleaned up when the hook was not
|
|
61
|
+
* accessed in the current context.
|
|
62
|
+
* @returns The state object of type T.
|
|
63
|
+
|
|
64
|
+
]]
|
|
65
|
+
local function useHookState(key, discriminator, cleanup)
|
|
66
|
+
if discriminator == nil then
|
|
67
|
+
discriminator = key
|
|
68
|
+
end
|
|
69
|
+
local context = stack[#stack]
|
|
70
|
+
assert(context, "Hooks can only be used within a `start` function.")
|
|
71
|
+
local storage = context.node[key]
|
|
72
|
+
if not storage then
|
|
73
|
+
storage = {
|
|
74
|
+
cleanup = cleanup,
|
|
75
|
+
states = {},
|
|
76
|
+
}
|
|
77
|
+
context.node[key] = storage
|
|
78
|
+
end
|
|
79
|
+
local stringDiscriminator = tostring(discriminator)
|
|
80
|
+
local compositeKey = `{key}-{stringDiscriminator}`
|
|
81
|
+
context.activeKeys[compositeKey] = true
|
|
82
|
+
local state = storage.states[compositeKey]
|
|
83
|
+
if state == nil then
|
|
84
|
+
state = {}
|
|
85
|
+
local _states = storage.states
|
|
86
|
+
local _state = state
|
|
87
|
+
_states[compositeKey] = _state
|
|
88
|
+
end
|
|
89
|
+
return state
|
|
90
|
+
end
|
|
91
|
+
return {
|
|
92
|
+
start = start,
|
|
93
|
+
useSystem = useSystem,
|
|
94
|
+
useWorld = useWorld,
|
|
95
|
+
useHookState = useHookState,
|
|
96
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Entity } from "@rbxts/jecs";
|
|
2
|
+
import { ComponentKey } from "../flamecs/registry";
|
|
3
|
+
import { Modding } from "@flamework/core";
|
|
4
|
+
export interface QueryRecord<T> {
|
|
5
|
+
new?: T;
|
|
6
|
+
old?: T;
|
|
7
|
+
}
|
|
8
|
+
type Return<T> = [entity: Entity, record: QueryRecord<T>, isDestroyedEntity: boolean];
|
|
9
|
+
/** @metadata macro */
|
|
10
|
+
export declare function QueryChange<T>(componentTypeUd?: ComponentKey<T>, key?: Modding.Caller<"uuid">): IterableFunction<Return<T>>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local _flamecs = TS.import(script, script.Parent.Parent, "flamecs")
|
|
4
|
+
local useHookState = _flamecs.useHookState
|
|
5
|
+
local useSystem = _flamecs.useSystem
|
|
6
|
+
local useWorld = _flamecs.useWorld
|
|
7
|
+
--* @metadata macro
|
|
8
|
+
local function QueryChange(componentTypeUd, key)
|
|
9
|
+
local storage = useHookState(key, componentTypeUd, function()
|
|
10
|
+
return false
|
|
11
|
+
end)
|
|
12
|
+
local world = useWorld()
|
|
13
|
+
local system = useSystem()
|
|
14
|
+
local _value = storage.componentTypeUd
|
|
15
|
+
if not (_value ~= "" and _value) then
|
|
16
|
+
storage.componentTypeUd = componentTypeUd
|
|
17
|
+
local componentId = system:GetComponentId(componentTypeUd)
|
|
18
|
+
local query = world:query(componentId)
|
|
19
|
+
local _result = storage.connections
|
|
20
|
+
if _result ~= nil then
|
|
21
|
+
-- ▼ ReadonlyArray.forEach ▼
|
|
22
|
+
local _callback = function(disconnect)
|
|
23
|
+
return disconnect()
|
|
24
|
+
end
|
|
25
|
+
for _k, _v in _result do
|
|
26
|
+
_callback(_v, _k - 1, _result)
|
|
27
|
+
end
|
|
28
|
+
-- ▲ ReadonlyArray.forEach ▲
|
|
29
|
+
end
|
|
30
|
+
storage.connections = {}
|
|
31
|
+
storage.changes = {}
|
|
32
|
+
storage.prevEntityDatas = {}
|
|
33
|
+
local _connections = storage.connections
|
|
34
|
+
local _arg0 = world:added(componentId, function(entity, _, data)
|
|
35
|
+
local record = {
|
|
36
|
+
old = nil,
|
|
37
|
+
new = data,
|
|
38
|
+
}
|
|
39
|
+
local _changes = storage.changes
|
|
40
|
+
local _arg0_1 = { entity, record, false }
|
|
41
|
+
table.insert(_changes, _arg0_1)
|
|
42
|
+
end)
|
|
43
|
+
table.insert(_connections, _arg0)
|
|
44
|
+
local _connections_1 = storage.connections
|
|
45
|
+
local _arg0_1 = world:changed(componentId, function(entity, _, data)
|
|
46
|
+
local _prevEntityDatas = storage.prevEntityDatas
|
|
47
|
+
local _entity = entity
|
|
48
|
+
local prevData = _prevEntityDatas[_entity]
|
|
49
|
+
local _changes = storage.changes
|
|
50
|
+
local _arg0_2 = { entity, {
|
|
51
|
+
old = prevData,
|
|
52
|
+
new = data,
|
|
53
|
+
}, false }
|
|
54
|
+
table.insert(_changes, _arg0_2)
|
|
55
|
+
local _prevEntityDatas_1 = storage.prevEntityDatas
|
|
56
|
+
local _entity_1 = entity
|
|
57
|
+
local _data = data
|
|
58
|
+
_prevEntityDatas_1[_entity_1] = _data
|
|
59
|
+
end)
|
|
60
|
+
table.insert(_connections_1, _arg0_1)
|
|
61
|
+
local _connections_2 = storage.connections
|
|
62
|
+
local _arg0_2 = world:removed(componentId, function(entity)
|
|
63
|
+
local _prevEntityDatas = storage.prevEntityDatas
|
|
64
|
+
local _entity = entity
|
|
65
|
+
local prevData = _prevEntityDatas[_entity]
|
|
66
|
+
local _changes = storage.changes
|
|
67
|
+
local _arg0_3 = { entity, {
|
|
68
|
+
old = prevData,
|
|
69
|
+
new = nil,
|
|
70
|
+
}, system:HasComponent(entity, "$ecsframework:core:framework/components/destroyed-component@DestroyComponent") }
|
|
71
|
+
table.insert(_changes, _arg0_3)
|
|
72
|
+
end)
|
|
73
|
+
table.insert(_connections_2, _arg0_2)
|
|
74
|
+
local iter = query:iter()
|
|
75
|
+
return function()
|
|
76
|
+
local entity, componentData = iter()
|
|
77
|
+
if componentData == nil then
|
|
78
|
+
return nil
|
|
79
|
+
end
|
|
80
|
+
storage.prevEntityDatas[entity] = componentData
|
|
81
|
+
return { entity, {
|
|
82
|
+
new = componentData,
|
|
83
|
+
old = nil,
|
|
84
|
+
}, false }
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
return function()
|
|
88
|
+
local result = table.remove(storage.changes, 1)
|
|
89
|
+
if result == nil then
|
|
90
|
+
return nil
|
|
91
|
+
end
|
|
92
|
+
local _prevEntityDatas = storage.prevEntityDatas
|
|
93
|
+
local _arg0 = result[1]
|
|
94
|
+
local _condition = not (_prevEntityDatas[_arg0] ~= nil)
|
|
95
|
+
if _condition then
|
|
96
|
+
_condition = result[2].new
|
|
97
|
+
end
|
|
98
|
+
if _condition ~= 0 and _condition == _condition and _condition ~= "" and _condition then
|
|
99
|
+
local _prevEntityDatas_1 = storage.prevEntityDatas
|
|
100
|
+
local _arg0_1 = result[1]
|
|
101
|
+
local _new = result[2].new
|
|
102
|
+
_prevEntityDatas_1[_arg0_1] = _new
|
|
103
|
+
end
|
|
104
|
+
return result
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
return {
|
|
108
|
+
QueryChange = QueryChange,
|
|
109
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Modding } from "@flamework/core";
|
|
2
|
+
import { ComponentKey, Entity } from "../flamecs/registry";
|
|
3
|
+
/**
|
|
4
|
+
* Utility for handling event-like objects.
|
|
5
|
+
*
|
|
6
|
+
* Connects to the provided event-like object and stores incoming events.
|
|
7
|
+
* Returns an iterable function that yields the stored events in the order they
|
|
8
|
+
* were received.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The tuple type of event arguments.
|
|
11
|
+
* @param event - The event-like object to connect to.
|
|
12
|
+
* @param discriminator - An optional value to additionally key by.
|
|
13
|
+
* @param key - An automatically generated key to store the event state.
|
|
14
|
+
* @returns An iterable function that yields stored events.
|
|
15
|
+
* @metadata macro
|
|
16
|
+
*/
|
|
17
|
+
export declare function useAdded<T>(componentKey?: ComponentKey<T>, key?: Modding.Caller<"uuid">): IterableFunction<[Entity, T]>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local _flamecs = TS.import(script, script.Parent.Parent, "flamecs")
|
|
4
|
+
local useHookState = _flamecs.useHookState
|
|
5
|
+
local useSystem = _flamecs.useSystem
|
|
6
|
+
--[[
|
|
7
|
+
*
|
|
8
|
+
* Utility for handling event-like objects.
|
|
9
|
+
*
|
|
10
|
+
* Connects to the provided event-like object and stores incoming events.
|
|
11
|
+
* Returns an iterable function that yields the stored events in the order they
|
|
12
|
+
* were received.
|
|
13
|
+
*
|
|
14
|
+
* @template T - The tuple type of event arguments.
|
|
15
|
+
* @param event - The event-like object to connect to.
|
|
16
|
+
* @param discriminator - An optional value to additionally key by.
|
|
17
|
+
* @param key - An automatically generated key to store the event state.
|
|
18
|
+
* @returns An iterable function that yields stored events.
|
|
19
|
+
* @metadata macro
|
|
20
|
+
|
|
21
|
+
]]
|
|
22
|
+
local function useAdded(componentKey, key)
|
|
23
|
+
local _key = key
|
|
24
|
+
assert(_key ~= "" and _key)
|
|
25
|
+
local storage = useHookState(key, componentKey, function()
|
|
26
|
+
return false
|
|
27
|
+
end)
|
|
28
|
+
local system = useSystem()
|
|
29
|
+
if storage.component ~= componentKey and storage.connection then
|
|
30
|
+
storage.connection()
|
|
31
|
+
storage.connection = nil
|
|
32
|
+
end
|
|
33
|
+
if not storage.connection then
|
|
34
|
+
storage.events = {}
|
|
35
|
+
for entity in system:Each(componentKey) do
|
|
36
|
+
local _events = storage.events
|
|
37
|
+
local _arg0 = { entity, system:GetComponent(entity, componentKey) }
|
|
38
|
+
table.insert(_events, _arg0)
|
|
39
|
+
end
|
|
40
|
+
storage.component = componentKey
|
|
41
|
+
storage.connection = system:Added(componentKey):connect(function(entity, data)
|
|
42
|
+
local _events = storage.events
|
|
43
|
+
local _arg0 = { entity, data }
|
|
44
|
+
table.insert(_events, _arg0)
|
|
45
|
+
return #_events
|
|
46
|
+
end)
|
|
47
|
+
end
|
|
48
|
+
return function()
|
|
49
|
+
return table.remove(storage.events, 1)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
return {
|
|
53
|
+
useAdded = useAdded,
|
|
54
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Modding } from "@flamework/core";
|
|
2
|
+
import { ComponentKey, Entity } from "../flamecs/registry";
|
|
3
|
+
/**
|
|
4
|
+
* Utility for handling event-like objects.
|
|
5
|
+
*
|
|
6
|
+
* Connects to the provided event-like object and stores incoming events.
|
|
7
|
+
* Returns an iterable function that yields the stored events in the order they
|
|
8
|
+
* were received.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The tuple type of event arguments.
|
|
11
|
+
* @param event - The event-like object to connect to.
|
|
12
|
+
* @param discriminator - An optional value to additionally key by.
|
|
13
|
+
* @param key - An automatically generated key to store the event state.
|
|
14
|
+
* @returns An iterable function that yields stored events.
|
|
15
|
+
* @metadata macro
|
|
16
|
+
*/
|
|
17
|
+
export declare function useChanged<T>(componentKey?: ComponentKey<T>, key?: Modding.Caller<"uuid">): IterableFunction<[Entity, T]>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local _flamecs = TS.import(script, script.Parent.Parent, "flamecs")
|
|
4
|
+
local useHookState = _flamecs.useHookState
|
|
5
|
+
local useSystem = _flamecs.useSystem
|
|
6
|
+
--[[
|
|
7
|
+
*
|
|
8
|
+
* Utility for handling event-like objects.
|
|
9
|
+
*
|
|
10
|
+
* Connects to the provided event-like object and stores incoming events.
|
|
11
|
+
* Returns an iterable function that yields the stored events in the order they
|
|
12
|
+
* were received.
|
|
13
|
+
*
|
|
14
|
+
* @template T - The tuple type of event arguments.
|
|
15
|
+
* @param event - The event-like object to connect to.
|
|
16
|
+
* @param discriminator - An optional value to additionally key by.
|
|
17
|
+
* @param key - An automatically generated key to store the event state.
|
|
18
|
+
* @returns An iterable function that yields stored events.
|
|
19
|
+
* @metadata macro
|
|
20
|
+
|
|
21
|
+
]]
|
|
22
|
+
local function useChanged(componentKey, key)
|
|
23
|
+
local _key = key
|
|
24
|
+
assert(_key ~= "" and _key)
|
|
25
|
+
local storage = useHookState(key, componentKey, function()
|
|
26
|
+
return false
|
|
27
|
+
end)
|
|
28
|
+
local system = useSystem()
|
|
29
|
+
if storage.component ~= componentKey and storage.connection then
|
|
30
|
+
storage.connection()
|
|
31
|
+
storage.connection = nil
|
|
32
|
+
end
|
|
33
|
+
if not storage.connection then
|
|
34
|
+
storage.events = {}
|
|
35
|
+
for entity in system:Each(componentKey) do
|
|
36
|
+
local _events = storage.events
|
|
37
|
+
local _arg0 = { entity, system:GetComponent(entity, componentKey) }
|
|
38
|
+
table.insert(_events, _arg0)
|
|
39
|
+
end
|
|
40
|
+
storage.component = componentKey
|
|
41
|
+
storage.connection = system:Changed(componentKey):connect(function(entity, data)
|
|
42
|
+
local _events = storage.events
|
|
43
|
+
local _arg0 = { entity, data }
|
|
44
|
+
table.insert(_events, _arg0)
|
|
45
|
+
return #_events
|
|
46
|
+
end)
|
|
47
|
+
end
|
|
48
|
+
return function()
|
|
49
|
+
return table.remove(storage.events, 1)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
return {
|
|
53
|
+
useChanged = useChanged,
|
|
54
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Modding } from "@flamework/core";
|
|
2
|
+
type Callback<T extends Array<unknown>> = (...args: T) => void;
|
|
3
|
+
type EventLike<T extends Array<unknown> = Array<unknown>> = ((callback: Callback<T>) => ConnectionLike) | {
|
|
4
|
+
Connect(callback: Callback<T>): ConnectionLike;
|
|
5
|
+
} | {
|
|
6
|
+
connect(callback: Callback<T>): ConnectionLike;
|
|
7
|
+
} | {
|
|
8
|
+
on(callback: Callback<T>): ConnectionLike;
|
|
9
|
+
};
|
|
10
|
+
type ConnectionLike = (() => void) | {
|
|
11
|
+
Disconnect(): void;
|
|
12
|
+
} | {
|
|
13
|
+
disconnect(): void;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Utility for handling event-like objects.
|
|
17
|
+
*
|
|
18
|
+
* Connects to the provided event-like object and stores incoming events.
|
|
19
|
+
* Returns an iterable function that yields the stored events in the order they
|
|
20
|
+
* were received.
|
|
21
|
+
*
|
|
22
|
+
* @template T - The tuple type of event arguments.
|
|
23
|
+
* @param event - The event-like object to connect to.
|
|
24
|
+
* @param discriminator - An optional value to additionally key by.
|
|
25
|
+
* @param key - An automatically generated key to store the event state.
|
|
26
|
+
* @returns An iterable function that yields stored events.
|
|
27
|
+
* @metadata macro
|
|
28
|
+
*/
|
|
29
|
+
export declare function useEvent<T extends Array<unknown>>(event: EventLike<T>, discriminator?: unknown, key?: Modding.Caller<"uuid">): IterableFunction<T>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local useHookState = TS.import(script, script.Parent.Parent, "flamecs").useHookState
|
|
4
|
+
local function connect(event, callback)
|
|
5
|
+
local _event = event
|
|
6
|
+
if type(_event) == "function" then
|
|
7
|
+
return event(callback)
|
|
8
|
+
else
|
|
9
|
+
local _event_1 = event
|
|
10
|
+
local _condition = typeof(_event_1) == "RBXScriptSignal"
|
|
11
|
+
if not _condition then
|
|
12
|
+
_condition = event.Connect ~= nil
|
|
13
|
+
end
|
|
14
|
+
if _condition then
|
|
15
|
+
return event:Connect(callback)
|
|
16
|
+
elseif event.connect ~= nil then
|
|
17
|
+
return event:connect(callback)
|
|
18
|
+
elseif event.on ~= nil then
|
|
19
|
+
return event:on(callback)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
error("Event-like object does not have a supported connect method.")
|
|
23
|
+
end
|
|
24
|
+
local function disconnect(connection)
|
|
25
|
+
local _connection = connection
|
|
26
|
+
if type(_connection) == "function" then
|
|
27
|
+
connection()
|
|
28
|
+
else
|
|
29
|
+
local _connection_1 = connection
|
|
30
|
+
local _condition = typeof(_connection_1) == "RBXScriptConnection"
|
|
31
|
+
if not _condition then
|
|
32
|
+
_condition = connection.Disconnect ~= nil
|
|
33
|
+
end
|
|
34
|
+
if _condition then
|
|
35
|
+
connection:Disconnect()
|
|
36
|
+
elseif connection.disconnect ~= nil then
|
|
37
|
+
connection:disconnect()
|
|
38
|
+
else
|
|
39
|
+
error("Connection-like object does not have a supported disconnect method.")
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
local function cleanup(storage)
|
|
44
|
+
if storage.connection then
|
|
45
|
+
disconnect(storage.connection)
|
|
46
|
+
end
|
|
47
|
+
return false
|
|
48
|
+
end
|
|
49
|
+
--[[
|
|
50
|
+
*
|
|
51
|
+
* Utility for handling event-like objects.
|
|
52
|
+
*
|
|
53
|
+
* Connects to the provided event-like object and stores incoming events.
|
|
54
|
+
* Returns an iterable function that yields the stored events in the order they
|
|
55
|
+
* were received.
|
|
56
|
+
*
|
|
57
|
+
* @template T - The tuple type of event arguments.
|
|
58
|
+
* @param event - The event-like object to connect to.
|
|
59
|
+
* @param discriminator - An optional value to additionally key by.
|
|
60
|
+
* @param key - An automatically generated key to store the event state.
|
|
61
|
+
* @returns An iterable function that yields stored events.
|
|
62
|
+
* @metadata macro
|
|
63
|
+
|
|
64
|
+
]]
|
|
65
|
+
local function useEvent(event, discriminator, key)
|
|
66
|
+
local _key = key
|
|
67
|
+
assert(_key ~= "" and _key)
|
|
68
|
+
local storage = useHookState(key, discriminator, function()
|
|
69
|
+
return false
|
|
70
|
+
end)
|
|
71
|
+
if storage.event ~= event and storage.connection then
|
|
72
|
+
disconnect(storage.connection)
|
|
73
|
+
storage.connection = nil
|
|
74
|
+
end
|
|
75
|
+
if not storage.connection then
|
|
76
|
+
storage.events = {}
|
|
77
|
+
storage.event = event
|
|
78
|
+
storage.connection = connect(event, function(...)
|
|
79
|
+
local args = { ... }
|
|
80
|
+
local _events = storage.events
|
|
81
|
+
local _args = args
|
|
82
|
+
table.insert(_events, _args)
|
|
83
|
+
return #_events
|
|
84
|
+
end)
|
|
85
|
+
end
|
|
86
|
+
return function()
|
|
87
|
+
return table.remove(storage.events, 1)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
return {
|
|
91
|
+
useEvent = useEvent,
|
|
92
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Modding } from "@flamework/core";
|
|
2
|
+
import { ComponentKey, Entity } from "../flamecs/registry";
|
|
3
|
+
/**
|
|
4
|
+
* A hook that provides an iterable function that yields entities that have been removed.
|
|
5
|
+
* It works by connecting to the Removed event of the system and storing the incoming events.
|
|
6
|
+
* It returns the stored events in the order they were received.
|
|
7
|
+
*
|
|
8
|
+
* @param componentKey - The component key of the component to connect to.
|
|
9
|
+
* @param key - An automatically generated key to store the event state.
|
|
10
|
+
* @returns An iterable function that yields stored events.
|
|
11
|
+
* @metadata macro
|
|
12
|
+
*/
|
|
13
|
+
export declare function useRemoved<T>(componentKey?: ComponentKey<T>, key?: Modding.Caller<"uuid">): IterableFunction<[Entity, T]>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local _flamecs = TS.import(script, script.Parent.Parent, "flamecs")
|
|
4
|
+
local useHookState = _flamecs.useHookState
|
|
5
|
+
local useSystem = _flamecs.useSystem
|
|
6
|
+
--[[
|
|
7
|
+
*
|
|
8
|
+
* A hook that provides an iterable function that yields entities that have been removed.
|
|
9
|
+
* It works by connecting to the Removed event of the system and storing the incoming events.
|
|
10
|
+
* It returns the stored events in the order they were received.
|
|
11
|
+
*
|
|
12
|
+
* @param componentKey - The component key of the component to connect to.
|
|
13
|
+
* @param key - An automatically generated key to store the event state.
|
|
14
|
+
* @returns An iterable function that yields stored events.
|
|
15
|
+
* @metadata macro
|
|
16
|
+
|
|
17
|
+
]]
|
|
18
|
+
local function useRemoved(componentKey, key)
|
|
19
|
+
local _key = key
|
|
20
|
+
assert(_key ~= "" and _key)
|
|
21
|
+
local storage = useHookState(key, componentKey, function()
|
|
22
|
+
return false
|
|
23
|
+
end)
|
|
24
|
+
local system = useSystem()
|
|
25
|
+
if storage.component ~= componentKey and storage.connection then
|
|
26
|
+
storage.connection()
|
|
27
|
+
storage.connection = nil
|
|
28
|
+
end
|
|
29
|
+
if not storage.connection then
|
|
30
|
+
storage.events = {}
|
|
31
|
+
for entity in system:Each(componentKey) do
|
|
32
|
+
local _events = storage.events
|
|
33
|
+
local _arg0 = { entity, system:GetComponent(entity, componentKey) }
|
|
34
|
+
table.insert(_events, _arg0)
|
|
35
|
+
end
|
|
36
|
+
-- Store the component key and the connection.
|
|
37
|
+
storage.component = componentKey
|
|
38
|
+
storage.connection = system:Removed(componentKey):connect(function(entity)
|
|
39
|
+
local _events = storage.events
|
|
40
|
+
local _arg0 = { entity, system:GetComponent(entity, componentKey) }
|
|
41
|
+
table.insert(_events, _arg0)
|
|
42
|
+
return #_events
|
|
43
|
+
end)
|
|
44
|
+
end
|
|
45
|
+
-- Return an iterable function that yields the stored events.
|
|
46
|
+
return function()
|
|
47
|
+
return table.remove(storage.events, 1)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
return {
|
|
51
|
+
useRemoved = useRemoved,
|
|
52
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Modding } from "@flamework/core";
|
|
2
|
+
/**
|
|
3
|
+
* Utility for easy time-based throttling.
|
|
4
|
+
*
|
|
5
|
+
* Accepts a duration and returns `true` if it has been that long since the last
|
|
6
|
+
* time this function returned `true`. Always returns `true` the first time.
|
|
7
|
+
*
|
|
8
|
+
* @param seconds - The number of seconds to throttle for.
|
|
9
|
+
* @param discriminator - An optional value to additionally key by.
|
|
10
|
+
* @param key - An automatically generated key to store the throttle state.
|
|
11
|
+
* @returns - Returns true every x seconds, otherwise false.
|
|
12
|
+
* @metadata macro
|
|
13
|
+
*/
|
|
14
|
+
export declare function useThrottle(seconds: number, discriminator?: unknown, key?: Modding.Caller<"uuid">): boolean;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local useHookState = TS.import(script, script.Parent.Parent, "flamecs").useHookState
|
|
4
|
+
local function cleanup(storage)
|
|
5
|
+
return os.clock() >= storage.expiry
|
|
6
|
+
end
|
|
7
|
+
--[[
|
|
8
|
+
*
|
|
9
|
+
* Utility for easy time-based throttling.
|
|
10
|
+
*
|
|
11
|
+
* Accepts a duration and returns `true` if it has been that long since the last
|
|
12
|
+
* time this function returned `true`. Always returns `true` the first time.
|
|
13
|
+
*
|
|
14
|
+
* @param seconds - The number of seconds to throttle for.
|
|
15
|
+
* @param discriminator - An optional value to additionally key by.
|
|
16
|
+
* @param key - An automatically generated key to store the throttle state.
|
|
17
|
+
* @returns - Returns true every x seconds, otherwise false.
|
|
18
|
+
* @metadata macro
|
|
19
|
+
|
|
20
|
+
]]
|
|
21
|
+
local function useThrottle(seconds, discriminator, key)
|
|
22
|
+
local storage = useHookState(key, discriminator, cleanup)
|
|
23
|
+
local currentTime = os.clock()
|
|
24
|
+
if storage.time == nil or currentTime - storage.time >= seconds then
|
|
25
|
+
storage.time = currentTime
|
|
26
|
+
storage.expiry = currentTime + seconds
|
|
27
|
+
return true
|
|
28
|
+
end
|
|
29
|
+
return false
|
|
30
|
+
end
|
|
31
|
+
return {
|
|
32
|
+
useThrottle = useThrottle,
|
|
33
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Constructor } from "@flamework/core/out/utility";
|
|
2
|
+
import { Entity } from "@rbxts/jecs";
|
|
3
|
+
import { DependenciesContainer } from "./dependencies-container";
|
|
4
|
+
import { Signal } from "./flamecs/signal";
|
|
5
|
+
export declare class ECSFramework {
|
|
6
|
+
private container;
|
|
7
|
+
private systems;
|
|
8
|
+
private canCallEffect;
|
|
9
|
+
private isStarted;
|
|
10
|
+
private baseSystemCtor;
|
|
11
|
+
readonly componentsMap: ReadonlyMap<string, Constructor>;
|
|
12
|
+
private components;
|
|
13
|
+
private world;
|
|
14
|
+
readonly signals: {
|
|
15
|
+
added: ReadonlyMap<Entity, Signal<[Entity, unknown]>>;
|
|
16
|
+
changed: ReadonlyMap<Entity, Signal<[Entity, unknown]>>;
|
|
17
|
+
removed: ReadonlyMap<Entity, Signal<[Entity]>>;
|
|
18
|
+
};
|
|
19
|
+
constructor(container?: DependenciesContainer);
|
|
20
|
+
GetAllComponents(): Constructor[];
|
|
21
|
+
private initSystems;
|
|
22
|
+
private invokeStartup;
|
|
23
|
+
private initUpdate;
|
|
24
|
+
private initComponents;
|
|
25
|
+
private initComponentLifecycles;
|
|
26
|
+
private initEvents;
|
|
27
|
+
Start(): void;
|
|
28
|
+
}
|