@quenty/inputkeymaputils 7.4.1 → 7.5.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,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
+ # [7.5.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/inputkeymaputils@7.4.1...@quenty/inputkeymaputils@7.5.0) (2022-11-08)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add InputChordUtils ([4418e7b](https://github.com/Quenty/NevermoreEngine/commit/4418e7b5542429708ed4559d3b5e0f83dc4a5c5a))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [7.4.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/inputkeymaputils@7.4.0...@quenty/inputkeymaputils@7.4.1) (2022-11-04)
7
18
 
8
19
  **Note:** Version bump only for package @quenty/inputkeymaputils
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/inputkeymaputils",
3
- "version": "7.4.1",
3
+ "version": "7.5.0",
4
4
  "description": "System to define rebindable key bindings and inputs for Roblox.",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -29,6 +29,7 @@
29
29
  "@quenty/baseobject": "^6.0.1",
30
30
  "@quenty/brio": "^8.1.1",
31
31
  "@quenty/clienttranslator": "^8.3.1",
32
+ "@quenty/enumutils": "^3.0.0",
32
33
  "@quenty/inputmode": "^7.2.1",
33
34
  "@quenty/loader": "^6.0.1",
34
35
  "@quenty/maid": "^2.4.0",
@@ -45,5 +46,5 @@
45
46
  "publishConfig": {
46
47
  "access": "public"
47
48
  },
48
- "gitHead": "8b9877c26a3fc753409a5114e56717837291279d"
49
+ "gitHead": "3432599d8ed7bf7f0436d7cd5495925543450117"
49
50
  }
@@ -9,39 +9,23 @@
9
9
 
10
10
  local require = require(script.Parent.loader).load(script)
11
11
 
12
- local HttpService = game:GetService("HttpService")
13
-
14
12
  local BaseObject = require("BaseObject")
15
13
  local ValueObject = require("ValueObject")
16
14
  local InputModeType = require("InputModeType")
17
- local Set = require("Set")
18
-
19
- local function convertValuesToJSONIfNeeded(list)
20
- local result = {}
21
- for key, value in pairs(list) do
22
- if type(value) == "table" then
23
- result[key] = HttpService:JSONEncode(value)
24
- else
25
- result[key] = value
26
- end
27
- end
28
- return result
29
- end
30
-
31
- local function areInputTypesListsEquivalent(a, b)
32
- -- allocate, hehe
33
- local setA = Set.fromTableValue(convertValuesToJSONIfNeeded(a))
34
- local setB = Set.fromTableValue(convertValuesToJSONIfNeeded(b))
35
-
36
- local remaining = Set.difference(setA, setB)
37
- local left = Set.toList(remaining)
38
- return #left == 0
39
- end
15
+ local InputTypeUtils = require("InputTypeUtils")
40
16
 
41
17
  local InputKeyMap = setmetatable({}, BaseObject)
42
18
  InputKeyMap.ClassName = "InputKeyMap"
43
19
  InputKeyMap.__index = InputKeyMap
44
20
 
21
+ --[=[
22
+ Constructs a new InputKeyMap. Generally this would be sent immediately to an
23
+ [InputKeyMapList]. This holds a list of key bindings for a specific type.
24
+
25
+ @param inputModeType InputModeType
26
+ @param inputTypes { InputType }
27
+ @return InputKeyMap
28
+ ]=]
45
29
  function InputKeyMap.new(inputModeType, inputTypes)
46
30
  assert(InputModeType.isInputModeType(inputModeType), "Bad inputModeType")
47
31
  assert(type(inputTypes) == "table" or inputTypes == nil, "Bad inputTypes")
@@ -65,35 +49,67 @@ function InputKeyMap:GetInputModeType()
65
49
  return self._inputModeType
66
50
  end
67
51
 
52
+ --[=[
53
+ Sets the input types list for this input key map.
54
+
55
+ @param inputTypes { InputType }
56
+ ]=]
68
57
  function InputKeyMap:SetInputTypesList(inputTypes)
69
58
  assert(type(inputTypes) == "table", "Bad inputTypes")
70
59
 
71
60
  self._inputType.Value = inputTypes
72
61
  end
73
62
 
63
+ --[=[
64
+ Sets the default input types list. This is whatever the game has, which is
65
+ different than whatever the user has set.
66
+
67
+ This will also set the current input type to be the same as the default if they
68
+ are equivalent.
69
+
70
+ @param inputTypes { InputType }
71
+ ]=]
74
72
  function InputKeyMap:SetDefaultInputTypesList(inputTypes)
75
73
  assert(type(inputTypes) == "table", "Bad inputTypes")
76
74
  assert(type(self._defaultInputTypes) == "table", "bad self._defaultInputTypes")
77
75
 
78
- if areInputTypesListsEquivalent(self._inputType.Value, self._defaultInputTypes) then
76
+ if InputTypeUtils.areInputTypesListsEquivalent(self._inputType.Value, self._defaultInputTypes) then
79
77
  self._inputType.Value = inputTypes
80
78
  end
81
79
 
82
80
  self._defaultInputTypes = inputTypes
83
81
  end
84
82
 
83
+ --[=[
84
+ Gets the default input types list
85
+
86
+ @return { InputType }
87
+ ]=]
85
88
  function InputKeyMap:GetDefaultInputTypesList()
86
89
  return self._defaultInputTypes
87
90
  end
88
91
 
92
+ --[=[
93
+ Resets the input type to the default input types.
94
+ ]=]
89
95
  function InputKeyMap:RestoreDefault()
90
96
  self._inputType.Value = self._defaultInputTypes
91
97
  end
92
98
 
99
+ --[=[
100
+ Observes the current list for the input key map list.
101
+
102
+ @return Observable<{ InputType }>
103
+ ]=]
93
104
  function InputKeyMap:ObserveInputTypesList()
94
105
  return self._inputType:Observe()
95
106
  end
96
107
 
108
+ --[=[
109
+ Gets the input types list
110
+
111
+ @return { InputType }
112
+ ]=]
97
113
  function InputKeyMap:GetInputTypesList()
98
114
  return self._inputType.Value
99
115
  end
@@ -0,0 +1,47 @@
1
+ --[=[
2
+ Standardized data type to define an input chord, such as Ctrl+Z.
3
+
4
+ @class InputChordUtils
5
+ ]=]
6
+
7
+ local require = require(script.Parent.loader).load(script)
8
+
9
+ local EnumUtils = require("EnumUtils")
10
+
11
+ local InputChordUtils = {}
12
+
13
+ --[=[
14
+ Checks
15
+ @param data any
16
+ @return boolean
17
+ ]=]
18
+ function InputChordUtils.isModifierInputChord(data)
19
+ return type(data) == "table"
20
+ and data.type == "ModifierInputChord"
21
+ and type(data.modifiers) == "table"
22
+ and EnumUtils.isOfType(Enum.KeyCode, data.keyCode)
23
+ end
24
+
25
+ --[=[
26
+ Creates a modifier input chord. This chord specifically separates the
27
+ order such that the event only triggers when the keyCode is pressed, but
28
+ also requires the modifier key to be down at the trigger point.
29
+
30
+ This mirrors the existing modifier standards for Windows.
31
+
32
+ @param modifiers { KeyCode }
33
+ @param keyCode KeyCode
34
+ @return ModifierInputChord
35
+ ]=]
36
+ function InputChordUtils.createModifierInputChord(modifiers, keyCode)
37
+ assert(type(modifiers) == "table", "Bad modifiers")
38
+ assert(EnumUtils.isOfType(Enum.KeyCode, keyCode), "Bad keyCode")
39
+
40
+ return {
41
+ type = "ModifierInputChord";
42
+ modifiers = modifiers;
43
+ keyCode = keyCode;
44
+ }
45
+ end
46
+
47
+ return InputChordUtils
@@ -4,7 +4,10 @@
4
4
 
5
5
  local require = require(script.Parent.loader).load(script)
6
6
 
7
+ local HttpService = game:GetService("HttpService")
8
+
7
9
  local SlottedTouchButtonUtils = require("SlottedTouchButtonUtils")
10
+ local Set = require("Set")
8
11
 
9
12
  local InputTypeUtils = {}
10
13
 
@@ -84,4 +87,33 @@ function InputTypeUtils.getUniqueKeyForInputType(inputType)
84
87
  end
85
88
  end
86
89
 
90
+ local function convertValuesToJSONIfNeeded(list)
91
+ local result = {}
92
+ for key, value in pairs(list) do
93
+ if type(value) == "table" then
94
+ result[key] = HttpService:JSONEncode(value)
95
+ else
96
+ result[key] = value
97
+ end
98
+ end
99
+ return result
100
+ end
101
+
102
+ --[=[
103
+ Expensive comparison check to see if InputTypes are the same or not.
104
+
105
+ @param a { InputType }
106
+ @param b { InputType }
107
+ @return boolean
108
+ ]=]
109
+ function InputTypeUtils.areInputTypesListsEquivalent(a, b)
110
+ -- allocate, hehe
111
+ local setA = Set.fromTableValue(convertValuesToJSONIfNeeded(a))
112
+ local setB = Set.fromTableValue(convertValuesToJSONIfNeeded(b))
113
+
114
+ local remaining = Set.difference(setA, setB)
115
+ local left = Set.toList(remaining)
116
+ return #left == 0
117
+ end
118
+
87
119
  return InputTypeUtils