diff --git a/packages/client/src/lib/canvas.ts b/packages/client/src/lib/canvas.ts index 2adcf6d..f028e4e 100644 --- a/packages/client/src/lib/canvas.ts +++ b/packages/client/src/lib/canvas.ts @@ -60,6 +60,7 @@ export class Canvas extends EventEmitter { Network.waitFor("pixelLastPlaced").then( ([time]) => (this.lastPlace = time) ); + Network.on("pixel", this.handlePixel); this.draw(); } @@ -110,12 +111,12 @@ export class Canvas extends EventEmitter { }); } - handlePixel({ x, y, color }: Pixel) { + handlePixel = ({ x, y, color }: Pixel) => { this.pixels[x + "_" + y] = { color, type: "full", }; - } + }; palleteCtx: IPalleteContext = {}; Pallete = { diff --git a/packages/client/src/lib/network.ts b/packages/client/src/lib/network.ts index 8b7ffb5..8c11c2d 100644 --- a/packages/client/src/lib/network.ts +++ b/packages/client/src/lib/network.ts @@ -4,6 +4,7 @@ import { AuthSession, ClientConfig, ClientToServerEvents, + Pixel, ServerToClientEvents, } from "@sc07-canvas/lib/src/net"; @@ -14,6 +15,7 @@ export interface INetworkEvents { pixels: (data: { available: number }) => void; pixelLastPlaced: (time: number) => void; online: (count: number) => void; + pixel: (pixel: Pixel) => void; } type SentEventValue = EventEmitter.ArgumentMap< @@ -60,6 +62,10 @@ class Network extends EventEmitter { this._emit("online", count); }); + this.socket.on("pixel", (pixel) => { + this.emit("pixel", pixel); + }); + // this.socket.on("config", (config) => { // Pallete.load(config.pallete); // Canvas.load(config.canvas);