@wwawing/virtual-pad 3.12.10 → 3.12.14
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/LICENSE +1 -1
- package/lib/VirtualPad.js +71 -86
- package/lib/makeInject.js +14 -1
- package/lib/viewportFit.js +13 -13
- package/package.json +2 -2
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
3
|
Copyright (c) 1996-2015 NAO
|
|
4
|
-
Copyright (c) 2015-
|
|
4
|
+
Copyright (c) 2015-2024 WWA Wing Team
|
|
5
5
|
|
|
6
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
of this software and associated documentation files (the "Software"), to deal
|
package/lib/VirtualPad.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const VirtualPadButtonCodes = [
|
|
2
2
|
"BUTTON_ENTER",
|
|
3
3
|
"BUTTON_ESC",
|
|
4
4
|
"BUTTON_SIDEBAR",
|
|
@@ -9,21 +9,15 @@ export var VirtualPadButtonCodes = [
|
|
|
9
9
|
"BUTTON_RIGHT",
|
|
10
10
|
"BUTTON_DOWN"
|
|
11
11
|
];
|
|
12
|
-
|
|
12
|
+
const VirtualPadMoveButtonCodes = [
|
|
13
13
|
"BUTTON_LEFT",
|
|
14
14
|
"BUTTON_UP",
|
|
15
15
|
"BUTTON_RIGHT",
|
|
16
16
|
"BUTTON_DOWN"
|
|
17
17
|
];
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (firstVisible === void 0) { firstVisible = false; }
|
|
22
|
-
if (buttonWrapper === void 0) { buttonWrapper = null; }
|
|
23
|
-
if (moveButtons === void 0) { moveButtons = null; }
|
|
24
|
-
if (onTouchStart === void 0) { onTouchStart = null; }
|
|
25
|
-
if (onTouchEnd === void 0) { onTouchEnd = null; }
|
|
26
|
-
var _this = this;
|
|
18
|
+
const VirtualPadMoveButtonsSet = new Set(VirtualPadMoveButtonCodes);
|
|
19
|
+
export default class VirtualPadStore {
|
|
20
|
+
constructor(buttons, firstVisible = false, buttonWrapper = null, moveButtons = null, onTouchStart = null, onTouchEnd = null) {
|
|
27
21
|
this._enabled = buttons !== null;
|
|
28
22
|
this._visible = firstVisible;
|
|
29
23
|
this._onTouchStart = onTouchStart || null;
|
|
@@ -42,65 +36,61 @@ var VirtualPadStore = (function () {
|
|
|
42
36
|
if (buttons === null) {
|
|
43
37
|
return;
|
|
44
38
|
}
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
for (const buttonTypeString in buttons) {
|
|
40
|
+
const button = buttons[buttonTypeString];
|
|
47
41
|
if (!button) {
|
|
48
|
-
|
|
42
|
+
continue;
|
|
49
43
|
}
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
const buttonCode = buttonTypeString;
|
|
45
|
+
this._availableButtons.push(buttonCode);
|
|
52
46
|
button.setAttribute("type", buttonTypeString);
|
|
53
|
-
|
|
47
|
+
this._isTouchingButtons[buttonCode] = {
|
|
54
48
|
prev: false,
|
|
55
49
|
current: false,
|
|
56
50
|
next: false
|
|
57
51
|
};
|
|
58
|
-
|
|
52
|
+
const cancelBrowserTouchEvent = (event) => {
|
|
59
53
|
if (event.cancelable) {
|
|
60
54
|
event.preventDefault();
|
|
61
55
|
}
|
|
62
56
|
};
|
|
63
|
-
|
|
57
|
+
const cancelVirtualPad = (event) => {
|
|
64
58
|
cancelBrowserTouchEvent(event);
|
|
65
|
-
|
|
59
|
+
this.allClear();
|
|
66
60
|
};
|
|
67
|
-
button.addEventListener("touchstart",
|
|
61
|
+
button.addEventListener("touchstart", (event) => {
|
|
68
62
|
cancelBrowserTouchEvent(event);
|
|
69
|
-
|
|
63
|
+
this.setTouchInfo(buttonCode);
|
|
70
64
|
});
|
|
71
65
|
button.addEventListener("touchcancel", cancelVirtualPad);
|
|
72
66
|
if (VirtualPadStore.isMoveButton(buttonCode)) {
|
|
73
|
-
button.addEventListener("touchmove",
|
|
74
|
-
button.addEventListener("touchend",
|
|
67
|
+
button.addEventListener("touchmove", this._detectMovingMoveButton.bind(this));
|
|
68
|
+
button.addEventListener("touchend", this.allMoveClear.bind(this));
|
|
75
69
|
}
|
|
76
70
|
else {
|
|
77
|
-
button.addEventListener("touchend",
|
|
71
|
+
button.addEventListener("touchend", (event) => {
|
|
78
72
|
cancelBrowserTouchEvent(event);
|
|
79
|
-
|
|
73
|
+
this.clearTouchInfo(buttonCode);
|
|
80
74
|
});
|
|
81
75
|
}
|
|
82
|
-
};
|
|
83
|
-
var this_1 = this;
|
|
84
|
-
for (var buttonTypeString in buttons) {
|
|
85
|
-
_loop_1(buttonTypeString);
|
|
86
76
|
}
|
|
87
77
|
if (moveButtons !== null) {
|
|
88
78
|
moveButtons.addEventListener("touchmove", this._detectMovingMoveButton.bind(this));
|
|
89
79
|
}
|
|
90
80
|
}
|
|
91
|
-
|
|
81
|
+
_detectMovingMoveButton(event) {
|
|
92
82
|
event.preventDefault();
|
|
93
83
|
this.allMoveClear();
|
|
94
|
-
|
|
84
|
+
const touch = event.targetTouches.item(0);
|
|
95
85
|
if (!this._moveButtonsElement || touch === null) {
|
|
96
86
|
return;
|
|
97
87
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
88
|
+
const moveButtonRect = this._moveButtonsElement.getBoundingClientRect();
|
|
89
|
+
const bodyRect = document.body.getBoundingClientRect();
|
|
90
|
+
const centerPositionX = moveButtonRect.left - bodyRect.left + (moveButtonRect.width / 2);
|
|
91
|
+
const centerPositionY = moveButtonRect.top - bodyRect.top + (moveButtonRect.height / 2);
|
|
92
|
+
const touchX = touch.pageX - centerPositionX;
|
|
93
|
+
const touchY = touch.pageY - centerPositionY;
|
|
104
94
|
if (touchX >= touchY) {
|
|
105
95
|
if (touchX <= -touchY) {
|
|
106
96
|
this.setTouchInfo("BUTTON_UP");
|
|
@@ -117,8 +107,8 @@ var VirtualPadStore = (function () {
|
|
|
117
107
|
this.setTouchInfo("BUTTON_LEFT");
|
|
118
108
|
}
|
|
119
109
|
}
|
|
120
|
-
}
|
|
121
|
-
|
|
110
|
+
}
|
|
111
|
+
_setVisible(visible) {
|
|
122
112
|
if (this._moveButtonsElement !== null) {
|
|
123
113
|
this._moveButtonsElement.style.display = visible ? "grid" : "none";
|
|
124
114
|
}
|
|
@@ -126,28 +116,28 @@ var VirtualPadStore = (function () {
|
|
|
126
116
|
this._buttonWrapperElement.style.display = visible ? "grid" : "none";
|
|
127
117
|
}
|
|
128
118
|
this._visible = visible;
|
|
129
|
-
}
|
|
130
|
-
|
|
119
|
+
}
|
|
120
|
+
checkTouchButton(buttonType) {
|
|
131
121
|
if (!this._enabled) {
|
|
132
122
|
return false;
|
|
133
123
|
}
|
|
134
|
-
|
|
124
|
+
const state = this.getButtonState(buttonType);
|
|
135
125
|
return state === "TOUCH";
|
|
136
|
-
}
|
|
137
|
-
|
|
126
|
+
}
|
|
127
|
+
checkTouchingButton(buttonType) {
|
|
138
128
|
if (!this._enabled) {
|
|
139
129
|
return false;
|
|
140
130
|
}
|
|
141
|
-
|
|
131
|
+
const state = this.getButtonState(buttonType);
|
|
142
132
|
return state === "TOUCH" || state === "TOUCHING";
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
133
|
+
}
|
|
134
|
+
getButtonState(buttonType) {
|
|
135
|
+
const button = this._isTouchingButtons[buttonType];
|
|
146
136
|
if (!this._enabled || button === undefined) {
|
|
147
137
|
return "NONE";
|
|
148
138
|
}
|
|
149
|
-
|
|
150
|
-
|
|
139
|
+
const touched = button.prev;
|
|
140
|
+
const isTouching = button.current;
|
|
151
141
|
if (touched && isTouching) {
|
|
152
142
|
return "TOUCHING";
|
|
153
143
|
}
|
|
@@ -158,69 +148,64 @@ var VirtualPadStore = (function () {
|
|
|
158
148
|
return "LEAVE";
|
|
159
149
|
}
|
|
160
150
|
return "NONE";
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
151
|
+
}
|
|
152
|
+
setTouchInfo(buttonType) {
|
|
153
|
+
const button = this._isTouchingButtons[buttonType];
|
|
164
154
|
if (!this._enabled || button === undefined) {
|
|
165
155
|
return;
|
|
166
156
|
}
|
|
167
157
|
button.next = true;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
158
|
+
}
|
|
159
|
+
clearTouchInfo(buttonType) {
|
|
160
|
+
const button = this._isTouchingButtons[buttonType];
|
|
171
161
|
if (!this._enabled || button === undefined) {
|
|
172
162
|
return;
|
|
173
163
|
}
|
|
174
164
|
button.next = false;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
_this.clearTouchInfo(buttonCode);
|
|
165
|
+
}
|
|
166
|
+
allMoveClear() {
|
|
167
|
+
VirtualPadMoveButtonCodes.forEach((buttonCode) => {
|
|
168
|
+
if (this._availableButtons.includes(buttonCode)) {
|
|
169
|
+
this.clearTouchInfo(buttonCode);
|
|
181
170
|
}
|
|
182
171
|
});
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
this._availableButtons.forEach(function (buttonCode) {
|
|
172
|
+
}
|
|
173
|
+
allClear() {
|
|
174
|
+
this._availableButtons.forEach((buttonCode) => {
|
|
187
175
|
if (buttonCode !== undefined) {
|
|
188
|
-
|
|
176
|
+
const button = this._isTouchingButtons[buttonCode];
|
|
189
177
|
if (button !== undefined) {
|
|
190
178
|
button.next = false;
|
|
191
179
|
}
|
|
192
180
|
}
|
|
193
181
|
});
|
|
194
|
-
}
|
|
195
|
-
|
|
182
|
+
}
|
|
183
|
+
static isMoveButton(buttonType) {
|
|
196
184
|
return VirtualPadMoveButtonsSet.has(buttonType);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
this._availableButtons.forEach(function (buttonCode) {
|
|
185
|
+
}
|
|
186
|
+
update() {
|
|
187
|
+
this._availableButtons.forEach((buttonCode) => {
|
|
201
188
|
var _a, _b;
|
|
202
189
|
if (buttonCode === undefined) {
|
|
203
190
|
return;
|
|
204
191
|
}
|
|
205
|
-
|
|
192
|
+
const currentButtonTouching = this._isTouchingButtons[buttonCode];
|
|
206
193
|
if (currentButtonTouching === undefined) {
|
|
207
194
|
return;
|
|
208
195
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
switch (
|
|
196
|
+
this._isTouchingButtons[buttonCode].prev = currentButtonTouching.current;
|
|
197
|
+
this._isTouchingButtons[buttonCode].current = currentButtonTouching.next;
|
|
198
|
+
switch (this.getButtonState(buttonCode)) {
|
|
212
199
|
case "TOUCH":
|
|
213
|
-
(_a =
|
|
200
|
+
(_a = this._onTouchStart) === null || _a === void 0 ? void 0 : _a.call(this, buttonCode);
|
|
214
201
|
break;
|
|
215
202
|
case "LEAVE":
|
|
216
|
-
(_b =
|
|
203
|
+
(_b = this._onTouchEnd) === null || _b === void 0 ? void 0 : _b.call(this, buttonCode);
|
|
217
204
|
break;
|
|
218
205
|
}
|
|
219
206
|
});
|
|
220
|
-
}
|
|
221
|
-
|
|
207
|
+
}
|
|
208
|
+
toggleVisible() {
|
|
222
209
|
this._setVisible(!this._visible);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
}());
|
|
226
|
-
export default VirtualPadStore;
|
|
210
|
+
}
|
|
211
|
+
}
|
package/lib/makeInject.js
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
1
|
export default function makeInject() {
|
|
2
|
-
return
|
|
2
|
+
return `
|
|
3
|
+
<div id="wwa-virtualpad-left">
|
|
4
|
+
<button class="wwa-virtualpad__button" id="wwa-up-button"></button>
|
|
5
|
+
<button class="wwa-virtualpad__button" id="wwa-left-button"></button>
|
|
6
|
+
<button class="wwa-virtualpad__button" id="wwa-right-button"></button>
|
|
7
|
+
<button class="wwa-virtualpad__button" id="wwa-down-button"></button>
|
|
8
|
+
<div class="wwa-virtualpad__hole"></div>
|
|
9
|
+
</div>
|
|
10
|
+
<div id="wwa-virtualpad-right">
|
|
11
|
+
<button class="wwa-virtualpad__button" id="wwa-slow-button">I</button>
|
|
12
|
+
<button class="wwa-virtualpad__button" id="wwa-fast-button">P</button>
|
|
13
|
+
<button class="wwa-virtualpad__button" id="wwa-enter-button">Y</button>
|
|
14
|
+
<button class="wwa-virtualpad__button" id="wwa-esc-button">N</button>
|
|
15
|
+
</div>`;
|
|
3
16
|
}
|
package/lib/viewportFit.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
export function initializeViewport() {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const headElement = document.getElementsByTagName('head')[0];
|
|
3
|
+
let viewportElement = document.createElement('meta');
|
|
4
4
|
viewportElement.setAttribute('name', 'viewport');
|
|
5
5
|
headElement.appendChild(viewportElement);
|
|
6
6
|
viewportFit();
|
|
7
7
|
}
|
|
8
8
|
export default function viewportFit() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
const WWA_WIDTH = 560;
|
|
10
|
+
const WWA_HEIGHT = 440;
|
|
11
|
+
const BROWSER_MARGIN = 8;
|
|
12
|
+
const viewportElement = document.querySelector("meta[name='viewport']");
|
|
13
|
+
const browserWidth = window.innerWidth;
|
|
14
|
+
const browserHeight = window.innerHeight;
|
|
15
|
+
let viewportValue = "user-scalable=no";
|
|
16
16
|
if (browserWidth > browserHeight) {
|
|
17
|
-
|
|
18
|
-
viewportValue =
|
|
17
|
+
const width = Math.floor((browserWidth / browserHeight) * (WWA_HEIGHT + (BROWSER_MARGIN) * 2));
|
|
18
|
+
viewportValue = `width=${width},${viewportValue}`;
|
|
19
19
|
}
|
|
20
20
|
else if (browserWidth <= browserHeight) {
|
|
21
|
-
viewportValue =
|
|
21
|
+
viewportValue = `width=${WWA_WIDTH + (BROWSER_MARGIN * 2)},${viewportValue}`;
|
|
22
22
|
}
|
|
23
|
-
viewportElement === null || viewportElement === void 0 ? void 0 : viewportElement.setAttribute("content",
|
|
23
|
+
viewportElement === null || viewportElement === void 0 ? void 0 : viewportElement.setAttribute("content", `${viewportValue}`);
|
|
24
24
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wwawing/virtual-pad",
|
|
3
|
-
"version": "3.12.
|
|
3
|
+
"version": "3.12.14",
|
|
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": "
|
|
19
|
+
"gitHead": "a4289ff989f8b50056ddaa56fafce2bdcd794823"
|
|
20
20
|
}
|