c trop bieeeen

This commit is contained in:
Guillem George 2026-05-16 17:18:47 +02:00
parent 50d46d0f0c
commit c6f5ab3438
6 changed files with 83 additions and 13 deletions

View file

@ -16,11 +16,11 @@ async function fetchCanvas(room) {
if (!response || !response.ok) {
console.error(
"Could not retrieve room canvas: " + response
"Could not retrieve room canvas: " + response && response.statusText
? response.statusText
: "null",
: "no more informations",
);
console.debug(await response.text());
// console.debug(await response.text());
return null;
}
@ -83,6 +83,42 @@ function subscribeToRoom() {}
function getPixelInfo() {}
// place a pixel in a room
function placePixel() {}
async function placePixel(room, posX, posY, color) {
if (!room) {
console.error("Cannot place pixel on an undefined room");
return null;
}
const response = await authedAPIRequest(
"/rooms/" + room + "/canvas/pixels",
{
method: "POST",
body: JSON.stringify({
posX: posX,
posY: posY,
color: color,
}),
},
);
if (!response || !response.ok) {
console.error(
"Could not place pixel on map: " + response && response.statusText
? response.statusText
: "no more informations",
);
// console.debug(await response.text());
return null;
}
const res = await response.json();
console.debug(
`Placed pixel on map at ${posX}:${posY} (${color}) in room ${room}:`,
);
// console.debug(res);
return res;
}
export { getCanvas, subscribeToRoom, getPixelInfo, placePixel };