From 8748991912a3660ba1dd02d55ed910ee778474b9 Mon Sep 17 00:00:00 2001 From: 10672208+mind-ar <10672208+mind-ar@users.noreply.github.com> Date: Fri, 15 Mar 2024 01:15:31 +0000 Subject: [PATCH 1/2] fix: duplicated flush event on reload --- src/commands/run.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/commands/run.ts b/src/commands/run.ts index b898ee7..f82598a 100644 --- a/src/commands/run.ts +++ b/src/commands/run.ts @@ -194,7 +194,6 @@ export const eventsFor = (io: Server, interpreter: Interpreter, dynamicDiagramCl const sizeCanvas = canvasResolution(interpreter) io.on('connection', socket => { logger.info(successDescription('Running game!')) - socket.on('disconnect', () => { logger.info(successDescription('Game finished')) }) socket.on('keyPressed', key => { queueEvent(interpreter, buildKeyPressEvent(interpreter, wKeyCode(key.key, key.keyCode)), buildKeyPressEvent(interpreter, 'ANY')) }) @@ -221,6 +220,12 @@ export const eventsFor = (io: Server, interpreter: Interpreter, dynamicDiagramCl clearInterval(id) } }, 100) + + socket.on('disconnect', () => { + clearInterval(id) + logger.info(successDescription('Game finished')) + }) + }) } From 0f41fec14c996ac292d8f5079d1c3cf205b6872b Mon Sep 17 00:00:00 2001 From: 10672208+mind-ar <10672208+mind-ar@users.noreply.github.com> Date: Fri, 15 Mar 2024 21:45:19 +0000 Subject: [PATCH 2/2] corregida diferencia de tiempo en flushEvent --- src/commands/run.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/commands/run.ts b/src/commands/run.ts index f82598a..3d21f9b 100644 --- a/src/commands/run.ts +++ b/src/commands/run.ts @@ -202,12 +202,13 @@ export const eventsFor = (io: Server, interpreter: Interpreter, dynamicDiagramCl socket.emit('images', getImages(project, assets)) socket.emit('sizeCanvasInic', [sizeCanvas.width, sizeCanvas.height]) + const flushInterval = 100 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 + timer += flushInterval // We could pass the interpreter but a program does not change it dynamicDiagramClient.onReload() if (!gameSingleton.get('running')?.innerBoolean) { @@ -219,7 +220,7 @@ export const eventsFor = (io: Server, interpreter: Interpreter, dynamicDiagramCl socket.emit('errorDetected', error.message) clearInterval(id) } - }, 100) + }, flushInterval) socket.on('disconnect', () => { clearInterval(id)