Commit ea4b462a authored by Grant's avatar Grant
Browse files

fix canvas randomly flipping (fixes #24)

parent 528a1dfd
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -57,8 +57,11 @@ class Canvas {

    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
    // 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
+1 −2
Original line number Diff line number Diff line
@@ -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 = {