amongous
This commit is contained in:
parent
c6f5ab3438
commit
3d1a427dcf
2 changed files with 41 additions and 5 deletions
|
|
@ -88,7 +88,7 @@ socket.on("pixel-update", async (msg) => {
|
|||
// Buttons
|
||||
//
|
||||
async function placePixelButton() {
|
||||
const { posX, posY, color } = getPlacementData();
|
||||
const { color, posX, posY } = getPlacementData();
|
||||
|
||||
await placePixel(room, posX, posY, color);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,40 @@ async function getCanvas(room) {
|
|||
function subscribeToRoom() {}
|
||||
|
||||
// get the pixel info of a room
|
||||
function getPixelInfo() {}
|
||||
async function getPixelInfo(room, posX, posY) {
|
||||
if (!room) {
|
||||
console.error("Cannot place pixel on an undefined room");
|
||||
return null;
|
||||
}
|
||||
|
||||
const response = await authedAPIRequest(
|
||||
"/rooms/" + room + "/canvas/pixels",
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
posX,
|
||||
posY,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
if (!response || !response.ok) {
|
||||
console.error(
|
||||
"Could not retrieve pixel infos: " + response && response.statusText
|
||||
? response.statusText
|
||||
: "no more informations",
|
||||
);
|
||||
// console.debug(await response.text());
|
||||
return null;
|
||||
}
|
||||
|
||||
const res = await response.json();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// place a pixel in a room
|
||||
async function placePixel(room, posX, posY, color) {
|
||||
|
|
@ -93,10 +126,13 @@ async function placePixel(room, posX, posY, color) {
|
|||
"/rooms/" + room + "/canvas/pixels",
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
posX: posX,
|
||||
posY: posY,
|
||||
color: color,
|
||||
posX,
|
||||
posY,
|
||||
color,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue