@next2d/core 3.6.0 → 3.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next2d/core",
3
- "version": "3.6.0",
3
+ "version": "3.8.0",
4
4
  "description": "Next2D Core Package",
5
5
  "author": "Toshiyuki Ienaga<ienaga@next2d.app> (https://github.com/ienaga/)",
6
6
  "license": "MIT",
@@ -24,15 +24,15 @@
24
24
  "url": "git+https://github.com/Next2D/Player.git"
25
25
  },
26
26
  "dependencies": {
27
- "@next2d/core": "3.6.0",
28
- "@next2d/display": "3.6.0",
29
- "@next2d/events": "3.6.0",
30
- "@next2d/filters": "3.6.0",
31
- "@next2d/geom": "3.6.0",
32
- "@next2d/media": "3.6.0",
33
- "@next2d/net": "3.6.0",
34
- "@next2d/text": "3.6.0",
35
- "@next2d/ui": "3.6.0",
36
- "@next2d/render-queue": "3.6.0"
27
+ "@next2d/core": "3.8.0",
28
+ "@next2d/display": "3.8.0",
29
+ "@next2d/events": "3.8.0",
30
+ "@next2d/filters": "3.8.0",
31
+ "@next2d/geom": "3.8.0",
32
+ "@next2d/media": "3.8.0",
33
+ "@next2d/net": "3.8.0",
34
+ "@next2d/text": "3.8.0",
35
+ "@next2d/ui": "3.8.0",
36
+ "@next2d/render-queue": "3.8.0"
37
37
  }
38
38
  }
package/src/Events.js CHANGED
@@ -1,9 +1,10 @@
1
- import { Event, EventDispatcher, EventPhase, FocusEvent, HTTPStatusEvent, IOErrorEvent, PointerEvent, JobEvent, ProgressEvent, VideoEvent } from "@next2d/events";
1
+ import { Event, EventDispatcher, EventPhase, FocusEvent, GamepadEvent, HTTPStatusEvent, IOErrorEvent, PointerEvent, JobEvent, ProgressEvent, VideoEvent } from "@next2d/events";
2
2
  const events = {
3
3
  Event,
4
4
  EventDispatcher,
5
5
  EventPhase,
6
6
  FocusEvent,
7
+ GamepadEvent,
7
8
  HTTPStatusEvent,
8
9
  IOErrorEvent,
9
10
  PointerEvent,
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @description ゲームパッドの前フレームのボタン押下状態 (gamepadIndex => boolean[])
3
+ * Previous frame button pressed state per gamepad (gamepadIndex => boolean[])
4
+ *
5
+ * @type {Map<number, boolean[]>}
6
+ * @protected
7
+ */
8
+ export declare const $gamepadButtonStates: Map<number, boolean[]>;
9
+ /**
10
+ * @description ゲームパッドの前フレームの軸値 (gamepadIndex => number[])
11
+ * Previous frame axis values per gamepad (gamepadIndex => number[])
12
+ *
13
+ * @type {Map<number, number[]>}
14
+ * @protected
15
+ */
16
+ export declare const $gamepadAxisStates: Map<number, number[]>;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @description ゲームパッドの前フレームのボタン押下状態 (gamepadIndex => boolean[])
3
+ * Previous frame button pressed state per gamepad (gamepadIndex => boolean[])
4
+ *
5
+ * @type {Map<number, boolean[]>}
6
+ * @protected
7
+ */
8
+ export const $gamepadButtonStates = new Map();
9
+ /**
10
+ * @description ゲームパッドの前フレームの軸値 (gamepadIndex => number[])
11
+ * Previous frame axis values per gamepad (gamepadIndex => number[])
12
+ *
13
+ * @type {Map<number, number[]>}
14
+ * @protected
15
+ */
16
+ export const $gamepadAxisStates = new Map();
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @description ゲームパッド接続イベントを実行する
3
+ * Execute the gamepad connected event
4
+ *
5
+ * @param {GamepadEvent} event
6
+ * @return {void}
7
+ * @method
8
+ * @protected
9
+ */
10
+ export declare const execute: (event: GamepadEvent) => void;
@@ -0,0 +1,26 @@
1
+ import { $gamepadButtonStates, $gamepadAxisStates } from "../../GamepadState";
2
+ import { stage } from "@next2d/display";
3
+ import { GamepadEvent as Next2DGamepadEvent } from "@next2d/events";
4
+ /**
5
+ * @description ゲームパッド接続イベントを実行する
6
+ * Execute the gamepad connected event
7
+ *
8
+ * @param {GamepadEvent} event
9
+ * @return {void}
10
+ * @method
11
+ * @protected
12
+ */
13
+ export const execute = (event) => {
14
+ const gamepad = event.gamepad;
15
+ if (!gamepad) {
16
+ return;
17
+ }
18
+ $gamepadButtonStates.set(gamepad.index, Array.from({ "length": gamepad.buttons.length }, () => false));
19
+ $gamepadAxisStates.set(gamepad.index, Array.from({ "length": gamepad.axes.length }, () => 0));
20
+ if (!stage.hasEventListener(Next2DGamepadEvent.GAMEPAD_CONNECTED)) {
21
+ return;
22
+ }
23
+ const gamepadEvent = new Next2DGamepadEvent(Next2DGamepadEvent.GAMEPAD_CONNECTED);
24
+ gamepadEvent.gamepadIndex = gamepad.index;
25
+ stage.dispatchEvent(gamepadEvent);
26
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @description ゲームパッド切断イベントを実行する
3
+ * Execute the gamepad disconnected event
4
+ *
5
+ * @param {GamepadEvent} event
6
+ * @return {void}
7
+ * @method
8
+ * @protected
9
+ */
10
+ export declare const execute: (event: GamepadEvent) => void;
@@ -0,0 +1,26 @@
1
+ import { $gamepadButtonStates, $gamepadAxisStates } from "../../GamepadState";
2
+ import { stage } from "@next2d/display";
3
+ import { GamepadEvent as Next2DGamepadEvent } from "@next2d/events";
4
+ /**
5
+ * @description ゲームパッド切断イベントを実行する
6
+ * Execute the gamepad disconnected event
7
+ *
8
+ * @param {GamepadEvent} event
9
+ * @return {void}
10
+ * @method
11
+ * @protected
12
+ */
13
+ export const execute = (event) => {
14
+ const gamepad = event.gamepad;
15
+ if (!gamepad) {
16
+ return;
17
+ }
18
+ $gamepadButtonStates.delete(gamepad.index);
19
+ $gamepadAxisStates.delete(gamepad.index);
20
+ if (!stage.hasEventListener(Next2DGamepadEvent.GAMEPAD_DISCONNECTED)) {
21
+ return;
22
+ }
23
+ const gamepadEvent = new Next2DGamepadEvent(Next2DGamepadEvent.GAMEPAD_DISCONNECTED);
24
+ gamepadEvent.gamepadIndex = gamepad.index;
25
+ stage.dispatchEvent(gamepadEvent);
26
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description ゲームパッドのポーリング処理を実行する
3
+ * Execute gamepad polling process
4
+ *
5
+ * @return {void}
6
+ * @method
7
+ * @protected
8
+ */
9
+ export declare const execute: () => void;
@@ -0,0 +1,95 @@
1
+ import { $gamepadButtonStates, $gamepadAxisStates } from "../../GamepadState";
2
+ import { stage } from "@next2d/display";
3
+ import { GamepadEvent } from "@next2d/events";
4
+ /**
5
+ * @private
6
+ * @constant
7
+ * @type {number}
8
+ */
9
+ const AXIS_DEAD_ZONE = 0.1;
10
+ /**
11
+ * @description ゲームパッドのボタン変化を処理する
12
+ * Process gamepad button changes
13
+ *
14
+ * @param {Gamepad} gamepad
15
+ * @param {boolean[]} prevButtons
16
+ * @return {void}
17
+ * @method
18
+ * @private
19
+ */
20
+ const processButtons = (gamepad, prevButtons) => {
21
+ const hasButtonDown = stage.hasEventListener(GamepadEvent.BUTTON_DOWN);
22
+ const hasButtonUp = stage.hasEventListener(GamepadEvent.BUTTON_UP);
23
+ if (!hasButtonDown && !hasButtonUp) {
24
+ return;
25
+ }
26
+ for (let i = 0; i < gamepad.buttons.length; i++) {
27
+ const pressed = gamepad.buttons[i].pressed;
28
+ if (pressed === prevButtons[i]) {
29
+ continue;
30
+ }
31
+ const type = pressed ? GamepadEvent.BUTTON_DOWN : GamepadEvent.BUTTON_UP;
32
+ if (pressed && !hasButtonDown || !pressed && !hasButtonUp) {
33
+ prevButtons[i] = pressed;
34
+ continue;
35
+ }
36
+ const event = new GamepadEvent(type);
37
+ event.gamepadIndex = gamepad.index;
38
+ event.buttonIndex = i;
39
+ event.buttonValue = gamepad.buttons[i].value;
40
+ stage.dispatchEvent(event);
41
+ prevButtons[i] = pressed;
42
+ }
43
+ };
44
+ /**
45
+ * @description ゲームパッドの軸変化を処理する
46
+ * Process gamepad axis changes
47
+ *
48
+ * @param {Gamepad} gamepad
49
+ * @param {number[]} prevAxes
50
+ * @return {void}
51
+ * @method
52
+ * @private
53
+ */
54
+ const processAxes = (gamepad, prevAxes) => {
55
+ if (!stage.hasEventListener(GamepadEvent.AXES_MOTION)) {
56
+ return;
57
+ }
58
+ for (let i = 0; i < gamepad.axes.length; i++) {
59
+ const value = gamepad.axes[i];
60
+ if (Math.abs(value - prevAxes[i]) < AXIS_DEAD_ZONE) {
61
+ continue;
62
+ }
63
+ const event = new GamepadEvent(GamepadEvent.AXES_MOTION);
64
+ event.gamepadIndex = gamepad.index;
65
+ event.axisIndex = i;
66
+ event.axisValue = value;
67
+ stage.dispatchEvent(event);
68
+ prevAxes[i] = value;
69
+ }
70
+ };
71
+ /**
72
+ * @description ゲームパッドのポーリング処理を実行する
73
+ * Execute gamepad polling process
74
+ *
75
+ * @return {void}
76
+ * @method
77
+ * @protected
78
+ */
79
+ export const execute = () => {
80
+ const gamepads = navigator.getGamepads();
81
+ for (let idx = 0; idx < gamepads.length; idx++) {
82
+ const gamepad = gamepads[idx];
83
+ if (!gamepad) {
84
+ continue;
85
+ }
86
+ if (!$gamepadButtonStates.has(gamepad.index)) {
87
+ $gamepadButtonStates.set(gamepad.index, Array.from({ "length": gamepad.buttons.length }, () => false));
88
+ $gamepadAxisStates.set(gamepad.index, Array.from({ "length": gamepad.axes.length }, () => 0));
89
+ }
90
+ const prevButtons = $gamepadButtonStates.get(gamepad.index);
91
+ const prevAxes = $gamepadAxisStates.get(gamepad.index);
92
+ processButtons(gamepad, prevButtons);
93
+ processAxes(gamepad, prevAxes);
94
+ }
95
+ };
@@ -1,6 +1,6 @@
1
1
  /**
2
- * @description キーボードイベントを登録する
3
- * Register keyboard events
2
+ * @description キーボード・ゲームパッドイベントを登録する
3
+ * Register keyboard and gamepad events
4
4
  *
5
5
  * @return {void}
6
6
  * @method
@@ -1,9 +1,11 @@
1
1
  import { execute as playerKeyDownEventService } from "../service/PlayerKeyDownEventService";
2
2
  import { execute as playerKeyUpEventService } from "../service/PlayerKeyUpEventService";
3
- import { KeyboardEvent } from "@next2d/events";
3
+ import { execute as playerGamepadConnectService } from "../service/PlayerGamepadConnectService";
4
+ import { execute as playerGamepadDisconnectService } from "../service/PlayerGamepadDisconnectService";
5
+ import { KeyboardEvent, GamepadEvent } from "@next2d/events";
4
6
  /**
5
- * @description キーボードイベントを登録する
6
- * Register keyboard events
7
+ * @description キーボード・ゲームパッドイベントを登録する
8
+ * Register keyboard and gamepad events
7
9
  *
8
10
  * @return {void}
9
11
  * @method
@@ -12,4 +14,6 @@ import { KeyboardEvent } from "@next2d/events";
12
14
  export const execute = () => {
13
15
  window.addEventListener(KeyboardEvent.KEY_DOWN, playerKeyDownEventService);
14
16
  window.addEventListener(KeyboardEvent.KEY_UP, playerKeyUpEventService);
17
+ window.addEventListener(GamepadEvent.GAMEPAD_CONNECTED, playerGamepadConnectService);
18
+ window.addEventListener(GamepadEvent.GAMEPAD_DISCONNECTED, playerGamepadDisconnectService);
15
19
  };
@@ -4,6 +4,7 @@ import { Event } from "@next2d/events";
4
4
  import { $cacheStore } from "@next2d/cache";
5
5
  import { execute as playerRenderingPostMessageService } from "../service/PlayerRenderingPostMessageService";
6
6
  import { execute as playerRemoveCachePostMessageService } from "../service/PlayerRemoveCachePostMessageService";
7
+ import { execute as playerGamepadTickerService } from "../service/PlayerGamepadTickerService";
7
8
  /**
8
9
  * @private
9
10
  * @constant
@@ -32,6 +33,8 @@ export const execute = (timestamp) => {
32
33
  $player.startTime = timestamp - time % $player.fps;
33
34
  // 定期処理
34
35
  stage.$ticker();
36
+ // gamepad polling
37
+ playerGamepadTickerService();
35
38
  // enter frame event
36
39
  if (stage.hasEventListener(Event.ENTER_FRAME)) {
37
40
  stage.dispatchEvent(enterFrameEvent);
@@ -1,9 +1,10 @@
1
- import type { Event, EventDispatcher, EventPhase, FocusEvent, HTTPStatusEvent, IOErrorEvent, PointerEvent, JobEvent, ProgressEvent, VideoEvent } from "@next2d/events";
1
+ import type { Event, EventDispatcher, EventPhase, FocusEvent, GamepadEvent, HTTPStatusEvent, IOErrorEvent, PointerEvent, JobEvent, ProgressEvent, VideoEvent } from "@next2d/events";
2
2
  export interface IEvents {
3
3
  Event: typeof Event;
4
4
  EventDispatcher: typeof EventDispatcher;
5
5
  EventPhase: typeof EventPhase;
6
6
  FocusEvent: typeof FocusEvent;
7
+ GamepadEvent: typeof GamepadEvent;
7
8
  HTTPStatusEvent: typeof HTTPStatusEvent;
8
9
  IOErrorEvent: typeof IOErrorEvent;
9
10
  PointerEvent: typeof PointerEvent;