c trop bieeeen
This commit is contained in:
parent
50d46d0f0c
commit
c6f5ab3438
6 changed files with 83 additions and 13 deletions
|
|
@ -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 };
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ let isDrag = false;
|
|||
* Get the placement data, i.e. the color the user has selected and the
|
||||
* coordinates of the pixel he is focusing on.
|
||||
*
|
||||
* @returns {{color: number, posX: number, posX: number}} the data
|
||||
* @returns {{color: number, posX: number, posY: number}} the data
|
||||
*/
|
||||
export const getPlacementData = () => ({
|
||||
color: selectedColorIdx,
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ async function listRooms() {
|
|||
|
||||
if (!response || !response.ok) {
|
||||
console.error(
|
||||
"Could not retrieve rooms list: " + response
|
||||
"Could not retrieve rooms list: " + response && response.statusText
|
||||
? response.statusText
|
||||
: "null",
|
||||
);
|
||||
|
|
@ -87,7 +87,7 @@ async function fetchRoomConfig(room) {
|
|||
|
||||
if (!response || !response.ok) {
|
||||
console.error(
|
||||
"Could not retrieve room config" + response
|
||||
"Could not retrieve room config" + response && response.statusText
|
||||
? response.statusText
|
||||
: "null",
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue