@quenty/inputobjectutils 4.18.0 → 4.18.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/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
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
|
+
## [4.18.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/inputobjectutils@4.18.0...@quenty/inputobjectutils@4.18.1) (2025-04-05)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Add types to packages ([2374fb2](https://github.com/Quenty/NevermoreEngine/commit/2374fb2b043cfbe0e9b507b3316eec46a4e353a0))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [4.18.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/inputobjectutils@4.17.2...@quenty/inputobjectutils@4.18.0) (2025-04-02)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @quenty/inputobjectutils
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/inputobjectutils",
|
|
3
|
-
"version": "4.18.
|
|
3
|
+
"version": "4.18.1",
|
|
4
4
|
"description": "Provides utility functions involving input objects",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@quenty/baseobject": "^10.8.
|
|
32
|
-
"@quenty/loader": "^10.8.
|
|
33
|
-
"@quenty/maid": "^3.4.
|
|
34
|
-
"@quenty/rx": "^13.17.
|
|
35
|
-
"@quenty/rxsignal": "^7.17.
|
|
31
|
+
"@quenty/baseobject": "^10.8.1",
|
|
32
|
+
"@quenty/loader": "^10.8.1",
|
|
33
|
+
"@quenty/maid": "^3.4.1",
|
|
34
|
+
"@quenty/rx": "^13.17.1",
|
|
35
|
+
"@quenty/rxsignal": "^7.17.1"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "78c3ac0ab08dd18085b6e6e6e4f745e76ed99f68"
|
|
38
38
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
Utility functions for constructing rays from input objects
|
|
3
4
|
@class InputObjectRayUtils
|
|
@@ -17,12 +18,22 @@ local InputObjectRayUtils = {}
|
|
|
17
18
|
@param camera Camera? -- Optional
|
|
18
19
|
@return Ray
|
|
19
20
|
]=]
|
|
20
|
-
function InputObjectRayUtils.cameraRayFromInputObject(
|
|
21
|
+
function InputObjectRayUtils.cameraRayFromInputObject(
|
|
22
|
+
inputObject: InputObject,
|
|
23
|
+
distance: number,
|
|
24
|
+
offset: (Vector3 | Vector2)?,
|
|
25
|
+
camera: Camera?
|
|
26
|
+
): Ray
|
|
21
27
|
assert(inputObject, "Bad inputObject")
|
|
22
|
-
|
|
28
|
+
|
|
29
|
+
local rayOffset = offset or Vector3.zero
|
|
23
30
|
|
|
24
31
|
local position = inputObject.Position
|
|
25
|
-
return InputObjectRayUtils.cameraRayFromScreenPosition(
|
|
32
|
+
return InputObjectRayUtils.cameraRayFromScreenPosition(
|
|
33
|
+
Vector2.new(position.X + rayOffset.X, position.Y + rayOffset.Y),
|
|
34
|
+
distance,
|
|
35
|
+
camera
|
|
36
|
+
)
|
|
26
37
|
end
|
|
27
38
|
|
|
28
39
|
--[=[
|
|
@@ -33,14 +44,21 @@ end
|
|
|
33
44
|
@param camera Camera? -- Optional
|
|
34
45
|
@return Ray
|
|
35
46
|
]=]
|
|
36
|
-
function InputObjectRayUtils.cameraRayFromMouse(
|
|
47
|
+
function InputObjectRayUtils.cameraRayFromMouse(
|
|
48
|
+
mouse: Mouse,
|
|
49
|
+
distance: number,
|
|
50
|
+
offset: (Vector3 | Vector2)?,
|
|
51
|
+
camera: Camera?
|
|
52
|
+
): Ray
|
|
37
53
|
assert(mouse, "Bad mouse")
|
|
38
|
-
|
|
54
|
+
|
|
55
|
+
local rayOffset = offset or Vector3.zero
|
|
39
56
|
|
|
40
57
|
return InputObjectRayUtils.cameraRayFromScreenPosition(
|
|
41
|
-
Vector2.new(mouse.
|
|
58
|
+
Vector2.new(mouse.X + rayOffset.X, mouse.Y + rayOffset.Y),
|
|
42
59
|
distance,
|
|
43
|
-
camera
|
|
60
|
+
camera
|
|
61
|
+
)
|
|
44
62
|
end
|
|
45
63
|
|
|
46
64
|
--[=[
|
|
@@ -50,14 +68,20 @@ end
|
|
|
50
68
|
@param camera Camera? -- Optional
|
|
51
69
|
@return Ray
|
|
52
70
|
]=]
|
|
53
|
-
function InputObjectRayUtils.cameraRayFromInputObjectWithOffset(
|
|
71
|
+
function InputObjectRayUtils.cameraRayFromInputObjectWithOffset(
|
|
72
|
+
inputObject: InputObject,
|
|
73
|
+
distance: number?,
|
|
74
|
+
offset: Vector3 | Vector2,
|
|
75
|
+
camera: Camera?
|
|
76
|
+
): Ray
|
|
54
77
|
assert(inputObject, "Bad inputObject")
|
|
55
78
|
|
|
56
79
|
local position = inputObject.Position
|
|
57
80
|
return InputObjectRayUtils.cameraRayFromScreenPosition(
|
|
58
|
-
Vector2.new(position.
|
|
81
|
+
Vector2.new(position.X + offset.X, position.Y + offset.Y),
|
|
59
82
|
distance,
|
|
60
|
-
camera
|
|
83
|
+
camera
|
|
84
|
+
)
|
|
61
85
|
end
|
|
62
86
|
|
|
63
87
|
--[=[
|
|
@@ -66,11 +90,15 @@ end
|
|
|
66
90
|
@param camera Camera? -- Optional
|
|
67
91
|
@return Ray
|
|
68
92
|
]=]
|
|
69
|
-
function InputObjectRayUtils.cameraRayFromScreenPosition(
|
|
93
|
+
function InputObjectRayUtils.cameraRayFromScreenPosition(
|
|
94
|
+
position: Vector3 | Vector2,
|
|
95
|
+
distance: number?,
|
|
96
|
+
camera: Camera?
|
|
97
|
+
): Ray
|
|
70
98
|
distance = distance or DEFAULT_RAY_DISTANCE
|
|
71
|
-
|
|
99
|
+
local currentCamera = camera or Workspace.CurrentCamera
|
|
72
100
|
|
|
73
|
-
local baseRay =
|
|
101
|
+
local baseRay = currentCamera:ScreenPointToRay(position.X, position.Y)
|
|
74
102
|
return Ray.new(baseRay.Origin, baseRay.Direction.unit * distance)
|
|
75
103
|
end
|
|
76
104
|
|
|
@@ -80,11 +108,15 @@ end
|
|
|
80
108
|
@param camera Camera? -- Optional
|
|
81
109
|
@return Ray
|
|
82
110
|
]=]
|
|
83
|
-
function InputObjectRayUtils.cameraRayFromViewportPosition(
|
|
111
|
+
function InputObjectRayUtils.cameraRayFromViewportPosition(
|
|
112
|
+
position: Vector3 | Vector2,
|
|
113
|
+
distance: number?,
|
|
114
|
+
camera: Camera?
|
|
115
|
+
): Ray
|
|
84
116
|
distance = distance or DEFAULT_RAY_DISTANCE
|
|
85
|
-
|
|
117
|
+
local currentCamera = camera or Workspace.CurrentCamera
|
|
86
118
|
|
|
87
|
-
local baseRay =
|
|
119
|
+
local baseRay = currentCamera:ViewportPointToRay(position.X, position.Y)
|
|
88
120
|
return Ray.new(baseRay.Origin, baseRay.Direction.unit * distance)
|
|
89
121
|
end
|
|
90
122
|
|
|
@@ -95,8 +127,8 @@ end
|
|
|
95
127
|
@param radius number
|
|
96
128
|
@return { Ray }
|
|
97
129
|
]=]
|
|
98
|
-
function InputObjectRayUtils.generateCircleRays(ray, count, radius)
|
|
99
|
-
local rays = {
|
|
130
|
+
function InputObjectRayUtils.generateCircleRays(ray: Ray, count: number, radius: number): { Ray }
|
|
131
|
+
local rays = {}
|
|
100
132
|
|
|
101
133
|
local origin = ray.Origin
|
|
102
134
|
local direction = ray.Direction
|
|
@@ -104,8 +136,8 @@ function InputObjectRayUtils.generateCircleRays(ray, count, radius)
|
|
|
104
136
|
local cframePointing = CFrame.new(origin, origin + direction)
|
|
105
137
|
|
|
106
138
|
for i=1, count do
|
|
107
|
-
local angle = math.pi*2*(i-1)/count
|
|
108
|
-
local offset = cframePointing:
|
|
139
|
+
local angle = math.pi * 2 * (i - 1) / count
|
|
140
|
+
local offset = cframePointing:VectorToWorldSpace(Vector3.new(
|
|
109
141
|
math.cos(angle)*radius,
|
|
110
142
|
math.sin(angle)*radius,
|
|
111
143
|
0))
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
Tracks an input object, whether it's a mouse or a touch button for position
|
|
3
4
|
or mouse down.
|
|
@@ -38,39 +39,40 @@ local InputObjectUtils = require("InputObjectUtils")
|
|
|
38
39
|
local InputObjectRayUtils = require("InputObjectRayUtils")
|
|
39
40
|
local RxInputObjectUtils = require("RxInputObjectUtils")
|
|
40
41
|
local RxSignal = require("RxSignal")
|
|
42
|
+
local _Maid = require("Maid")
|
|
43
|
+
local _Observable = require("Observable")
|
|
41
44
|
|
|
42
45
|
local InputObjectTracker = setmetatable({}, BaseObject)
|
|
43
46
|
InputObjectTracker.ClassName = "InputObjectTracker"
|
|
44
47
|
InputObjectTracker.__index = InputObjectTracker
|
|
45
48
|
|
|
46
|
-
|
|
49
|
+
export type InputObjectTracker = typeof(setmetatable(
|
|
50
|
+
{} :: {
|
|
51
|
+
_maid: _Maid.Maid,
|
|
52
|
+
_initialPosition: Vector2,
|
|
53
|
+
_initialInputObject: InputObject,
|
|
54
|
+
_lastMousePosition: Vector2,
|
|
55
|
+
_isMouse: boolean,
|
|
56
|
+
_camera: Camera?,
|
|
57
|
+
|
|
58
|
+
InputEnded: RxSignal.RxSignal<()>,
|
|
59
|
+
},
|
|
60
|
+
{ __index = InputObjectTracker }
|
|
61
|
+
))
|
|
62
|
+
|
|
63
|
+
local function toVector2(vector3: Vector3): Vector2
|
|
64
|
+
return Vector2.new(vector3.X, vector3.Y)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
function InputObjectTracker.new(initialInputObject: InputObject): InputObjectTracker
|
|
47
68
|
assert(typeof(initialInputObject) == "Instance" and initialInputObject:IsA("InputObject"), "Bad initialInputObject")
|
|
48
69
|
|
|
49
|
-
local self = setmetatable(BaseObject.new(), InputObjectTracker)
|
|
70
|
+
local self: InputObjectTracker = setmetatable(BaseObject.new() :: any, InputObjectTracker)
|
|
50
71
|
|
|
51
72
|
self._initialInputObject = assert(initialInputObject, "No initialInputObject")
|
|
52
73
|
|
|
53
74
|
if InputObjectUtils.isMouseUserInputType(self._initialInputObject.UserInputType) then
|
|
54
|
-
self
|
|
55
|
-
self._isMouse = true
|
|
56
|
-
|
|
57
|
-
self._maid:GiveTask(UserInputService.InputBegan:Connect(function(inputObject)
|
|
58
|
-
if InputObjectUtils.isMouseUserInputType(inputObject.UserInputType) then
|
|
59
|
-
self._lastMousePosition = inputObject.Position
|
|
60
|
-
end
|
|
61
|
-
end))
|
|
62
|
-
|
|
63
|
-
self._maid:GiveTask(UserInputService.InputChanged:Connect(function(inputObject)
|
|
64
|
-
if InputObjectUtils.isMouseUserInputType(inputObject.UserInputType) then
|
|
65
|
-
self._lastMousePosition = inputObject.Position
|
|
66
|
-
end
|
|
67
|
-
end))
|
|
68
|
-
|
|
69
|
-
self._maid:GiveTask(UserInputService.InputEnded:Connect(function(inputObject)
|
|
70
|
-
if InputObjectUtils.isMouseUserInputType(inputObject.UserInputType) then
|
|
71
|
-
self._lastMousePosition = inputObject.Position
|
|
72
|
-
end
|
|
73
|
-
end))
|
|
75
|
+
self:_setupMouse()
|
|
74
76
|
end
|
|
75
77
|
|
|
76
78
|
self._initialPosition = self:GetPosition()
|
|
@@ -80,12 +82,34 @@ function InputObjectTracker.new(initialInputObject)
|
|
|
80
82
|
return self
|
|
81
83
|
end
|
|
82
84
|
|
|
85
|
+
function InputObjectTracker._setupMouse(self: InputObjectTracker): ()
|
|
86
|
+
self._lastMousePosition = toVector2(self._initialInputObject.Position)
|
|
87
|
+
self._isMouse = true
|
|
88
|
+
|
|
89
|
+
self._maid:GiveTask(UserInputService.InputBegan:Connect(function(inputObject)
|
|
90
|
+
if InputObjectUtils.isMouseUserInputType(inputObject.UserInputType) then
|
|
91
|
+
self._lastMousePosition = toVector2(inputObject.Position)
|
|
92
|
+
end
|
|
93
|
+
end))
|
|
94
|
+
|
|
95
|
+
self._maid:GiveTask(UserInputService.InputChanged:Connect(function(inputObject)
|
|
96
|
+
if InputObjectUtils.isMouseUserInputType(inputObject.UserInputType) then
|
|
97
|
+
self._lastMousePosition = toVector2(inputObject.Position)
|
|
98
|
+
end
|
|
99
|
+
end))
|
|
100
|
+
|
|
101
|
+
self._maid:GiveTask(UserInputService.InputEnded:Connect(function(inputObject)
|
|
102
|
+
if InputObjectUtils.isMouseUserInputType(inputObject.UserInputType) then
|
|
103
|
+
self._lastMousePosition = toVector2(inputObject.Position)
|
|
104
|
+
end
|
|
105
|
+
end))
|
|
106
|
+
end
|
|
83
107
|
--[=[
|
|
84
108
|
Observes when the input is ended
|
|
85
109
|
|
|
86
110
|
@return Observable
|
|
87
111
|
]=]
|
|
88
|
-
function InputObjectTracker
|
|
112
|
+
function InputObjectTracker.ObserveInputEnded(self: InputObjectTracker): _Observable.Observable<()>
|
|
89
113
|
return RxInputObjectUtils.observeInputObjectEnded(self._initialInputObject)
|
|
90
114
|
end
|
|
91
115
|
|
|
@@ -94,7 +118,7 @@ end
|
|
|
94
118
|
|
|
95
119
|
@return Vector2
|
|
96
120
|
]=]
|
|
97
|
-
function InputObjectTracker
|
|
121
|
+
function InputObjectTracker.GetInitialPosition(self: InputObjectTracker): Vector2
|
|
98
122
|
return self._initialPosition
|
|
99
123
|
end
|
|
100
124
|
|
|
@@ -103,28 +127,37 @@ end
|
|
|
103
127
|
|
|
104
128
|
@return Observable<Vector2>
|
|
105
129
|
]=]
|
|
106
|
-
function InputObjectTracker
|
|
130
|
+
function InputObjectTracker.GetPosition(self: InputObjectTracker): Vector2
|
|
107
131
|
if self._isMouse then
|
|
108
132
|
return self._lastMousePosition
|
|
109
133
|
else
|
|
110
134
|
local position = self._initialInputObject.Position
|
|
111
|
-
return Vector2.new(position.
|
|
135
|
+
return Vector2.new(position.X, position.Y)
|
|
112
136
|
end
|
|
113
137
|
end
|
|
114
138
|
|
|
115
139
|
--[=[
|
|
116
140
|
Observes the input object ray
|
|
117
141
|
|
|
118
|
-
@param
|
|
119
|
-
@return
|
|
142
|
+
@param rayDistance number? -- Optional number, defaults to 1000
|
|
143
|
+
@return Ray
|
|
120
144
|
]=]
|
|
121
|
-
function InputObjectTracker
|
|
122
|
-
distance =
|
|
145
|
+
function InputObjectTracker.GetRay(self: InputObjectTracker, rayDistance: number?): Ray
|
|
146
|
+
local distance = rayDistance or 1000
|
|
123
147
|
|
|
124
148
|
if self._isMouse then
|
|
125
|
-
return InputObjectRayUtils.cameraRayFromScreenPosition(
|
|
149
|
+
return InputObjectRayUtils.cameraRayFromScreenPosition(
|
|
150
|
+
self._lastMousePosition,
|
|
151
|
+
distance,
|
|
152
|
+
self._camera or Workspace.CurrentCamera
|
|
153
|
+
)
|
|
126
154
|
else
|
|
127
|
-
return InputObjectRayUtils.cameraRayFromInputObject(
|
|
155
|
+
return InputObjectRayUtils.cameraRayFromInputObject(
|
|
156
|
+
self._initialInputObject,
|
|
157
|
+
distance,
|
|
158
|
+
Vector2.zero,
|
|
159
|
+
self._camera or Workspace.CurrentCamera
|
|
160
|
+
)
|
|
128
161
|
end
|
|
129
162
|
end
|
|
130
163
|
|
|
@@ -133,7 +166,7 @@ end
|
|
|
133
166
|
|
|
134
167
|
@param camera Camera
|
|
135
168
|
]=]
|
|
136
|
-
function InputObjectTracker
|
|
169
|
+
function InputObjectTracker.SetCamera(self: InputObjectTracker, camera: Camera): ()
|
|
137
170
|
assert(typeof(camera) == "Instance", "Bad camera")
|
|
138
171
|
|
|
139
172
|
self._camera = camera
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
Provides utility functions involving input objects
|
|
3
4
|
@class InputObjectUtils
|
|
@@ -25,7 +26,7 @@ local MOUSE_BUTTON_USER_INPUT_TYPES = {
|
|
|
25
26
|
@param userInputType UserInputType
|
|
26
27
|
@return boolean
|
|
27
28
|
]=]
|
|
28
|
-
function InputObjectUtils.isMouseUserInputType(userInputType)
|
|
29
|
+
function InputObjectUtils.isMouseUserInputType(userInputType: Enum.UserInputType): boolean
|
|
29
30
|
assert(typeof(userInputType) == "EnumItem", "Bad userInputType")
|
|
30
31
|
|
|
31
32
|
return MOUSE_USER_INPUT_TYPES[userInputType] or false
|
|
@@ -37,7 +38,7 @@ end
|
|
|
37
38
|
@param userInputType UserInputType
|
|
38
39
|
@return boolean
|
|
39
40
|
]=]
|
|
40
|
-
function InputObjectUtils.isMouseButtonInputType(userInputType)
|
|
41
|
+
function InputObjectUtils.isMouseButtonInputType(userInputType: Enum.UserInputType): boolean
|
|
41
42
|
assert(typeof(userInputType) == "EnumItem", "Bad userInputType")
|
|
42
43
|
|
|
43
44
|
return MOUSE_BUTTON_USER_INPUT_TYPES[userInputType] or false
|
|
@@ -51,7 +52,7 @@ end
|
|
|
51
52
|
@param otherInputObject InputObject
|
|
52
53
|
@return boolean
|
|
53
54
|
]=]
|
|
54
|
-
function InputObjectUtils.isSameInputObject(inputObject, otherInputObject)
|
|
55
|
+
function InputObjectUtils.isSameInputObject(inputObject: InputObject, otherInputObject: InputObject): boolean
|
|
55
56
|
assert(inputObject, "Bad inputObject")
|
|
56
57
|
assert(otherInputObject, "Bad otherInputObject")
|
|
57
58
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
@class RxInputObjectUtils
|
|
3
4
|
]=]
|
|
@@ -12,7 +13,13 @@ local InputObjectUtils = require("InputObjectUtils")
|
|
|
12
13
|
|
|
13
14
|
local RxInputObjectUtils = {}
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
--[=[
|
|
17
|
+
Observes the input object ended event. This will fire immediately if the input object is already ended.
|
|
18
|
+
|
|
19
|
+
@param initialInputObject InputObject
|
|
20
|
+
@return Observable<()>
|
|
21
|
+
]=]
|
|
22
|
+
function RxInputObjectUtils.observeInputObjectEnded(initialInputObject: InputObject): Observable.Observable<()>
|
|
16
23
|
assert(initialInputObject, "Bad initialInputObject")
|
|
17
24
|
|
|
18
25
|
return Observable.new(function(sub)
|