|
9 | 9 | "name": "Gamepads", |
10 | 10 | "previewIconUrl": "https://resources.gdevelop-app.com/assets/Icons/gamepad-variant-outline.svg", |
11 | 11 | "shortDescription": "Add support for gamepads (or other controllers) to your game, giving access to information such as button presses, axis positions, trigger pressure, etc...", |
12 | | - "version": "0.9.0", |
| 12 | + "version": "0.9.1", |
13 | 13 | "description": [ |
14 | 14 | "Add support for gamepads (or other physical controllers).", |
15 | 15 | "", |
|
290 | 290 | " }\r", |
291 | 291 | "}();\r", |
292 | 292 | "\r", |
293 | | - "function onScenePostEvents() {\r", |
| 293 | + "/**\r", |
| 294 | + " * @param {gdjs.RuntimeScene} runtimeScene\r", |
| 295 | + " */\r", |
| 296 | + "function addFrameBeginningTaskIfNeeded(runtimeScene) {\r", |
| 297 | + " const taskManager = runtimeScene.getAsyncTasksManager();\r", |
| 298 | + " for (const taskWithCallback of taskManager.tasksWithCallback) {\r", |
| 299 | + " if (taskWithCallback.asyncTask === frameBeginningTask) {\r", |
| 300 | + " return;\r", |
| 301 | + " }\r", |
| 302 | + " }\r", |
| 303 | + " // Async tasks are run before everything.\r", |
| 304 | + " // This is a hack to make sure that button states are updated\r", |
| 305 | + " // before mapping behavior events.\r", |
| 306 | + " taskManager.addTask(frameBeginningTask);\r", |
| 307 | + "}\r", |
| 308 | + "\r", |
| 309 | + "/**\r", |
| 310 | + " * @param {gdjs.RuntimeScene} runtimeScene\r", |
| 311 | + " */\r", |
| 312 | + "function onScenePostEvents(runtimeScene) {\r", |
| 313 | + " addFrameBeginningTaskIfNeeded(runtimeScene);\r", |
294 | 314 | " /** @type {Gamepad[]} */\r", |
295 | 315 | " const gamepads = navigator.getGamepads ? navigator.getGamepads() : [];\r", |
296 | 316 | " for (let playerId = 0; playerId < gamepads.length; playerId++) {\r", |
|
471 | 491 | " getGamepad,\r", |
472 | 492 | " onScenePostEvents,\r", |
473 | 493 | " frameBeginningTask,\r", |
| 494 | + " addFrameBeginningTaskIfNeeded,\r", |
474 | 495 | "}" |
475 | 496 | ], |
476 | 497 | "parameterObjects": "", |
|
489 | 510 | "events": [ |
490 | 511 | { |
491 | 512 | "type": "BuiltinCommonInstructions::JsCode", |
492 | | - "inlineCode": [ |
493 | | - "// Async tasks are run before everything.\r", |
494 | | - "// This is a hack to make sure that button states are updated\r", |
495 | | - "// before mapping behavior events.\r", |
496 | | - "runtimeScene.getAsyncTasksManager().addTask(gdjs._extensionController.frameBeginningTask);" |
497 | | - ], |
| 513 | + "inlineCode": "gdjs._extensionController.addFrameBeginningTaskIfNeeded(runtimeScene);", |
498 | 514 | "parameterObjects": "", |
499 | 515 | "useStrict": true, |
500 | 516 | "eventsSheetExpanded": false |
|
512 | 528 | { |
513 | 529 | "type": "BuiltinCommonInstructions::JsCode", |
514 | 530 | "inlineCode": [ |
515 | | - "gdjs._extensionController.onScenePostEvents();", |
| 531 | + "gdjs._extensionController.onScenePostEvents(runtimeScene);", |
516 | 532 | "" |
517 | 533 | ], |
518 | 534 | "parameterObjects": "", |
|
1920 | 1936 | { |
1921 | 1937 | "type": "BuiltinCommonInstructions::JsCode", |
1922 | 1938 | "inlineCode": [ |
1923 | | - "", |
1924 | 1939 | "const playerId = eventsFunctionContext.getArgument(\"PlayerId\") - 1;", |
1925 | 1940 | "/** @type {Gamepad[]} */", |
1926 | 1941 | "const gamepads = navigator.getGamepads ? navigator.getGamepads() : [];", |
|
0 commit comments