@vnejs/plugins.compatibility.controls.cursor-controls.gamepad 0.1.1 → 0.1.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.
@@ -0,0 +1,23 @@
1
+ import { Module } from "@vnejs/module";
2
+ import type { ControlsPushPayload } from "@vnejs/plugins.controls.contract";
3
+ import type { PluginConstants, PluginEvents, PluginParams, PluginSettings } from "./types.js";
4
+ type CursorShiftPayload = {
5
+ x?: number;
6
+ y?: number;
7
+ };
8
+ type JoypadAxisMoveEvent = {
9
+ detail: {
10
+ axis: number;
11
+ axisMovementValue: number;
12
+ };
13
+ };
14
+ export declare class CompatibilityCursorGamepadControls extends Module<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
15
+ name: string;
16
+ hideTimeout: ReturnType<typeof setTimeout> | null;
17
+ emitHide: () => Promise<unknown[]> | undefined;
18
+ controls: NonNullable<ControlsPushPayload["controls"]>;
19
+ axisMoveHandler: (e: JoypadAxisMoveEvent) => void;
20
+ init: () => Promise<unknown[]> | undefined;
21
+ getShiftArg: (axis: number, value: number) => CursorShiftPayload;
22
+ }
23
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ import { Module } from "@vnejs/module";
2
+ import { regModule } from "@vnejs/shared";
3
+ export class CompatibilityCursorGamepadControls extends Module {
4
+ name = "compatibility.cursor.controls.gamepad";
5
+ hideTimeout = null;
6
+ emitHide = () => this.emit(this.EVENTS.CURSOR.HIDE);
7
+ controls = {
8
+ [this.CONST.GAMEPAD.BUTTONS.TRIGGER_RIGHT_KEYUP]: () => {
9
+ void this.emit(this.EVENTS.CURSOR.CLICK);
10
+ },
11
+ };
12
+ axisMoveHandler = (e) => {
13
+ this.emit(this.EVENTS.CURSOR.SHIFT, this.getShiftArg(e.detail.axis, e.detail.axisMovementValue));
14
+ this.emit(this.EVENTS.CURSOR.SHOW);
15
+ if (this.hideTimeout)
16
+ clearTimeout(this.hideTimeout);
17
+ this.hideTimeout = setTimeout(this.emitHide, 2000);
18
+ };
19
+ init = () => {
20
+ joypad.set({ axisMovementThreshold: 0.1 });
21
+ joypad.on("axis_move", this.axisMoveHandler);
22
+ return this.emit(this.EVENTS.CONTROLS.PUSH, {
23
+ key: this.name,
24
+ controls: this.controls,
25
+ index: 99999999999999,
26
+ checkNext: true,
27
+ });
28
+ };
29
+ getShiftArg = (axis, value) => (axis % 2 === 1 ? { y: value, x: 0 } : { y: 0, x: value });
30
+ }
31
+ regModule(CompatibilityCursorGamepadControls);
@@ -0,0 +1,8 @@
1
+ import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry, VnePluginParamsMapRegistry, VnePluginSettingsMapRegistry } from "@vnejs/shared";
2
+ import type { PluginName as ControlsPluginName, SubscribeEvents as ControlsSubscribeEvents } from "@vnejs/plugins.controls.contract";
3
+ import type { PluginName as CursorPluginName, SubscribeEvents as CursorSubscribeEvents } from "@vnejs/plugins.controls.cursor.contract";
4
+ import type { PluginName as GamepadPluginName, Constants as GamepadConstants } from "@vnejs/plugins.controls.gamepad.contract";
5
+ export type PluginEvents = VnePluginEventsMapRegistry & Record<ControlsPluginName, ControlsSubscribeEvents> & Record<CursorPluginName, CursorSubscribeEvents>;
6
+ export type PluginConstants = VnePluginConstantsMapRegistry & Record<GamepadPluginName, GamepadConstants>;
7
+ export type PluginSettings = VnePluginSettingsMapRegistry;
8
+ export type PluginParams = VnePluginParamsMapRegistry;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,17 +1,42 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.compatibility.controls.cursor-controls.gamepad",
3
- "version": "0.1.1",
4
- "main": "index.js",
3
+ "version": "0.1.2",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "src",
18
+ "tsconfig.json"
19
+ ],
5
20
  "scripts": {
6
21
  "test": "echo \"Error: no test specified\" && exit 1",
22
+ "build": "npx @vnejs/monorepo package",
7
23
  "publish:major:plugin": "npm run publish:major",
8
24
  "publish:minor:plugin": "npm run publish:minor",
9
25
  "publish:patch:plugin": "npm run publish:patch",
10
- "publish:major": "npm version major && npm publish --access public",
11
- "publish:minor": "npm version minor && npm publish --access public",
12
- "publish:patch": "npm version patch && npm publish --access public"
26
+ "publish:major": "npx @vnejs/monorepo publish major --access public",
27
+ "publish:minor": "npx @vnejs/monorepo publish minor --access public",
28
+ "publish:patch": "npx @vnejs/monorepo publish patch --access public"
13
29
  },
14
30
  "author": "",
15
31
  "license": "ISC",
16
- "description": ""
32
+ "peerDependencies": {
33
+ "@vnejs/module": "~0.0.1",
34
+ "@vnejs/plugins.controls.contract": "~0.0.1",
35
+ "@vnejs/plugins.controls.cursor.contract": "~0.0.1",
36
+ "@vnejs/plugins.controls.gamepad.contract": "~0.0.1",
37
+ "@vnejs/shared": "~0.0.9"
38
+ },
39
+ "devDependencies": {
40
+ "@vnejs/configs.ts-common": "~0.0.1"
41
+ }
17
42
  }
package/src/index.ts ADDED
@@ -0,0 +1,56 @@
1
+ import { Module } from "@vnejs/module";
2
+ import type { ControlsPushPayload } from "@vnejs/plugins.controls.contract";
3
+ import { regModule } from "@vnejs/shared";
4
+
5
+ import type { PluginConstants, PluginEvents, PluginParams, PluginSettings } from "./types.js";
6
+
7
+ type CursorShiftPayload = {
8
+ x?: number;
9
+ y?: number;
10
+ };
11
+
12
+ type JoypadAxisMoveEvent = {
13
+ detail: {
14
+ axis: number;
15
+ axisMovementValue: number;
16
+ };
17
+ };
18
+
19
+ export class CompatibilityCursorGamepadControls extends Module<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
20
+ name = "compatibility.cursor.controls.gamepad";
21
+
22
+ hideTimeout: ReturnType<typeof setTimeout> | null = null;
23
+
24
+ emitHide = () => this.emit(this.EVENTS.CURSOR.HIDE);
25
+
26
+ controls: NonNullable<ControlsPushPayload["controls"]> = {
27
+ [this.CONST.GAMEPAD.BUTTONS.TRIGGER_RIGHT_KEYUP]: () => {
28
+ void this.emit(this.EVENTS.CURSOR.CLICK);
29
+ },
30
+ };
31
+
32
+ axisMoveHandler = (e: JoypadAxisMoveEvent) => {
33
+ this.emit(this.EVENTS.CURSOR.SHIFT, this.getShiftArg(e.detail.axis, e.detail.axisMovementValue) satisfies CursorShiftPayload);
34
+
35
+ this.emit(this.EVENTS.CURSOR.SHOW);
36
+
37
+ if (this.hideTimeout) clearTimeout(this.hideTimeout);
38
+ this.hideTimeout = setTimeout(this.emitHide, 2000);
39
+ };
40
+
41
+ init = () => {
42
+ joypad.set({ axisMovementThreshold: 0.1 });
43
+ joypad.on("axis_move", this.axisMoveHandler as Parameters<typeof joypad.on>[1]);
44
+
45
+ return this.emit(this.EVENTS.CONTROLS.PUSH, {
46
+ key: this.name,
47
+ controls: this.controls,
48
+ index: 99999999999999,
49
+ checkNext: true,
50
+ } satisfies ControlsPushPayload);
51
+ };
52
+
53
+ getShiftArg = (axis: number, value: number): CursorShiftPayload => (axis % 2 === 1 ? { y: value, x: 0 } : { y: 0, x: value });
54
+ }
55
+
56
+ regModule(CompatibilityCursorGamepadControls);
@@ -0,0 +1,4 @@
1
+ declare const joypad: {
2
+ on: (event: string, handler: (e: { detail: { buttonName?: string; axis?: number; axisMovementValue?: number } }) => void) => void;
3
+ set: (options: Record<string, unknown>) => void;
4
+ };
package/src/types.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry, VnePluginParamsMapRegistry, VnePluginSettingsMapRegistry } from "@vnejs/shared";
2
+ import type { PluginName as ControlsPluginName, SubscribeEvents as ControlsSubscribeEvents } from "@vnejs/plugins.controls.contract";
3
+ import type { PluginName as CursorPluginName, SubscribeEvents as CursorSubscribeEvents } from "@vnejs/plugins.controls.cursor.contract";
4
+ import type { PluginName as GamepadPluginName, Constants as GamepadConstants } from "@vnejs/plugins.controls.gamepad.contract";
5
+
6
+ export type PluginEvents = VnePluginEventsMapRegistry &
7
+ Record<ControlsPluginName, ControlsSubscribeEvents> &
8
+ Record<CursorPluginName, CursorSubscribeEvents>;
9
+
10
+ export type PluginConstants = VnePluginConstantsMapRegistry & Record<GamepadPluginName, GamepadConstants>;
11
+
12
+ export type PluginSettings = VnePluginSettingsMapRegistry;
13
+
14
+ export type PluginParams = VnePluginParamsMapRegistry;
package/tsconfig.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": "@vnejs/configs.ts-common/tsconfig.json",
3
+ "compilerOptions": { "rootDir": "src", "outDir": "dist" },
4
+ "include": ["src/**/*.ts"],
5
+ "exclude": ["dist", "node_modules"]
6
+ }
package/index.js DELETED
@@ -1,32 +0,0 @@
1
- import { Module } from "@vnejs/module";
2
- import { regModule } from "@vnejs/shared";
3
-
4
- export class CompatibilityCursorGamepadControls extends Module {
5
- name = "compatibility.cursor.controls.gamepad";
6
-
7
- hideTimeout = null;
8
-
9
- emitHide = () => this.emit(this.EVENTS.CURSOR.HIDE);
10
-
11
- controls = { [this.CONST.GAMEPAD.BUTTONS.TRIGGER_RIGHT_KEYUP]: () => this.emit(this.EVENTS.CURSOR.CLICK) };
12
-
13
- axisMoveHandler = (e) => {
14
- this.emit(this.EVENTS.CURSOR.SHIFT, this.getShiftArg(e.detail.axis, e.detail.axisMovementValue));
15
-
16
- this.emit(this.EVENTS.CURSOR.SHOW);
17
-
18
- if (this.hideTimeout) clearTimeout(this.hideTimeout);
19
- this.hideTimeout = setTimeout(this.emitHide, 2000);
20
- };
21
-
22
- init = () => {
23
- joypad.set({ axisMovementThreshold: 0.1 });
24
- joypad.on("axis_move", this.axisMoveHandler);
25
-
26
- return this.emit(this.EVENTS.CONTROLS.PUSH, { key: this.name, controls: this.controls, index: 99999999999999, checkNext: true });
27
- };
28
-
29
- getShiftArg = (axis, value) => (axis % 2 === 1 ? { y: value, x: 0 } : { y: 0, x: value });
30
- }
31
-
32
- regModule(CompatibilityCursorGamepadControls);