-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathgamepads.json
More file actions
3551 lines (3551 loc) · 142 KB
/
gamepads.json
File metadata and controls
3551 lines (3551 loc) · 142 KB
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"author": "Bouh",
"category": "Input",
"extensionNamespace": "",
"fullName": "Gamepads (controllers)",
"helpPath": "/all-features/gamepad",
"iconUrl": "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0ibWRpLWdhbWVwYWQtdmFyaWFudC1vdXRsaW5lIiB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZD0iTTYsOUg4VjExSDEwVjEzSDhWMTVINlYxM0g0VjExSDZWOU0xOC41LDlBMS41LDEuNSAwIDAsMSAyMCwxMC41QTEuNSwxLjUgMCAwLDEgMTguNSwxMkExLjUsMS41IDAgMCwxIDE3LDEwLjVBMS41LDEuNSAwIDAsMSAxOC41LDlNMTUuNSwxMkExLjUsMS41IDAgMCwxIDE3LDEzLjVBMS41LDEuNSAwIDAsMSAxNS41LDE1QTEuNSwxLjUgMCAwLDEgMTQsMTMuNUExLjUsMS41IDAgMCwxIDE1LjUsMTJNMTcsNUE3LDcgMCAwLDEgMjQsMTJBNyw3IDAgMCwxIDE3LDE5QzE1LjA0LDE5IDEzLjI3LDE4LjIgMTIsMTYuOUMxMC43MywxOC4yIDguOTYsMTkgNywxOUE3LDcgMCAwLDEgMCwxMkE3LDcgMCAwLDEgNyw1SDE3TTcsN0E1LDUgMCAwLDAgMiwxMkE1LDUgMCAwLDAgNywxN0M4LjY0LDE3IDEwLjA5LDE2LjIxIDExLDE1SDEzQzEzLjkxLDE2LjIxIDE1LjM2LDE3IDE3LDE3QTUsNSAwIDAsMCAyMiwxMkE1LDUgMCAwLDAgMTcsN0g3WiIgLz48L3N2Zz4=",
"name": "Gamepads",
"previewIconUrl": "https://resources.gdevelop-app.com/assets/Icons/gamepad-variant-outline.svg",
"shortDescription": "Add support for gamepads (or other controllers) to your game, giving access to information such as button presses, axis positions, trigger pressure, etc...",
"version": "0.6.1",
"description": [
"Add support for gamepads (or other controllers).",
"",
"It gives access to:",
"- button presses",
"- axis positions and force",
"- trigger pressure",
"- configurable deadzone",
"- vibration",
"- automatic mappers for platformer characters and top-down movement",
"",
"The Bomberman-like example handles 4 players with gamepads ([open the project online](https://editor.gdevelop.io/?project=example://goose-bomberman))."
],
"origin": {
"identifier": "Gamepads",
"name": "gdevelop-extension-store"
},
"tags": [
"controllers",
"gamepads",
"joysticks",
"axis",
"xbox",
"ps4",
"platformer",
"platform",
"top-down"
],
"authorIds": [
"2OwwM8ToR9dx9RJ2sAKTcrLmCB92",
"taRwmWxwAFYFL9yyBwB3cwBw0BO2",
"mnImQKdn8nQxwzkS5D6a1JB27V23"
],
"dependencies": [],
"eventsFunctions": [
{
"description": "Get the value of the pressure on a gamepad trigger.",
"fullName": "Pressure on a gamepad trigger",
"functionType": "Expression",
"name": "TriggerPressure",
"sentence": "Player _PARAM1_ push axis _PARAM2_ to _PARAM3_",
"events": [
{
"type": "BuiltinCommonInstructions::JsCode",
"inlineCode": [
"/** @type {Gamepad[]} */\r",
"const gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);\r",
"\r",
"//Get function parameters\r",
"const playerId = eventsFunctionContext.getArgument(\"player_ID\") - 1;\r",
"const trigger = eventsFunctionContext.getArgument(\"trigger\").toUpperCase();\r",
"\r",
"if (playerId < 0 || playerId > 4) {\r",
" console.error('Parameter gamepad identifier in expression: \"Pressure on a gamepad trigger\", is not valid number, must be between 0 and 4.');\r",
" return;\r",
"}\r",
"if (trigger != \"LT\" && trigger != \"RT\" && trigger != \"L2\" && trigger != \"R2\") {\r",
" console.error('Parameter trigger is not valid in expression: \"Pressure on a gamepad trigger\"');\r",
" return;\r",
"}\r",
"\r",
"const gamepad = gamepads[playerId];\r",
"\r",
"//we need keep this condition because when use have not yet plug her controller we can't get the controller in the gamepad variable.\r",
"if (gamepad == null) return;\r",
"\r",
"switch (trigger) {\r",
" case 'LT':\r",
" case 'L2':\r",
" eventsFunctionContext.returnValue = gamepad.buttons[6].value;\r",
" break;\r",
"\r",
" case 'RT':\r",
" case 'R2':\r",
" eventsFunctionContext.returnValue = gamepad.buttons[7].value;\r",
" break;\r",
"\r",
" default:\r",
" eventsFunctionContext.returnValue = -1;\r",
" break;\r",
"}"
],
"parameterObjects": "",
"useStrict": true,
"eventsSheetExpanded": true
}
],
"expressionType": {
"type": "expression"
},
"parameters": [
{
"description": "The gamepad identifier: 1, 2, 3 or 4",
"name": "player_ID",
"type": "expression"
},
{
"description": "Trigger button",
"name": "trigger",
"supplementaryInformation": "[\"LT\",\"RT\",\"L2\",\"R2\"]",
"type": "stringWithSelector"
}
],
"objectGroups": []
},
{
"description": "the force of gamepad stick (from 0 to 1).",
"fullName": "Stick force",
"functionType": "ExpressionAndCondition",
"name": "StickForce",
"sentence": "the gamepad _PARAM1_ _PARAM2_ stick force",
"events": [
{
"type": "BuiltinCommonInstructions::JsCode",
"inlineCode": [
"/** @type {Gamepad[]} */\r",
"const gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);\r",
"\r",
"//Get function parameters\r",
"const playerId = eventsFunctionContext.getArgument(\"player_ID\") - 1;\r",
"const stick = eventsFunctionContext.getArgument(\"stick\").toUpperCase();\r",
"\r",
"\r",
"if (playerId < 0 || playerId > 4) {\r",
" console.error('Parameter gamepad identifier is not valid in expression: \"Value of a stick force\"');\r",
" return;\r",
"}\r",
"\r",
"if (stick !== \"LEFT\" && stick !== \"RIGHT\") {\r",
" console.error('Parameter stick is not valid in expression: \"Value of a stick force\"');\r",
" return;\r",
"}\r",
"\r",
"const gamepad = gamepads[playerId];\r",
"\r",
"//we need keep this condition because when use have not yet plug her controller we can't get the controller in the gamepad variable.\r",
"if (gamepad == null) return;\r",
"\r",
"\r",
"switch (stick) {\r",
" case 'LEFT':\r",
" eventsFunctionContext.returnValue = gdjs.evtTools.common.clamp(Math.abs(gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[0], playerId)) + Math.abs(gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[1], playerId)), 0, 1);\r",
" break;\r",
"\r",
" case 'RIGHT':\r",
" eventsFunctionContext.returnValue = gdjs.evtTools.common.clamp(Math.abs(gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[2], playerId)) + Math.abs(gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[3], playerId)), 0, 1);\r",
" break;\r",
"\r",
" default:\r",
" eventsFunctionContext.returnValue = -1;\r",
" break;\r",
"}"
],
"parameterObjects": "",
"useStrict": true,
"eventsSheetExpanded": true
}
],
"expressionType": {
"type": "expression"
},
"parameters": [
{
"description": "The gamepad identifier: 1, 2, 3 or 4",
"name": "player_ID",
"type": "expression"
},
{
"description": "Stick: \"Left\" or \"Right\"",
"name": "stick",
"supplementaryInformation": "[\"Left\",\"Right\"]",
"type": "stringWithSelector"
}
],
"objectGroups": []
},
{
"description": "Get the rotation value of a gamepad stick.\nIf the deadzone value is high, the angle value is rounded to main axes, left, left, up, down.\nAn zero deadzone value give a total freedom on the angle value.",
"fullName": "Value of a stick rotation (deprecated)",
"functionType": "Expression",
"name": "StickRotationValue",
"private": true,
"sentence": "Player _PARAM1_ push axis _PARAM2_ to _PARAM3_",
"events": [
{
"type": "BuiltinCommonInstructions::Standard",
"conditions": [],
"actions": [
{
"type": {
"value": "SetReturnNumber"
},
"parameters": [
"Gamepads::StickAngle(GetArgumentAsNumber(\"player_ID\"), GetArgumentAsString(\"stick\"))"
]
}
]
}
],
"expressionType": {
"type": "expression"
},
"parameters": [
{
"description": "The gamepad identifier: 1, 2, 3 or 4",
"name": "player_ID",
"type": "expression"
},
{
"description": "Stick: \"Left\" or \"Right\"",
"name": "stick",
"supplementaryInformation": "[\"Left\",\"Right\"]",
"type": "stringWithSelector"
}
],
"objectGroups": []
},
{
"description": "Return the angle of a gamepad stick.\nIf the deadzone value is high, the angle value is rounded to main axes, left, left, up, down.\nAn zero deadzone value give a total freedom on the angle value.",
"fullName": "Stick angle",
"functionType": "Expression",
"name": "StickAngle",
"sentence": "",
"events": [
{
"type": "BuiltinCommonInstructions::JsCode",
"inlineCode": [
"/** @type {Gamepad[]} */\r",
"const gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);\r",
"\r",
"//Get function parameters\r",
"const playerId = eventsFunctionContext.getArgument(\"player_ID\") - 1;\r",
"const stick = eventsFunctionContext.getArgument(\"stick\").toUpperCase();\r",
"\r",
"\r",
"if (playerId < 0 || playerId > 4) {\r",
" console.error('Parameter gamepad identifier is not valid in expression: \"Value of a stick rotation\"');\r",
" return;\r",
"}\r",
"if (stick !== \"LEFT\" && stick !== \"RIGHT\") {\r",
" console.error('Parameter stick is not valid in expression: \"Value of a stick rotation\"');\r",
" return;\r",
"}\r",
"const gamepad = gamepads[playerId];\r",
"\r",
"//we need keep this condition because when use have not yet plug her controller we can't get the controller in the gamepad variable.\r",
"if (gamepad == null) return;\r",
"\r",
"switch (stick) {\r",
" case 'LEFT':\r",
" eventsFunctionContext.returnValue = gdjs._extensionController.axisToAngle(gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[0], playerId), gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[1], playerId));\r",
" break;\r",
"\r",
" case 'RIGHT':\r",
" eventsFunctionContext.returnValue = gdjs._extensionController.axisToAngle(gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[2], playerId), gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[3], playerId));\r",
" break;\r",
"\r",
" default:\r",
" eventsFunctionContext.returnValue = -1;\r",
" break;\r",
"}"
],
"parameterObjects": "",
"useStrict": true,
"eventsSheetExpanded": true
}
],
"expressionType": {
"type": "expression"
},
"parameters": [
{
"description": "The gamepad identifier: 1, 2, 3 or 4",
"name": "player_ID",
"type": "expression"
},
{
"description": "Stick: \"Left\" or \"Right\"",
"name": "stick",
"supplementaryInformation": "[\"Left\",\"Right\"]",
"type": "stringWithSelector"
}
],
"objectGroups": []
},
{
"description": "Get the value of axis of a gamepad stick.",
"fullName": "Value of a gamepad axis (deprecated)",
"functionType": "Expression",
"name": "AxisValue",
"private": true,
"sentence": "Player _PARAM1_ push axis _PARAM2_ to _PARAM3_",
"events": [
{
"type": "BuiltinCommonInstructions::JsCode",
"inlineCode": [
"/** @type {Gamepad[]} */\r",
"const gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);\r",
"\r",
"//Get function parameters\r",
"const playerId = eventsFunctionContext.getArgument(\"player_ID\") - 1;\r",
"const stick = eventsFunctionContext.getArgument(\"stick\").toUpperCase();\r",
"const direction = eventsFunctionContext.getArgument(\"direction\").toUpperCase();\r",
"\r",
"if (playerId < 0 || playerId > 4) {\r",
" console.error('Parameter gamepad identifier is not valid in expression: \"Value of a gamepad axis\"');\r",
" return;\r",
"}\r",
"if (stick != \"LEFT\" && stick != \"RIGHT\") {\r",
" console.error('Parameter stick is not valid in expression: \"Value of a gamepad axis\"');\r",
" return;\r",
"}\r",
"if (direction != \"UP\" && direction != \"DOWN\" && direction != \"LEFT\" && direction != \"RIGHT\" && direction != \"HORIZONTAL\" && direction != \"VERTICAL\") {\r",
" console.error('Parameter direction is not valid in expression: \"Value of a gamepad axis\"');\r",
" return;\r",
"}\r",
"const gamepad = gamepads[playerId];\r",
"\r",
"//we need keep this condition because when use have not yet plug her controller we can't get the controller in the gamepad variable.\r",
"if (gamepad == null) return;\r",
"\r",
"let parameterError = false;\r",
"switch (stick) {\r",
" case 'LEFT':\r",
" switch (direction) {\r",
" case 'LEFT':\r",
" if (gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[0], playerId) < 0) {\r",
" eventsFunctionContext.returnValue = -gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[0], playerId);\r",
" }\r",
" break;\r",
"\r",
" case 'RIGHT':\r",
" if (gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[0], playerId) > 0) {\r",
" eventsFunctionContext.returnValue = gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[0], playerId);\r",
" }\r",
" break;\r",
"\r",
" case 'UP':\r",
" if (gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[1], playerId) < 0) {\r",
" eventsFunctionContext.returnValue = -gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[1], playerId);\r",
" }\r",
" break;\r",
"\r",
" case 'DOWN':\r",
" if (gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[1], playerId) > 0) {\r",
" eventsFunctionContext.returnValue = gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[1], playerId);\r",
" }\r",
" break;\r",
"\r",
" case \"HORIZONTAL\":\r",
" eventsFunctionContext.returnValue = gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[0], playerId);\r",
" break;\r",
"\r",
" case \"VERTICAL\":\r",
" eventsFunctionContext.returnValue = gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[1], playerId);\r",
" break;\r",
"\r",
" default:\r",
" break;\r",
" }\r",
" break;\r",
"\r",
" case 'RIGHT':\r",
" switch (direction) {\r",
" case 'LEFT':\r",
" if (gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[2], playerId) < 0) {\r",
" eventsFunctionContext.returnValue = -gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[2], playerId);\r",
" }\r",
" break;\r",
"\r",
" case 'RIGHT':\r",
" if (gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[2], playerId) > 0) {\r",
" eventsFunctionContext.returnValue = gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[2], playerId);\r",
" }\r",
" break;\r",
"\r",
" case 'UP':\r",
" if (gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[3], playerId) < 0) {\r",
" eventsFunctionContext.returnValue = -gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[3], playerId);\r",
" }\r",
" break;\r",
"\r",
" case 'DOWN':\r",
" if (gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[3], playerId) > 0) {\r",
" eventsFunctionContext.returnValue = gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[3], playerId);\r",
" }\r",
" break;\r",
"\r",
" case \"HORIZONTAL\":\r",
" eventsFunctionContext.returnValue = gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[2], playerId);\r",
" break;\r",
"\r",
" case \"VERTICAL\":\r",
" eventsFunctionContext.returnValue = gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[3], playerId);\r",
" break;\r",
"\r",
" default:\r",
" break;\r",
" }\r",
" break;\r",
"\r",
" default:\r",
" break;\r",
"}\r",
""
],
"parameterObjects": "",
"useStrict": true,
"eventsSheetExpanded": true
}
],
"expressionType": {
"type": "expression"
},
"parameters": [
{
"description": "The gamepad identifier: 1, 2, 3 or 4",
"name": "player_ID",
"type": "expression"
},
{
"description": "Stick: \"Left\" or \"Right\"",
"name": "stick",
"supplementaryInformation": "[\"Left\",\"Right\"]",
"type": "stringWithSelector"
},
{
"description": "Direction",
"name": "direction",
"supplementaryInformation": "[\"Up\",\"Down\",\"Left\",\"Right\",\"Horizontal\",\"Vertical\"]",
"type": "stringWithSelector"
}
],
"objectGroups": []
},
{
"description": "Return the gamepad stick force on X axis (from -1 at the left to 1 at the right).",
"fullName": "Stick X force",
"functionType": "Expression",
"name": "StickForceX",
"sentence": "",
"events": [
{
"type": "BuiltinCommonInstructions::JsCode",
"inlineCode": [
"/** @type {Gamepad[]} */\r",
"const gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);\r",
"\r",
"//Get function parameters\r",
"const playerId = eventsFunctionContext.getArgument(\"Gamepad\") - 1;\r",
"const stick = eventsFunctionContext.getArgument(\"Stick\").toLowerCase();\r",
"\r",
"if (playerId < 0 || playerId > 4) {\r",
" console.error('Parameter gamepad identifier is not valid in expression: \"Value of a gamepad axis\"');\r",
" return;\r",
"}\r",
"if (stick != \"left\" && stick != \"right\") {\r",
" console.error('Parameter stick is not valid in expression: \"Value of a gamepad axis\"');\r",
" return;\r",
"}\r",
"const gamepad = gamepads[playerId];\r",
"\r",
"//we need keep this condition because when use have not yet plug her controller we can't get the controller in the gamepad variable.\r",
"if (gamepad == null) return;\r",
"\r",
"const axisIndex = stick === 'right' ? 2 : 0;\r",
"eventsFunctionContext.returnValue = gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[axisIndex], playerId);\r",
""
],
"parameterObjects": "",
"useStrict": true,
"eventsSheetExpanded": true
}
],
"expressionType": {
"type": "expression"
},
"parameters": [
{
"description": "The gamepad identifier: 1, 2, 3 or 4",
"name": "Gamepad",
"type": "expression"
},
{
"description": "Stick: \"Left\" or \"Right\"",
"name": "Stick",
"supplementaryInformation": "[\"Left\",\"Right\"]",
"type": "stringWithSelector"
}
],
"objectGroups": []
},
{
"description": "Return the gamepad stick force on Y axis (from -1 at the top to 1 at the bottom).",
"fullName": "Stick Y force",
"functionType": "Expression",
"name": "StickForceY",
"sentence": "",
"events": [
{
"type": "BuiltinCommonInstructions::JsCode",
"inlineCode": [
"/** @type {Gamepad[]} */\r",
"const gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);\r",
"\r",
"//Get function parameters\r",
"const playerId = eventsFunctionContext.getArgument(\"Gamepad\") - 1;\r",
"const stick = eventsFunctionContext.getArgument(\"Stick\").toLowerCase();\r",
"\r",
"if (playerId < 0 || playerId > 4) {\r",
" console.error('Parameter gamepad identifier is not valid in expression: \"Value of a gamepad axis\"');\r",
" return;\r",
"}\r",
"if (stick != \"left\" && stick != \"right\") {\r",
" console.error('Parameter stick is not valid in expression: \"Value of a gamepad axis\"');\r",
" return;\r",
"}\r",
"const gamepad = gamepads[playerId];\r",
"\r",
"//we need keep this condition because when use have not yet plug her controller we can't get the controller in the gamepad variable.\r",
"if (gamepad == null) return;\r",
"\r",
"const axisIndex = stick === 'right' ? 3 : 1;\r",
"eventsFunctionContext.returnValue = gdjs._extensionController.getNormalizedAxisValue(gamepad.axes[axisIndex], playerId);\r",
""
],
"parameterObjects": "",
"useStrict": true,
"eventsSheetExpanded": true
}
],
"expressionType": {
"type": "expression"
},
"parameters": [
{
"description": "The gamepad identifier: 1, 2, 3 or 4",
"name": "Gamepad",
"type": "expression"
},
{
"description": "Stick: \"Left\" or \"Right\"",
"name": "Stick",
"supplementaryInformation": "[\"Left\",\"Right\"]",
"type": "stringWithSelector"
}
],
"objectGroups": []
},
{
"description": "Test if a button is released on a gamepad. Buttons can be:\n* Xbox: \"A\", \"B\", \"X\", \"Y\", \"LB\", \"RB\", \"LT\", \"RT\", \"BACK\", \"START\",\n* PS4: \"CROSS\", \"SQUARE\", \"CIRCLE\", \"TRIANGLE\", \"L1\", \"L2\", \"R1\", \"R2\", \"SHARE\", \"OPTIONS\", \"PS_BUTTON\", \"CLICK_TOUCHPAD\",\n* Other: \"UP\", \"DOWN\", \"LEFT\", \"RIGHT\", \"CLICK_STICK_LEFT\", \"CLICK_STICK_RIGHT\".",
"fullName": "Gamepad button released",
"functionType": "Condition",
"name": "C_Button_released",
"sentence": "Button _PARAM2_ of gamepad _PARAM1_ is released",
"events": [
{
"type": "BuiltinCommonInstructions::JsCode",
"inlineCode": [
"/** @type {Gamepad[]} */\r",
"const gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);\r",
"\r",
"//Get function parameters\r",
"const playerId = eventsFunctionContext.getArgument(\"player_ID\") - 1;\r",
"const button = eventsFunctionContext.getArgument(\"button\").toUpperCase();\r",
"\r",
"if (playerId < 0 || playerId > 4) {\r",
" console.error('Parameter gamepad identifier in condition: \"Gamepad button released\", is not valid number, must be between 0 and 4.');\r",
" return;\r",
"}\r",
"if (button === \"\") {\r",
" console.error('Parameter button is not valid in condition: \"Gamepad button released\"');\r",
" return;\r",
"}\r",
"\r",
"const gamepad = gamepads[playerId];\r",
"\r",
"//we need keep this condition because when use have not yet plug her controller we can't get the controller in the gamepad variable.\r",
"if (gamepad == null) return;\r",
"\r",
"let buttonId;\r",
"\r",
"switch (button) {\r",
" case 'A':\r",
" case 'CROSS':\r",
" buttonId = 0;\r",
" break;\r",
" case 'B':\r",
" case 'CIRCLE':\r",
" buttonId = 1;\r",
" break;\r",
" case 'X':\r",
" case 'SQUARE':\r",
" buttonId = 2;\r",
" break;\r",
" case 'Y':\r",
" case 'TRIANGLE':\r",
" buttonId = 3;\r",
" break;\r",
" case 'LB':\r",
" case 'L1':\r",
" buttonId = 4;\r",
" break;\r",
" case 'RB':\r",
" case 'R1':\r",
" buttonId = 5;\r",
" break;\r",
" case 'LT':\r",
" case 'L2':\r",
" buttonId = 6;\r",
" break;\r",
" case 'RT':\r",
" case 'R2':\r",
" buttonId = 7;\r",
" break;\r",
"\r",
" case 'UP':\r",
" buttonId = 12;\r",
" break;\r",
" case 'DOWN':\r",
" buttonId = 13;\r",
" break;\r",
" case 'LEFT':\r",
" buttonId = 14;\r",
" break;\r",
" case 'RIGHT':\r",
" buttonId = 15;\r",
" break;\r",
"\r",
" case 'BACK':\r",
" case 'SHARE':\r",
" buttonId = 8;\r",
" break;\r",
" case 'START':\r",
" case 'OPTIONS':\r",
" buttonId = 9;\r",
" break;\r",
"\r",
" case 'CLICK_STICK_LEFT':\r",
" buttonId = 10;\r",
" break;\r",
" case 'CLICK_STICK_RIGHT':\r",
" buttonId = 11;\r",
" break;\r",
"\r",
" //PS4\r",
" case 'PS_BUTTON':\r",
" buttonId = 16;\r",
" break;\r",
" case 'CLICK_TOUCHPAD':\r",
" buttonId = 17;\r",
" break;\r",
"\r",
" default:\r",
" console.error('The button: ' + button + ' in condition: \"Gamepad button released\" is not valid.');\r",
" break;\r",
"}\r",
"\r",
"if (buttonId === undefined) {\r",
" console.error('There is no buttons valid in condition: \"Gamepad button released\"');\r",
" eventsFunctionContext.returnValue = false;\r",
" return;\r",
"}\r",
"\r",
"if (gamepad.buttons == null || gamepad.buttons[buttonId] == null) {\r",
" console.error('Buttons on the gamepad are not accessible in condition: \"Gamepad button released\"');\r",
" eventsFunctionContext.returnValue = false;\r",
" return;\r",
"}\r",
"\r",
"//Define default value on pressed button or use previous value\r",
"gdjs._extensionController.players[playerId].previousFrameStateButtons[buttonId] = gdjs._extensionController.players[playerId].previousFrameStateButtons[buttonId] || { pressed: false };\r",
"\r",
"//Get state of button at previous frame\r",
"const previousStateButton = gdjs._extensionController.players[playerId].previousFrameStateButtons[buttonId].pressed;\r",
"\r",
"//When previousStateButton is true and actual button state is not pressed\r",
"//Player have release the button\r",
"if (previousStateButton === true && gamepad.buttons[buttonId].pressed === false) {\r",
" // Save the last button used for the player \r",
" gdjs._extensionController.players[playerId].lastButtonUsed = buttonId;\r",
" gdjs._extensionController.players[playerId].previousFrameStateButtons[buttonId].pressed = true;\r",
" eventsFunctionContext.returnValue = true;\r",
"\r",
"} else {\r",
" gdjs._extensionController.players[playerId].previousFrameStateButtons[buttonId].pressed = false;\r",
" eventsFunctionContext.returnValue = false;\r",
"}\r",
""
],
"parameterObjects": "",
"useStrict": true,
"eventsSheetExpanded": true
}
],
"parameters": [
{
"description": "The gamepad identifier: 1, 2, 3 or 4",
"name": "player_ID",
"type": "expression"
},
{
"description": "Name of the button",
"name": "button",
"supplementaryInformation": "[\"A\",\"Cross\",\"B\",\"Circle\",\"X\",\"Square\",\"Y\",\"Triangle\",\"LB\",\"L1\",\"RB\",\"R1\",\"LT\",\"L2\",\"RT\",\"R2\",\"Up\",\"Down\",\"Left\",\"Right\",\"Back\",\"Share\",\"Start\",\"Options\",\"Click_Stick_Left\",\"Click_Stick_Right\",\"PS_Button\",\"Click_Touchpad\"]",
"type": "stringWithSelector"
}
],
"objectGroups": []
},
{
"description": "Return the index of the last pressed button of a gamepad.",
"fullName": "Last pressed button (id)",
"functionType": "Expression",
"name": "LastButtonID",
"sentence": "",
"events": [
{
"type": "BuiltinCommonInstructions::JsCode",
"inlineCode": [
"//Get function parameter\r",
"const playerId = eventsFunctionContext.getArgument(\"player_ID\") - 1;\r",
"\r",
"//Player id is not valid\r",
"if (playerId < 0 || playerId > 4) {\r",
" console.error('Parameter gamepad identifier in expression: \"Last pressed button (id)\", is not valid number, must be between 0 and 4.');\r",
" return;\r",
"}\r",
"\r",
"//Return the last button used by the player\r",
"eventsFunctionContext.returnValue = gdjs._extensionController.players[playerId].lastButtonUsed;"
],
"parameterObjects": "",
"useStrict": true,
"eventsSheetExpanded": true
}
],
"expressionType": {
"type": "expression"
},
"parameters": [
{
"description": "The gamepad identifier: 1, 2, 3 or 4",
"name": "player_ID",
"type": "expression"
}
],
"objectGroups": []
},
{
"description": "Check if any button is pressed on a gamepad.",
"fullName": "Any gamepad button pressed",
"functionType": "Condition",
"name": "C_Any_Button_pressed",
"sentence": "Any button of gamepad _PARAM1_ is pressed",
"events": [
{
"type": "BuiltinCommonInstructions::JsCode",
"inlineCode": [
"/** @type {Gamepad[]} */\r",
"const gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);\r",
"\r",
"//Get function parameter\r",
"const playerId = eventsFunctionContext.getArgument(\"player_ID\") - 1;\r",
"\r",
"if (playerId < 0 || playerId > 4) {\r",
" console.error('Parameter gamepad identifier in condition: \"Any gamepad button pressed\", is not valid number, must be between 0 and 4.');\r",
" return;\r",
"}\r",
"const gamepad = gamepads[playerId];\r",
"\r",
"//we need keep this condition because when use have not yet plug her controller we can't get the controller in the gamepad variable.\r",
"if (gamepad == null) return;\r",
"\r",
"let buttonId;\r",
"for (let i = 0; i < gamepad.buttons.length; i++) { //For each buttons\r",
" if (gamepad.buttons[i].pressed) { //One of them is pressed\r",
" buttonId = i; //Save the button pressed\r",
" break;\r",
" }\r",
"}\r",
"\r",
"if (buttonId === undefined) {\r",
" // No buttons are pressed.\r",
" eventsFunctionContext.returnValue = false;\r",
" return;\r",
"}\r",
"\r",
"if (gamepad.buttons == null || gamepad.buttons[buttonId] == null) {\r",
" console.error('Buttons on the gamepad are not accessible in condition: \"Any gamepad button pressed\"');\r",
" eventsFunctionContext.returnValue = false;\r",
" return;\r",
"}\r",
"\r",
"//When a button is pressed, save the button in lastButtonUsed for each players\r",
"if (gamepad.buttons[buttonId].pressed) gdjs._extensionController.players[playerId].lastButtonUsed = buttonId;\r",
"eventsFunctionContext.returnValue = gamepad.buttons[buttonId].pressed;\r",
"\r",
"\r",
""
],
"parameterObjects": "",
"useStrict": true,
"eventsSheetExpanded": true
}
],
"parameters": [
{
"description": "The gamepad identifier: 1, 2, 3 or 4",
"name": "player_ID",
"type": "expression"
}
],
"objectGroups": []
},
{
"description": "Return the last button pressed. \nButtons for Xbox and PS4 can be:\n* Xbox: \"A\", \"B\", \"X\", \"Y\", \"LB\", \"RB\", \"LT\", \"RT\", \"BACK\", \"START\",\n* PS4: \"CROSS\", \"SQUARE\", \"CIRCLE\", \"TRIANGLE\", \"L1\", \"L2\", \"R1\", \"R2\", \"SHARE\", \"OPTIONS\", \"PS_BUTTON\", \"CLICK_TOUCHPAD\",\n* Both: \"UP\", \"DOWN\", \"LEFT\", \"RIGHT\", \"CLICK_STICK_LEFT\", \"CLICK_STICK_RIGHT\".",
"fullName": "Last pressed button (string)",
"functionType": "StringExpression",
"name": "LastButtonString",
"sentence": "Button _PARAM2_ of gamepad _PARAM1_ is pressed",
"events": [
{
"type": "BuiltinCommonInstructions::JsCode",
"inlineCode": [
"/** @type {Gamepad[]} */\r",
"const gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);\r",
"\r",
"//Get function parameters\r",
"const playerId = eventsFunctionContext.getArgument(\"player_ID\") - 1;\r",
"const controllerType = eventsFunctionContext.getArgument(\"controller_type\").toUpperCase();\r",
"\r",
"if (playerId < 0 || playerId > 4) {\r",
" console.error('Parameter gamepad identifier in string expression: \"Last pressed button (LastButtonString)\", is not valid number, must be between 0 and 4.');\r",
" return;\r",
"}\r",
"if (controllerType === \"\") {\r",
" console.error('Parameter controller type is not valid in string expression: \"Last pressed button (LastButtonString)\"');\r",
" return;\r",
"}\r",
"\r",
"const gamepad = gamepads[playerId];\r",
"\r",
"if (gamepad !== null) { //Gamepad exist\r",
" //Get last btn id\r",
" const lastButtonUsedID = gdjs._extensionController.players[playerId].lastButtonUsed;\r",
"\r",
" //Return last button as string \r",
" eventsFunctionContext.returnValue = gdjs._extensionController.getInputString(controllerType, lastButtonUsedID);\r",
"\r",
"} else { //Gamepad dosen't exist\r",
" console.error('Your controller is not supported or the gamepad wasn\\'t detected in string expression: \"Last pressed button (LastButtonString)\"');\r",
" eventsFunctionContext.returnValue = \"Gamepad not connected\";\r",
"}"
],
"parameterObjects": "",
"useStrict": true,
"eventsSheetExpanded": true
}
],
"expressionType": {
"type": "string"
},
"parameters": [
{
"description": "The gamepad identifier: 1, 2, 3 or 4",
"name": "player_ID",
"type": "expression"
},
{
"description": "Controller type",
"name": "controller_type",
"supplementaryInformation": "[\"Xbox\",\"PS4\"]",
"type": "stringWithSelector"
}
],
"objectGroups": []
},
{
"description": "Return the number of gamepads.",
"fullName": "Gamepad count",
"functionType": "Expression",
"name": "GamepadCount",
"sentence": "",
"events": [
{
"type": "BuiltinCommonInstructions::JsCode",
"inlineCode": [
"const gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);\r",
"\r",
"//Get the last activated controller\r",
"const controllerId = gdjs._extensionController.lastActiveController;\r",
"\r",
"// Check if controller is active\r",
"const gamepad = gamepads[controllerId];\r",
"if (gamepad == null) {\r",
" eventsFunctionContext.returnValue = 0;\r",
"} else {\r",
" // Return active controller id\r",
" eventsFunctionContext.returnValue = controllerId + 1;\r",
"}\r",
""
],
"parameterObjects": "",
"useStrict": true,
"eventsSheetExpanded": true
}
],
"expressionType": {
"type": "expression"
},
"parameters": [],
"objectGroups": []
},
{
"description": "Check if a button is pressed on a gamepad. \nButtons can be:\n* Xbox: \"A\", \"B\", \"X\", \"Y\", \"LB\", \"RB\", \"LT\", \"RT\", \"BACK\", \"START\",\n* PS4: \"CROSS\", \"SQUARE\", \"CIRCLE\", \"TRIANGLE\", \"L1\", \"L2\", \"R1\", \"R2\", \"SHARE\", \"OPTIONS\", \"PS_BUTTON\", \"CLICK_TOUCHPAD\",\n* Other: \"UP\", \"DOWN\", \"LEFT\", \"RIGHT\", \"CLICK_STICK_LEFT\", \"CLICK_STICK_RIGHT\".",
"fullName": "Gamepad button pressed",
"functionType": "Condition",
"name": "C_Button_pressed",
"sentence": "Button _PARAM2_ of gamepad _PARAM1_ is pressed",
"events": [
{
"type": "BuiltinCommonInstructions::JsCode",
"inlineCode": [
"/** @type {Gamepad[]} */\r",
"const gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);\r",
"\r",
"//Get function parameters\r",
"const playerId = eventsFunctionContext.getArgument(\"player_ID\") - 1;\r",
"const button = eventsFunctionContext.getArgument(\"button\").toUpperCase();\r",
"\r",
"if (playerId < 0 || playerId > 4) {\r",
" console.error('Parameter gamepad identifier in condition: \"Gamepad button pressed\", is not valid number, must be between 0 and 4.');\r",
" return;\r",
"}\r",
"if (button === \"\") {\r",
" console.error('Parameter button is not valid in condition: \"Gamepad button pressed\"');\r",
" eventsFunctionContext.returnValue = false;\r",
" return;\r",
"}\r",
"\r",
"const gamepad = gamepads[playerId];\r",
"\r",
"//we need keep this condition because when use have not yet plug her controller we can't get the controller in the gamepad variable.\r",
"if (gamepad == null) return;\r",
"\r",
"let buttonId;\r",
"\r",
"switch (button) {\r",
" case 'A':\r",
" case 'CROSS':\r",
" buttonId = 0;\r",
" break;\r",
" case 'B':\r",
" case 'CIRCLE':\r",
" buttonId = 1;\r",
" break;\r",
" case 'X':\r",
" case 'SQUARE':\r",
" buttonId = 2;\r",
" break;\r",
" case 'Y':\r",
" case 'TRIANGLE':\r",
" buttonId = 3;\r",
" break;\r",
" case 'LB':\r",
" case 'L1':\r",
" buttonId = 4;\r",
" break;\r",
" case 'RB':\r",
" case 'R1':\r",
" buttonId = 5;\r",
" break;\r",
" case 'LT':\r",
" case 'L2':\r",
" buttonId = 6;\r",
" break;\r",
" case 'RT':\r",
" case 'R2':\r",
" buttonId = 7;\r",
" break;\r",
"\r",
" case 'UP':\r",
" buttonId = 12;\r",
" break;\r",
" case 'DOWN':\r",
" buttonId = 13;\r",
" break;\r",
" case 'LEFT':\r",