@wwawing/virtual-pad 3.8.0-beta.1 → 3.9.0-beta.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.
@@ -31,13 +31,16 @@ export declare type VirtualPadButtons = {
31
31
  declare type VirtualPadEventFunction = (buttonCode: VirtualPadButtonCode) => void;
32
32
  export default class VirtualPadStore {
33
33
  private _enabled;
34
+ private _visible;
34
35
  private _onTouchStart;
35
36
  private _onTouchEnd;
36
37
  private _availableButtons;
37
38
  private _isTouchingButtons;
38
39
  private _moveButtonsElement;
39
- constructor(buttons: VirtualPadButtons | {}, moveButtons?: HTMLElement, onTouchStart?: VirtualPadEventFunction, onTouchEnd?: VirtualPadEventFunction);
40
+ private _buttonWrapperElement;
41
+ constructor(buttons: VirtualPadButtons | {}, firstVisible?: boolean, buttonWrapper?: HTMLElement, moveButtons?: HTMLElement, onTouchStart?: VirtualPadEventFunction, onTouchEnd?: VirtualPadEventFunction);
40
42
  private _detectMovingMoveButton;
43
+ private _setVisible;
41
44
  checkTouchButton(buttonType: VirtualPadButtonCode): boolean;
42
45
  checkTouchingButton(buttonType: VirtualPadButtonCode): boolean;
43
46
  getButtonState(buttonType: VirtualPadButtonCode): VirtualPadState;
@@ -47,5 +50,6 @@ export default class VirtualPadStore {
47
50
  allClear(): void;
48
51
  static isMoveButton(buttonType: VirtualPadButtonCode): boolean;
49
52
  update(): void;
53
+ toggleVisible(): void;
50
54
  }
51
55
  export {};
package/lib/VirtualPad.js CHANGED
@@ -25,17 +25,22 @@ var VirtualPadMoveButtonCodes = [
25
25
  VirtualPadButtonCode.BUTTON_DOWN
26
26
  ];
27
27
  var VirtualPadStore = (function () {
28
- function VirtualPadStore(buttons, moveButtons, onTouchStart, onTouchEnd) {
28
+ function VirtualPadStore(buttons, firstVisible, buttonWrapper, moveButtons, onTouchStart, onTouchEnd) {
29
+ if (firstVisible === void 0) { firstVisible = false; }
30
+ if (buttonWrapper === void 0) { buttonWrapper = null; }
29
31
  if (moveButtons === void 0) { moveButtons = null; }
30
32
  if (onTouchStart === void 0) { onTouchStart = null; }
31
33
  if (onTouchEnd === void 0) { onTouchEnd = null; }
32
34
  var _this = this;
33
35
  this._enabled = Object.keys(buttons).length > 0;
36
+ this._visible = firstVisible;
34
37
  this._onTouchStart = onTouchStart || null;
35
38
  this._onTouchEnd = onTouchEnd || null;
36
39
  this._availableButtons = [];
37
40
  this._isTouchingButtons = {};
38
41
  this._moveButtonsElement = moveButtons;
42
+ this._buttonWrapperElement = buttonWrapper;
43
+ this._setVisible(firstVisible);
39
44
  var _loop_1 = function (buttonTypeString) {
40
45
  var buttonCode = parseInt(buttonTypeString);
41
46
  var button = buttons[buttonCode];
@@ -107,6 +112,15 @@ var VirtualPadStore = (function () {
107
112
  }
108
113
  }
109
114
  };
115
+ VirtualPadStore.prototype._setVisible = function (visible) {
116
+ if (this._moveButtonsElement !== null) {
117
+ this._moveButtonsElement.style.display = visible ? "grid" : "none";
118
+ }
119
+ if (this._moveButtonsElement !== null) {
120
+ this._buttonWrapperElement.style.display = visible ? "grid" : "none";
121
+ }
122
+ this._visible = visible;
123
+ };
110
124
  VirtualPadStore.prototype.checkTouchButton = function (buttonType) {
111
125
  if (!this._enabled) {
112
126
  return false;
@@ -183,6 +197,9 @@ var VirtualPadStore = (function () {
183
197
  }
184
198
  });
185
199
  };
200
+ VirtualPadStore.prototype.toggleVisible = function () {
201
+ this._setVisible(!this._visible);
202
+ };
186
203
  return VirtualPadStore;
187
204
  }());
188
205
  export default VirtualPadStore;
package/lib/autoRotate.js CHANGED
@@ -8,16 +8,17 @@ export function initializeRotate() {
8
8
  export default function autoRotate() {
9
9
  var WWA_WIDTH = 560;
10
10
  var WWA_HEIGHT = 440;
11
+ var BROWSER_MARGIN = 8;
11
12
  var viewportElement = document.querySelector("meta[name='viewport']");
12
13
  var browserWidth = window.innerWidth;
13
14
  var browserHeight = window.innerHeight;
14
15
  var viewportValue = "user-scalable=no";
15
16
  if (browserWidth > browserHeight) {
16
- var width = Math.floor((browserWidth / browserHeight) * WWA_HEIGHT);
17
+ var width = Math.floor((browserWidth / browserHeight) * (WWA_HEIGHT + (BROWSER_MARGIN) * 2));
17
18
  viewportValue = "width=".concat(width, ",").concat(viewportValue);
18
19
  }
19
20
  else if (browserWidth <= browserHeight) {
20
- viewportValue = "width=".concat(WWA_WIDTH, ",").concat(viewportValue);
21
+ viewportValue = "width=".concat(WWA_WIDTH + (BROWSER_MARGIN * 2), ",").concat(viewportValue);
21
22
  }
22
23
  viewportElement.setAttribute("content", "".concat(viewportValue));
23
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wwawing/virtual-pad",
3
- "version": "3.8.0-beta.1",
3
+ "version": "3.9.0-beta.2",
4
4
  "description": "WWA Wing Virtual Pad for mobile phone",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -16,5 +16,5 @@
16
16
  "publishConfig": {
17
17
  "access": "public"
18
18
  },
19
- "gitHead": "f27dbc4de044cc28ab944997ea1c3361e94228cc"
19
+ "gitHead": "a736ed0e709d1049bbd3c3f4b521790161ba2d50"
20
20
  }
package/src/VirtualPad.ts CHANGED
@@ -65,6 +65,8 @@ export default class VirtualPadStore {
65
65
  */
66
66
  private _enabled: boolean;
67
67
 
68
+ private _visible: boolean;
69
+
68
70
  private _onTouchStart: VirtualPadEventFunction | null;
69
71
  private _onTouchEnd: VirtualPadEventFunction | null;
70
72
 
@@ -83,24 +85,37 @@ export default class VirtualPadStore {
83
85
  */
84
86
  private _moveButtonsElement: HTMLElement;
85
87
 
88
+ /**
89
+ * 操作ボタン群の親要素です。 {@code _moveButtonsElement} と併せて表示や非表示の切り替えに使用します。
90
+ */
91
+ private _buttonWrapperElement: HTMLElement;
92
+
86
93
  /**
87
94
  * @param buttons 仮想パッドの各要素
95
+ * @param firstVisible インスタンス化時点で仮想パッドを表示するか
96
+ * @param buttonWrapper 仮想パッドのボタン (主に右側) を覆う親要素
88
97
  * @param moveButtons 仮想パッドの移動ボタンの要素
89
98
  * @param onTouchStart 仮想パッドを押下した場合に発生するコールバック関数
90
99
  * @param onTouchEnd 仮想パッドを話した場合に発生するコールバック関数
91
100
  */
92
101
  constructor(
93
102
  buttons: VirtualPadButtons | {},
103
+ firstVisible: boolean = false,
104
+ buttonWrapper: HTMLElement = null,
94
105
  moveButtons: HTMLElement = null,
95
106
  onTouchStart: VirtualPadEventFunction = null,
96
- onTouchEnd: VirtualPadEventFunction = null
107
+ onTouchEnd: VirtualPadEventFunction = null,
97
108
  ) {
98
109
  this._enabled = Object.keys(buttons).length > 0;
110
+ this._visible = firstVisible;
99
111
  this._onTouchStart = onTouchStart || null;
100
112
  this._onTouchEnd = onTouchEnd || null;
101
113
  this._availableButtons = [];
102
114
  this._isTouchingButtons = {};
103
115
  this._moveButtonsElement = moveButtons;
116
+ this._buttonWrapperElement = buttonWrapper;
117
+
118
+ this._setVisible(firstVisible);
104
119
 
105
120
  for (let buttonTypeString in buttons) {
106
121
  /**
@@ -202,6 +217,16 @@ export default class VirtualPadStore {
202
217
  }
203
218
  }
204
219
 
220
+ private _setVisible(visible: boolean) {
221
+ if (this._moveButtonsElement !== null) {
222
+ this._moveButtonsElement.style.display = visible ? "grid" : "none";
223
+ }
224
+ if (this._moveButtonsElement !== null) {
225
+ this._buttonWrapperElement.style.display = visible ? "grid" : "none";
226
+ }
227
+ this._visible = visible;
228
+ }
229
+
205
230
  /**
206
231
  * 指定したボタンが押されたかを判別します。
207
232
  * 戦闘予測ボタンといった、1回しか押さないボタンの判定に使用します。
@@ -323,4 +348,8 @@ export default class VirtualPadStore {
323
348
  }
324
349
  });
325
350
  }
351
+
352
+ public toggleVisible() {
353
+ this._setVisible(!this._visible);
354
+ }
326
355
  }
package/src/autoRotate.ts CHANGED
@@ -17,6 +17,8 @@ export function initializeRotate() {
17
17
  export default function autoRotate() {
18
18
  const WWA_WIDTH = 560;
19
19
  const WWA_HEIGHT = 440;
20
+ // ブラウザーCSSをここから取得することはできないようなのでここで仮の値を設定しておく
21
+ const BROWSER_MARGIN = 8;
20
22
 
21
23
  const viewportElement = document.querySelector("meta[name='viewport']");
22
24
  const browserWidth = window.innerWidth;
@@ -28,10 +30,10 @@ export default function autoRotate() {
28
30
  let viewportValue = "user-scalable=no";
29
31
 
30
32
  if (browserWidth > browserHeight) {
31
- const width = Math.floor((browserWidth / browserHeight) * WWA_HEIGHT);
33
+ const width = Math.floor((browserWidth / browserHeight) * (WWA_HEIGHT + (BROWSER_MARGIN) * 2));
32
34
  viewportValue = `width=${width},${viewportValue}`;
33
35
  } else if (browserWidth <= browserHeight) {
34
- viewportValue = `width=${WWA_WIDTH},${viewportValue}`;
36
+ viewportValue = `width=${WWA_WIDTH + (BROWSER_MARGIN * 2)},${viewportValue}`;
35
37
  }
36
38
  viewportElement.setAttribute("content", `${viewportValue}`);
37
39
  }