@quenty/immediateutils 1.1.0
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/CHANGELOG.md +14 -0
- package/LICENSE.md +21 -0
- package/README.md +23 -0
- package/default.project.json +14 -0
- package/package.json +52 -0
- package/src/Client/ImmediateServiceClient.lua +30 -0
- package/src/Server/ImmediateService.lua +25 -0
- package/src/Shared/core/ImmediateCoreComponents.lua +43 -0
- package/src/Shared/core/ImmediateCoreUtils.lua +188 -0
- package/src/Shared/core/ImmediateInstall.lua +53 -0
- package/src/Shared/core/ImmediateJecsUtils.lua +249 -0
- package/src/Shared/core/ImmediateTypes.lua +79 -0
- package/src/Shared/middleware/ImmediateBuffers/ImmediateBufferUtils.lua +65 -0
- package/src/Shared/middleware/ImmediateBuffers/ImmediateBuffersInstall.lua +35 -0
- package/src/Shared/middleware/ImmediateHooks/ImmediateCommonHooks.lua +86 -0
- package/src/Shared/middleware/ImmediateHooks/ImmediateHookAverageUtils.lua +26 -0
- package/src/Shared/middleware/ImmediateHooks/ImmediateHookSpringUtils.lua +31 -0
- package/src/Shared/middleware/ImmediateHooks/ImmediateHookUtils.lua +214 -0
- package/src/Shared/middleware/ImmediateHooks/ImmediateHooksInstall.lua +46 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/async.lua +30 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/cache.lua +34 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/changed.lua +39 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/conditionSustained.lua +31 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/counter.lua +19 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/delayed.lua +31 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/delta.lua +41 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/deltatime.lua +32 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/difference.lua +31 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/draw.lua +17 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/entity.lua +21 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/filterDescendants.lua +62 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/findChild.lua +36 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/gate.lua +23 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/gatecounter.lua +37 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/hookEntity.lua +29 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/linearWalk.lua +143 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/maid.lua +25 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/noise.lua +54 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/random.lua +20 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/randomChoice.lua +52 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/rtbuffer.lua +28 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/scheduledValues.lua +143 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/scheduler.lua +191 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/sin.lua +38 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/slidingAvg.lua +78 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/spring.lua +118 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/state.lua +23 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/subscribe.lua +47 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/throttle.lua +37 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/tween.lua +14 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/useBinder.lua +54 -0
- package/src/Shared/middleware/ImmediateHooks/commonhooks/useTieInterface.lua +34 -0
- package/src/Shared/scheduler/ImmediateScheduler.lua +307 -0
- package/src/jest.config.lua +3 -0
- package/src/node_modules.project.json +7 -0
- package/test/default.project.json +32 -0
- package/test/scripts/Client/ClientMain.client.lua +10 -0
- package/test/scripts/Server/ServerMain.server.lua +18 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# 1.1.0 (2026-08-16)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @quenty/immediateutils
|
|
9
|
+
|
|
10
|
+
# 1.0.0 (2026-08-14)
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- **immediateutils:** add immediate-mode ECS loop and hooks
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014-2026 James Onnen (Quenty)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
## ImmediateUtils
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
<a href="http://quenty.github.io/NevermoreEngine/">
|
|
5
|
+
<img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/docs.yml/badge.svg" alt="Documentation status" />
|
|
6
|
+
</a>
|
|
7
|
+
<a href="https://discord.gg/mhtGUS8">
|
|
8
|
+
<img src="https://img.shields.io/discord/385151591524597761?color=5865F2&label=discord&logo=discord&logoColor=white" alt="Discord" />
|
|
9
|
+
</a>
|
|
10
|
+
<a href="https://github.com/Quenty/NevermoreEngine/actions">
|
|
11
|
+
<img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/build.yml/badge.svg" alt="Build and release status" />
|
|
12
|
+
</a>
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
Immediate-mode ECS loop and hooks built on jecs
|
|
16
|
+
|
|
17
|
+
<div align="center"><a href="https://quenty.github.io/NevermoreEngine/api/ImmediateSystem">View docs →</a></div>
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
npm install @quenty/immediateutils --save
|
|
23
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@quenty/immediateutils",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Immediate-mode ECS loop and hooks built on jecs",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Roblox",
|
|
7
|
+
"Nevermore",
|
|
8
|
+
"Lua",
|
|
9
|
+
"ecs",
|
|
10
|
+
"jecs",
|
|
11
|
+
"immediate"
|
|
12
|
+
],
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/Quenty/NevermoreEngine/issues"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/Quenty/NevermoreEngine.git",
|
|
19
|
+
"directory": "src/immediateutils/"
|
|
20
|
+
},
|
|
21
|
+
"funding": {
|
|
22
|
+
"type": "patreon",
|
|
23
|
+
"url": "https://www.patreon.com/quenty"
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"preinstall": "npx only-allow pnpm"
|
|
28
|
+
},
|
|
29
|
+
"contributors": [
|
|
30
|
+
"Quenty"
|
|
31
|
+
],
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@quenty/baseobject": "10.15.1",
|
|
34
|
+
"@quenty/brio": "14.35.2",
|
|
35
|
+
"@quenty/instanceutils": "13.35.2",
|
|
36
|
+
"@quenty/jecs": "1.1.0",
|
|
37
|
+
"@quenty/loader": "10.11.1",
|
|
38
|
+
"@quenty/maid": "3.11.1",
|
|
39
|
+
"@quenty/nevermore-test-runner": "1.5.1",
|
|
40
|
+
"@quenty/randomutils": "6.19.1",
|
|
41
|
+
"@quenty/rx": "13.33.1",
|
|
42
|
+
"@quenty/servicebag": "11.20.1",
|
|
43
|
+
"@quenty/signal": "7.13.2",
|
|
44
|
+
"@quenty/spring": "10.12.1",
|
|
45
|
+
"@quenty/tie": "10.47.1",
|
|
46
|
+
"@quentystudios/jest-lua": "3.10.0-quenty.2"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"gitHead": "bb227ab222e1887b1d5f65333ef06e2bedba31c1"
|
|
52
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
--[=[
|
|
3
|
+
@client
|
|
4
|
+
@class ImmediateLoopServiceClient
|
|
5
|
+
|
|
6
|
+
Maintains a single loop for immediate-mode ECS systems.
|
|
7
|
+
There is exactly one world and one loop per running client or server.
|
|
8
|
+
All added systems will be run synchronously and non-yielding inside RunService events.
|
|
9
|
+
]=]
|
|
10
|
+
|
|
11
|
+
local require = require(script.Parent.loader).load(script)
|
|
12
|
+
|
|
13
|
+
local ServiceBag = require("ServiceBag")
|
|
14
|
+
|
|
15
|
+
local ImmediateServiceClient = {}
|
|
16
|
+
ImmediateServiceClient.ServiceName = "ImmediateServiceClient"
|
|
17
|
+
|
|
18
|
+
export type ImmediateServiceClient = typeof(setmetatable(
|
|
19
|
+
{} :: {
|
|
20
|
+
_serviceBag: ServiceBag.ServiceBag,
|
|
21
|
+
},
|
|
22
|
+
{} :: typeof({ __index = ImmediateServiceClient })
|
|
23
|
+
))
|
|
24
|
+
|
|
25
|
+
function ImmediateServiceClient.Init(self: ImmediateServiceClient, serviceBag: ServiceBag.ServiceBag): ()
|
|
26
|
+
assert(not (self :: any)._serviceBag, "Already initialized")
|
|
27
|
+
self._serviceBag = assert(serviceBag, "No serviceBag")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
return ImmediateServiceClient
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
--[=[
|
|
3
|
+
@class ImmediateLoopService
|
|
4
|
+
]=]
|
|
5
|
+
|
|
6
|
+
local require = require(script.Parent.loader).load(script)
|
|
7
|
+
|
|
8
|
+
local ServiceBag = require("ServiceBag")
|
|
9
|
+
|
|
10
|
+
local ImmediateService = {}
|
|
11
|
+
ImmediateService.ServiceName = "ImmediateService"
|
|
12
|
+
|
|
13
|
+
export type ImmediateService = typeof(setmetatable(
|
|
14
|
+
{} :: {
|
|
15
|
+
_serviceBag: ServiceBag.ServiceBag,
|
|
16
|
+
},
|
|
17
|
+
{} :: typeof({ __index = ImmediateService })
|
|
18
|
+
))
|
|
19
|
+
|
|
20
|
+
function ImmediateService.Init(self: ImmediateService, serviceBag: ServiceBag.ServiceBag): ()
|
|
21
|
+
assert(not (self :: any)._serviceBag, "Already initialized")
|
|
22
|
+
self._serviceBag = assert(serviceBag, "No serviceBag")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
return ImmediateService
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
--!nonstrict
|
|
2
|
+
|
|
3
|
+
-- These components are assumed to exist in any ImmediateRuntime world. (they're required.)
|
|
4
|
+
-- Component files like these should be factory functions because they have to directly apply and call stuff on the jecs world.
|
|
5
|
+
|
|
6
|
+
local require = require(script.Parent.loader).load(script)
|
|
7
|
+
|
|
8
|
+
local Jecs = require("Jecs")
|
|
9
|
+
local Jecst = require("Jecst")
|
|
10
|
+
local Maid = require("Maid")
|
|
11
|
+
|
|
12
|
+
return function(world: Jecst.World)
|
|
13
|
+
local newComponents = {
|
|
14
|
+
Name = Jecs.Name,
|
|
15
|
+
Previous = Jecs.Rest,
|
|
16
|
+
ChildOf = Jecs.ChildOf,
|
|
17
|
+
|
|
18
|
+
Maid = world:component() :: Jecst.Id<Maid.Maid>,
|
|
19
|
+
MetaHookState = world:component() :: Jecst.Id<{
|
|
20
|
+
filename: string,
|
|
21
|
+
line: number,
|
|
22
|
+
discriminator: any,
|
|
23
|
+
flagForCleanup: boolean,
|
|
24
|
+
shouldCleanupCallback: ((state: any) -> boolean)?,
|
|
25
|
+
runtimePersistent: boolean?,
|
|
26
|
+
}>,
|
|
27
|
+
HookState = world:component() :: Jecst.Id<{ [any]: any }>,
|
|
28
|
+
HookRuntimeBuffer = world:component() :: Jecst.Id<nil>,
|
|
29
|
+
_ChangeCallbacks = world:component() :: Jecst.Id<{
|
|
30
|
+
_counter: number,
|
|
31
|
+
callbacks: { [string]: (entity: Jecst.Entity, id: number, data: any) -> () },
|
|
32
|
+
}>,
|
|
33
|
+
_AddCallbacks = world:component() :: Jecst.Id<{
|
|
34
|
+
_counter: number,
|
|
35
|
+
callbacks: { [string]: (entity: Jecst.Entity, id: number, data: any) -> () },
|
|
36
|
+
}>,
|
|
37
|
+
_RemoveCallbacks = world:component() :: Jecst.Id<{
|
|
38
|
+
_counter: number,
|
|
39
|
+
callbacks: { [string]: (entity: Jecst.Entity, id: number, delete: boolean?) -> () },
|
|
40
|
+
}>,
|
|
41
|
+
}
|
|
42
|
+
return newComponents
|
|
43
|
+
end
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
--!nonstrict
|
|
2
|
+
|
|
3
|
+
-- These components are assumed to exist in any ImmediateRuntime world. (they're required.)
|
|
4
|
+
-- Component files like these should be factory functions because they have to directly apply and call stuff on the jecs world.
|
|
5
|
+
local require = require(script.Parent.loader).load(script)
|
|
6
|
+
|
|
7
|
+
local ImmediateCoreComponents = require("ImmediateCoreComponents")
|
|
8
|
+
local ImmediateTypes = require("ImmediateTypes")
|
|
9
|
+
local Jecs = require("Jecs")
|
|
10
|
+
local Jecst = require("Jecst")
|
|
11
|
+
local Maid = require("Maid")
|
|
12
|
+
local ServiceBag = require("ServiceBag")
|
|
13
|
+
|
|
14
|
+
local ImmediateCoreUtils = {}
|
|
15
|
+
|
|
16
|
+
-- This sets up some meta behavior, and should be called exactly once given a world and a full component dictionary.
|
|
17
|
+
local function _setupComponentDictionaryWithWorld(
|
|
18
|
+
world: Jecst.World,
|
|
19
|
+
fullComponentDictionary: ImmediateTypes.JecsComponentDictionary
|
|
20
|
+
)
|
|
21
|
+
for _componentName, component in pairs(fullComponentDictionary) do
|
|
22
|
+
if
|
|
23
|
+
component == fullComponentDictionary._ChangeCallbacks
|
|
24
|
+
or component == fullComponentDictionary._AddCallbacks
|
|
25
|
+
or component == fullComponentDictionary._RemoveCallbacks
|
|
26
|
+
then
|
|
27
|
+
continue
|
|
28
|
+
end
|
|
29
|
+
world:set(component, fullComponentDictionary._ChangeCallbacks, {
|
|
30
|
+
_counter = 0,
|
|
31
|
+
callbacks = {},
|
|
32
|
+
})
|
|
33
|
+
world:set(component, fullComponentDictionary._AddCallbacks, {
|
|
34
|
+
_counter = 0,
|
|
35
|
+
callbacks = {},
|
|
36
|
+
})
|
|
37
|
+
world:set(component, fullComponentDictionary._RemoveCallbacks, {
|
|
38
|
+
_counter = 0,
|
|
39
|
+
callbacks = {},
|
|
40
|
+
})
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
-- Every component will run callbacks assigned to them.
|
|
44
|
+
for _componentName, component in pairs(fullComponentDictionary) do
|
|
45
|
+
world:set(component, Jecs.OnChange, function(entity, id, data)
|
|
46
|
+
local changeCallbacks = world:get(id, fullComponentDictionary._ChangeCallbacks)
|
|
47
|
+
if changeCallbacks then
|
|
48
|
+
for _key, callback in pairs(changeCallbacks.callbacks) do
|
|
49
|
+
callback(entity, id, data)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
for _componentName, component in pairs(fullComponentDictionary) do
|
|
56
|
+
world:set(component, Jecs.OnAdd, function(entity, id, data)
|
|
57
|
+
local addCallbacks = world:get(id, fullComponentDictionary._AddCallbacks)
|
|
58
|
+
if addCallbacks then
|
|
59
|
+
for _key, callback in pairs(addCallbacks.callbacks) do
|
|
60
|
+
callback(entity, id, data)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
for _componentName, component in pairs(fullComponentDictionary) do
|
|
67
|
+
world:set(component, Jecs.OnRemove, function(entity, id, delete)
|
|
68
|
+
local removeCallbacks = world:get(id, fullComponentDictionary._RemoveCallbacks)
|
|
69
|
+
if removeCallbacks then
|
|
70
|
+
for _key, callback in pairs(removeCallbacks.callbacks) do
|
|
71
|
+
callback(entity, id, delete)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
-- Cleanup behavior if for some reason we remove the _Callbacks themselves
|
|
78
|
+
world:set(fullComponentDictionary._ChangeCallbacks, Jecs.OnRemove, function(entity)
|
|
79
|
+
local changeCallbacks = world:get(entity, fullComponentDictionary._ChangeCallbacks)
|
|
80
|
+
if changeCallbacks then
|
|
81
|
+
table.clear(changeCallbacks.callbacks)
|
|
82
|
+
table.clear(changeCallbacks)
|
|
83
|
+
end
|
|
84
|
+
end)
|
|
85
|
+
|
|
86
|
+
world:set(fullComponentDictionary._AddCallbacks, Jecs.OnRemove, function(entity)
|
|
87
|
+
local addCallbacks = world:get(entity, fullComponentDictionary._AddCallbacks)
|
|
88
|
+
if addCallbacks then
|
|
89
|
+
table.clear(addCallbacks.callbacks)
|
|
90
|
+
table.clear(addCallbacks)
|
|
91
|
+
end
|
|
92
|
+
end)
|
|
93
|
+
|
|
94
|
+
world:set(fullComponentDictionary._RemoveCallbacks, Jecs.OnRemove, function(entity)
|
|
95
|
+
local removeCallbacks = world:get(entity, fullComponentDictionary._RemoveCallbacks)
|
|
96
|
+
if removeCallbacks then
|
|
97
|
+
table.clear(removeCallbacks.callbacks)
|
|
98
|
+
table.clear(removeCallbacks)
|
|
99
|
+
end
|
|
100
|
+
end)
|
|
101
|
+
|
|
102
|
+
-- Every component should usually have their Name component set.
|
|
103
|
+
for _componentName, component in pairs(fullComponentDictionary) do
|
|
104
|
+
world:set(component, fullComponentDictionary.Name, _componentName)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
local function _setupRuntimeMaidComponentCallbacks(rt: ImmediateTypes.ImmediateRuntime<any, any>)
|
|
109
|
+
local ImmediateJecsUtils = require("ImmediateJecsUtils")
|
|
110
|
+
local world = rt.world
|
|
111
|
+
local maidComponent = assert(rt.comps.Maid, "no Maid component in runtime")
|
|
112
|
+
|
|
113
|
+
local trackEntityMaid = function(entity, _, m)
|
|
114
|
+
assert(Maid.isMaid(m), "Maid component must be a Maid")
|
|
115
|
+
rt.maid[`{entity}_maid`] = m
|
|
116
|
+
end
|
|
117
|
+
ImmediateJecsUtils.addAddCallback(rt, maidComponent, trackEntityMaid, "trackEntityMaid")
|
|
118
|
+
ImmediateJecsUtils.addChangeCallback(rt, maidComponent, trackEntityMaid, "trackEntityMaid")
|
|
119
|
+
ImmediateJecsUtils.addRemoveCallback(rt, maidComponent, function(entity)
|
|
120
|
+
rt.maid[`{entity}_maid`] = nil
|
|
121
|
+
local entityMaid = world:get(entity, maidComponent)
|
|
122
|
+
if entityMaid then
|
|
123
|
+
entityMaid:DoCleaning()
|
|
124
|
+
end
|
|
125
|
+
end, "maid")
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
function ImmediateCoreUtils.createImmediateRuntime<CustomComponentDictionaries, CustomBlackboardType>(
|
|
129
|
+
serviceBag: ServiceBag.ServiceBag,
|
|
130
|
+
requireCallback: (
|
|
131
|
+
path: string
|
|
132
|
+
) -> any,
|
|
133
|
+
initialBlackboard: CustomBlackboardType?,
|
|
134
|
+
extraComponents: {
|
|
135
|
+
[string]: Jecst.Id<any>,
|
|
136
|
+
}?,
|
|
137
|
+
debugEnabled: boolean?,
|
|
138
|
+
plugin: Plugin?
|
|
139
|
+
): ImmediateTypes.ImmediateRuntime<
|
|
140
|
+
CustomComponentDictionaries,
|
|
141
|
+
CustomBlackboardType
|
|
142
|
+
>
|
|
143
|
+
local maid = Maid.new()
|
|
144
|
+
local DEBUG = debugEnabled ~= false
|
|
145
|
+
local world = maid:Add(Jecs.world(DEBUG))
|
|
146
|
+
local usingServiceBag = serviceBag or maid:Add(ServiceBag.new())
|
|
147
|
+
|
|
148
|
+
-- Register initial components, exposing through rt.comps
|
|
149
|
+
local comps = ImmediateCoreComponents(world)
|
|
150
|
+
if extraComponents then
|
|
151
|
+
for name, component in extraComponents do
|
|
152
|
+
comps[name] = component
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
_setupComponentDictionaryWithWorld(world, comps)
|
|
156
|
+
|
|
157
|
+
-- Create final runtime table
|
|
158
|
+
local runtime: ImmediateTypes.ImmediateRuntime<CustomComponentDictionaries, CustomBlackboardType>
|
|
159
|
+
runtime = {
|
|
160
|
+
DEBUG = DEBUG,
|
|
161
|
+
require = requireCallback,
|
|
162
|
+
serviceBag = usingServiceBag,
|
|
163
|
+
|
|
164
|
+
jecs = Jecs,
|
|
165
|
+
world = world,
|
|
166
|
+
comps = comps,
|
|
167
|
+
|
|
168
|
+
maid = maid,
|
|
169
|
+
blackboard = (initialBlackboard :: any) or {},
|
|
170
|
+
|
|
171
|
+
errorlog = {
|
|
172
|
+
lastErrorShout = 0,
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
Destroy = function()
|
|
176
|
+
maid:DoCleaning()
|
|
177
|
+
table.clear(runtime)
|
|
178
|
+
end,
|
|
179
|
+
|
|
180
|
+
plugin = plugin,
|
|
181
|
+
} :: ImmediateTypes.ImmediateRuntime<CustomComponentDictionaries, CustomBlackboardType>
|
|
182
|
+
|
|
183
|
+
_setupRuntimeMaidComponentCallbacks(runtime)
|
|
184
|
+
|
|
185
|
+
return runtime
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
return ImmediateCoreUtils
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
--[=[
|
|
3
|
+
@class ImmediateInstall
|
|
4
|
+
|
|
5
|
+
Applies runtime addons as a flat argument list while preserving the
|
|
6
|
+
stacked type: `Rt & AddonA & AddonB & ...`.
|
|
7
|
+
|
|
8
|
+
A Lua table `{ installer, installer }` will not produce that megatype:
|
|
9
|
+
Luau treats it as an array of a union, so both installers collapse to the
|
|
10
|
+
same function type. Separate arguments keep each step's `From -> To`.
|
|
11
|
+
|
|
12
|
+
The game alias can be `typeof(ImmediateInstall.stack(...))` with a dummy
|
|
13
|
+
runtime, so the addon list *is* the combined type.
|
|
14
|
+
]=]
|
|
15
|
+
local require = require(script.Parent.loader).load(script)
|
|
16
|
+
|
|
17
|
+
local ImmediateScheduler = require("ImmediateScheduler")
|
|
18
|
+
|
|
19
|
+
local ImmediateInstall = {}
|
|
20
|
+
|
|
21
|
+
export type Addon<From, To> = (From, ImmediateScheduler.ImmediateScheduler?) -> To
|
|
22
|
+
|
|
23
|
+
function ImmediateInstall.stack<R0, R1, R2>(
|
|
24
|
+
rt: R0,
|
|
25
|
+
scheduler: ImmediateScheduler.ImmediateScheduler?,
|
|
26
|
+
a: Addon<R0, R1>,
|
|
27
|
+
b: Addon<R1, R2>
|
|
28
|
+
): R2
|
|
29
|
+
return b(a(rt, scheduler), scheduler)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
function ImmediateInstall.stack3<R0, R1, R2, R3>(
|
|
33
|
+
rt: R0,
|
|
34
|
+
scheduler: ImmediateScheduler.ImmediateScheduler?,
|
|
35
|
+
a: Addon<R0, R1>,
|
|
36
|
+
b: Addon<R1, R2>,
|
|
37
|
+
c: Addon<R2, R3>
|
|
38
|
+
): R3
|
|
39
|
+
return c(b(a(rt, scheduler), scheduler), scheduler)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
function ImmediateInstall.stack4<R0, R1, R2, R3, R4>(
|
|
43
|
+
rt: R0,
|
|
44
|
+
scheduler: ImmediateScheduler.ImmediateScheduler?,
|
|
45
|
+
a: Addon<R0, R1>,
|
|
46
|
+
b: Addon<R1, R2>,
|
|
47
|
+
c: Addon<R2, R3>,
|
|
48
|
+
d: Addon<R3, R4>
|
|
49
|
+
): R4
|
|
50
|
+
return d(c(b(a(rt, scheduler), scheduler), scheduler), scheduler)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
return ImmediateInstall
|