@quenty/humanoidutils 2.16.0 → 2.18.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 +10 -0
- package/deploy.nevermore.json +10 -0
- package/package.json +6 -3
- package/src/Shared/HumanoidUtils.lua +36 -0
- package/src/Shared/HumanoidUtils.spec.lua +186 -0
- package/src/Shared/RxHumanoidUtils.lua +55 -0
- package/src/Shared/RxHumanoidUtils.spec.lua +312 -0
- package/src/jest.config.lua +3 -0
- package/test/default.project.json +25 -0
- package/test/scripts/Server/ServerMain.server.lua +13 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [2.18.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/humanoidutils@2.17.0...@quenty/humanoidutils@2.18.0) (2026-08-13)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **humanoidutils:** observe whether a humanoid can jump ([d067e10](https://github.com/Quenty/NevermoreEngine/commit/d067e108ce7872cf0b763829bbf959fa59b4858c))
|
|
11
|
+
|
|
12
|
+
# [2.17.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/humanoidutils@2.16.0...@quenty/humanoidutils@2.17.0) (2026-07-25)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @quenty/humanoidutils
|
|
15
|
+
|
|
6
16
|
# [2.16.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/humanoidutils@2.15.0...@quenty/humanoidutils@2.16.0) (2026-07-23)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @quenty/humanoidutils
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/humanoidutils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.18.0",
|
|
4
4
|
"description": "General humanoid utility code.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -31,9 +31,12 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
+
"@quenty/instanceutils": "13.35.1",
|
|
34
35
|
"@quenty/loader": "10.11.0",
|
|
35
36
|
"@quenty/maid": "3.11.0",
|
|
36
|
-
"@quenty/
|
|
37
|
+
"@quenty/nevermore-test-runner": "1.5.0",
|
|
38
|
+
"@quenty/rx": "13.33.0",
|
|
39
|
+
"@quentystudios/jest-lua": "3.10.0-quenty.2"
|
|
37
40
|
},
|
|
38
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "dff15e975aae294612ff2f07cefcfa140656738f"
|
|
39
42
|
}
|
|
@@ -26,6 +26,42 @@ function HumanoidUtils.getHumanoid(descendant: Instance): Humanoid?
|
|
|
26
26
|
return nil
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
+
--[=[
|
|
30
|
+
Returns whether a humanoid state type is enabled on the humanoid.
|
|
31
|
+
|
|
32
|
+
@param humanoid Humanoid
|
|
33
|
+
@param stateType Enum.HumanoidStateType
|
|
34
|
+
@return boolean
|
|
35
|
+
]=]
|
|
36
|
+
function HumanoidUtils.isHumanoidStateEnabled(humanoid: Humanoid, stateType: Enum.HumanoidStateType): boolean
|
|
37
|
+
assert(typeof(humanoid) == "Instance" and humanoid:IsA("Humanoid"), "No humanoid")
|
|
38
|
+
assert(typeof(stateType) == "EnumItem", "No stateType")
|
|
39
|
+
|
|
40
|
+
return humanoid:GetStateEnabled(stateType)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
--[=[
|
|
44
|
+
Returns whether the humanoid is allowed to jump. This is true when the jumping state is enabled
|
|
45
|
+
and the humanoid's jump strength is above zero, which is the strength Roblox reads for the
|
|
46
|
+
humanoid's [Humanoid.UseJumpPower] mode.
|
|
47
|
+
|
|
48
|
+
@param humanoid Humanoid
|
|
49
|
+
@return boolean
|
|
50
|
+
]=]
|
|
51
|
+
function HumanoidUtils.isJumpEnabled(humanoid: Humanoid): boolean
|
|
52
|
+
assert(typeof(humanoid) == "Instance" and humanoid:IsA("Humanoid"), "No humanoid")
|
|
53
|
+
|
|
54
|
+
if not humanoid:GetStateEnabled(Enum.HumanoidStateType.Jumping) then
|
|
55
|
+
return false
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
if humanoid.UseJumpPower then
|
|
59
|
+
return humanoid.JumpPower > 0
|
|
60
|
+
else
|
|
61
|
+
return humanoid.JumpHeight > 0
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
29
65
|
--[=[
|
|
30
66
|
Forcefully unseats the humanoid. Useful when teleporting humanoid.
|
|
31
67
|
Definitely a non-intuitive operation to do safely.
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
--[[
|
|
3
|
+
@class HumanoidUtils.spec.lua
|
|
4
|
+
]]
|
|
5
|
+
|
|
6
|
+
local require = require(script.Parent.loader).load(script)
|
|
7
|
+
|
|
8
|
+
local HumanoidUtils = require("HumanoidUtils")
|
|
9
|
+
local Jest = require("Jest")
|
|
10
|
+
local Maid = require("Maid")
|
|
11
|
+
|
|
12
|
+
local describe = Jest.Globals.describe
|
|
13
|
+
local expect = Jest.Globals.expect
|
|
14
|
+
local it = Jest.Globals.it
|
|
15
|
+
|
|
16
|
+
local function setup(): any
|
|
17
|
+
local maid = Maid.new()
|
|
18
|
+
|
|
19
|
+
local controller = {
|
|
20
|
+
newHumanoid = function(): Humanoid
|
|
21
|
+
return maid:Add(Instance.new("Humanoid"))
|
|
22
|
+
end,
|
|
23
|
+
newRig = function(): (Model, Humanoid)
|
|
24
|
+
local rig = maid:Add(Instance.new("Model"))
|
|
25
|
+
local humanoid = Instance.new("Humanoid")
|
|
26
|
+
humanoid.Parent = rig
|
|
27
|
+
return rig, humanoid
|
|
28
|
+
end,
|
|
29
|
+
destroy = function()
|
|
30
|
+
maid:DoCleaning()
|
|
31
|
+
end,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return controller
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe("HumanoidUtils.getHumanoid", function()
|
|
38
|
+
it("finds the humanoid from a limb", function()
|
|
39
|
+
local controller = setup()
|
|
40
|
+
local rig, humanoid = controller.newRig()
|
|
41
|
+
|
|
42
|
+
local limb = Instance.new("Part")
|
|
43
|
+
limb.Parent = rig
|
|
44
|
+
|
|
45
|
+
expect(HumanoidUtils.getHumanoid(limb)).toBe(humanoid)
|
|
46
|
+
|
|
47
|
+
controller.destroy()
|
|
48
|
+
end)
|
|
49
|
+
|
|
50
|
+
it("finds the humanoid from a nested descendant", function()
|
|
51
|
+
local controller = setup()
|
|
52
|
+
local rig, humanoid = controller.newRig()
|
|
53
|
+
|
|
54
|
+
local accessory = Instance.new("Model")
|
|
55
|
+
accessory.Parent = rig
|
|
56
|
+
|
|
57
|
+
local handle = Instance.new("Part")
|
|
58
|
+
handle.Parent = accessory
|
|
59
|
+
|
|
60
|
+
expect(HumanoidUtils.getHumanoid(handle)).toBe(humanoid)
|
|
61
|
+
|
|
62
|
+
controller.destroy()
|
|
63
|
+
end)
|
|
64
|
+
|
|
65
|
+
it("returns nil outside of a humanoid model", function()
|
|
66
|
+
local controller = setup()
|
|
67
|
+
|
|
68
|
+
local part = Instance.new("Part")
|
|
69
|
+
|
|
70
|
+
expect(HumanoidUtils.getHumanoid(part)).toBeNil()
|
|
71
|
+
|
|
72
|
+
controller.destroy()
|
|
73
|
+
end)
|
|
74
|
+
end)
|
|
75
|
+
|
|
76
|
+
describe("HumanoidUtils.isHumanoidStateEnabled", function()
|
|
77
|
+
it("errors without a humanoid", function()
|
|
78
|
+
local controller = setup()
|
|
79
|
+
|
|
80
|
+
expect(function()
|
|
81
|
+
(HumanoidUtils :: any).isHumanoidStateEnabled(nil, Enum.HumanoidStateType.Jumping)
|
|
82
|
+
end).toThrow("No humanoid")
|
|
83
|
+
|
|
84
|
+
controller.destroy()
|
|
85
|
+
end)
|
|
86
|
+
|
|
87
|
+
it("errors without a state type", function()
|
|
88
|
+
local controller = setup()
|
|
89
|
+
local humanoid = controller.newHumanoid()
|
|
90
|
+
|
|
91
|
+
expect(function()
|
|
92
|
+
(HumanoidUtils :: any).isHumanoidStateEnabled(humanoid, nil)
|
|
93
|
+
end).toThrow("No stateType")
|
|
94
|
+
|
|
95
|
+
controller.destroy()
|
|
96
|
+
end)
|
|
97
|
+
|
|
98
|
+
it("reads the enabled state per state type", function()
|
|
99
|
+
local controller = setup()
|
|
100
|
+
local humanoid = controller.newHumanoid()
|
|
101
|
+
|
|
102
|
+
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
|
|
103
|
+
|
|
104
|
+
expect(HumanoidUtils.isHumanoidStateEnabled(humanoid, Enum.HumanoidStateType.Jumping)).toBe(false)
|
|
105
|
+
expect(HumanoidUtils.isHumanoidStateEnabled(humanoid, Enum.HumanoidStateType.Climbing)).toBe(true)
|
|
106
|
+
|
|
107
|
+
controller.destroy()
|
|
108
|
+
end)
|
|
109
|
+
end)
|
|
110
|
+
|
|
111
|
+
describe("HumanoidUtils.isJumpEnabled", function()
|
|
112
|
+
it("errors without a humanoid", function()
|
|
113
|
+
local controller = setup()
|
|
114
|
+
|
|
115
|
+
expect(function()
|
|
116
|
+
(HumanoidUtils :: any).isJumpEnabled(nil)
|
|
117
|
+
end).toThrow("No humanoid")
|
|
118
|
+
|
|
119
|
+
controller.destroy()
|
|
120
|
+
end)
|
|
121
|
+
|
|
122
|
+
it("is enabled for a default humanoid", function()
|
|
123
|
+
local controller = setup()
|
|
124
|
+
local humanoid = controller.newHumanoid()
|
|
125
|
+
|
|
126
|
+
expect(HumanoidUtils.isJumpEnabled(humanoid)).toBe(true)
|
|
127
|
+
|
|
128
|
+
controller.destroy()
|
|
129
|
+
end)
|
|
130
|
+
|
|
131
|
+
it("is disabled while the jumping state is disabled", function()
|
|
132
|
+
local controller = setup()
|
|
133
|
+
local humanoid = controller.newHumanoid()
|
|
134
|
+
|
|
135
|
+
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
|
|
136
|
+
|
|
137
|
+
expect(HumanoidUtils.isJumpEnabled(humanoid)).toBe(false)
|
|
138
|
+
|
|
139
|
+
controller.destroy()
|
|
140
|
+
end)
|
|
141
|
+
|
|
142
|
+
it("reads jump power while UseJumpPower is true", function()
|
|
143
|
+
local controller = setup()
|
|
144
|
+
local humanoid = controller.newHumanoid()
|
|
145
|
+
|
|
146
|
+
humanoid.UseJumpPower = true
|
|
147
|
+
humanoid.JumpHeight = 7
|
|
148
|
+
humanoid.JumpPower = 0
|
|
149
|
+
|
|
150
|
+
expect(HumanoidUtils.isJumpEnabled(humanoid)).toBe(false)
|
|
151
|
+
|
|
152
|
+
humanoid.JumpPower = 50
|
|
153
|
+
expect(HumanoidUtils.isJumpEnabled(humanoid)).toBe(true)
|
|
154
|
+
|
|
155
|
+
controller.destroy()
|
|
156
|
+
end)
|
|
157
|
+
|
|
158
|
+
it("reads jump height while UseJumpPower is false", function()
|
|
159
|
+
local controller = setup()
|
|
160
|
+
local humanoid = controller.newHumanoid()
|
|
161
|
+
|
|
162
|
+
humanoid.UseJumpPower = false
|
|
163
|
+
humanoid.JumpPower = 50
|
|
164
|
+
humanoid.JumpHeight = 0
|
|
165
|
+
|
|
166
|
+
expect(HumanoidUtils.isJumpEnabled(humanoid)).toBe(false)
|
|
167
|
+
|
|
168
|
+
humanoid.JumpHeight = 7
|
|
169
|
+
expect(HumanoidUtils.isJumpEnabled(humanoid)).toBe(true)
|
|
170
|
+
|
|
171
|
+
controller.destroy()
|
|
172
|
+
end)
|
|
173
|
+
end)
|
|
174
|
+
|
|
175
|
+
describe("HumanoidUtils.forceUnseatHumanoid", function()
|
|
176
|
+
it("leaves an unseated humanoid unseated", function()
|
|
177
|
+
local controller = setup()
|
|
178
|
+
local humanoid = controller.newHumanoid()
|
|
179
|
+
|
|
180
|
+
HumanoidUtils.forceUnseatHumanoid(humanoid)
|
|
181
|
+
|
|
182
|
+
expect(humanoid.Sit).toBe(false)
|
|
183
|
+
|
|
184
|
+
controller.destroy()
|
|
185
|
+
end)
|
|
186
|
+
end)
|
|
@@ -5,8 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
local require = require(script.Parent.loader).load(script)
|
|
7
7
|
|
|
8
|
+
local HumanoidUtils = require("HumanoidUtils")
|
|
8
9
|
local Maid = require("Maid")
|
|
9
10
|
local Observable = require("Observable")
|
|
11
|
+
local Rx = require("Rx")
|
|
12
|
+
local RxInstanceUtils = require("RxInstanceUtils")
|
|
10
13
|
|
|
11
14
|
local RxHumanoidUtils = {}
|
|
12
15
|
|
|
@@ -90,4 +93,56 @@ function RxHumanoidUtils.observeHumanoidStateType(humanoid: Humanoid): Observabl
|
|
|
90
93
|
end) :: any
|
|
91
94
|
end
|
|
92
95
|
|
|
96
|
+
--[=[
|
|
97
|
+
Observes whether a humanoid state type is enabled on the humanoid.
|
|
98
|
+
|
|
99
|
+
@param humanoid Humanoid
|
|
100
|
+
@param stateType Enum.HumanoidStateType
|
|
101
|
+
@return Observable<boolean>
|
|
102
|
+
]=]
|
|
103
|
+
function RxHumanoidUtils.observeHumanoidStateEnabled(
|
|
104
|
+
humanoid: Humanoid,
|
|
105
|
+
stateType: Enum.HumanoidStateType
|
|
106
|
+
): Observable.Observable<boolean>
|
|
107
|
+
assert(typeof(humanoid) == "Instance" and humanoid:IsA("Humanoid"), "No humanoid")
|
|
108
|
+
assert(typeof(stateType) == "EnumItem", "No stateType")
|
|
109
|
+
|
|
110
|
+
return Rx.fromSignal(humanoid.StateEnabledChanged):Pipe({
|
|
111
|
+
Rx.where(function(changedStateType)
|
|
112
|
+
return changedStateType == stateType
|
|
113
|
+
end) :: any,
|
|
114
|
+
Rx.map(function(_changedStateType, isEnabled)
|
|
115
|
+
return isEnabled
|
|
116
|
+
end) :: any,
|
|
117
|
+
Rx.startFrom(function()
|
|
118
|
+
return { HumanoidUtils.isHumanoidStateEnabled(humanoid, stateType) }
|
|
119
|
+
end) :: any,
|
|
120
|
+
Rx.distinct() :: any,
|
|
121
|
+
}) :: any
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
--[=[
|
|
125
|
+
Observes whether the humanoid is allowed to jump. This is true when the jumping state is enabled
|
|
126
|
+
and the humanoid's jump strength is above zero, which is the strength Roblox reads for the
|
|
127
|
+
humanoid's [Humanoid.UseJumpPower] mode.
|
|
128
|
+
|
|
129
|
+
@param humanoid Humanoid
|
|
130
|
+
@return Observable<boolean>
|
|
131
|
+
]=]
|
|
132
|
+
function RxHumanoidUtils.observeJumpEnabled(humanoid: Humanoid): Observable.Observable<boolean>
|
|
133
|
+
assert(typeof(humanoid) == "Instance" and humanoid:IsA("Humanoid"), "No humanoid")
|
|
134
|
+
|
|
135
|
+
return Rx.combineLatest({
|
|
136
|
+
isJumpStateEnabled = RxHumanoidUtils.observeHumanoidStateEnabled(humanoid, Enum.HumanoidStateType.Jumping),
|
|
137
|
+
useJumpPower = RxInstanceUtils.observeProperty(humanoid, "UseJumpPower"),
|
|
138
|
+
jumpPower = RxInstanceUtils.observeProperty(humanoid, "JumpPower"),
|
|
139
|
+
jumpHeight = RxInstanceUtils.observeProperty(humanoid, "JumpHeight"),
|
|
140
|
+
}):Pipe({
|
|
141
|
+
Rx.map(function()
|
|
142
|
+
return HumanoidUtils.isJumpEnabled(humanoid)
|
|
143
|
+
end) :: any,
|
|
144
|
+
Rx.distinct() :: any,
|
|
145
|
+
}) :: any
|
|
146
|
+
end
|
|
147
|
+
|
|
93
148
|
return RxHumanoidUtils
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
--[[
|
|
3
|
+
@class RxHumanoidUtils.spec.lua
|
|
4
|
+
]]
|
|
5
|
+
|
|
6
|
+
local require = require(script.Parent.loader).load(script)
|
|
7
|
+
|
|
8
|
+
local Jest = require("Jest")
|
|
9
|
+
local Maid = require("Maid")
|
|
10
|
+
local RxHumanoidUtils = require("RxHumanoidUtils")
|
|
11
|
+
|
|
12
|
+
local describe = Jest.Globals.describe
|
|
13
|
+
local expect = Jest.Globals.expect
|
|
14
|
+
local it = Jest.Globals.it
|
|
15
|
+
|
|
16
|
+
local function setup(): any
|
|
17
|
+
local maid = Maid.new()
|
|
18
|
+
|
|
19
|
+
local controller = {
|
|
20
|
+
newHumanoid = function(): Humanoid
|
|
21
|
+
return maid:Add(Instance.new("Humanoid"))
|
|
22
|
+
end,
|
|
23
|
+
record = function(observable: any): { any }
|
|
24
|
+
local values = {}
|
|
25
|
+
maid:GiveTask(observable:Subscribe(function(value)
|
|
26
|
+
table.insert(values, value)
|
|
27
|
+
end))
|
|
28
|
+
return values
|
|
29
|
+
end,
|
|
30
|
+
recordUntilStopped = function(observable: any): ({ any }, () -> ())
|
|
31
|
+
local values = {}
|
|
32
|
+
local subscription = maid:Add(observable:Subscribe(function(value)
|
|
33
|
+
table.insert(values, value)
|
|
34
|
+
end))
|
|
35
|
+
return values, function()
|
|
36
|
+
subscription:Destroy()
|
|
37
|
+
end
|
|
38
|
+
end,
|
|
39
|
+
destroy = function()
|
|
40
|
+
maid:DoCleaning()
|
|
41
|
+
end,
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return controller
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe("RxHumanoidUtils.observeRunningSpeed", function()
|
|
48
|
+
it("errors without a humanoid", function()
|
|
49
|
+
local controller = setup()
|
|
50
|
+
|
|
51
|
+
expect(function()
|
|
52
|
+
(RxHumanoidUtils :: any).observeRunningSpeed(nil)
|
|
53
|
+
end).toThrow("No humanoid")
|
|
54
|
+
|
|
55
|
+
controller.destroy()
|
|
56
|
+
end)
|
|
57
|
+
|
|
58
|
+
-- Cloud runs never step the humanoid state machine, so Running/Jumping/Seated never fire and only
|
|
59
|
+
-- the initial emission is observable here.
|
|
60
|
+
it("emits a stopped speed on subscribe", function()
|
|
61
|
+
local controller = setup()
|
|
62
|
+
local humanoid = controller.newHumanoid()
|
|
63
|
+
|
|
64
|
+
local speeds = controller.record(RxHumanoidUtils.observeRunningSpeed(humanoid))
|
|
65
|
+
|
|
66
|
+
expect(speeds).toEqual({ 0 })
|
|
67
|
+
|
|
68
|
+
controller.destroy()
|
|
69
|
+
end)
|
|
70
|
+
end)
|
|
71
|
+
|
|
72
|
+
describe("RxHumanoidUtils.observeHumanoidStateType", function()
|
|
73
|
+
it("emits the current state type on subscribe", function()
|
|
74
|
+
local controller = setup()
|
|
75
|
+
local humanoid = controller.newHumanoid()
|
|
76
|
+
|
|
77
|
+
local stateTypes = controller.record(RxHumanoidUtils.observeHumanoidStateType(humanoid))
|
|
78
|
+
|
|
79
|
+
expect(stateTypes).toEqual({ humanoid:GetState() })
|
|
80
|
+
|
|
81
|
+
controller.destroy()
|
|
82
|
+
end)
|
|
83
|
+
end)
|
|
84
|
+
|
|
85
|
+
describe("RxHumanoidUtils.observeHumanoidStateEnabled", function()
|
|
86
|
+
it("errors without a humanoid", function()
|
|
87
|
+
local controller = setup()
|
|
88
|
+
|
|
89
|
+
expect(function()
|
|
90
|
+
(RxHumanoidUtils :: any).observeHumanoidStateEnabled(nil, Enum.HumanoidStateType.Jumping)
|
|
91
|
+
end).toThrow("No humanoid")
|
|
92
|
+
|
|
93
|
+
controller.destroy()
|
|
94
|
+
end)
|
|
95
|
+
|
|
96
|
+
it("errors without a state type", function()
|
|
97
|
+
local controller = setup()
|
|
98
|
+
local humanoid = controller.newHumanoid()
|
|
99
|
+
|
|
100
|
+
expect(function()
|
|
101
|
+
(RxHumanoidUtils :: any).observeHumanoidStateEnabled(humanoid, nil)
|
|
102
|
+
end).toThrow("No stateType")
|
|
103
|
+
|
|
104
|
+
controller.destroy()
|
|
105
|
+
end)
|
|
106
|
+
|
|
107
|
+
it("emits the current enabled state on subscribe", function()
|
|
108
|
+
local controller = setup()
|
|
109
|
+
local humanoid = controller.newHumanoid()
|
|
110
|
+
|
|
111
|
+
local enabled =
|
|
112
|
+
controller.record(RxHumanoidUtils.observeHumanoidStateEnabled(humanoid, Enum.HumanoidStateType.Jumping))
|
|
113
|
+
|
|
114
|
+
expect(enabled).toEqual({ true })
|
|
115
|
+
|
|
116
|
+
controller.destroy()
|
|
117
|
+
end)
|
|
118
|
+
|
|
119
|
+
it("emits when the state is disabled and re-enabled", function()
|
|
120
|
+
local controller = setup()
|
|
121
|
+
local humanoid = controller.newHumanoid()
|
|
122
|
+
|
|
123
|
+
local enabled =
|
|
124
|
+
controller.record(RxHumanoidUtils.observeHumanoidStateEnabled(humanoid, Enum.HumanoidStateType.Jumping))
|
|
125
|
+
|
|
126
|
+
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
|
|
127
|
+
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
|
|
128
|
+
|
|
129
|
+
expect(enabled).toEqual({ true, false, true })
|
|
130
|
+
|
|
131
|
+
controller.destroy()
|
|
132
|
+
end)
|
|
133
|
+
|
|
134
|
+
it("only emits distinct values", function()
|
|
135
|
+
local controller = setup()
|
|
136
|
+
local humanoid = controller.newHumanoid()
|
|
137
|
+
|
|
138
|
+
local enabled =
|
|
139
|
+
controller.record(RxHumanoidUtils.observeHumanoidStateEnabled(humanoid, Enum.HumanoidStateType.Jumping))
|
|
140
|
+
|
|
141
|
+
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
|
|
142
|
+
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
|
|
143
|
+
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
|
|
144
|
+
|
|
145
|
+
expect(enabled).toEqual({ true, false })
|
|
146
|
+
|
|
147
|
+
controller.destroy()
|
|
148
|
+
end)
|
|
149
|
+
|
|
150
|
+
it("ignores other state types", function()
|
|
151
|
+
local controller = setup()
|
|
152
|
+
local humanoid = controller.newHumanoid()
|
|
153
|
+
|
|
154
|
+
local enabled =
|
|
155
|
+
controller.record(RxHumanoidUtils.observeHumanoidStateEnabled(humanoid, Enum.HumanoidStateType.Jumping))
|
|
156
|
+
|
|
157
|
+
humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, false)
|
|
158
|
+
humanoid:SetStateEnabled(Enum.HumanoidStateType.Seated, false)
|
|
159
|
+
|
|
160
|
+
expect(enabled).toEqual({ true })
|
|
161
|
+
|
|
162
|
+
controller.destroy()
|
|
163
|
+
end)
|
|
164
|
+
|
|
165
|
+
it("stops emitting once unsubscribed", function()
|
|
166
|
+
local controller = setup()
|
|
167
|
+
local humanoid = controller.newHumanoid()
|
|
168
|
+
|
|
169
|
+
local enabled, stop = controller.recordUntilStopped(
|
|
170
|
+
RxHumanoidUtils.observeHumanoidStateEnabled(humanoid, Enum.HumanoidStateType.Jumping)
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
stop()
|
|
174
|
+
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
|
|
175
|
+
|
|
176
|
+
expect(enabled).toEqual({ true })
|
|
177
|
+
|
|
178
|
+
controller.destroy()
|
|
179
|
+
end)
|
|
180
|
+
end)
|
|
181
|
+
|
|
182
|
+
describe("RxHumanoidUtils.observeJumpEnabled", function()
|
|
183
|
+
it("errors without a humanoid", function()
|
|
184
|
+
local controller = setup()
|
|
185
|
+
|
|
186
|
+
expect(function()
|
|
187
|
+
(RxHumanoidUtils :: any).observeJumpEnabled(nil)
|
|
188
|
+
end).toThrow("No humanoid")
|
|
189
|
+
|
|
190
|
+
controller.destroy()
|
|
191
|
+
end)
|
|
192
|
+
|
|
193
|
+
it("is enabled for a default humanoid", function()
|
|
194
|
+
local controller = setup()
|
|
195
|
+
local humanoid = controller.newHumanoid()
|
|
196
|
+
|
|
197
|
+
local enabled = controller.record(RxHumanoidUtils.observeJumpEnabled(humanoid))
|
|
198
|
+
|
|
199
|
+
expect(enabled).toEqual({ true })
|
|
200
|
+
|
|
201
|
+
controller.destroy()
|
|
202
|
+
end)
|
|
203
|
+
|
|
204
|
+
it("is disabled while the jumping state is disabled", function()
|
|
205
|
+
local controller = setup()
|
|
206
|
+
local humanoid = controller.newHumanoid()
|
|
207
|
+
|
|
208
|
+
local enabled = controller.record(RxHumanoidUtils.observeJumpEnabled(humanoid))
|
|
209
|
+
|
|
210
|
+
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
|
|
211
|
+
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
|
|
212
|
+
|
|
213
|
+
expect(enabled).toEqual({ true, false, true })
|
|
214
|
+
|
|
215
|
+
controller.destroy()
|
|
216
|
+
end)
|
|
217
|
+
|
|
218
|
+
it("reads jump power while UseJumpPower is true", function()
|
|
219
|
+
local controller = setup()
|
|
220
|
+
local humanoid = controller.newHumanoid()
|
|
221
|
+
humanoid.UseJumpPower = true
|
|
222
|
+
humanoid.JumpHeight = 0
|
|
223
|
+
|
|
224
|
+
local enabled = controller.record(RxHumanoidUtils.observeJumpEnabled(humanoid))
|
|
225
|
+
|
|
226
|
+
humanoid.JumpPower = 0
|
|
227
|
+
humanoid.JumpPower = 50
|
|
228
|
+
|
|
229
|
+
expect(enabled).toEqual({ true, false, true })
|
|
230
|
+
|
|
231
|
+
controller.destroy()
|
|
232
|
+
end)
|
|
233
|
+
|
|
234
|
+
it("reads jump height while UseJumpPower is false", function()
|
|
235
|
+
local controller = setup()
|
|
236
|
+
local humanoid = controller.newHumanoid()
|
|
237
|
+
humanoid.UseJumpPower = false
|
|
238
|
+
humanoid.JumpPower = 0
|
|
239
|
+
|
|
240
|
+
local enabled = controller.record(RxHumanoidUtils.observeJumpEnabled(humanoid))
|
|
241
|
+
|
|
242
|
+
humanoid.JumpHeight = 0
|
|
243
|
+
humanoid.JumpHeight = 7
|
|
244
|
+
|
|
245
|
+
expect(enabled).toEqual({ true, false, true })
|
|
246
|
+
|
|
247
|
+
controller.destroy()
|
|
248
|
+
end)
|
|
249
|
+
|
|
250
|
+
it("switches which jump strength it reads with UseJumpPower", function()
|
|
251
|
+
local controller = setup()
|
|
252
|
+
local humanoid = controller.newHumanoid()
|
|
253
|
+
humanoid.UseJumpPower = true
|
|
254
|
+
humanoid.JumpPower = 50
|
|
255
|
+
humanoid.JumpHeight = 0
|
|
256
|
+
|
|
257
|
+
local enabled = controller.record(RxHumanoidUtils.observeJumpEnabled(humanoid))
|
|
258
|
+
|
|
259
|
+
humanoid.UseJumpPower = false
|
|
260
|
+
humanoid.UseJumpPower = true
|
|
261
|
+
|
|
262
|
+
expect(enabled).toEqual({ true, false, true })
|
|
263
|
+
|
|
264
|
+
controller.destroy()
|
|
265
|
+
end)
|
|
266
|
+
|
|
267
|
+
it("ignores the unused jump strength", function()
|
|
268
|
+
local controller = setup()
|
|
269
|
+
local humanoid = controller.newHumanoid()
|
|
270
|
+
humanoid.UseJumpPower = true
|
|
271
|
+
humanoid.JumpPower = 50
|
|
272
|
+
|
|
273
|
+
local enabled = controller.record(RxHumanoidUtils.observeJumpEnabled(humanoid))
|
|
274
|
+
|
|
275
|
+
humanoid.JumpHeight = 0
|
|
276
|
+
humanoid.JumpHeight = 12
|
|
277
|
+
|
|
278
|
+
expect(enabled).toEqual({ true })
|
|
279
|
+
|
|
280
|
+
controller.destroy()
|
|
281
|
+
end)
|
|
282
|
+
|
|
283
|
+
it("stays disabled while both the state and the jump power are disabled", function()
|
|
284
|
+
local controller = setup()
|
|
285
|
+
local humanoid = controller.newHumanoid()
|
|
286
|
+
humanoid.JumpPower = 0
|
|
287
|
+
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
|
|
288
|
+
|
|
289
|
+
local enabled = controller.record(RxHumanoidUtils.observeJumpEnabled(humanoid))
|
|
290
|
+
|
|
291
|
+
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
|
|
292
|
+
humanoid.JumpPower = 50
|
|
293
|
+
|
|
294
|
+
expect(enabled).toEqual({ false, true })
|
|
295
|
+
|
|
296
|
+
controller.destroy()
|
|
297
|
+
end)
|
|
298
|
+
|
|
299
|
+
it("stops emitting once unsubscribed", function()
|
|
300
|
+
local controller = setup()
|
|
301
|
+
local humanoid = controller.newHumanoid()
|
|
302
|
+
|
|
303
|
+
local enabled, stop = controller.recordUntilStopped(RxHumanoidUtils.observeJumpEnabled(humanoid))
|
|
304
|
+
|
|
305
|
+
stop()
|
|
306
|
+
humanoid.JumpPower = 0
|
|
307
|
+
|
|
308
|
+
expect(enabled).toEqual({ true })
|
|
309
|
+
|
|
310
|
+
controller.destroy()
|
|
311
|
+
end)
|
|
312
|
+
end)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "HumanoidutilsTest",
|
|
3
|
+
"globIgnorePaths": [
|
|
4
|
+
"**/.package-lock.json",
|
|
5
|
+
"**/.pnpm",
|
|
6
|
+
"**/.pnpm-workspace-state-v1.json",
|
|
7
|
+
"**/.modules.yaml",
|
|
8
|
+
"**/.ignored",
|
|
9
|
+
"**/.ignored_*"
|
|
10
|
+
],
|
|
11
|
+
"tree": {
|
|
12
|
+
"$className": "DataModel",
|
|
13
|
+
"ServerScriptService": {
|
|
14
|
+
"$properties": {
|
|
15
|
+
"LoadStringEnabled": true
|
|
16
|
+
},
|
|
17
|
+
"humanoidutils": {
|
|
18
|
+
"$path": ".."
|
|
19
|
+
},
|
|
20
|
+
"Script": {
|
|
21
|
+
"$path": "scripts/Server"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
--[[
|
|
2
|
+
@class ServerMain
|
|
3
|
+
]]
|
|
4
|
+
local ServerScriptService = game:GetService("ServerScriptService")
|
|
5
|
+
|
|
6
|
+
local root = ServerScriptService.humanoidutils
|
|
7
|
+
local loader = root:FindFirstChild("LoaderUtils", true).Parent
|
|
8
|
+
local require = require(loader).bootstrapGame(root)
|
|
9
|
+
|
|
10
|
+
local NevermoreTestRunnerUtils = require("NevermoreTestRunnerUtils")
|
|
11
|
+
if NevermoreTestRunnerUtils.runTestsIfNeededAsync(root) then
|
|
12
|
+
return
|
|
13
|
+
end
|