Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: duplicated flushEvent on reload #136

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@
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'))
})
Expand All @@ -203,12 +202,13 @@
socket.emit('images', getImages(project, assets))
socket.emit('sizeCanvasInic', [sizeCanvas.width, sizeCanvas.height])

const flushInterval = 100

Check warning on line 205 in src/commands/run.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/run.ts#L205

Added line #L205 was not covered by tests
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

Check warning on line 211 in src/commands/run.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/run.ts#L211

Added line #L211 was not covered by tests
// We could pass the interpreter but a program does not change it
dynamicDiagramClient.onReload()
if (!gameSingleton.get('running')?.innerBoolean) {
Expand All @@ -220,7 +220,13 @@
socket.emit('errorDetected', error.message)
clearInterval(id)
}
}, 100)
}, flushInterval)

socket.on('disconnect', () => {
clearInterval(id)
logger.info(successDescription('Game finished'))

Check warning on line 227 in src/commands/run.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/run.ts#L225-L227

Added lines #L225 - L227 were not covered by tests
})

})
}

Expand Down
Loading