@quenty/inputobjectutils 4.1.0 → 4.2.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 +11 -0
- package/LICENSE.md +1 -1
- package/package.json +6 -2
- package/src/Client/InputObjectPositionTracker.lua +70 -0
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.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/inputobjectutils@4.1.0...@quenty/inputobjectutils@4.2.0) (2024-03-27)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Update avatar editor stuff ([16d10a8](https://github.com/Quenty/NevermoreEngine/commit/16d10a876c90d3b43d69b5f66e217e4c3749296b))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [4.1.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/inputobjectutils@4.0.0...@quenty/inputobjectutils@4.1.0) (2023-05-26)
|
|
7
18
|
|
|
8
19
|
|
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2014-
|
|
3
|
+
Copyright (c) 2014-2024 James Onnen (Quenty)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/inputobjectutils",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Provides utility functions involving input objects",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -27,5 +27,9 @@
|
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
|
-
"
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@quenty/baseobject": "^10.1.0",
|
|
32
|
+
"@quenty/maid": "^3.1.0"
|
|
33
|
+
},
|
|
34
|
+
"gitHead": "ab3631a54c4e8d448b4229c7e422a9c7f43c0dd7"
|
|
31
35
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|