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 5 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
2 changes: 1 addition & 1 deletion public/game/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<script type="module">
import { io } from "https://cdn.socket.io/4.4.1/socket.io.esm.min.js";

socket = io("http://localhost:3000");
socket = io();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto qué onda?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hola, en #133 se permite utilizar cualquier puerto para games, pero en el frontend estaba forzado a localhost:3000, al dejarlo en blanco toma los datos de la url para iniciar el websocket (sino falla por crossorigin y coso)
Ojo, no sé si esto rompe algun test, si es así puedo buscar alguna alternativa

socket.on("connect", function () {
console.log("conectado!");
});
Expand Down
6 changes: 4 additions & 2 deletions public/game/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function setup() {
})
loadBackground()
loadVisuals()
socket.emit("ready")
}

function draw() {
Expand Down Expand Up @@ -60,9 +61,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
19 changes: 12 additions & 7 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@
*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 ?? []
Expand Down Expand Up @@ -188,7 +186,6 @@
}
}


export const eventsFor = (io: Server, interpreter: Interpreter, dynamicDiagramClient: DynamicDiagramClient, { game, project, assets }: Options): void => {
if (!game) return
const sizeCanvas = canvasResolution(interpreter)
Expand All @@ -199,13 +196,21 @@
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 200 in src/commands/run.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/run.ts#L199-L200

Added lines #L199 - L200 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])

const id = setInterval(() => {
const gameSingleton = interpreter?.object('wollok.game.game')
// send assets only when frontend is ready
socket.on("ready", () => {

Check warning on line 205 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])

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

View check run for this annotation

Codecov / codecov/patch

src/commands/run.ts#L205-L208

Added lines #L205 - L208 were not covered by tests
socket.emit('cellPixelSize', gameSingleton.get('cellSize')!.innerNumber!)
socket.emit('background', background)

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

View check run for this annotation

Codecov / codecov/patch

src/commands/run.ts#L210

Added line #L210 was not covered by tests
})

const id = setInterval(() => {

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

View check run for this annotation

Codecov / codecov/patch

src/commands/run.ts#L213

Added line #L213 was not covered by tests
try {
interpreter.send('flushEvents', gameSingleton, interpreter.reify(timer))
timer += 300
Expand Down
Loading