@quenty/inputobjectutils 4.5.0 → 4.6.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 CHANGED
@@ -3,6 +3,22 @@
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.6.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/inputobjectutils@4.5.0...@quenty/inputobjectutils@4.6.0) (2024-09-12)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * InputObjectUtils didn't load dependencies properly ([bfeb42c](https://github.com/Quenty/NevermoreEngine/commit/bfeb42c9fe16ce5a8ba50e0451fdc1d304e6bc9c))
12
+
13
+
14
+ ### Features
15
+
16
+ * Recreate InputObjectTracker to be easier to use ([dc78fe7](https://github.com/Quenty/NevermoreEngine/commit/dc78fe7b83d4be3a08eadf690b13685111e38e25))
17
+
18
+
19
+
20
+
21
+
6
22
  # [4.5.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/inputobjectutils@4.4.0...@quenty/inputobjectutils@4.5.0) (2024-08-09)
7
23
 
8
24
  **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.5.0",
3
+ "version": "4.6.0",
4
4
  "description": "Provides utility functions involving input objects",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -28,9 +28,11 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@quenty/baseobject": "^10.3.0",
32
- "@quenty/maid": "^3.2.0",
33
- "@quenty/rx": "^13.4.0"
31
+ "@quenty/baseobject": "^10.4.0",
32
+ "@quenty/loader": "^10.4.0",
33
+ "@quenty/maid": "^3.3.0",
34
+ "@quenty/rx": "^13.5.0",
35
+ "@quenty/rxsignal": "^7.5.0"
34
36
  },
35
- "gitHead": "ba466bdbc05c42fb607cf5e228c16339201d21d7"
37
+ "gitHead": "fb172906f3ee725269ec1e5f4daf9dca227e729d"
36
38
  }
@@ -0,0 +1,142 @@
1
+ --[=[
2
+ Tracks an input object, whether it's a mouse or a touch button for position
3
+ or mouse down.
4
+
5
+ Works around a bug in the mouse object where the mouse input objects are new
6
+ per a mouse event.
7
+
8
+ ```lua
9
+ local maid = Maid.new()
10
+ local tracker = maid:Add(InputObjectTracker.new(initialInputObject))
11
+
12
+ maid:GiveTask(RunService.RenderStepped:Connect(function()
13
+ print("Input down at", tracker:GetPosition())
14
+
15
+ -- Can also cast a ray
16
+ print("Cast ray at", tracker:GetRay())
17
+ end))
18
+
19
+ maid:GiveTask(tracker:ObserveInputEnded():Subscribe(function()
20
+ maid:DoCleaning()
21
+ end))
22
+
23
+ maid:GiveTask(tracker.InputEnded:Connect(function()
24
+
25
+ end))
26
+ ```
27
+
28
+ @class InputObjectTracker
29
+ ]=]
30
+
31
+ local require = require(script.Parent.loader).load(script)
32
+
33
+ local Workspace = game:GetService("Workspace")
34
+ local UserInputService = game:GetService("UserInputService")
35
+
36
+ local BaseObject = require("BaseObject")
37
+ local InputObjectUtils = require("InputObjectUtils")
38
+ local InputObjectRayUtils = require("InputObjectRayUtils")
39
+ local RxInputObjectUtils = require("RxInputObjectUtils")
40
+ local RxSignal = require("RxSignal")
41
+
42
+ local InputObjectTracker = setmetatable({}, BaseObject)
43
+ InputObjectTracker.ClassName = "InputObjectTracker"
44
+ InputObjectTracker.__index = InputObjectTracker
45
+
46
+ function InputObjectTracker.new(initialInputObject)
47
+ assert(typeof(initialInputObject) == "Instance" and initialInputObject:IsA("InputObject"), "Bad initialInputObject")
48
+
49
+ local self = setmetatable(BaseObject.new(), InputObjectTracker)
50
+
51
+ self._initialInputObject = assert(initialInputObject, "No initialInputObject")
52
+
53
+ if InputObjectUtils.isMouseUserInputType(self._initialInputObject.UserInputType) then
54
+ self._lastMousePosition = self._initialInputObject.Position
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))
74
+ end
75
+
76
+ self._initialPosition = self:GetPosition()
77
+
78
+ self.InputEnded = RxSignal.new(self:ObserveInputEnded())
79
+
80
+ return self
81
+ end
82
+
83
+ --[=[
84
+ Observes when the input is ended
85
+
86
+ @return Observable
87
+ ]=]
88
+ function InputObjectTracker:ObserveInputEnded()
89
+ return RxInputObjectUtils.observeInputObjectEnded(self._initialInputObject)
90
+ end
91
+
92
+ --[=[
93
+ Gets the initial position for the input object
94
+
95
+ @return Vector2
96
+ ]=]
97
+ function InputObjectTracker:GetInitialPosition()
98
+ return self._initialPosition
99
+ end
100
+
101
+ --[=[
102
+ Observes input object position
103
+
104
+ @return Observable<Vector2>
105
+ ]=]
106
+ function InputObjectTracker:GetPosition()
107
+ if self._isMouse then
108
+ return self._lastMousePosition
109
+ else
110
+ local position = self._initialInputObject.Position
111
+ return Vector2.new(position.x, position.y)
112
+ end
113
+ end
114
+
115
+ --[=[
116
+ Observes the input object ray
117
+
118
+ @param distance number? -- Optional number, defaults to 1000
119
+ @return Observable<Vector2>
120
+ ]=]
121
+ function InputObjectTracker:GetRay(distance)
122
+ distance = distance or 1000
123
+
124
+ if self._isMouse then
125
+ return InputObjectRayUtils.cameraRayFromScreenPosition(self._lastMousePosition, distance, self._camera or Workspace.CurrentCamera)
126
+ else
127
+ return InputObjectRayUtils.cameraRayFromInputObject(self._initialInputObject, distance, Vector2.zero, self._camera or Workspace.CurrentCamera)
128
+ end
129
+ end
130
+
131
+ --[=[
132
+ Sets the camera for the input object tracker to retrieve rays from
133
+
134
+ @param camera Camera
135
+ ]=]
136
+ function InputObjectTracker:SetCamera(camera)
137
+ assert(typeof(camera) == "Instance", "Bad camera")
138
+
139
+ self._camera = camera
140
+ end
141
+
142
+ return InputObjectTracker
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "node_modules",
3
+ "globIgnorePaths": [ "**/.package-lock.json" ],
4
+ "tree": {
5
+ "$path": { "optional": "../node_modules" }
6
+ }
7
+ }
@@ -1,70 +0,0 @@
1
- --[=[
2
- @class InputObjectPositionTracker
3
- ]=]
4
-
5
- local require = require(script.Parent.loader).load(script)
6
-
7
- local Workspace = game:GetService("Workspace")
8
- local UserInputService = game:GetService("UserInputService")
9
-
10
- local BaseObject = require("BaseObject")
11
- local InputObjectUtils = require("InputObjectUtils")
12
- local InputObjectRayUtils = require("InputObjectRayUtils")
13
-
14
- local InputObjectPositionTracker = setmetatable({}, BaseObject)
15
- InputObjectPositionTracker.ClassName = "InputObjectPositionTracker"
16
- InputObjectPositionTracker.__index = InputObjectPositionTracker
17
-
18
- function InputObjectPositionTracker.new(initialInputObject)
19
- assert(typeof(initialInputObject) == "Instance" and initialInputObject:IsA("InputObject"), "Bad initialInputObject")
20
-
21
- local self = setmetatable(BaseObject.new(), InputObjectPositionTracker)
22
-
23
- self._initialInputObject = assert(initialInputObject, "No initialInputObject")
24
-
25
- if InputObjectUtils.isMouseUserInputType(self._initialInputObject.UserInputType) then
26
- self._lastMousePosition = self._initialInputObject.Position
27
- self._isMouse = true
28
-
29
- self._maid:GiveTask(UserInputService.InputBegan:Connect(function(inputObject)
30
- if InputObjectUtils.isMouseUserInputType(inputObject.UserInputType) then
31
- self._lastMousePosition = inputObject.Position
32
- end
33
- end))
34
-
35
- self._maid:GiveTask(UserInputService.InputChanged:Connect(function(inputObject)
36
- if InputObjectUtils.isMouseUserInputType(inputObject.UserInputType) then
37
- self._lastMousePosition = inputObject.Position
38
- end
39
- end))
40
-
41
- self._maid:GiveTask(UserInputService.InputEnded:Connect(function(inputObject)
42
- if InputObjectUtils.isMouseUserInputType(inputObject.UserInputType) then
43
- self._lastMousePosition = inputObject.Position
44
- end
45
- end))
46
- end
47
-
48
- return self
49
- end
50
-
51
- function InputObjectPositionTracker:GetInputObjectPosition()
52
- if self._isMouse then
53
- return self._lastMousePosition
54
- else
55
- local position = self._initialInputObject.Position
56
- return Vector2.new(position.x, position.y)
57
- end
58
- end
59
-
60
- function InputObjectPositionTracker:GetInputObjectRay(distance)
61
- distance = distance or 1000
62
-
63
- if self._isMouse then
64
- return InputObjectRayUtils.cameraRayFromScreenPosition(self._lastMousePosition, distance, Workspace.CurrentCamera)
65
- else
66
- return InputObjectRayUtils.cameraRayFromInputObject(self._initialInputObject, distance, Vector2.zero, Workspace.CurrentCamera)
67
- end
68
- end
69
-
70
- return InputObjectPositionTracker