Commit 95bbd633 authored by Grant's avatar Grant
Browse files

fix weird stretching issue (related #12)

parent 0cf27d80
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -70,6 +70,11 @@ export class Canvas extends EventEmitter<CanvasEvents> {
    this.canvas.width = config.canvas.size[0];
    this.canvas.height = config.canvas.size[1];

    // we want the new one if possible
    // (this might cause a timing issue though)
    // if we don't clear the old one, if the canvas gets resized we get weird stretching
    if (Object.keys(this.pixels).length > 0) Network.clearPrevious("canvas");

    Network.waitFor("canvas").then(([pixels]) => {
      console.log("loadConfig just received new canvas data");
      this.handleBatch(pixels);
+16 −0
Original line number Diff line number Diff line
@@ -121,6 +121,22 @@ class Network extends EventEmitter<INetworkEvents> {
    return this.emit(event, ...args);
  };

  /**
   * Discard the existing state-like event, if it exists in cache
   * @param ev
   */
  clearPrevious<Ev extends keyof INetworkEvents & (string | symbol)>(ev: Ev) {
    delete this.sentEvents[ev];
  }

  /**
   * Wait for event, either being already sent, or new one
   *
   * Used for state-like events
   *
   * @param ev
   * @returns
   */
  waitFor<Ev extends keyof INetworkEvents & (string | symbol)>(
    ev: Ev
  ): Promise<SentEventValue<Ev>> {