@rbxts/input-categorizer 1.0.1 → 1.0.2
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/README.md +6 -0
- package/package.json +8 -13
- package/src/index.d.ts +9 -0
- package/src/init.lua +46 -0
- package/out/index.d.ts +0 -7
- package/out/init.luau +0 -49
package/README.md
ADDED
package/package.json
CHANGED
|
@@ -1,30 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rbxts/input-categorizer",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "
|
|
6
|
-
"scripts": {
|
|
7
|
-
"build": "rbxtsc",
|
|
8
|
-
"watch": "rbxtsc -w",
|
|
9
|
-
"prepublishOnly": "npm run build"
|
|
10
|
-
},
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Observe the preferred input category of the player.",
|
|
5
|
+
"main": "src/init.lua",
|
|
6
|
+
"scripts": {},
|
|
11
7
|
"keywords": [],
|
|
12
8
|
"author": "CriShoux",
|
|
13
9
|
"license": "ISC",
|
|
14
10
|
"type": "commonjs",
|
|
15
|
-
"types": "
|
|
11
|
+
"types": "src/index.d.ts",
|
|
16
12
|
"files": [
|
|
17
|
-
"
|
|
18
|
-
"!**/*.tsbuildinfo"
|
|
13
|
+
"src"
|
|
19
14
|
],
|
|
20
15
|
"publishConfig": {
|
|
21
16
|
"access": "public"
|
|
22
17
|
},
|
|
23
18
|
"devDependencies": {
|
|
24
19
|
"@rbxts/compiler-types": "^3.0.0-types.0",
|
|
25
|
-
"@rbxts/types": "^1.0.
|
|
20
|
+
"@rbxts/types": "^1.0.896",
|
|
26
21
|
"roblox-ts": "^3.0.0",
|
|
27
|
-
"typescript": "^5.
|
|
22
|
+
"typescript": "^5.9.3"
|
|
28
23
|
},
|
|
29
24
|
"dependencies": {
|
|
30
25
|
"@rbxts/charm": "^0.10.0"
|
package/src/index.d.ts
ADDED
package/src/init.lua
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
local UserInputService = game:GetService('UserInputService');
|
|
3
|
+
|
|
4
|
+
local dependencies = script.Parent.Parent;
|
|
5
|
+
local Charm = require(dependencies:FindFirstChild('charm') or dependencies.Charm);
|
|
6
|
+
|
|
7
|
+
export type InputCategory = 'KeyboardAndMouse' | 'Gamepad' | 'Touch' | 'Unknown'
|
|
8
|
+
|
|
9
|
+
local lastInputTypeAtom = Charm.atom(UserInputService:GetLastInputType());
|
|
10
|
+
|
|
11
|
+
UserInputService.LastInputTypeChanged:Connect(lastInputTypeAtom)
|
|
12
|
+
|
|
13
|
+
local function categorizeInput(inputType: Enum.UserInputType): InputCategory
|
|
14
|
+
if inputType.Name:find('Gamepad') then
|
|
15
|
+
return 'Gamepad';
|
|
16
|
+
elseif inputType == Enum.UserInputType.Keyboard or inputType.Name:find('Mouse') then
|
|
17
|
+
return 'KeyboardAndMouse';
|
|
18
|
+
elseif inputType == Enum.UserInputType.Touch then
|
|
19
|
+
return 'Touch';
|
|
20
|
+
else
|
|
21
|
+
return 'Unknown';
|
|
22
|
+
end;
|
|
23
|
+
end;
|
|
24
|
+
|
|
25
|
+
local InputCategorizer = {};
|
|
26
|
+
|
|
27
|
+
InputCategorizer.inputCategoryAtom = Charm.computed(function(): InputCategory
|
|
28
|
+
local lastInputType = lastInputTypeAtom();
|
|
29
|
+
|
|
30
|
+
local category = categorizeInput(lastInputType);
|
|
31
|
+
if category ~= 'Unknown' then
|
|
32
|
+
return category;
|
|
33
|
+
end;
|
|
34
|
+
|
|
35
|
+
if UserInputService.KeyboardEnabled and UserInputService.MouseEnabled then
|
|
36
|
+
return 'KeyboardAndMouse'
|
|
37
|
+
elseif UserInputService.TouchEnabled then
|
|
38
|
+
return 'Touch';
|
|
39
|
+
elseif UserInputService.GamepadEnabled then
|
|
40
|
+
return 'Gamepad';
|
|
41
|
+
else
|
|
42
|
+
return 'Unknown';
|
|
43
|
+
end;
|
|
44
|
+
end);
|
|
45
|
+
|
|
46
|
+
return InputCategorizer;
|
package/out/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare const InputCategory: {
|
|
2
|
-
readonly KeyboardAndMouse: "KeyboardAndMouse";
|
|
3
|
-
readonly Gamepad: "Gamepad";
|
|
4
|
-
readonly Touch: "Touch";
|
|
5
|
-
readonly Unknown: "Unknown";
|
|
6
|
-
};
|
|
7
|
-
export declare const inputCategoryAtom: import("@rbxts/charm").Selector<"KeyboardAndMouse" | "Gamepad" | "Touch" | "Unknown">;
|
package/out/init.luau
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
-- Compiled with roblox-ts v3.0.0
|
|
2
|
-
local TS = _G[script]
|
|
3
|
-
local _charm = TS.import(script, TS.getModule(script, "@rbxts", "charm"))
|
|
4
|
-
local atom = _charm.atom
|
|
5
|
-
local computed = _charm.computed
|
|
6
|
-
local UserInputService = game:GetService("UserInputService")
|
|
7
|
-
local InputCategory = {
|
|
8
|
-
KeyboardAndMouse = "KeyboardAndMouse",
|
|
9
|
-
Gamepad = "Gamepad",
|
|
10
|
-
Touch = "Touch",
|
|
11
|
-
Unknown = "Unknown",
|
|
12
|
-
}
|
|
13
|
-
local lastInputTypeAtom = atom(UserInputService:GetLastInputType())
|
|
14
|
-
UserInputService.LastInputTypeChanged:Connect(lastInputTypeAtom)
|
|
15
|
-
local function categorizeInput(inputType)
|
|
16
|
-
local _value = (string.find(inputType.Name, "Gamepad"))
|
|
17
|
-
if _value ~= 0 and _value == _value and _value then
|
|
18
|
-
return InputCategory.Gamepad
|
|
19
|
-
else
|
|
20
|
-
local _value_1 = (inputType == Enum.UserInputType.Keyboard) or ((string.find(inputType.Name, "Mouse")))
|
|
21
|
-
if _value_1 ~= 0 and _value_1 == _value_1 and _value_1 then
|
|
22
|
-
return InputCategory.KeyboardAndMouse
|
|
23
|
-
elseif inputType == Enum.UserInputType.Touch then
|
|
24
|
-
return InputCategory.Touch
|
|
25
|
-
else
|
|
26
|
-
return InputCategory.Unknown
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
local inputCategoryAtom = computed(function()
|
|
31
|
-
local lastInputType = lastInputTypeAtom()
|
|
32
|
-
local category = categorizeInput(lastInputType)
|
|
33
|
-
if category ~= InputCategory.Unknown then
|
|
34
|
-
return category
|
|
35
|
-
end
|
|
36
|
-
if UserInputService.KeyboardEnabled and UserInputService.MouseEnabled then
|
|
37
|
-
return InputCategory.KeyboardAndMouse
|
|
38
|
-
elseif UserInputService.TouchEnabled then
|
|
39
|
-
return InputCategory.Touch
|
|
40
|
-
elseif UserInputService.GamepadEnabled then
|
|
41
|
-
return InputCategory.Gamepad
|
|
42
|
-
else
|
|
43
|
-
return InputCategory.Unknown
|
|
44
|
-
end
|
|
45
|
-
end)
|
|
46
|
-
return {
|
|
47
|
-
InputCategory = InputCategory,
|
|
48
|
-
inputCategoryAtom = inputCategoryAtom,
|
|
49
|
-
}
|