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

Corrección de falla al intentar cargar imagen de fondo #132

Merged
merged 6 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions public/game/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function setup() {
})
loadBackground()
loadVisuals()
socket.emit("ready")
}

function draw() {
Expand Down Expand Up @@ -59,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
})
}
Expand Down
21 changes: 13 additions & 8 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,8 @@
drawer: {
*apply() {
try {
const game = interpreter?.object(GAME_MODULE)
const background = game.get('boardGround') ? game.get('boardGround')?.innerString : 'default'
const game = interpreter?.object('wollok.game.game')

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

View check run for this annotation

Codecov / codecov/patch

src/commands/run.ts#L89

Added line #L89 was not covered by tests
const visuals = getVisuals(game, interpreter)
io.emit('background', background)
io.emit('visuals', visuals)

const gameSounds = game.get('sounds')?.innerCollection ?? []
Expand Down Expand Up @@ -185,7 +183,6 @@
}
}


export const eventsFor = (io: Server, interpreter: Interpreter, dynamicDiagramClient: DynamicDiagramClient, { game, project, assets }: Options): void => {
if (!game) return
const sizeCanvas = canvasResolution(interpreter)
Expand All @@ -195,14 +192,22 @@
queueEvent(interpreter, buildKeyPressEvent(interpreter, wKeyCode(key.key, key.keyCode)), buildKeyPressEvent(interpreter, 'ANY'))
})

const gameSingleton = interpreter?.object('wollok.game.game')
const background = gameSingleton.get('boardGround') ? gameSingleton.get('boardGround')?.innerString : 'default'

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

View check run for this annotation

Codecov / codecov/patch

src/commands/run.ts#L195-L196

Added lines #L195 - L196 were not covered by tests

if (!assets) logger.warn(failureDescription('Folder for assets not found!'))
socket.emit('images', getImages(project, assets))
socket.emit('sizeCanvasInic', [sizeCanvas.width, sizeCanvas.height])

// send assets only when frontend is ready
socket.on("ready", () => {

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

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote
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)

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

View check run for this annotation

Codecov / codecov/patch

src/commands/run.ts#L201-L206

Added lines #L201 - L206 were not covered by tests
})

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 += flushInterval
Expand Down
Loading