@quenty/immediateutils 1.1.0 → 1.3.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.
Files changed (52) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +1 -1
  3. package/package.json +14 -13
  4. package/src/Shared/core/ImmediateCoreUtils.lua +56 -149
  5. package/src/Shared/core/ImmediateInstall.lua +79 -11
  6. package/src/Shared/middleware/Defer/ImmediateDeferInstall.lua +49 -0
  7. package/src/Shared/scheduler/ImmediateScheduler.lua +20 -11
  8. package/src/Client/ImmediateServiceClient.lua +0 -30
  9. package/src/Server/ImmediateService.lua +0 -25
  10. package/src/Shared/core/ImmediateCoreComponents.lua +0 -43
  11. package/src/Shared/core/ImmediateJecsUtils.lua +0 -249
  12. package/src/Shared/core/ImmediateTypes.lua +0 -79
  13. package/src/Shared/middleware/ImmediateBuffers/ImmediateBufferUtils.lua +0 -65
  14. package/src/Shared/middleware/ImmediateBuffers/ImmediateBuffersInstall.lua +0 -35
  15. package/src/Shared/middleware/ImmediateHooks/ImmediateCommonHooks.lua +0 -86
  16. package/src/Shared/middleware/ImmediateHooks/ImmediateHookAverageUtils.lua +0 -26
  17. package/src/Shared/middleware/ImmediateHooks/ImmediateHookSpringUtils.lua +0 -31
  18. package/src/Shared/middleware/ImmediateHooks/ImmediateHookUtils.lua +0 -214
  19. package/src/Shared/middleware/ImmediateHooks/ImmediateHooksInstall.lua +0 -46
  20. package/src/Shared/middleware/ImmediateHooks/commonhooks/async.lua +0 -30
  21. package/src/Shared/middleware/ImmediateHooks/commonhooks/cache.lua +0 -34
  22. package/src/Shared/middleware/ImmediateHooks/commonhooks/changed.lua +0 -39
  23. package/src/Shared/middleware/ImmediateHooks/commonhooks/conditionSustained.lua +0 -31
  24. package/src/Shared/middleware/ImmediateHooks/commonhooks/counter.lua +0 -19
  25. package/src/Shared/middleware/ImmediateHooks/commonhooks/delayed.lua +0 -31
  26. package/src/Shared/middleware/ImmediateHooks/commonhooks/delta.lua +0 -41
  27. package/src/Shared/middleware/ImmediateHooks/commonhooks/deltatime.lua +0 -32
  28. package/src/Shared/middleware/ImmediateHooks/commonhooks/difference.lua +0 -31
  29. package/src/Shared/middleware/ImmediateHooks/commonhooks/draw.lua +0 -17
  30. package/src/Shared/middleware/ImmediateHooks/commonhooks/entity.lua +0 -21
  31. package/src/Shared/middleware/ImmediateHooks/commonhooks/filterDescendants.lua +0 -62
  32. package/src/Shared/middleware/ImmediateHooks/commonhooks/findChild.lua +0 -36
  33. package/src/Shared/middleware/ImmediateHooks/commonhooks/gate.lua +0 -23
  34. package/src/Shared/middleware/ImmediateHooks/commonhooks/gatecounter.lua +0 -37
  35. package/src/Shared/middleware/ImmediateHooks/commonhooks/hookEntity.lua +0 -29
  36. package/src/Shared/middleware/ImmediateHooks/commonhooks/linearWalk.lua +0 -143
  37. package/src/Shared/middleware/ImmediateHooks/commonhooks/maid.lua +0 -25
  38. package/src/Shared/middleware/ImmediateHooks/commonhooks/noise.lua +0 -54
  39. package/src/Shared/middleware/ImmediateHooks/commonhooks/random.lua +0 -20
  40. package/src/Shared/middleware/ImmediateHooks/commonhooks/randomChoice.lua +0 -52
  41. package/src/Shared/middleware/ImmediateHooks/commonhooks/rtbuffer.lua +0 -28
  42. package/src/Shared/middleware/ImmediateHooks/commonhooks/scheduledValues.lua +0 -143
  43. package/src/Shared/middleware/ImmediateHooks/commonhooks/scheduler.lua +0 -191
  44. package/src/Shared/middleware/ImmediateHooks/commonhooks/sin.lua +0 -38
  45. package/src/Shared/middleware/ImmediateHooks/commonhooks/slidingAvg.lua +0 -78
  46. package/src/Shared/middleware/ImmediateHooks/commonhooks/spring.lua +0 -118
  47. package/src/Shared/middleware/ImmediateHooks/commonhooks/state.lua +0 -23
  48. package/src/Shared/middleware/ImmediateHooks/commonhooks/subscribe.lua +0 -47
  49. package/src/Shared/middleware/ImmediateHooks/commonhooks/throttle.lua +0 -37
  50. package/src/Shared/middleware/ImmediateHooks/commonhooks/tween.lua +0 -14
  51. package/src/Shared/middleware/ImmediateHooks/commonhooks/useBinder.lua +0 -54
  52. package/src/Shared/middleware/ImmediateHooks/commonhooks/useTieInterface.lua +0 -34
@@ -1,214 +0,0 @@
1
- --!nonstrict
2
- --[=[
3
- @class ImmediateHookUtils
4
-
5
- Optional runtime extension: hook entity lookup on `rt.hookBook`.
6
- Install onto a bare ImmediateRuntime before calling getOrCreateHookState.
7
- ]=]
8
- local require = require(script.Parent.loader).load(script)
9
-
10
- local ImmediateTypes = require("ImmediateTypes")
11
- local Jecs = require("Jecs")
12
- local Jecst = require("Jecst")
13
- local Maid = require("Maid")
14
-
15
- local WARN_HOOK_CLEANUP = false
16
-
17
- export type HookBook = {
18
- orderOfCalls: { [string]: number },
19
- stateEntities: { [string]: { [any]: Jecst.Entity } },
20
- }
21
-
22
- export type ImmediateHookBookAddon = {
23
- hookBook: HookBook,
24
- }
25
-
26
- export type ImmediateRuntimeWithHookBook<C = {}, B = {}> = ImmediateTypes.ImmediateRuntime<C, B> & ImmediateHookBookAddon
27
-
28
- local ImmediateHookUtils = {}
29
-
30
- function ImmediateHookUtils.install<Rt>(rt: Rt): Rt & ImmediateHookBookAddon
31
- local runtime = rt :: Rt & ImmediateHookBookAddon
32
- if runtime.hookBook == nil then
33
- runtime.hookBook = {
34
- orderOfCalls = {},
35
- stateEntities = {},
36
- }
37
- end
38
- return runtime
39
- end
40
-
41
- local function getHookBook(rt: ImmediateRuntimeWithHookBook): HookBook
42
- return assert(rt.hookBook, "ImmediateHookUtils.install(rt) was not called")
43
- end
44
-
45
- function ImmediateHookUtils.getOrCreateHookState<T>(
46
- rt: ImmediateRuntimeWithHookBook,
47
- discriminator: any,
48
- cleanupIfTrue: ((state: T) -> boolean)?,
49
- runtimePersistent: boolean? -- be very careful using this. will not be cleaned up
50
- ): (T, Maid.Maid, Jecst.Entity)
51
- local hookBook = getHookBook(rt)
52
- local _filename = debug.info(3, "s")
53
- local _line = debug.info(3, "l")
54
- local _firstKey = `{_filename}:{_line}`
55
-
56
- -- Order of calls logged per file/line.
57
- -- If multiple hooks are called in the same line, we default to discriminating
58
- -- by the order of calls (so if you omitted the discriminator in a loop, you'd get a
59
- -- unique hook state per iteration).
60
- if not hookBook.orderOfCalls[_firstKey] then
61
- hookBook.orderOfCalls[_firstKey] = 0
62
- end
63
- hookBook.orderOfCalls[_firstKey] = hookBook.orderOfCalls[_firstKey] + 1
64
-
65
- local entityToParentTo = nil
66
-
67
- if
68
- discriminator
69
- and typeof(discriminator) == "number"
70
- and rt.world:contains(discriminator :: any)
71
- and discriminator > 50
72
- then
73
- warn(`Hook discriminator {discriminator} is an entity, did you mean to wrap it in hooks.entity()?`)
74
- warn(debug.traceback())
75
- end
76
-
77
- local _discriminator = discriminator
78
- if _discriminator and typeof(_discriminator) == "table" and _discriminator.__hookentity then
79
- entityToParentTo = _discriminator.__hookentity
80
- _discriminator = _discriminator.__hookentity
81
- end
82
-
83
- if _discriminator == nil then
84
- _discriminator = `__call_{hookBook.orderOfCalls[_firstKey]}`
85
- end
86
-
87
- if not hookBook.stateEntities[_firstKey] then
88
- hookBook.stateEntities[_firstKey] = {}
89
- end
90
-
91
- -- Find the hook state.
92
- local hookStateEntity = hookBook.stateEntities[_firstKey][_discriminator]
93
- if hookStateEntity then
94
- if not rt.world:contains(hookStateEntity) then
95
- hookBook.stateEntities[_firstKey][_discriminator] = nil
96
- hookBook.orderOfCalls[_firstKey] = nil
97
- error(`Hook state entity for {_filename}:{_line} with discriminator {_discriminator} is not in the world`)
98
- end
99
- local hookMaid = rt.world:get(hookStateEntity, rt.comps.Maid)
100
- local mhs = rt.world:get(hookStateEntity, rt.comps.MetaHookState)
101
- mhs.flagForCleanup = false
102
- return rt.world:get(hookStateEntity, rt.comps.HookState) :: T, hookMaid, hookStateEntity
103
- end
104
-
105
- -- If not, create it.
106
- local newHookEntity = rt.world:entity()
107
- if entityToParentTo then
108
- rt.world:add(newHookEntity, Jecs.pair(rt.comps.ChildOf, entityToParentTo))
109
- end
110
- if runtimePersistent then
111
- rt.world:add(newHookEntity, rt.comps.HookRuntimeBuffer)
112
- end
113
- local newHookState = {}
114
- local maid = Maid.new()
115
-
116
- -- The actual cleanup task should be defined in the returned maid.
117
- -- This one only clears the table.
118
- maid:GiveTask(function()
119
- hookBook.stateEntities[_firstKey][_discriminator] = nil
120
- hookBook.orderOfCalls[_firstKey] = nil
121
- if WARN_HOOK_CLEANUP then
122
- warn(`Cleaned up hook state for {_filename}:{_line} with discriminator {_discriminator}`)
123
- end
124
- end)
125
- rt.world:set(newHookEntity, rt.comps.MetaHookState, {
126
- filename = _filename,
127
- line = _line,
128
- discriminator = discriminator,
129
- flagForCleanup = false,
130
- shouldCleanupCallback = cleanupIfTrue,
131
- runtimePersistent = runtimePersistent,
132
- })
133
- rt.world:set(newHookEntity, rt.comps.Maid, maid)
134
- rt.world:set(newHookEntity, rt.comps.HookState, newHookState)
135
- hookBook.stateEntities[_firstKey][_discriminator] = newHookEntity
136
-
137
- return rt.world:get(newHookEntity, rt.comps.HookState) :: T, maid, newHookEntity
138
- end
139
-
140
- ImmediateHookUtils._getOrCreateHookState = ImmediateHookUtils.getOrCreateHookState
141
-
142
- function ImmediateHookUtils.forceCleanupHooks(rt: ImmediateRuntimeWithHookBook)
143
- local toDelete = {}
144
- for entity, _mhs, _hs, _maid in rt.world:query(rt.comps.MetaHookState, rt.comps.HookState, rt.comps.Maid) do
145
- if _mhs.runtimePersistent then
146
- continue
147
- end
148
- table.insert(toDelete, entity)
149
- end
150
- for _, entity in toDelete do
151
- if rt.world:contains(entity) then
152
- rt.world:delete(entity)
153
- end
154
- end
155
- end
156
-
157
- function ImmediateHookUtils.forceCleanupHooksOfFile(rt: ImmediateRuntimeWithHookBook, filename: string)
158
- local toDelete = {}
159
- for entity, mhs in rt.world:query(rt.comps.MetaHookState) do
160
- if mhs.runtimePersistent then
161
- continue
162
- end
163
- if mhs.filename == filename then
164
- table.insert(toDelete, entity)
165
- else
166
- -- could be expanded full name, so split by '.' and get the last part.
167
- local lastPart = string.split(mhs.filename, ".")[#string.split(mhs.filename, ".")]
168
- if lastPart == filename then
169
- table.insert(toDelete, entity)
170
- end
171
- end
172
- end
173
- for _, entity in toDelete do
174
- if rt.world:contains(entity) then
175
- rt.world:delete(entity)
176
- end
177
- end
178
- end
179
-
180
- function ImmediateHookUtils.evaluateAndCleanupHooks(rt: ImmediateRuntimeWithHookBook)
181
- local toDelete = {}
182
- for entity, mhs, hs, _maid in rt.world:query(rt.comps.MetaHookState, rt.comps.HookState, rt.comps.Maid) do
183
- if mhs.runtimePersistent then
184
- continue
185
- end
186
- if not mhs.flagForCleanup then
187
- mhs.flagForCleanup = true
188
- continue
189
- end
190
- if mhs.shouldCleanupCallback == nil or mhs.shouldCleanupCallback(hs) then
191
- table.insert(toDelete, entity)
192
- end
193
- end
194
- for _, entity in toDelete do
195
- if rt.world:contains(entity) then
196
- rt.world:delete(entity)
197
- end
198
- end
199
- local orderOfCalls = getHookBook(rt).orderOfCalls
200
- for _key, _ in orderOfCalls do
201
- orderOfCalls[_key] = 0
202
- end
203
- end
204
-
205
- function ImmediateHookUtils.flushHookRuntimeBuffers(rt: ImmediateRuntimeWithHookBook)
206
- for _et, hookState, _ in rt.world:query(rt.comps.HookState, rt.comps.HookRuntimeBuffer) do
207
- if hookState.calledThisFrame then
208
- table.clear(hookState.tab)
209
- end
210
- hookState.calledThisFrame = false
211
- end
212
- end
213
-
214
- return ImmediateHookUtils
@@ -1,46 +0,0 @@
1
- --!nonstrict
2
- --[=[
3
- @class ImmediateHooksInstall
4
-
5
- Runtime decorator: adds hookBook + common hooks, and optionally registers
6
- scheduler middleware (rtbuffer flush after each system, hook GC after the tick).
7
- ]=]
8
- local require = require(script.Parent.loader).load(script)
9
-
10
- local ImmediateCommonHooks = require("ImmediateCommonHooks")
11
- local ImmediateHookUtils = require("ImmediateHookUtils")
12
- local ImmediateScheduler = require("ImmediateScheduler")
13
-
14
- local DEFAULT_PRIORITY = 100
15
-
16
- return function<Rt>(
17
- rt: Rt,
18
- scheduler: ImmediateScheduler.ImmediateScheduler?
19
- ): Rt & ImmediateCommonHooks.ImmediateHooksAddon
20
- local runtime = ImmediateCommonHooks.install(rt)
21
-
22
- if scheduler then
23
- scheduler:RegisterSystem({
24
- name = "mw_immediate_hooks_rtbuffer",
25
- postSystem = true,
26
- priority = DEFAULT_PRIORITY,
27
- notProtected = false,
28
- system = function(r)
29
- ImmediateHookUtils.flushHookRuntimeBuffers(r)
30
- end,
31
- Destroy = function() end,
32
- })
33
- scheduler:RegisterSystem({
34
- name = "mw_immediate_hooks_gc",
35
- postTick = true,
36
- priority = DEFAULT_PRIORITY,
37
- notProtected = false,
38
- system = function(r)
39
- ImmediateHookUtils.evaluateAndCleanupHooks(r)
40
- end,
41
- Destroy = function() end,
42
- })
43
- end
44
-
45
- return runtime
46
- end
@@ -1,30 +0,0 @@
1
- --!nonstrict
2
- --[=[
3
- @class async
4
-
5
- Pass a function that gets access to a table called ret, the hookmaid,
6
- and it will execute in a new task.spawn thread. (asyncFunction only runs once.)
7
- This hook function itself returns the 'ret' table,
8
- and you can modify the 'ret' table inside the asyncFunction to store
9
- returned values.
10
- ]=]
11
-
12
- local require = require(script.Parent.loader).load(script)
13
-
14
- local ImmediateTypes = require("ImmediateTypes")
15
- local Maid = require("Maid")
16
- local getOrCreateHookState = require("ImmediateHookUtils").getOrCreateHookState
17
-
18
- return function(rt: ImmediateTypes.ImmediateRuntime)
19
- return function(dis: any?, asyncFunction: (Maid.Maid, { any }) -> any)
20
- local hookState, hookMaid = getOrCreateHookState(rt, dis)
21
- if hookState._startedAsync == nil then
22
- hookState._startedAsync = true
23
- hookState._ret = {}
24
- hookMaid:GiveTask(task.spawn(function()
25
- asyncFunction(hookState._ret, hookMaid)
26
- end))
27
- end
28
- return hookState._ret
29
- end
30
- end
@@ -1,34 +0,0 @@
1
- --!nonstrict
2
- --[=[
3
- @class cache
4
- ]=]
5
-
6
- local require = require(script.Parent.loader).load(script)
7
-
8
- local ImmediateTypes = require("ImmediateTypes")
9
- local Maid = require("Maid")
10
- local getOrCreateHookState = require("ImmediateHookUtils").getOrCreateHookState
11
-
12
- return function(rt: ImmediateTypes.ImmediateRuntime)
13
- return function(dis: any?, cacheFunction: (maid: Maid.Maid) -> any, cleanup: (value: any) -> any, debug: boolean?)
14
- if debug then
15
- print(`cache: called with dis {dis}`)
16
- end
17
- local hookState, hookMaid = getOrCreateHookState(rt, dis)
18
- if hookState.cachedValue == nil then
19
- hookState.cachedValue = table.pack(cacheFunction(hookMaid))
20
- hookState.cleanup = cleanup
21
- local cachedValue = hookState.cachedValue
22
-
23
- hookMaid:GiveTask(function()
24
- if cachedValue == nil then
25
- return
26
- end
27
- if cleanup then
28
- cleanup(table.unpack(cachedValue))
29
- end
30
- end)
31
- end
32
- return table.unpack(hookState.cachedValue)
33
- end
34
- end
@@ -1,39 +0,0 @@
1
- --!nonstrict
2
- --[=[
3
- @class changed
4
-
5
- Returns true if the value has changed since the last call.
6
- ]=]
7
-
8
- local require = require(script.Parent.loader).load(script)
9
-
10
- local ImmediateTypes = require("ImmediateTypes")
11
- local getOrCreateHookState = require("ImmediateHookUtils").getOrCreateHookState
12
-
13
- return function(rt: ImmediateTypes.ImmediateRuntime)
14
- return function(value: any, dis: any?, runFirst: boolean?, onlyOnEqualTo: any?)
15
- local hookState, _hookMaid = getOrCreateHookState(rt, dis)
16
-
17
- if hookState.lastValue == nil then
18
- hookState.lastValue = value
19
- if onlyOnEqualTo ~= nil then
20
- return value == onlyOnEqualTo
21
- end
22
- if runFirst == true then
23
- return true
24
- end
25
- return false
26
- end
27
-
28
- if hookState.lastValue ~= value then
29
- hookState.lastValue = value
30
- if onlyOnEqualTo ~= nil then
31
- return value == onlyOnEqualTo
32
- else
33
- return true
34
- end
35
- end
36
-
37
- return false
38
- end
39
- end
@@ -1,31 +0,0 @@
1
- --!nonstrict
2
- --[=[
3
- @class conditionSustained
4
-
5
- Seconds the condition has been continuously true. Resets when false or when
6
- this hook is not invoked for a frame (evaluateAndCleanupHooks).
7
- ]=]
8
-
9
- local require = require(script.Parent.loader).load(script)
10
-
11
- local ImmediateTypes = require("ImmediateTypes")
12
- local getOrCreateHookState = require("ImmediateHookUtils").getOrCreateHookState
13
-
14
- return function(rt: ImmediateTypes.ImmediateRuntime)
15
- return function(condition: boolean, dis: any?)
16
- local hookState, _hookMaid = getOrCreateHookState(rt, dis)
17
-
18
- if not condition then
19
- hookState.lastSatisfiedClock = nil
20
- return 0
21
- end
22
-
23
- local now = os.clock()
24
- if not hookState.lastSatisfiedClock then
25
- hookState.lastSatisfiedClock = now
26
- return 0
27
- end
28
-
29
- return now - hookState.lastSatisfiedClock
30
- end
31
- end
@@ -1,19 +0,0 @@
1
- --!nonstrict
2
- --[=[
3
- @class counter
4
-
5
- Every time it is called it counts up.
6
- ]=]
7
-
8
- local require = require(script.Parent.loader).load(script)
9
-
10
- local ImmediateTypes = require("ImmediateTypes")
11
- local getOrCreateHookState = require("ImmediateHookUtils").getOrCreateHookState
12
-
13
- return function(rt: ImmediateTypes.ImmediateRuntime)
14
- return function(dis)
15
- local hookState, _hookMaid = getOrCreateHookState(rt, dis)
16
- hookState.counter = (hookState.counter or 0) + 1
17
- return hookState.counter
18
- end
19
- end
@@ -1,31 +0,0 @@
1
- --!nonstrict
2
- --[=[
3
- @class delayed
4
-
5
- Returns false for the first `seconds` seconds, then true after that.
6
- ]=]
7
-
8
- local require = require(script.Parent.loader).load(script)
9
-
10
- local ImmediateTypes = require("ImmediateTypes")
11
- local getOrCreateHookState = require("ImmediateHookUtils").getOrCreateHookState
12
-
13
- return function(rt: ImmediateTypes.ImmediateRuntime)
14
- return function(seconds: number, dis: any?)
15
- local hookState, _hookMaid = getOrCreateHookState(rt, dis)
16
-
17
- local now = os.clock()
18
-
19
- if hookState.lastRanAtClock == nil then
20
- hookState.lastRanAtClock = now
21
- return false
22
- end
23
-
24
- if now - hookState.lastRanAtClock >= seconds then
25
- hookState.lastRanAtClock = now
26
- return true
27
- end
28
-
29
- return false
30
- end
31
- end
@@ -1,41 +0,0 @@
1
- --!nonstrict
2
- --[=[
3
- @class delta
4
-
5
- Kinda like deltaTime and changed: pass in a value (should be of same type) and it
6
- returns the difference between the last call and the current call.
7
-
8
- Pass conditionToEvaluate = false for a no-op: returns zero and does not update
9
- the stored value, so the next evaluated call still diffs against the last included sample.
10
- ]=]
11
-
12
- local require = require(script.Parent.loader).load(script)
13
-
14
- local ImmediateHookAverageUtils = require("ImmediateHookAverageUtils")
15
- local ImmediateTypes = require("ImmediateTypes")
16
- local getOrCreateHookState = require("ImmediateHookUtils").getOrCreateHookState
17
-
18
- return function(rt: ImmediateTypes.ImmediateRuntime)
19
- return function(
20
- value: ImmediateHookAverageUtils.AverageableValue,
21
- dis: any?,
22
- conditionToEvaluate: boolean?
23
- ): ImmediateHookAverageUtils.AverageableValue
24
- local hookState, _hookMaid = getOrCreateHookState(rt, dis)
25
-
26
- if conditionToEvaluate == false then
27
- if hookState.lastValue then
28
- return value - hookState.lastValue
29
- else
30
- return ImmediateHookAverageUtils.zeroSum(value)
31
- end
32
- end
33
-
34
- local lastValue = hookState.lastValue
35
- hookState.lastValue = value
36
- if lastValue == nil then
37
- return ImmediateHookAverageUtils.zeroSum(value)
38
- end
39
- return (value :: any) - lastValue, lastValue
40
- end
41
- end
@@ -1,32 +0,0 @@
1
- --!nonstrict
2
- --[=[
3
- @class deltatime
4
-
5
- Returns the time gap between the last call and the current call.
6
- ]=]
7
-
8
- local require = require(script.Parent.loader).load(script)
9
-
10
- local ImmediateTypes = require("ImmediateTypes")
11
- local getOrCreateHookState = require("ImmediateHookUtils").getOrCreateHookState
12
-
13
- return function(rt: ImmediateTypes.ImmediateRuntime)
14
- return function(dis: any?, flagToUpdate: boolean?)
15
- local hookState, _hookMaid = getOrCreateHookState(rt, dis)
16
-
17
- local now = os.clock()
18
- local lastAtClock = hookState.lastAtClock
19
- if lastAtClock == nil then
20
- hookState.lastAtClock = now
21
- return 0
22
- end
23
-
24
- local delta = now - lastAtClock
25
-
26
- if flagToUpdate == nil or flagToUpdate == true then
27
- hookState.lastAtClock = now
28
- end
29
-
30
- return delta
31
- end
32
- end
@@ -1,31 +0,0 @@
1
- --!nonstrict
2
- --[=[
3
- @class difference
4
-
5
- Like changed but you need to pass in a number value.
6
- Will return the difference between the last call and the current call.
7
- ]=]
8
-
9
- local require = require(script.Parent.loader).load(script)
10
-
11
- local ImmediateTypes = require("ImmediateTypes")
12
- local getOrCreateHookState = require("ImmediateHookUtils").getOrCreateHookState
13
-
14
- return function(rt: ImmediateTypes.ImmediateRuntime)
15
- return function(currentNumber: number, dis: any?, flagToUpdate: boolean?)
16
- local hookState, _hookMaid = getOrCreateHookState(rt, dis)
17
-
18
- if hookState.lastNumber == nil then
19
- hookState.lastNumber = currentNumber
20
- return 0
21
- end
22
-
23
- local difference = currentNumber - hookState.lastNumber
24
-
25
- if flagToUpdate == nil or flagToUpdate == true then
26
- hookState.lastNumber = currentNumber
27
- end
28
-
29
- return difference
30
- end
31
- end
@@ -1,17 +0,0 @@
1
- --!nonstrict
2
- --[=[
3
- @class draw
4
- ]=]
5
-
6
- local require = require(script.Parent.loader).load(script)
7
-
8
- local ImmediateTypes = require("ImmediateTypes")
9
- local getOrCreateHookState = require("ImmediateHookUtils").getOrCreateHookState
10
-
11
- return function(rt: ImmediateTypes.ImmediateRuntime)
12
- return function(drawnThing: any, dis: any?)
13
- local _hookState, _hookMaid = getOrCreateHookState(rt, dis)
14
- _hookMaid._currentlyDrawnThing = drawnThing
15
- return drawnThing
16
- end
17
- end
@@ -1,21 +0,0 @@
1
- --!strict
2
- --[=[
3
- @class entity
4
-
5
- Use this within a hook's discriminator argument, such as:
6
- `gatecounter(entity(SomeEntityHere))`.
7
-
8
- This tells getOrCreateHookState to parent the hook entity to SomeEntityHere.
9
- If the entity dies, the hook will be cleaned up.
10
- ]=]
11
-
12
- local require = require(script.Parent.loader).load(script)
13
-
14
- local ImmediateTypes = require("ImmediateTypes")
15
- local Jecst = require("Jecst")
16
-
17
- return function(_rt: ImmediateTypes.ImmediateRuntime)
18
- return function(entity: Jecst.Entity)
19
- return { __hookentity = entity }
20
- end
21
- end
@@ -1,62 +0,0 @@
1
- --!nonstrict
2
- --[=[
3
- @class filterDescendants
4
-
5
- Live filtered descendant list. observeDescendantsBrio already seeds current
6
- matches + tracks add/remove; brio death pulls the instance out of the array.
7
- ]=]
8
-
9
- local require = require(script.Parent.loader).load(script)
10
-
11
- local ImmediateTypes = require("ImmediateTypes")
12
- local RxInstanceUtils = require("RxInstanceUtils")
13
- local getOrCreateHookState = require("ImmediateHookUtils").getOrCreateHookState
14
-
15
- return function(rt: ImmediateTypes.ImmediateRuntime)
16
- return function(
17
- dis: any?,
18
- instanceArg: Instance | { Instance },
19
- filterFunction: (Instance) -> boolean
20
- ): { Instance }
21
- local hookState, hookMaid = getOrCreateHookState(rt, dis)
22
- assert(instanceArg, "instanceArg is nil")
23
- assert(
24
- typeof(instanceArg) == "Instance" or typeof(instanceArg) == "table",
25
- "instanceArg must be an Instance or a table of Instances"
26
- )
27
-
28
- if not hookState.instances then
29
- hookState.instances = if typeof(instanceArg) == "table" then table.clone(instanceArg) else { instanceArg }
30
- for _, instance in hookState.instances do
31
- assert(instance, "instance is nil")
32
- assert(instance:IsA("Instance"), "instance must be an Instance")
33
- end
34
- end
35
-
36
- if hookState.filteredDescendants == nil then
37
- local list: { Instance } = {}
38
- hookState.filteredDescendants = list
39
- for _, instance in hookState.instances do
40
- hookMaid:GiveTask(
41
- RxInstanceUtils.observeDescendantsBrio(instance, filterFunction):Subscribe(function(descendantBrio)
42
- if descendantBrio:IsDead() then
43
- return
44
- end
45
-
46
- local maid, descendant = descendantBrio:ToMaidAndValue()
47
- table.insert(list, descendant)
48
- maid:GiveTask(function()
49
- local index = table.find(list, descendant)
50
- if index then
51
- local last = #list
52
- list[index] = list[last]
53
- list[last] = nil
54
- end
55
- end)
56
- end)
57
- )
58
- end
59
- end
60
- return hookState.filteredDescendants
61
- end
62
- end
@@ -1,36 +0,0 @@
1
- --!nonstrict
2
- --[=[
3
- @class findChild
4
- ]=]
5
-
6
- local require = require(script.Parent.loader).load(script)
7
-
8
- local ImmediateTypes = require("ImmediateTypes")
9
- local getOrCreateHookState = require("ImmediateHookUtils").getOrCreateHookState
10
-
11
- return function(rt: ImmediateTypes.ImmediateRuntime)
12
- return function(dis: any?, parentInstance: Instance, name: string, recursive: boolean?)
13
- if not parentInstance then
14
- error(`parentInstance is nil: {dis} {name} {recursive}`)
15
- end
16
- local hookState, _hookMaid = getOrCreateHookState(rt, dis)
17
- if hookState._init == nil then
18
- hookState._init = true
19
- hookState._startedAt = os.clock()
20
- hookState._warnedAt = os.clock()
21
- hookState.foundChild = nil
22
- end
23
- if hookState.foundChild == nil then
24
- hookState.foundChild = parentInstance:FindFirstChild(name, recursive)
25
- end
26
- if
27
- hookState.foundChild == nil
28
- and os.clock() - hookState._startedAt > 5
29
- and os.clock() - hookState._warnedAt > 5
30
- then
31
- hookState._warnedAt = os.clock()
32
- warn(`findFirstChild: not finding {name} in {parentInstance:GetFullName()} after 5 seconds...`)
33
- end
34
- return hookState.foundChild
35
- end
36
- end