From 02d44bbba49be81464b32297c216e2fc3bddb2df Mon Sep 17 00:00:00 2001 From: Florian Rival Date: Wed, 18 Dec 2024 18:16:13 +0100 Subject: [PATCH] Remove unused API method to initialize game rendering [skip ci] (#7235) --- .../runtimegame-pixi-renderer.ts | 22 +++++++++++-------- GDJS/tests/tests/game-canvas.js | 3 ++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/GDJS/Runtime/pixi-renderers/runtimegame-pixi-renderer.ts b/GDJS/Runtime/pixi-renderers/runtimegame-pixi-renderer.ts index a0199b767062..1868630b63dd 100644 --- a/GDJS/Runtime/pixi-renderers/runtimegame-pixi-renderer.ts +++ b/GDJS/Runtime/pixi-renderers/runtimegame-pixi-renderer.ts @@ -62,7 +62,7 @@ namespace gdjs { /** * Create the canvas on which the game will be rendered, inside the specified DOM element, and * setup the rendering of the game. - * If you want to use your own canvas, use `initializeForCanvas` instead. + * If you want to use your own canvas, use `initializeRenderers` and `initializeCanvas` instead. * * @param parentElement The parent element to which the canvas will be added. */ @@ -72,20 +72,18 @@ namespace gdjs { const gameCanvas = document.createElement('canvas'); parentElement.appendChild(gameCanvas); - this.initializeForCanvas(gameCanvas); + this.initializeRenderers(gameCanvas); + this.initializeCanvas(gameCanvas); } /** - * Setup the rendering of the game to use a canvas that was already created. - * @param gameCanvas The canvas to use. + * Set up the rendering of the game for the given canvas. + * + * In most cases, you can use `createStandardCanvas` instead to initialize the game. */ - initializeForCanvas(gameCanvas: HTMLCanvasElement): void { + initializeRenderers(gameCanvas: HTMLCanvasElement): void { this._throwIfDisposed(); - this.initializeRenderers(gameCanvas); - this.initializeCanvas(gameCanvas); - } - initializeRenderers(gameCanvas: HTMLCanvasElement): void { if (typeof THREE !== 'undefined') { this._threeRenderer = new THREE.WebGLRenderer({ canvas: gameCanvas, @@ -136,6 +134,10 @@ namespace gdjs { delete this._pixiRenderer.plugins.accessibility; } + /** + * Set up the game canvas so that it covers the size required by the game + * and has a container for DOM elements required by the game. + */ initializeCanvas(gameCanvas: HTMLCanvasElement): void { // Add the renderer view element to the DOM this._gameCanvas = gameCanvas; @@ -537,6 +539,8 @@ namespace gdjs { /** * Add the standard events handler. + * + * The game canvas must have been initialized before calling this. */ bindStandardEvents( manager: gdjs.InputManager, diff --git a/GDJS/tests/tests/game-canvas.js b/GDJS/tests/tests/game-canvas.js index ead09bf8dbaf..724735d3634c 100644 --- a/GDJS/tests/tests/game-canvas.js +++ b/GDJS/tests/tests/game-canvas.js @@ -24,7 +24,8 @@ describe('gdjs.RuntimeGameRenderer canvas tests', () => { it('should correctly initialize external canvas and create domElementsContainer', () => { const gameCanvas = document.createElement('canvas'); gameContainer.appendChild(gameCanvas); - renderer.initializeForCanvas(gameCanvas); + renderer.initializeRenderers(gameCanvas); + renderer.initializeCanvas(gameCanvas); const actualGameCanvas = renderer.getCanvas(); const actualDomElementsContainer = renderer.getDomElementContainer();