Skip to content
Snippets Groups Projects
Commit 03e422e9 authored by Paolo.Brasolin's avatar Paolo.Brasolin
Browse files

feat: #fe #be fetch actual data

parent 5c190576
No related branches found
No related tags found
No related merge requests found
......@@ -26,34 +26,32 @@ server.route({
method: "POST",
url: "/GetImage",
schema: {
body: {
type: "object",
properties: {
sessionImages: {
type: "array",
items: { type: "number" },
},
},
},
// body: {},
response: {
200: {
type: "object",
properties: {
id: { type: "number" },
id: { type: "string", format: "uuid" },
image: { type: "string" },
ocr_confidence: { type: "number", minimum: 0, maximum: 1 },
ocr_transcript: { type: "string" },
},
},
},
},
handler: async function (request, reply) {
// TODO: skip images already used in current game
const image = await connection
.table("images")
// TODO: skip images already used in current game (overkill? we prolly have thousands so collisions should be irrelevant...)
const word = await connection
.table("words")
.whereBetween("ocr_confidence", [0.4, 0.8]) // i.e. needs improvement but it's not trash
.whereRaw(`"ocr_transcript" ~ '^[[:alpha:]]+$'`) // i.e. no numbers nor symbols
.orderByRaw("RANDOM()")
.first();
reply.send({
id: image.id,
image: image.image,
id: word.id,
image: word.image,
ocr_confidence: word.ocr_confidence,
ocr_transcript: word.ocr_transcript,
});
},
});
......
BACKEND_URL=http://localhost:8080/
BACKEND_URL=http://localhost:8080
......@@ -320,28 +320,22 @@ function dispatchEnemy(scene) {
let e = new enemy(scene);
window.onscreenEnemies.push(e);
backend
.post("GetImage", {
sessionImages: [],
})
.then(function (response) {
e.refData = response.data;
const imageData = `data:image/png;base64,${response.data.image}`;
scene.textures.addBase64(`WORD-${response.data.id}`, imageData);
scene.textures.once(
"addtexture",
function () {
e.run((v) => {
setTimeout(() => {
dispatchEnemy(scene);
}, Math.floor(Math.random() * 10000 + 3000));
});
},
scene,
);
});
backend.post("GetImage", {}).then(function (response) {
e.refData = response.data;
scene.textures.addBase64(`WORD-${response.data.id}`, response.data.image);
scene.textures.once(
"addtexture",
function () {
e.run((v) => {
setTimeout(() => {
dispatchEnemy(scene);
}, Math.floor(Math.random() * 10000 + 3000));
});
},
scene,
);
});
}
export default fightScene;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment