@rbxts/axis 0.2.3-v.1 → 0.2.4

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 CHANGED
@@ -1,3 +1,68 @@
1
1
  # @rbxts/axis
2
2
 
3
- Typings for [axis](https://neond00m.github.io/Axis/)
3
+ roblox-ts typings for [axis](https://neond00m.github.io/Axis/)
4
+
5
+ ## Deviations
6
+
7
+ ### Map<T>
8
+
9
+ ```diff
10
+ - export type Map<T> = { [any]: any }
11
+ + export type _Map<T> = Map<defined, T> | defined[];
12
+ ```
13
+
14
+ ### InputConstructor
15
+
16
+ ```diff
17
+ - export type InputConstructor = <T>(Map<T> | (Map<T> & { deadzone: number? })) -> Input<T>
18
+ + export type InputConstructor = <T>(keyMap: _Map<T>, deadzone?: number) => Input<T>;
19
+ ```
20
+ ### Input Constructor function
21
+
22
+ ```diff
23
+ - local function new<T>(inputMap: types.Map<T> & { deadzone: number? }): types.Input<T>
24
+ + local function new<T>(inputMap: types.Map<T>, deadzone: number?): types.Input<T>
25
+ local input: types.Input<T> = {
26
+ vector = false,
27
+ current = {},
28
+ previous = {},
29
+ active = {
30
+ {}, -- separate input axes for each controller
31
+ },
32
+ resets = {}, --resets input on next update
33
+ connections = {},
34
+ inputMap = inputMap,
35
+ - deadzone = inputMap.deadzone
36
+ + deadzone = deadzone,
37
+
38
+ read = read,
39
+ pressing = pressing,
40
+ pressed = pressed,
41
+ released = released,
42
+ changed = changed,
43
+ hold = hold,
44
+ map = map,
45
+ update = update,
46
+ move = move,
47
+ }
48
+ map(input, inputMap)
49
+
50
+ return input
51
+ end
52
+ ```
53
+
54
+ ## Examples
55
+
56
+ ```ts
57
+ input(
58
+ new Map<Enum.KeyCode, Vector3>([
59
+ [Enum.KeyCode.Up, new Vector3(0, 1, 0)],
60
+ [Enum.KeyCode.Down, new Vector3(0, -1, 0)],
61
+ [Enum.KeyCode.Left, new Vector3(-1, 0, 0)],
62
+ [Enum.KeyCode.Right, new Vector3(1, 0, 0)],
63
+ ]),
64
+ , 1);
65
+
66
+ input([Enum.KeyCode.W, Enum.KeyCode.A, Enum.KeyCode.S, Enum.KeyCode.D], 1);
67
+ ```
68
+
package/out/index.d.ts CHANGED
@@ -1,49 +1,58 @@
1
- export namespace Axis {
2
- /**
3
- * @within Axis
4
- * @type DeviceType "Desktop" | "Touch" | "Controller"
5
- */
6
- type DeviceType = "Desktop" | "Touch" | "Controller";
1
+ export type DeviceType = "Desktop" | "Touch" | "Controller";
2
+
3
+ export type _Map<T> = Map<defined, T> | defined[];
7
4
 
5
+ export interface Input<T> {
8
6
  /**
9
- * @within Axis
10
- * @type Map<T> { [Enum | string]: T } & { Enum.KeyCode | Enum.UserInputType }
7
+ * Reads current and previous values for the axis
8
+ *
9
+ * ```ts
10
+ * const [current, previous] = attack.read()
11
+ * ```
12
+ *
13
+ * @param controller
11
14
  */
12
- type _Map = Map<defined, defined>; //Map<Enum | string, T> & Array<Enum.KeyCode | Enum.UserInputType>;
13
-
14
- interface Input<T> {
15
- read: (controller?: number) => LuaTuple<[T, T]>;
16
- pressing: (controller?: number) => boolean;
17
- pressed: (controller?: number) => boolean;
18
- released: (controller?: number) => boolean;
19
- changed: (controller?: number) => boolean;
20
- hold: (value: T, controller?: number) => void;
21
- move: (value: T, controller?: number) => void;
22
- map: (keyMap: _Map) => void;
23
- update: () => void;
24
-
25
- deadzone?: number;
26
- vector: boolean;
27
- current: T[];
28
- previous: T[];
29
- active: Array<Map<defined, T>>;
30
- resets: Map<defined, defined>;
31
- connections: RBXScriptConnection[];
32
- keyMap: _Map;
33
- inputMap: Map<Enum.KeyCode | Enum.UserInputType, T>;
34
- }
35
-
36
- type InputConstructor = <T>(input: _Map | (_Map & { deadzone?: number })) => Input<T>;
37
-
38
- interface Axis {
39
- device: (inputType: Enum.UserInputType | undefined) => DeviceType;
40
- update: (inputs: Map<defined, Input<defined>>) => void;
41
- input: InputConstructor;
42
- }
43
-
44
- function input<T>(inputMap: (_Map & { deadzone?: number }) | _Map): Input<T>;
45
-
46
- function update(inputs: Map<defined, Input<defined>>): void;
47
-
48
- function device(input?: Enum.UserInputType): DeviceType;
15
+ read(controller?: number): LuaTuple<[T, T]>;
16
+ pressing(controller?: number): boolean;
17
+ pressed(controller?: number): boolean;
18
+ released(controller?: number): boolean;
19
+ changed(controller?: number): boolean;
20
+ hold(value: T, controller?: number): void;
21
+ move(value: T, controller?: number): void;
22
+ map(keyMap: _Map<T>): void;
23
+ update(): void;
24
+
25
+ deadzone?: number;
26
+ vector: boolean;
27
+ current: T[];
28
+ previous: T[];
29
+ active: Array<Map<defined, T>>;
30
+ resets: Map<defined, defined>;
31
+ connections: RBXScriptConnection[];
32
+ keyMap: _Map<T>;
33
+ inputMap: Map<Enum.KeyCode | Enum.UserInputType, T>;
49
34
  }
35
+
36
+ export type InputConstructor = <T>(keyMap: _Map<T>, deadzone?: number) => Input<T>;
37
+
38
+ /**
39
+ * Gets the device of the provided UserInputType (or the last UserInputType if none is provided)
40
+ * @param inputType UserInputType
41
+ * @returns "Desktop" "Touch" or "Controller"
42
+ */
43
+ export function device(inputType?: Enum.UserInputType): DeviceType;
44
+
45
+ /**
46
+ * Updates all input axes in a array
47
+ *
48
+ * @param inputs A array of `Input` to update,
49
+ */
50
+ export function update(inputs: Input<defined>[]): void;
51
+
52
+ /**
53
+ * Creates a new input axis with the provided keymap
54
+ *
55
+ * @param keyMap It can be a `Map<Enum.KeyCode | string, defined | number>` for deadzone or `Map<Enum.KeyCode, defined>` or Enum.KeyCode[]
56
+ * @returns The input axis
57
+ */
58
+ export const input: InputConstructor;
package/out/input.luau CHANGED
@@ -306,7 +306,8 @@ local function update<T>(input: types.Input<T>)
306
306
  end
307
307
  end
308
308
 
309
- local function new<T>(inputMap: types.Map<T> & { deadzone: number? }): types.Input<T>
309
+ -- Added a parameter of deadzone for roblox-ts typings!
310
+ local function new<T>(inputMap: types.Map<T>, deadzone: number?): types.Input<T>
310
311
  local input: types.Input<T> = {
311
312
  vector = false,
312
313
  current = {},
@@ -317,7 +318,8 @@ local function new<T>(inputMap: types.Map<T> & { deadzone: number? }): types.Inp
317
318
  resets = {}, --resets input on next update
318
319
  connections = {},
319
320
  inputMap = inputMap,
320
- deadzone = inputMap.deadzone,
321
+ --Changed deadzone = inputMap.deadzone to deadzone parameter for roblox-ts typings!
322
+ deadzone = deadzone,
321
323
 
322
324
  read = read,
323
325
  pressing = pressing,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbxts/axis",
3
- "version": "0.2.3-v.1",
3
+ "version": "0.2.4",
4
4
  "description": "roblox-ts typings for NeonD00m/axis",
5
5
  "main": "out/init.lua",
6
6
  "scripts": {