@quenty/inputmode 4.1.1-canary.256.edbbcfc.0 → 5.0.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 +9 -1
- package/LICENSE.md +1 -1
- package/package.json +7 -7
- package/src/Client/InputMode.lua +9 -0
- package/src/Client/InputModeSelector.lua +89 -4
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
|
-
|
|
6
|
+
# [5.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/inputmode@4.2.0...@quenty/inputmode@5.0.0) (2022-05-21)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @quenty/inputmode
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [4.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/inputmode@4.1.0...@quenty/inputmode@4.2.0) (2022-03-27)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @quenty/inputmode
|
|
9
17
|
|
package/LICENSE.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/inputmode",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.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": "2.
|
|
30
|
-
"@quenty/signal": "2.
|
|
31
|
-
"@quenty/table": "
|
|
32
|
-
"@quenty/valueobject": "
|
|
28
|
+
"@quenty/loader": "^5.0.0",
|
|
29
|
+
"@quenty/maid": "^2.3.0",
|
|
30
|
+
"@quenty/signal": "^2.2.0",
|
|
31
|
+
"@quenty/table": "^3.0.0",
|
|
32
|
+
"@quenty/valueobject": "^5.0.0"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "9f7eaea7543c33c89d2e32c38491b13f9271f4f7"
|
|
38
38
|
}
|
package/src/Client/InputMode.lua
CHANGED
|
@@ -46,6 +46,15 @@ function InputMode.new(name, typesAndInputModes)
|
|
|
46
46
|
return self
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
+
--[=[
|
|
50
|
+
Returns true if a given value is an InputMode
|
|
51
|
+
@param value any
|
|
52
|
+
@return boolean
|
|
53
|
+
]=]
|
|
54
|
+
function InputMode.isInputMode(value)
|
|
55
|
+
return type(value) == "table" and getmetatable(value) == InputMode
|
|
56
|
+
end
|
|
57
|
+
|
|
49
58
|
--[=[
|
|
50
59
|
Checks the last point this input mode was used.
|
|
51
60
|
@return number
|
|
@@ -27,6 +27,9 @@ function InputModeSelector.new(inputModes)
|
|
|
27
27
|
|
|
28
28
|
self._maid = Maid.new()
|
|
29
29
|
|
|
30
|
+
-- keep this ordered so we are always stable in selection.
|
|
31
|
+
self._inputModeList = {}
|
|
32
|
+
|
|
30
33
|
self._activeMode = ValueObject.new()
|
|
31
34
|
self._maid:GiveTask(self._activeMode)
|
|
32
35
|
|
|
@@ -38,12 +41,39 @@ function InputModeSelector.new(inputModes)
|
|
|
38
41
|
self.Changed = self._activeMode.Changed
|
|
39
42
|
|
|
40
43
|
for _, inputMode in pairs(inputModes or InputModeSelector.DEFAULT_MODES) do
|
|
41
|
-
self:
|
|
44
|
+
self:AddInputMode(inputMode)
|
|
42
45
|
end
|
|
43
46
|
|
|
44
47
|
return self
|
|
45
48
|
end
|
|
46
49
|
|
|
50
|
+
--[=[
|
|
51
|
+
Constructs a new InputModeSelector
|
|
52
|
+
@param observeInputModesBrio Observable<Brio<InputMode>>
|
|
53
|
+
@return InputModeSelector
|
|
54
|
+
]=]
|
|
55
|
+
function InputModeSelector.fromObservableBrio(observeInputModesBrio)
|
|
56
|
+
local selector = InputModeSelector.new({})
|
|
57
|
+
|
|
58
|
+
selector._maid:GiveTask(observeInputModesBrio:Subscribe(function(brio)
|
|
59
|
+
if brio:IsDead() then
|
|
60
|
+
return
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
local inputMode = brio:GetValue()
|
|
64
|
+
local maid = brio:ToMaid()
|
|
65
|
+
selector:AddInputMode(inputMode)
|
|
66
|
+
|
|
67
|
+
maid:GiveTask(function()
|
|
68
|
+
if selector.Destroy then
|
|
69
|
+
selector:RemoveInputMode(inputMode)
|
|
70
|
+
end
|
|
71
|
+
end)
|
|
72
|
+
end))
|
|
73
|
+
|
|
74
|
+
return selector
|
|
75
|
+
end
|
|
76
|
+
|
|
47
77
|
--[=[
|
|
48
78
|
Returns the current active mode
|
|
49
79
|
@return InputMode
|
|
@@ -52,6 +82,14 @@ function InputModeSelector:GetActiveMode()
|
|
|
52
82
|
return rawget(self, "_activeMode").Value
|
|
53
83
|
end
|
|
54
84
|
|
|
85
|
+
--[=[
|
|
86
|
+
Observes the current active mode
|
|
87
|
+
@return Observable<InputMode>
|
|
88
|
+
]=]
|
|
89
|
+
function InputModeSelector:ObserveActiveMode()
|
|
90
|
+
return rawget(self, "_activeMode"):Observe()
|
|
91
|
+
end
|
|
92
|
+
|
|
55
93
|
--[=[
|
|
56
94
|
The current active input mode
|
|
57
95
|
@prop Value InputMode?
|
|
@@ -106,7 +144,10 @@ function InputModeSelector:Bind(updateBindFunction)
|
|
|
106
144
|
if newMode then
|
|
107
145
|
local modeMaid = Maid.new()
|
|
108
146
|
maid._modeMaid = modeMaid
|
|
109
|
-
|
|
147
|
+
|
|
148
|
+
if newMode then
|
|
149
|
+
updateBindFunction(newMode, modeMaid)
|
|
150
|
+
end
|
|
110
151
|
end
|
|
111
152
|
end
|
|
112
153
|
|
|
@@ -116,9 +157,39 @@ function InputModeSelector:Bind(updateBindFunction)
|
|
|
116
157
|
return self
|
|
117
158
|
end
|
|
118
159
|
|
|
119
|
-
|
|
120
|
-
|
|
160
|
+
--[=[
|
|
161
|
+
Removes the input mode
|
|
162
|
+
@param inputMode InputMode
|
|
163
|
+
]=]
|
|
164
|
+
function InputModeSelector:RemoveInputMode(inputMode)
|
|
165
|
+
if not self._maid[inputMode] then
|
|
166
|
+
return
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
local index = table.find(self._inputModeList, inputMode)
|
|
170
|
+
if index then
|
|
171
|
+
table.remove(self._inputModeList, index)
|
|
172
|
+
else
|
|
173
|
+
warn("[InputModeSelector] - Failed to find inputMode")
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
self._maid[inputMode] = nil
|
|
177
|
+
|
|
178
|
+
if self._activeMode.Value == inputMode then
|
|
179
|
+
self:_pickNewInputMode()
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
--[=[
|
|
184
|
+
Adds a new input mode
|
|
185
|
+
@param inputMode InputMode
|
|
186
|
+
]=]
|
|
187
|
+
function InputModeSelector:AddInputMode(inputMode)
|
|
188
|
+
if self._maid[inputMode] then
|
|
189
|
+
return
|
|
190
|
+
end
|
|
121
191
|
|
|
192
|
+
table.insert(self._inputModeList, inputMode)
|
|
122
193
|
self._maid[inputMode] = inputMode.Enabled:Connect(function()
|
|
123
194
|
self._activeMode.Value = inputMode
|
|
124
195
|
end)
|
|
@@ -129,6 +200,20 @@ function InputModeSelector:_addInputMode(inputMode)
|
|
|
129
200
|
end
|
|
130
201
|
end
|
|
131
202
|
|
|
203
|
+
function InputModeSelector:_pickNewInputMode()
|
|
204
|
+
local bestEnabledTime = -math.huge
|
|
205
|
+
local bestMode
|
|
206
|
+
for _, inputMode in pairs(self._inputModeList) do
|
|
207
|
+
local enableTime = inputMode:GetLastEnabledTime()
|
|
208
|
+
if enableTime >= bestEnabledTime then
|
|
209
|
+
bestEnabledTime = enableTime
|
|
210
|
+
bestMode = inputMode
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
self._activeMode.Value = bestMode
|
|
215
|
+
end
|
|
216
|
+
|
|
132
217
|
--[=[
|
|
133
218
|
Cleans up the input mode selector.
|
|
134
219
|
|