fix weird stretching issue (related #12)

This commit is contained in:
Grant 2024-05-29 12:47:39 -06:00
parent 0cf27d80f3
commit 95bbd633c8
2 changed files with 21 additions and 0 deletions

View File

@ -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);

View File

@ -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>> {