@quenty/inputmode 3.5.0 → 3.5.1-canary.238.2c4d310.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 +8 -0
- package/README.md +2 -2
- package/package.json +7 -7
- package/src/Client/INPUT_MODES.lua +65 -4
- package/src/Client/InputMode.lua +43 -9
- package/src/Client/InputModeProcessor.lua +21 -4
- package/src/Client/InputModeSelector.lua +37 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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
|
+
## [3.5.1-canary.238.2c4d310.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/inputmode@3.5.0...@quenty/inputmode@3.5.1-canary.238.2c4d310.0) (2021-12-29)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @quenty/inputmode
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [3.5.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/inputmode@3.4.0...@quenty/inputmode@3.5.0) (2021-12-18)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @quenty/inputmode
|
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
## InputMode
|
|
2
2
|
<div align="center">
|
|
3
|
-
<a href="http://quenty.github.io/
|
|
3
|
+
<a href="http://quenty.github.io/NevermoreEngine/">
|
|
4
4
|
<img src="https://img.shields.io/badge/docs-website-green.svg" alt="Documentation" />
|
|
5
5
|
</a>
|
|
6
6
|
<a href="https://discord.gg/mhtGUS8">
|
|
7
|
-
<img src="https://img.shields.io/
|
|
7
|
+
<img src="https://img.shields.io/discord/385151591524597761?color=5865F2&label=discord&logo=discord&logoColor=white" alt="Discord" />
|
|
8
8
|
</a>
|
|
9
9
|
<a href="https://github.com/Quenty/NevermoreEngine/actions">
|
|
10
10
|
<img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/build.yml/badge.svg" alt="Build and release status" />
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/inputmode",
|
|
3
|
-
"version": "3.5.0",
|
|
3
|
+
"version": "3.5.1-canary.238.2c4d310.0",
|
|
4
4
|
"description": "Trace input mode state and trigger changes correctly",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"Quenty"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@quenty/loader": "
|
|
29
|
-
"@quenty/maid": "
|
|
30
|
-
"@quenty/signal": "
|
|
31
|
-
"@quenty/table": "
|
|
32
|
-
"@quenty/valueobject": "
|
|
28
|
+
"@quenty/loader": "3.1.2-canary.238.2c4d310.0",
|
|
29
|
+
"@quenty/maid": "2.0.2-canary.238.2c4d310.0",
|
|
30
|
+
"@quenty/signal": "2.0.1-canary.238.2c4d310.0",
|
|
31
|
+
"@quenty/table": "2.1.1-canary.238.2c4d310.0",
|
|
32
|
+
"@quenty/valueobject": "3.5.1-canary.238.2c4d310.0"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "2c4d310b84afd0570d89667dc5d4aa69a0ef304a"
|
|
38
38
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
--[=[
|
|
2
|
+
Holds input states for Keyboard, Mouse, et cetera. Mostly useful for providing UI input hints to the user by
|
|
3
|
+
identifying the most recent input state provided.
|
|
4
|
+
|
|
5
|
+
@class INPUT_MODES
|
|
6
|
+
]=]
|
|
4
7
|
|
|
5
8
|
local UserInputService = game:GetService("UserInputService")
|
|
6
9
|
local GuiService = game:GetService("GuiService")
|
|
@@ -15,6 +18,12 @@ local INPUT_MODES = {
|
|
|
15
18
|
THUMBSTICK_DEADZONE = 0.14
|
|
16
19
|
}
|
|
17
20
|
|
|
21
|
+
--[=[
|
|
22
|
+
Input from a keypad
|
|
23
|
+
@prop Keypad InputMode
|
|
24
|
+
@readonly
|
|
25
|
+
@within INPUT_MODES
|
|
26
|
+
]=]
|
|
18
27
|
INPUT_MODES.Keypad = InputMode.new("Keypad", {
|
|
19
28
|
Enum.KeyCode.KeypadZero;
|
|
20
29
|
Enum.KeyCode.KeypadOne;
|
|
@@ -35,6 +44,12 @@ INPUT_MODES.Keypad = InputMode.new("Keypad", {
|
|
|
35
44
|
Enum.KeyCode.KeypadEquals;
|
|
36
45
|
})
|
|
37
46
|
|
|
47
|
+
--[=[
|
|
48
|
+
Input from a keyboard
|
|
49
|
+
@prop Keyboard InputMode
|
|
50
|
+
@readonly
|
|
51
|
+
@within INPUT_MODES
|
|
52
|
+
]=]
|
|
38
53
|
INPUT_MODES.Keyboard = InputMode.new("Keyboard", {
|
|
39
54
|
Enum.UserInputType.Keyboard;
|
|
40
55
|
|
|
@@ -166,6 +181,12 @@ INPUT_MODES.Keyboard = InputMode.new("Keyboard", {
|
|
|
166
181
|
Enum.KeyCode.Undo;
|
|
167
182
|
})
|
|
168
183
|
|
|
184
|
+
--[=[
|
|
185
|
+
Input involving arrow keys!
|
|
186
|
+
@prop ArrowKeys InputMode
|
|
187
|
+
@readonly
|
|
188
|
+
@within INPUT_MODES
|
|
189
|
+
]=]
|
|
169
190
|
INPUT_MODES.ArrowKeys = InputMode.new("ArrowKeys", {
|
|
170
191
|
Enum.KeyCode.Left;
|
|
171
192
|
Enum.KeyCode.Right;
|
|
@@ -173,6 +194,12 @@ INPUT_MODES.ArrowKeys = InputMode.new("ArrowKeys", {
|
|
|
173
194
|
Enum.KeyCode.Down;
|
|
174
195
|
})
|
|
175
196
|
|
|
197
|
+
--[=[
|
|
198
|
+
Input involving WASD
|
|
199
|
+
@prop WASD InputMode
|
|
200
|
+
@readonly
|
|
201
|
+
@within INPUT_MODES
|
|
202
|
+
]=]
|
|
176
203
|
INPUT_MODES.WASD = InputMode.new("WASD", {
|
|
177
204
|
Enum.KeyCode.W;
|
|
178
205
|
Enum.KeyCode.A;
|
|
@@ -180,6 +207,12 @@ INPUT_MODES.WASD = InputMode.new("WASD", {
|
|
|
180
207
|
Enum.KeyCode.D;
|
|
181
208
|
})
|
|
182
209
|
|
|
210
|
+
--[=[
|
|
211
|
+
Input involving the mouse
|
|
212
|
+
@prop Mouse InputMode
|
|
213
|
+
@readonly
|
|
214
|
+
@within INPUT_MODES
|
|
215
|
+
]=]
|
|
183
216
|
INPUT_MODES.Mouse = InputMode.new("Mouse", {
|
|
184
217
|
Enum.UserInputType.MouseButton1;
|
|
185
218
|
Enum.UserInputType.MouseButton2;
|
|
@@ -188,15 +221,32 @@ INPUT_MODES.Mouse = InputMode.new("Mouse", {
|
|
|
188
221
|
Enum.UserInputType.MouseMovement;
|
|
189
222
|
})
|
|
190
223
|
|
|
224
|
+
--[=[
|
|
225
|
+
Input involving the keyboard OR mouse.
|
|
226
|
+
@prop KeyboardAndMoues InputMode
|
|
227
|
+
@readonly
|
|
228
|
+
@within INPUT_MODES
|
|
229
|
+
]=]
|
|
191
230
|
INPUT_MODES.KeyboardAndMouse = InputMode.new("KeyboardAndMouse", {
|
|
192
231
|
INPUT_MODES.Mouse;
|
|
193
232
|
INPUT_MODES.Keyboard;
|
|
194
233
|
})
|
|
195
234
|
|
|
235
|
+
--[=[
|
|
236
|
+
Input involving touch input.
|
|
237
|
+
@prop Touch InputMode
|
|
238
|
+
@readonly
|
|
239
|
+
@within INPUT_MODES
|
|
240
|
+
]=]
|
|
196
241
|
INPUT_MODES.Touch = InputMode.new("Touch", {
|
|
197
242
|
Enum.UserInputType.Touch;
|
|
198
243
|
})
|
|
199
244
|
|
|
245
|
+
--[=[
|
|
246
|
+
@prop DPad InputMode
|
|
247
|
+
@readonly
|
|
248
|
+
@within INPUT_MODES
|
|
249
|
+
]=]
|
|
200
250
|
INPUT_MODES.DPad = InputMode.new("DPad", {
|
|
201
251
|
Enum.KeyCode.DPadLeft;
|
|
202
252
|
Enum.KeyCode.DPadRight;
|
|
@@ -204,11 +254,23 @@ INPUT_MODES.DPad = InputMode.new("DPad", {
|
|
|
204
254
|
Enum.KeyCode.DPadDown;
|
|
205
255
|
})
|
|
206
256
|
|
|
257
|
+
--[=[
|
|
258
|
+
Input involved thumbsticks.
|
|
259
|
+
@prop Thumbsticks InputMode
|
|
260
|
+
@readonly
|
|
261
|
+
@within INPUT_MODES
|
|
262
|
+
]=]
|
|
207
263
|
INPUT_MODES.Thumbsticks = InputMode.new("Thumbsticks", {
|
|
208
264
|
Enum.KeyCode.Thumbstick1;
|
|
209
265
|
Enum.KeyCode.Thumbstick2;
|
|
210
266
|
})
|
|
211
267
|
|
|
268
|
+
--[=[
|
|
269
|
+
Input involving gamepads
|
|
270
|
+
@prop Gamepads InputMode
|
|
271
|
+
@readonly
|
|
272
|
+
@within INPUT_MODES
|
|
273
|
+
]=]
|
|
212
274
|
INPUT_MODES.Gamepads = InputMode.new("Gamepads", {
|
|
213
275
|
Enum.UserInputType.Gamepad1;
|
|
214
276
|
Enum.UserInputType.Gamepad2;
|
|
@@ -238,7 +300,6 @@ INPUT_MODES.Gamepads = InputMode.new("Gamepads", {
|
|
|
238
300
|
Enum.KeyCode.DPadDown;
|
|
239
301
|
})
|
|
240
302
|
|
|
241
|
-
|
|
242
303
|
local function triggerEnabled()
|
|
243
304
|
if UserInputService.MouseEnabled then
|
|
244
305
|
INPUT_MODES.Mouse:Enable()
|
package/src/Client/InputMode.lua
CHANGED
|
@@ -1,14 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
--[=[
|
|
2
|
+
Trace input mode state and trigger changes correctly
|
|
3
|
+
@class InputMode
|
|
4
|
+
]=]
|
|
3
5
|
|
|
4
6
|
local require = require(script.Parent.loader).load(script)
|
|
5
7
|
|
|
6
8
|
local Signal = require("Signal")
|
|
7
9
|
|
|
10
|
+
--[=[
|
|
11
|
+
Fires off when the mode is enabled
|
|
12
|
+
@prop Enabled Signal<()>
|
|
13
|
+
@within InputMode
|
|
14
|
+
]=]
|
|
15
|
+
|
|
16
|
+
--[=[
|
|
17
|
+
Name of the InputMode
|
|
18
|
+
@prop Name Signal<()>
|
|
19
|
+
@within InputMode
|
|
20
|
+
]=]
|
|
21
|
+
|
|
8
22
|
local InputMode = {}
|
|
9
23
|
InputMode.__index = InputMode
|
|
10
24
|
InputMode.ClassName = "InputMode"
|
|
11
25
|
|
|
26
|
+
--[=[
|
|
27
|
+
Constructs a new InputMode
|
|
28
|
+
|
|
29
|
+
@param name string
|
|
30
|
+
@param typesAndInputModes { { UserInputType | KeyCode | string | InputMode } }
|
|
31
|
+
@return InputMode
|
|
32
|
+
]=]
|
|
12
33
|
function InputMode.new(name, typesAndInputModes)
|
|
13
34
|
local self = setmetatable({}, InputMode)
|
|
14
35
|
|
|
@@ -16,9 +37,6 @@ function InputMode.new(name, typesAndInputModes)
|
|
|
16
37
|
self._valid = {}
|
|
17
38
|
|
|
18
39
|
self.Name = name or "Unnamed"
|
|
19
|
-
|
|
20
|
-
--- Fires off when the mode is enabled
|
|
21
|
-
-- @signal Enabled
|
|
22
40
|
self.Enabled = Signal.new()
|
|
23
41
|
|
|
24
42
|
self:_addValidTypesFromTable(typesAndInputModes)
|
|
@@ -26,6 +44,10 @@ function InputMode.new(name, typesAndInputModes)
|
|
|
26
44
|
return self
|
|
27
45
|
end
|
|
28
46
|
|
|
47
|
+
--[=[
|
|
48
|
+
Checks the last point this input mode was used.
|
|
49
|
+
@return number
|
|
50
|
+
]=]
|
|
29
51
|
function InputMode:GetLastEnabledTime()
|
|
30
52
|
return self._lastEnabled
|
|
31
53
|
end
|
|
@@ -48,6 +70,10 @@ function InputMode:_addInputMode(inputMode)
|
|
|
48
70
|
end
|
|
49
71
|
end
|
|
50
72
|
|
|
73
|
+
--[=[
|
|
74
|
+
Returns all keys defining the input mode.
|
|
75
|
+
@return { UserInputType | KeyCode | string }
|
|
76
|
+
]=]
|
|
51
77
|
function InputMode:GetKeys()
|
|
52
78
|
local keys = {}
|
|
53
79
|
for key, _ in pairs(self._valid) do
|
|
@@ -56,21 +82,29 @@ function InputMode:GetKeys()
|
|
|
56
82
|
return keys
|
|
57
83
|
end
|
|
58
84
|
|
|
59
|
-
|
|
60
|
-
|
|
85
|
+
--[=[
|
|
86
|
+
Checks the validity of the inputType
|
|
87
|
+
@param inputType { UserInputType | KeyCode | string }
|
|
88
|
+
@return boolean
|
|
89
|
+
]=]
|
|
61
90
|
function InputMode:IsValid(inputType)
|
|
62
91
|
assert(inputType, "Must send in inputType")
|
|
63
92
|
|
|
64
93
|
return self._valid[inputType]
|
|
65
94
|
end
|
|
66
95
|
|
|
67
|
-
|
|
96
|
+
--[=[
|
|
97
|
+
Enables the mode
|
|
98
|
+
]=]
|
|
68
99
|
function InputMode:Enable()
|
|
69
100
|
self._lastEnabled = tick()
|
|
70
101
|
self.Enabled:Fire()
|
|
71
102
|
end
|
|
72
103
|
|
|
73
|
-
|
|
104
|
+
--[=[
|
|
105
|
+
Evaluates the input object, and if it's valid, enables the mode
|
|
106
|
+
@param inputObject InputObject
|
|
107
|
+
]=]
|
|
74
108
|
function InputMode:Evaluate(inputObject)
|
|
75
109
|
if self._valid[inputObject.UserInputType]
|
|
76
110
|
or self._valid[inputObject.KeyCode] then
|
|
@@ -1,26 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
--[=[
|
|
2
|
+
Process inputs by evaluating inputModes. Typically not used directly, but rather, just
|
|
3
|
+
use modes from INPUT_MODES.
|
|
4
|
+
|
|
5
|
+
@class InputModeProcessor
|
|
6
|
+
]=]
|
|
3
7
|
|
|
4
8
|
local InputModeProcessor = {}
|
|
5
9
|
InputModeProcessor.__index = InputModeProcessor
|
|
6
10
|
InputModeProcessor.ClassName = InputModeProcessor
|
|
7
11
|
|
|
8
|
-
|
|
12
|
+
--[=[
|
|
13
|
+
Construtcs a new inputModeProcessor
|
|
14
|
+
@param inputModes { InputMode }
|
|
15
|
+
@return InputModeProcessor
|
|
16
|
+
]=]
|
|
17
|
+
function InputModeProcessor.new(inputModes)
|
|
9
18
|
local self = setmetatable({}, InputModeProcessor)
|
|
10
19
|
|
|
11
20
|
self._inputModes = {}
|
|
12
21
|
|
|
13
|
-
for _, state in pairs(
|
|
22
|
+
for _, state in pairs(inputModes) do
|
|
14
23
|
self._inputModes[#self._inputModes+1] = state
|
|
15
24
|
end
|
|
16
25
|
|
|
17
26
|
return self
|
|
18
27
|
end
|
|
19
28
|
|
|
29
|
+
--[=[
|
|
30
|
+
Gets all input mode inputModes being used
|
|
31
|
+
@return { InputMode }
|
|
32
|
+
]=]
|
|
20
33
|
function InputModeProcessor:GetStates()
|
|
21
34
|
return self._inputModes
|
|
22
35
|
end
|
|
23
36
|
|
|
37
|
+
--[=[
|
|
38
|
+
Applies the inputObject as an evaluation for the inputm odes
|
|
39
|
+
@param inputObject InputObject
|
|
40
|
+
]=]
|
|
24
41
|
function InputModeProcessor:Evaluate(inputObject)
|
|
25
42
|
for _, inputMode in pairs(self._inputModes) do
|
|
26
43
|
inputMode:Evaluate(inputObject)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
--
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
--[=[
|
|
2
|
+
Selects the most recent input mode and attempts to identify the best state from it.
|
|
3
|
+
@class InputModeSelector
|
|
4
|
+
]=]
|
|
4
5
|
|
|
5
6
|
local require = require(script.Parent.loader).load(script)
|
|
6
7
|
|
|
@@ -16,6 +17,11 @@ InputModeSelector.DEFAULT_MODES = {
|
|
|
16
17
|
INPUT_MODES.Touch
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
--[=[
|
|
21
|
+
Constructs a new InputModeSelector
|
|
22
|
+
@param inputModes { InputMode }
|
|
23
|
+
@return InputModeSelector
|
|
24
|
+
]=]
|
|
19
25
|
function InputModeSelector.new(inputModes)
|
|
20
26
|
local self = setmetatable({}, InputModeSelector)
|
|
21
27
|
|
|
@@ -24,6 +30,11 @@ function InputModeSelector.new(inputModes)
|
|
|
24
30
|
self._activeMode = ValueObject.new()
|
|
25
31
|
self._maid:GiveTask(self._activeMode)
|
|
26
32
|
|
|
33
|
+
--[=[
|
|
34
|
+
Event that fires whenever the active mode changes.
|
|
35
|
+
@prop Changed Signal<InputMode, InputMode> -- newMode, oldMode
|
|
36
|
+
@within InputModeSelector
|
|
37
|
+
]=]
|
|
27
38
|
self.Changed = self._activeMode.Changed
|
|
28
39
|
|
|
29
40
|
for _, inputMode in pairs(inputModes or InputModeSelector.DEFAULT_MODES) do
|
|
@@ -33,10 +44,19 @@ function InputModeSelector.new(inputModes)
|
|
|
33
44
|
return self
|
|
34
45
|
end
|
|
35
46
|
|
|
47
|
+
--[=[
|
|
48
|
+
Returns the current active mode
|
|
49
|
+
@return InputMode
|
|
50
|
+
]=]
|
|
36
51
|
function InputModeSelector:GetActiveMode()
|
|
37
52
|
return rawget(self, "_activeMode").Value
|
|
38
53
|
end
|
|
39
54
|
|
|
55
|
+
--[=[
|
|
56
|
+
The current active input mode
|
|
57
|
+
@prop Value InputMode?
|
|
58
|
+
@within InputModeSelector
|
|
59
|
+
]=]
|
|
40
60
|
function InputModeSelector:__index(index)
|
|
41
61
|
if index == "Value" then
|
|
42
62
|
return rawget(self, "_activeMode").Value
|
|
@@ -52,6 +72,12 @@ function InputModeSelector:__index(index)
|
|
|
52
72
|
end
|
|
53
73
|
end
|
|
54
74
|
|
|
75
|
+
--[=[
|
|
76
|
+
Binds the updateBindFunction to the mode selector
|
|
77
|
+
|
|
78
|
+
@param updateBindFunction (newMode: InputMode, modeMaid: Maid) -> ()
|
|
79
|
+
@return InputModeSelector
|
|
80
|
+
]=]
|
|
55
81
|
function InputModeSelector:Bind(updateBindFunction)
|
|
56
82
|
local maid = Maid.new()
|
|
57
83
|
self._maid[updateBindFunction] = maid
|
|
@@ -85,8 +111,16 @@ function InputModeSelector:_addInputMode(inputMode)
|
|
|
85
111
|
end
|
|
86
112
|
end
|
|
87
113
|
|
|
114
|
+
--[=[
|
|
115
|
+
Cleans up the input mode selector.
|
|
116
|
+
|
|
117
|
+
:::info
|
|
118
|
+
This should be called whenever the mode selector is done being used.
|
|
119
|
+
:::
|
|
120
|
+
]=]
|
|
88
121
|
function InputModeSelector:Destroy()
|
|
89
122
|
self._maid:DoCleaning()
|
|
123
|
+
setmetatable(self, nil)
|
|
90
124
|
end
|
|
91
125
|
|
|
92
126
|
return InputModeSelector
|