fix canvas randomly flipping (fixes #24)
This commit is contained in:
parent
528a1dfde5
commit
ea4b462a5f
|
@ -57,8 +57,11 @@ class Canvas {
|
||||||
|
|
||||||
const pixels: string[] = [];
|
const pixels: string[] = [];
|
||||||
|
|
||||||
for (let x = 0; x < this.CANVAS_SIZE[0]; x++) {
|
// (y -> x) because of how the conversion needs to be done later
|
||||||
for (let y = 0; y < this.CANVAS_SIZE[1]; y++) {
|
// if this is inverted, the map will flip when rebuilding the cache (5 minute expiry)
|
||||||
|
// fixes #24
|
||||||
|
for (let y = 0; y < this.CANVAS_SIZE[1]; y++) {
|
||||||
|
for (let x = 0; x < this.CANVAS_SIZE[0]; x++) {
|
||||||
pixels.push(
|
pixels.push(
|
||||||
(await redis.get(Redis.key("pixelColor", x, y))) || "transparent"
|
(await redis.get(Redis.key("pixelColor", x, y))) || "transparent"
|
||||||
);
|
);
|
||||||
|
@ -114,7 +117,7 @@ class Canvas {
|
||||||
data: { lastPixelTime: new Date() },
|
data: { lastPixelTime: new Date() },
|
||||||
});
|
});
|
||||||
|
|
||||||
await redis.set(`CANVAS:PIXELS[${x},${y}]:COLOR`, hex);
|
await redis.set(Redis.key("pixelColor", x, y), hex);
|
||||||
|
|
||||||
// maybe only update specific element?
|
// maybe only update specific element?
|
||||||
// i don't think it needs to be awaited
|
// i don't think it needs to be awaited
|
||||||
|
|
|
@ -191,8 +191,6 @@ export class SocketServer {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await user.modifyStack(-1);
|
|
||||||
|
|
||||||
const paletteColor = await prisma.paletteColor.findFirst({
|
const paletteColor = await prisma.paletteColor.findFirst({
|
||||||
where: {
|
where: {
|
||||||
id: pixel.color,
|
id: pixel.color,
|
||||||
|
@ -206,6 +204,7 @@ export class SocketServer {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await user.modifyStack(-1);
|
||||||
await Canvas.setPixel(user, pixel.x, pixel.y, paletteColor.hex);
|
await Canvas.setPixel(user, pixel.x, pixel.y, paletteColor.hex);
|
||||||
|
|
||||||
const newPixel: Pixel = {
|
const newPixel: Pixel = {
|
||||||
|
|
Loading…
Reference in New Issue