-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdjs-evtsext__gamepads__c_axis_pushed-func.js
224 lines (187 loc) · 7.75 KB
/
gdjs-evtsext__gamepads__c_axis_pushed-func.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
if (typeof gdjs.evtsExt__Gamepads__C_Axis_pushed !== "undefined") {
gdjs.evtsExt__Gamepads__C_Axis_pushed.registeredGdjsCallbacks.forEach(callback =>
gdjs._unregisterCallback(callback)
);
}
gdjs.evtsExt__Gamepads__C_Axis_pushed = {};
gdjs.evtsExt__Gamepads__C_Axis_pushed.conditionTrue_0 = {val:false};
gdjs.evtsExt__Gamepads__C_Axis_pushed.condition0IsTrue_0 = {val:false};
gdjs.evtsExt__Gamepads__C_Axis_pushed.userFunc0x85a038 = function(runtimeScene, eventsFunctionContext) {
"use strict";
/** @type {Gamepad[]} */
const gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);
//Get function parameters
const playerId = eventsFunctionContext.getArgument("player_ID") - 1;
const stick = eventsFunctionContext.getArgument("stick").toUpperCase();
const direction = eventsFunctionContext.getArgument("direction").toUpperCase();
if (playerId < 0 || playerId > 4) {
console.error('Parameter gamepad identifier in condition: "Gamepad stick pushed (axis)", is not valid number, must be between 0 and 4.');
return;
}
if (stick != "LEFT" && stick != "RIGHT") {
console.error('Parameter stick in condition: "Gamepad stick pushed (axis)", is not valid, must be LEFT or RIGHT');
return;
}
if (direction != "UP" && direction != "DOWN" && direction != "LEFT" && direction != "RIGHT" && direction != "ANY") {
console.error('Parameter deadzone in condition: "Gamepad stick pushed (axis)", is not valid, must be UP, DOWN, LEFT or RIGHT');
return;
}
const gamepad = gamepads[playerId];
//we need keep this condition because when use have not yet plug her controller we can't get the controller in the gamepad variable.
if (gamepad == null) {
eventsFunctionContext.returnValue = false;
return;
}
//Define in onFirstSceneLoaded function
const getNormalizedAxisValue = gdjs._extensionController.getNormalizedAxisValue;
switch (stick) {
case 'LEFT':
switch (direction) {
case 'LEFT':
if (getNormalizedAxisValue(gamepad.axes[0], playerId) < 0) {
eventsFunctionContext.returnValue = true;
return;
}
break;
case 'RIGHT':
if (getNormalizedAxisValue(gamepad.axes[0], playerId) > 0) {
eventsFunctionContext.returnValue = true;
return;
}
break;
case 'UP':
if (getNormalizedAxisValue(gamepad.axes[1], playerId) < 0) {
eventsFunctionContext.returnValue = true;
return;
}
break;
case 'DOWN':
if (getNormalizedAxisValue(gamepad.axes[1], playerId) > 0) {
eventsFunctionContext.returnValue = true;
return;
}
break;
case 'ANY':
if ( getNormalizedAxisValue(gamepad.axes[0], playerId) < 0
|| getNormalizedAxisValue(gamepad.axes[0], playerId) > 0
|| getNormalizedAxisValue(gamepad.axes[1], playerId) < 0
|| getNormalizedAxisValue(gamepad.axes[1], playerId) > 0) {
eventsFunctionContext.returnValue = true;
return;
}
break;
default:
console.error('The value Direction on stick Left on the condition: "Gamepad stick pushed (axis)" is not valid.');
eventsFunctionContext.returnValue = false;
break;
}
break;
case 'RIGHT':
switch (direction) {
case 'LEFT':
if (getNormalizedAxisValue(gamepad.axes[2], playerId) < 0) {
eventsFunctionContext.returnValue = true;
return;
}
break;
case 'RIGHT':
if (getNormalizedAxisValue(gamepad.axes[2], playerId) > 0) {
eventsFunctionContext.returnValue = true;
return;
}
break;
case 'UP':
if (getNormalizedAxisValue(gamepad.axes[3], playerId) < 0) {
eventsFunctionContext.returnValue = true;
return;
}
break;
case 'DOWN':
if (getNormalizedAxisValue(gamepad.axes[3], playerId) > 0) {
eventsFunctionContext.returnValue = true;
return;
}
break;
case 'ANY':
if ( getNormalizedAxisValue(gamepad.axes[2], playerId) < 0
|| getNormalizedAxisValue(gamepad.axes[2], playerId) > 0
|| getNormalizedAxisValue(gamepad.axes[3], playerId) < 0
|| getNormalizedAxisValue(gamepad.axes[3], playerId) > 0) {
eventsFunctionContext.returnValue = true;
return;
}
break;
default:
console.error('The value Direction on stick Right on the condition: "Gamepad stick pushed (axis)" is not valid.');
eventsFunctionContext.returnValue = false;
break;
}
break;
default:
console.error('The value Stick on the condition: "Gamepad stick pushed (axis)" is not valid.');
eventsFunctionContext.returnValue = false;
break;
}
eventsFunctionContext.returnValue = false;
};
gdjs.evtsExt__Gamepads__C_Axis_pushed.eventsList0 = function(runtimeScene, eventsFunctionContext) {
{
gdjs.evtsExt__Gamepads__C_Axis_pushed.userFunc0x85a038(runtimeScene, typeof eventsFunctionContext !== 'undefined' ? eventsFunctionContext : undefined);
}
};
gdjs.evtsExt__Gamepads__C_Axis_pushed.func = function(runtimeScene, player_ID, stick, direction, parentEventsFunctionContext) {
var eventsFunctionContext = {
_objectsMap: {
},
_objectArraysMap: {
},
_behaviorNamesMap: {
},
getObjects: function(objectName) {
return eventsFunctionContext._objectArraysMap[objectName] || [];
},
getObjectsLists: function(objectName) {
return eventsFunctionContext._objectsMap[objectName] || null;
},
getBehaviorName: function(behaviorName) {
return eventsFunctionContext._behaviorNamesMap[behaviorName] || behaviorName;
},
createObject: function(objectName) {
const objectsList = eventsFunctionContext._objectsMap[objectName];
if (objectsList) {
const object = parentEventsFunctionContext ?
parentEventsFunctionContext.createObject(objectsList.firstKey()) :
runtimeScene.createObject(objectsList.firstKey());
if (object) {
objectsList.get(objectsList.firstKey()).push(object);
eventsFunctionContext._objectArraysMap[objectName].push(object);
}
return object; }
return null;
},
getInstancesCountOnScene: function(objectName) {
const objectsList = eventsFunctionContext._objectsMap[objectName];
let count = 0;
if (objectsList) {
for(const objectName in objectsList.items)
count += parentEventsFunctionContext ?
parentEventsFunctionContext.getInstancesCountOnScene(objectName) :
runtimeScene.getInstancesCountOnScene(objectName);
}
return count;
},
getLayer: function(layerName) {
return runtimeScene.getLayer(layerName);
},
getArgument: function(argName) {
if (argName === "player_ID") return player_ID;
if (argName === "stick") return stick;
if (argName === "direction") return direction;
return "";
},
getOnceTriggers: function() { return runtimeScene.getOnceTriggers(); }
};
gdjs.evtsExt__Gamepads__C_Axis_pushed.eventsList0(runtimeScene, eventsFunctionContext);
return !!eventsFunctionContext.returnValue;
}
gdjs.evtsExt__Gamepads__C_Axis_pushed.registeredGdjsCallbacks = [];