@quenty/inputkeymaputils 3.4.1-canary.8533eea.0 → 3.5.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 +9 -1
- package/README.md +6 -25
- package/package.json +5 -5
- package/src/Client/InputKeyMapUtils.lua +153 -8
- package/src/Client/ProximityPromptInputUtils.lua +25 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,15 @@
|
|
|
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.
|
|
6
|
+
## [3.5.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/inputkeymaputils@3.5.0...@quenty/inputkeymaputils@3.5.1) (2021-12-30)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @quenty/inputkeymaputils
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [3.5.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/inputkeymaputils@3.4.0...@quenty/inputkeymaputils@3.5.0) (2021-12-18)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @quenty/inputkeymaputils
|
|
9
17
|
|
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
## InputKeyMapUtils
|
|
2
2
|
<div align="center">
|
|
3
|
-
<a href="http://quenty.github.io/
|
|
4
|
-
<img src="https://
|
|
3
|
+
<a href="http://quenty.github.io/NevermoreEngine/">
|
|
4
|
+
<img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/docs.yml/badge.svg" alt="Documentation status" />
|
|
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" />
|
|
@@ -13,28 +13,9 @@
|
|
|
13
13
|
|
|
14
14
|
Utility methods for input map
|
|
15
15
|
|
|
16
|
+
<div align="center"><a href="https://quenty.github.io/NevermoreEngine/api/InputKeyMapUtils">View docs →</a></div>
|
|
17
|
+
|
|
16
18
|
## Installation
|
|
17
19
|
```
|
|
18
20
|
npm install @quenty/inputkeymaputils --save
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Usage
|
|
22
|
-
Usage is designed to be simple.
|
|
23
|
-
|
|
24
|
-
### `InputKeyMapUtils.createKeyMap(inputMode, inputTypes)`
|
|
25
|
-
|
|
26
|
-
### `InputKeyMapUtils.getInputTypesSetForActionBinding(inputKeyMapList)`
|
|
27
|
-
|
|
28
|
-
### `InputKeyMapUtils.getInputTypesForActionBinding(inputKeyMapList)`
|
|
29
|
-
Converts keymap into ContextActionService friendly types
|
|
30
|
-
|
|
31
|
-
### `InputKeyMapUtils.getInputTypeListForMode(inputKeyMapList, inputMode)`
|
|
32
|
-
|
|
33
|
-
### `InputKeyMapUtils.getInputTypeSetForMode(inputKeyMapList, inputMode)`
|
|
34
|
-
|
|
35
|
-
### `InputKeyMapUtils.getInputModes(inputKeyMapList)`
|
|
36
|
-
|
|
37
|
-
### `InputKeyMapUtils.isRobloxTouchButton(inputKeyMapList)`
|
|
38
|
-
|
|
39
|
-
### `InputKeyMapUtils.isTapInWorld(inputKeyMapList)`
|
|
40
|
-
|
|
21
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/inputkeymaputils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.1",
|
|
4
4
|
"description": "Utility methods for input map",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"Quenty"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@quenty/inputmode": "3.
|
|
30
|
-
"@quenty/loader": "3.1.
|
|
31
|
-
"@quenty/table": "2.1.
|
|
29
|
+
"@quenty/inputmode": "^3.5.1",
|
|
30
|
+
"@quenty/loader": "^3.1.2",
|
|
31
|
+
"@quenty/table": "^2.1.1"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "d146c77d0a8e452824de0ab0b4b03ba0370bcc1b"
|
|
37
37
|
}
|
|
@@ -1,6 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
--[=[
|
|
2
|
+
Utility methods for input. Centralizes input. In the future, this will allow
|
|
3
|
+
user configuration.
|
|
4
|
+
|
|
5
|
+
```lua
|
|
6
|
+
local inputMap = {
|
|
7
|
+
JUMP = {
|
|
8
|
+
InputKeyMapUtils.createKeyMap(INPUT_MODES.KeyboardAndMouse, { Enum.KeyCode.Space });
|
|
9
|
+
InputKeyMapUtils.createKeyMap(INPUT_MODES.Gamepads, { Enum.KeyCode.ButtonA });
|
|
10
|
+
InputKeyMapUtils.createKeyMap(INPUT_MODES.Touch, { InputKeyMapUtils.createSlottedTouchButton("primary3") });
|
|
11
|
+
};
|
|
12
|
+
HONK = {
|
|
13
|
+
InputKeyMapUtils.createKeyMap(INPUT_MODES.KeyboardAndMouse, { Enum.KeyCode.H });
|
|
14
|
+
InputKeyMapUtils.createKeyMap(INPUT_MODES.Gamepads, { Enum.KeyCode.DPadUp });
|
|
15
|
+
InputKeyMapUtils.createKeyMap(INPUT_MODES.Touch, { InputKeyMapUtils.createSlottedTouchButton("primary2") });
|
|
16
|
+
};
|
|
17
|
+
BOOST = {
|
|
18
|
+
InputKeyMapUtils.createKeyMap(INPUT_MODES.KeyboardAndMouse, { Enum.KeyCode.LeftControl });
|
|
19
|
+
InputKeyMapUtils.createKeyMap(INPUT_MODES.Gamepads, { Enum.KeyCode.ButtonX });
|
|
20
|
+
InputKeyMapUtils.createKeyMap(INPUT_MODES.Touch, { InputKeyMapUtils.createSlottedTouchButton("primary4") });
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Then, we can use these input maps in a variety of services, including [ScoredActionService] or
|
|
26
|
+
just binding directly to [ContextActionService].
|
|
27
|
+
|
|
28
|
+
```lua
|
|
29
|
+
local inputKeyMapList = inputMap.JUMP
|
|
30
|
+
|
|
31
|
+
ContextActionService:BindActionAtPriority(
|
|
32
|
+
"MyAction",
|
|
33
|
+
function(_actionName, userInputState, inputObject)
|
|
34
|
+
print("Process input", inputObject)
|
|
35
|
+
end,
|
|
36
|
+
InputKeyMapUtils.isRobloxTouchButton(inputKeyMapList),
|
|
37
|
+
Enum.ContextActionPriority.High.Value,
|
|
38
|
+
unpack(InputKeyMapUtils.getInputTypesForActionBinding(inputKeyMapList)))
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
@class InputKeyMapUtils
|
|
42
|
+
]=]
|
|
4
43
|
|
|
5
44
|
local require = require(script.Parent.loader).load(script)
|
|
6
45
|
|
|
@@ -9,7 +48,34 @@ local Table = require("Table")
|
|
|
9
48
|
|
|
10
49
|
local InputKeyMapUtils = {}
|
|
11
50
|
|
|
12
|
-
--
|
|
51
|
+
--[=[
|
|
52
|
+
A valid input type that can be represented here.
|
|
53
|
+
@type InputType KeyCode | UserInputType | SlottedTouchButton | "TouchButton" | "Tap" | any
|
|
54
|
+
@within InputKeyMapUtils
|
|
55
|
+
]=]
|
|
56
|
+
|
|
57
|
+
--[=[
|
|
58
|
+
A grouping of input types for a specific input mode to use.
|
|
59
|
+
|
|
60
|
+
@interface InputKeyMap
|
|
61
|
+
.inputMode InputMode
|
|
62
|
+
.inputTypes { InputType }
|
|
63
|
+
@within InputKeyMapUtils
|
|
64
|
+
]=]
|
|
65
|
+
|
|
66
|
+
--[=[
|
|
67
|
+
A mapping of input keys to maps
|
|
68
|
+
@type InputKeyMapList { InputKeyMap }
|
|
69
|
+
@within InputKeyMapUtils
|
|
70
|
+
]=]
|
|
71
|
+
|
|
72
|
+
--[=[
|
|
73
|
+
Should be called "createInputKeyMap". Creates a new InputKeyMap.
|
|
74
|
+
|
|
75
|
+
@param inputMode InputMode
|
|
76
|
+
@param inputTypes { InputType }
|
|
77
|
+
@return InputKeyMap
|
|
78
|
+
]=]
|
|
13
79
|
function InputKeyMapUtils.createKeyMap(inputMode, inputTypes)
|
|
14
80
|
assert(type(inputMode) == "table", "Bad inputMode")
|
|
15
81
|
assert(type(inputTypes) == "table", "Bad inputTypes")
|
|
@@ -20,11 +86,19 @@ function InputKeyMapUtils.createKeyMap(inputMode, inputTypes)
|
|
|
20
86
|
})
|
|
21
87
|
end
|
|
22
88
|
|
|
89
|
+
--[=[
|
|
90
|
+
@param inputKeyMapList InputKeyMapList
|
|
91
|
+
@return { KeyCode | UserInputType }
|
|
92
|
+
]=]
|
|
23
93
|
function InputKeyMapUtils.getInputTypesSetForActionBinding(inputKeyMapList)
|
|
24
94
|
return Set.fromList(InputKeyMapUtils.getInputTypesForActionBinding(inputKeyMapList))
|
|
25
95
|
end
|
|
26
96
|
|
|
27
|
-
|
|
97
|
+
--[=[
|
|
98
|
+
Converts keymap into ContextActionService friendly types
|
|
99
|
+
@param inputKeyMapList InputKeyMapList
|
|
100
|
+
@return { KeyCode | UserInputType }
|
|
101
|
+
]=]
|
|
28
102
|
function InputKeyMapUtils.getInputTypesForActionBinding(inputKeyMapList)
|
|
29
103
|
assert(type(inputKeyMapList) == "table", "inputKeyMapList must be a table")
|
|
30
104
|
local types = {}
|
|
@@ -43,6 +117,12 @@ function InputKeyMapUtils.getInputTypesForActionBinding(inputKeyMapList)
|
|
|
43
117
|
return types
|
|
44
118
|
end
|
|
45
119
|
|
|
120
|
+
--[=[
|
|
121
|
+
Given an inputMode, gets the relevant lists available
|
|
122
|
+
@param inputKeyMapList InputKeyMapList
|
|
123
|
+
@param inputMode InputMode
|
|
124
|
+
@return { InputKeyMap }
|
|
125
|
+
]=]
|
|
46
126
|
function InputKeyMapUtils.getInputTypeListForMode(inputKeyMapList, inputMode)
|
|
47
127
|
assert(type(inputKeyMapList) == "table", "inputKeyMapList must be a table")
|
|
48
128
|
|
|
@@ -63,6 +143,13 @@ function InputKeyMapUtils.getInputTypeListForMode(inputKeyMapList, inputMode)
|
|
|
63
143
|
return results
|
|
64
144
|
end
|
|
65
145
|
|
|
146
|
+
--[=[
|
|
147
|
+
Gets a set of input types for a given mode from the list.
|
|
148
|
+
|
|
149
|
+
@param inputKeyMapList InputKeyMapList
|
|
150
|
+
@param inputMode InputMode
|
|
151
|
+
@return { [InputType] = true }
|
|
152
|
+
]=]
|
|
66
153
|
function InputKeyMapUtils.getInputTypeSetForMode(inputKeyMapList, inputMode)
|
|
67
154
|
assert(type(inputKeyMapList) == "table", "inputKeyMapList must be a table")
|
|
68
155
|
|
|
@@ -79,7 +166,12 @@ function InputKeyMapUtils.getInputTypeSetForMode(inputKeyMapList, inputMode)
|
|
|
79
166
|
return results
|
|
80
167
|
end
|
|
81
168
|
|
|
169
|
+
--[=[
|
|
170
|
+
Retrieves the set of input modes for a given list.
|
|
82
171
|
|
|
172
|
+
@param inputKeyMapList InputKeyMapList
|
|
173
|
+
@return { InputMode }
|
|
174
|
+
]=]
|
|
83
175
|
function InputKeyMapUtils.getInputModes(inputKeyMapList)
|
|
84
176
|
assert(type(inputKeyMapList) == "table", "inputKeyMapList must be a table")
|
|
85
177
|
|
|
@@ -92,6 +184,20 @@ function InputKeyMapUtils.getInputModes(inputKeyMapList)
|
|
|
92
184
|
return modes
|
|
93
185
|
end
|
|
94
186
|
|
|
187
|
+
--[=[
|
|
188
|
+
Internal data representing a slotted touch button
|
|
189
|
+
@interface SlottedTouchButtonData
|
|
190
|
+
.slotId string
|
|
191
|
+
.inputMode InputMode
|
|
192
|
+
@within InputKeyMapUtils
|
|
193
|
+
]=]
|
|
194
|
+
|
|
195
|
+
--[=[
|
|
196
|
+
Gets slotted touch button data for an inputKeyMapList
|
|
197
|
+
|
|
198
|
+
@param inputKeyMapList InputKeyMapList
|
|
199
|
+
@return { SlottedTouchButtonData }
|
|
200
|
+
]=]
|
|
95
201
|
function InputKeyMapUtils.getSlottedTouchButtonData(inputKeyMapList)
|
|
96
202
|
local slottedTouchButtons = {}
|
|
97
203
|
|
|
@@ -112,12 +218,34 @@ function InputKeyMapUtils.getSlottedTouchButtonData(inputKeyMapList)
|
|
|
112
218
|
return slottedTouchButtons
|
|
113
219
|
end
|
|
114
220
|
|
|
221
|
+
--[=[
|
|
222
|
+
Returns whether an inputType is a SlottedTouchButton type
|
|
223
|
+
|
|
224
|
+
@param inputType any
|
|
225
|
+
@return boolean
|
|
226
|
+
]=]
|
|
115
227
|
function InputKeyMapUtils.isSlottedTouchButton(inputType)
|
|
116
228
|
return type(inputType) == "table" and inputType.type == "SlottedTouchButton"
|
|
117
229
|
end
|
|
118
230
|
|
|
119
|
-
--
|
|
120
|
-
|
|
231
|
+
--[=[
|
|
232
|
+
A touch button that goes into a specific slot. This ensures
|
|
233
|
+
consistent slot positions.
|
|
234
|
+
|
|
235
|
+
@interface SlottedTouchButton
|
|
236
|
+
.type "SlottedTouchButton"
|
|
237
|
+
.slotId string
|
|
238
|
+
@within InputKeyMapUtils
|
|
239
|
+
]=]
|
|
240
|
+
|
|
241
|
+
--[=[
|
|
242
|
+
Touch buttons should always show up in the same position
|
|
243
|
+
We use the SlotId to determine which slot we should put
|
|
244
|
+
these buttons in.
|
|
245
|
+
|
|
246
|
+
@param slotId string
|
|
247
|
+
@return SlottedTouchButton
|
|
248
|
+
]=]
|
|
121
249
|
function InputKeyMapUtils.createSlottedTouchButton(slotId)
|
|
122
250
|
assert(slotId == "primary1" or slotId == "primary2" or slotId == "primary3" or slotId == "primary4", "Bad slotId")
|
|
123
251
|
|
|
@@ -127,6 +255,14 @@ function InputKeyMapUtils.createSlottedTouchButton(slotId)
|
|
|
127
255
|
}
|
|
128
256
|
end
|
|
129
257
|
|
|
258
|
+
--[=[
|
|
259
|
+
Computes a unique id for an inputType which can be used
|
|
260
|
+
in a set to deduplicate/compare the objects. Used to know
|
|
261
|
+
when to exclude different types from each other.
|
|
262
|
+
|
|
263
|
+
@param inputType InputType
|
|
264
|
+
@return any
|
|
265
|
+
]=]
|
|
130
266
|
function InputKeyMapUtils.getUniqueKeyForInputType(inputType)
|
|
131
267
|
if InputKeyMapUtils.isSlottedTouchButton(inputType) then
|
|
132
268
|
return inputType.slotId
|
|
@@ -135,7 +271,11 @@ function InputKeyMapUtils.getUniqueKeyForInputType(inputType)
|
|
|
135
271
|
end
|
|
136
272
|
end
|
|
137
273
|
|
|
138
|
-
--
|
|
274
|
+
--[=[
|
|
275
|
+
Only returns true if we're a Roblox touch button
|
|
276
|
+
@param inputKeyMapList InputKeyMapList
|
|
277
|
+
@return boolean
|
|
278
|
+
]=]
|
|
139
279
|
function InputKeyMapUtils.isRobloxTouchButton(inputKeyMapList)
|
|
140
280
|
for _, inputKeyMap in pairs(inputKeyMapList) do
|
|
141
281
|
assert(inputKeyMap.inputMode, "Bad inputKeyMap.inputMode")
|
|
@@ -151,6 +291,11 @@ function InputKeyMapUtils.isRobloxTouchButton(inputKeyMapList)
|
|
|
151
291
|
return false
|
|
152
292
|
end
|
|
153
293
|
|
|
294
|
+
--[=[
|
|
295
|
+
Whether this input type is a tap in the world input (for touched events)
|
|
296
|
+
@param inputKeyMapList InputKeyMapList
|
|
297
|
+
@return boolean
|
|
298
|
+
]=]
|
|
154
299
|
function InputKeyMapUtils.isTapInWorld(inputKeyMapList)
|
|
155
300
|
assert(type(inputKeyMapList) == "table", "inputKeyMap must be a table")
|
|
156
301
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
--[=[
|
|
2
|
+
Utility functions to configure a proximity prompt based upon the
|
|
3
|
+
input key map given.
|
|
4
|
+
@class ProximityPromptInputUtils
|
|
5
|
+
]=]
|
|
4
6
|
|
|
5
7
|
local require = require(script.Parent.loader).load(script)
|
|
6
8
|
|
|
@@ -9,6 +11,12 @@ local INPUT_MODES = require("INPUT_MODES")
|
|
|
9
11
|
|
|
10
12
|
local ProximityPromptInputUtils = {}
|
|
11
13
|
|
|
14
|
+
--[=[
|
|
15
|
+
Creates an InputKeyMapList from a proximity prompt.
|
|
16
|
+
|
|
17
|
+
@param prompt ProximityPrompt
|
|
18
|
+
@return InputKeyMapList
|
|
19
|
+
]=]
|
|
12
20
|
function ProximityPromptInputUtils.inputKeyMapFromPrompt(prompt)
|
|
13
21
|
assert(typeof(prompt) == "Instance", "Bad prompt")
|
|
14
22
|
|
|
@@ -18,6 +26,13 @@ function ProximityPromptInputUtils.inputKeyMapFromPrompt(prompt)
|
|
|
18
26
|
}
|
|
19
27
|
end
|
|
20
28
|
|
|
29
|
+
|
|
30
|
+
--[=[
|
|
31
|
+
Sets the key codes for a proximity prompt to match an inputKeyMapList
|
|
32
|
+
|
|
33
|
+
@param prompt ProximityPrompt
|
|
34
|
+
@param inputKeyMapList InputKeyMapList
|
|
35
|
+
]=]
|
|
21
36
|
function ProximityPromptInputUtils.configurePromptFromInputKeyMap(prompt, inputKeyMapList)
|
|
22
37
|
assert(typeof(prompt) == "Instance", "Bad prompt")
|
|
23
38
|
assert(type(inputKeyMapList) == "table", "Bad inputKeyMapList")
|
|
@@ -34,6 +49,13 @@ function ProximityPromptInputUtils.configurePromptFromInputKeyMap(prompt, inputK
|
|
|
34
49
|
end
|
|
35
50
|
end
|
|
36
51
|
|
|
52
|
+
--[=[
|
|
53
|
+
Picks the first keyCode that matches the inputMode.
|
|
54
|
+
|
|
55
|
+
@param inputKeyMapList InputKeyMapList
|
|
56
|
+
@param inputMode InputMode
|
|
57
|
+
@return KeyCode?
|
|
58
|
+
]=]
|
|
37
59
|
function ProximityPromptInputUtils.getFirstInputKeyCode(inputKeyMapList, inputMode)
|
|
38
60
|
assert(type(inputKeyMapList) == "table", "Bad inputKeyMapList")
|
|
39
61
|
assert(inputMode, "Bad inputMode")
|