From 3e0fb6c88cd9c72515658d7c85ff9352ddc3f412 Mon Sep 17 00:00:00 2001 From: 10672208+mind-ar <10672208+mind-ar@users.noreply.github.com> Date: Wed, 13 Mar 2024 20:15:10 +0000 Subject: [PATCH 1/4] fix(web): corregido error al cargar imagen de fondo --- public/game/index.html | 18 ++++++++++-------- public/game/sketch.js | 9 +++++---- src/commands/run.ts | 15 ++++++++++----- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/public/game/index.html b/public/game/index.html index 5b32089..21d3f66 100644 --- a/public/game/index.html +++ b/public/game/index.html @@ -19,14 +19,16 @@ diff --git a/public/game/sketch.js b/public/game/sketch.js index 6b8c8c1..87190cf 100644 --- a/public/game/sketch.js +++ b/public/game/sketch.js @@ -10,6 +10,8 @@ var sounds = new Map() function preload() { loadAllImages() + loadBackground() + loadVisuals() wko = loadImage("./wko.png") defaultBackground = loadImage("./background.jpg") socket.on("sizeCanvasInic", (size) => { @@ -25,8 +27,6 @@ function setup() { socket.on("updateSound", (data) => { updateSound(data.soundInstances) }) - loadBackground() - loadVisuals() } function draw() { @@ -60,9 +60,10 @@ function checkError() { function loadBackground() { socket.on("background", (fondo) => { + const imagen = images.find((img) => img.name == fondo) backgroundImage = - fondo != "default" - ? images.find((img) => img.name == fondo).url + fondo != "default" && imagen != null + ? imagen.url : defaultBackground }) } diff --git a/src/commands/run.ts b/src/commands/run.ts index b898ee7..e5f2cf9 100644 --- a/src/commands/run.ts +++ b/src/commands/run.ts @@ -90,9 +90,7 @@ export const getGameInterpreter = (environment: Environment, io: Server): Interp *apply() { try { const game = interpreter?.object('wollok.game.game') - const background = game.get('boardGround') ? game.get('boardGround')?.innerString : 'default' const visuals = getVisuals(game, interpreter) - io.emit('background', background) io.emit('visuals', visuals) const gameSounds = game.get('sounds')?.innerCollection ?? [] @@ -188,7 +186,6 @@ export async function initializeDynamicDiagram(programPackage: Package, options: } } - export const eventsFor = (io: Server, interpreter: Interpreter, dynamicDiagramClient: DynamicDiagramClient, { game, project, assets }: Options): void => { if (!game) return const sizeCanvas = canvasResolution(interpreter) @@ -199,9 +196,17 @@ export const eventsFor = (io: Server, interpreter: Interpreter, dynamicDiagramCl queueEvent(interpreter, buildKeyPressEvent(interpreter, wKeyCode(key.key, key.keyCode)), buildKeyPressEvent(interpreter, 'ANY')) }) + const gameInterpreter = interpreter?.object('wollok.game.game') + const background = gameInterpreter.get('boardGround') ? gameInterpreter.get('boardGround')?.innerString : 'default' + if (!assets) logger.warn(failureDescription('Folder for assets not found!')) - socket.emit('images', getImages(project, assets)) - socket.emit('sizeCanvasInic', [sizeCanvas.width, sizeCanvas.height]) + // when frontend is ready, send assets + socket.on("ready", () => { + logger.info(successDescription('Ready!')) + socket.emit('images', getImages(project, assets)) + socket.emit('sizeCanvasInic', [sizeCanvas.width, sizeCanvas.height]) + socket.emit('background', background) + }) const id = setInterval(() => { const gameSingleton = interpreter?.object('wollok.game.game') From bb37a2ee91ad00c7ddd2e3f52936a7250b3332f2 Mon Sep 17 00:00:00 2001 From: 10672208+mind-ar <10672208+mind-ar@users.noreply.github.com> Date: Fri, 15 Mar 2024 00:17:17 +0000 Subject: [PATCH 2/4] =?UTF-8?q?se=20mejora=20carga=20inicial=20de=20p?= =?UTF-8?q?=C3=A1gina?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/game/index.html | 17 +++++++---------- public/game/sketch.js | 7 ++++--- src/commands/run.ts | 10 +++++----- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/public/game/index.html b/public/game/index.html index 21d3f66..5c8f670 100644 --- a/public/game/index.html +++ b/public/game/index.html @@ -19,16 +19,13 @@ diff --git a/public/game/sketch.js b/public/game/sketch.js index 87190cf..8ffc3e6 100644 --- a/public/game/sketch.js +++ b/public/game/sketch.js @@ -10,8 +10,6 @@ var sounds = new Map() function preload() { loadAllImages() - loadBackground() - loadVisuals() wko = loadImage("./wko.png") defaultBackground = loadImage("./background.jpg") socket.on("sizeCanvasInic", (size) => { @@ -27,7 +25,10 @@ function setup() { socket.on("updateSound", (data) => { updateSound(data.soundInstances) }) -} + + loadBackground() + loadVisuals() + } function draw() { clear() diff --git a/src/commands/run.ts b/src/commands/run.ts index e5f2cf9..a15f750 100644 --- a/src/commands/run.ts +++ b/src/commands/run.ts @@ -196,21 +196,21 @@ export const eventsFor = (io: Server, interpreter: Interpreter, dynamicDiagramCl queueEvent(interpreter, buildKeyPressEvent(interpreter, wKeyCode(key.key, key.keyCode)), buildKeyPressEvent(interpreter, 'ANY')) }) - const gameInterpreter = interpreter?.object('wollok.game.game') - const background = gameInterpreter.get('boardGround') ? gameInterpreter.get('boardGround')?.innerString : 'default' + const gameSingleton = interpreter?.object('wollok.game.game') + const background = gameSingleton.get('boardGround') ? gameSingleton.get('boardGround')?.innerString : 'default' if (!assets) logger.warn(failureDescription('Folder for assets not found!')) - // when frontend is ready, send assets + + // send assets only when frontend is ready socket.on("ready", () => { logger.info(successDescription('Ready!')) socket.emit('images', getImages(project, assets)) socket.emit('sizeCanvasInic', [sizeCanvas.width, sizeCanvas.height]) + socket.emit('cellPixelSize', gameSingleton.get('cellSize')!.innerNumber!) socket.emit('background', background) }) const id = setInterval(() => { - const gameSingleton = interpreter?.object('wollok.game.game') - socket.emit('cellPixelSize', gameSingleton.get('cellSize')!.innerNumber!) try { interpreter.send('flushEvents', gameSingleton, interpreter.reify(timer)) timer += 300 From 160310e6bc682f45999bcec05129777731f7ae91 Mon Sep 17 00:00:00 2001 From: 10672208+mind-ar <10672208+mind-ar@users.noreply.github.com> Date: Fri, 15 Mar 2024 00:20:24 +0000 Subject: [PATCH 3/4] fix: lint --- public/game/index.html | 1 + public/game/sketch.js | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/public/game/index.html b/public/game/index.html index 5c8f670..5438bfe 100644 --- a/public/game/index.html +++ b/public/game/index.html @@ -19,6 +19,7 @@