@rbxts/input-categorizer 1.0.1 → 1.0.3

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 ADDED
@@ -0,0 +1,6 @@
1
+ # Input Categorizer
2
+ Observe the preferred input category of the player.
3
+
4
+ ## Install
5
+ Install with [wally](https://wally.run/):\
6
+ `InputCategorizer = "shouxtech/input-categorizer@1.0.3"`
package/package.json CHANGED
@@ -1,30 +1,25 @@
1
1
  {
2
2
  "name": "@rbxts/input-categorizer",
3
- "version": "1.0.1",
4
- "description": "Categorize the input system that is being used.",
5
- "main": "out/init.lua",
6
- "scripts": {
7
- "build": "rbxtsc",
8
- "watch": "rbxtsc -w",
9
- "prepublishOnly": "npm run build"
10
- },
3
+ "version": "1.0.3",
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": "out/index.d.ts",
11
+ "types": "src/index.d.ts",
16
12
  "files": [
17
- "out",
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.841",
20
+ "@rbxts/types": "^1.0.896",
26
21
  "roblox-ts": "^3.0.0",
27
- "typescript": "^5.8.2"
22
+ "typescript": "^5.9.3"
28
23
  },
29
24
  "dependencies": {
30
25
  "@rbxts/charm": "^0.10.0"
package/src/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { Atom } from '@rbxts/charm';
2
+
3
+ export type InputCategory = 'KeyboardAndMouse' | 'Gamepad' | 'Touch' | 'Unknown';
4
+
5
+ declare namespace InputCategorizer {
6
+ const inputCategoryAtom: Atom<InputCategory>;
7
+ }
8
+
9
+ export = InputCategorizer;
package/src/init.lua ADDED
@@ -0,0 +1,47 @@
1
+ --!strict
2
+ local UserInputService = game:GetService('UserInputService');
3
+
4
+ local isTypeScriptEnv = script.Name == 'src';
5
+ local dependencies = if isTypeScriptEnv then script.Parent.Parent else script.Parent;
6
+ local Charm = require(isTypeScriptEnv and dependencies.charm or dependencies.Charm);
7
+
8
+ export type InputCategory = 'KeyboardAndMouse' | 'Gamepad' | 'Touch' | 'Unknown'
9
+
10
+ local lastInputTypeAtom = Charm.atom(UserInputService:GetLastInputType());
11
+
12
+ UserInputService.LastInputTypeChanged:Connect(lastInputTypeAtom)
13
+
14
+ local function categorizeInput(inputType: Enum.UserInputType): InputCategory
15
+ if inputType.Name:find('Gamepad') then
16
+ return 'Gamepad';
17
+ elseif inputType == Enum.UserInputType.Keyboard or inputType.Name:find('Mouse') then
18
+ return 'KeyboardAndMouse';
19
+ elseif inputType == Enum.UserInputType.Touch then
20
+ return 'Touch';
21
+ else
22
+ return 'Unknown';
23
+ end;
24
+ end;
25
+
26
+ local InputCategorizer = {};
27
+
28
+ InputCategorizer.inputCategoryAtom = Charm.computed(function(): InputCategory
29
+ local lastInputType = lastInputTypeAtom();
30
+
31
+ local category = categorizeInput(lastInputType);
32
+ if category ~= 'Unknown' then
33
+ return category;
34
+ end;
35
+
36
+ if UserInputService.KeyboardEnabled and UserInputService.MouseEnabled then
37
+ return 'KeyboardAndMouse'
38
+ elseif UserInputService.TouchEnabled then
39
+ return 'Touch';
40
+ elseif UserInputService.GamepadEnabled then
41
+ return 'Gamepad';
42
+ else
43
+ return 'Unknown';
44
+ end;
45
+ end);
46
+
47
+ 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
- }