fix canvas randomly flipping (fixes #24)

This commit is contained in:
Grant 2024-03-29 21:32:18 -06:00
parent 528a1dfde5
commit ea4b462a5f
2 changed files with 7 additions and 5 deletions

View File

@ -57,8 +57,11 @@ class Canvas {
const pixels: string[] = [];
for (let x = 0; x < this.CANVAS_SIZE[0]; x++) {
for (let y = 0; y < this.CANVAS_SIZE[1]; y++) {
// (y -> x) because of how the conversion needs to be done later
// 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(
(await redis.get(Redis.key("pixelColor", x, y))) || "transparent"
);
@ -114,7 +117,7 @@ class Canvas {
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?
// i don't think it needs to be awaited

View File

@ -191,8 +191,6 @@ export class SocketServer {
return;
}
await user.modifyStack(-1);
const paletteColor = await prisma.paletteColor.findFirst({
where: {
id: pixel.color,
@ -206,6 +204,7 @@ export class SocketServer {
return;
}
await user.modifyStack(-1);
await Canvas.setPixel(user, pixel.x, pixel.y, paletteColor.hex);
const newPixel: Pixel = {