From be66ffa5ef039b2dedb321d724031d0c5d72f092 Mon Sep 17 00:00:00 2001 From: adroitwhiz Date: Tue, 16 Jul 2024 08:37:59 -0400 Subject: [PATCH 1/3] Fix lints and typechecking errors --- src/Project.ts | 5 +++-- src/Renderer.ts | 4 +--- src/Sprite.ts | 17 +++++++++-------- src/Watcher.ts | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Project.ts b/src/Project.ts index 0d1e3e7..ebdfa19 100644 --- a/src/Project.ts +++ b/src/Project.ts @@ -133,10 +133,11 @@ export default class Project { let predicate; switch (trigger.trigger) { case Trigger.TIMER_GREATER_THAN: - predicate = this.timer > trigger.option("VALUE", target)!; + predicate = this.timer > (trigger.option("VALUE", target) as number); break; case Trigger.LOUDNESS_GREATER_THAN: - predicate = this.loudness > trigger.option("VALUE", target)!; + predicate = + this.loudness > (trigger.option("VALUE", target) as number); break; default: throw new Error(`Unimplemented trigger ${String(trigger.trigger)}`); diff --git a/src/Renderer.ts b/src/Renderer.ts index 7b116db..c79cae3 100644 --- a/src/Renderer.ts +++ b/src/Renderer.ts @@ -163,9 +163,7 @@ export default class Renderer { public _createFramebufferInfo( width: number, height: number, - filtering: - | WebGLRenderingContext["NEAREST"] - | WebGLRenderingContext["LINEAR"], + filtering: number, stencil = false ): FramebufferInfo { // Create an empty texture with this skin's dimensions. diff --git a/src/Sprite.ts b/src/Sprite.ts index 9ae6392..08a0a05 100644 --- a/src/Sprite.ts +++ b/src/Sprite.ts @@ -97,10 +97,11 @@ type InitialConditions = { }; abstract class SpriteBase { - protected _project!: Project; + // TODO: make this protected and pass it in via the constructor + public _project!: Project; protected _costumeNumber: number; - protected _layerOrder: number; + public _layerOrder: number; public triggers: Trigger[]; public watchers: Partial>; protected costumes: Costume[]; @@ -701,7 +702,7 @@ export class Sprite extends SpriteBase { } while (t < 1); } - ifOnEdgeBounce() { + public ifOnEdgeBounce(): void { const nearestEdge = this.nearestEdge(); if (!nearestEdge) return; const rad = this.scratchToRad(this.direction); @@ -725,7 +726,7 @@ export class Sprite extends SpriteBase { this.positionInFence(); } - positionInFence() { + private positionInFence(): void { // https://github.com/LLK/scratch-vm/blob/develop/src/sprites/rendered-target.js#L949 const fence = this.stage.fence; const bounds = this._project.renderer.getTightBoundingBox(this); @@ -869,7 +870,7 @@ export class Sprite extends SpriteBase { } } - nearestEdge() { + private nearestEdge(): symbol | null { const bounds = this._project.renderer.getTightBoundingBox(this); const { width: stageWidth, height: stageHeight } = this.stage; const distLeft = Math.max(0, stageWidth / 2 + bounds.left); @@ -953,7 +954,7 @@ export class Sprite extends SpriteBase { BOTTOM: Symbol("BOTTOM"), LEFT: Symbol("LEFT"), RIGHT: Symbol("RIGHT"), - TOP: Symbol("TOP") + TOP: Symbol("TOP"), }); } @@ -971,7 +972,7 @@ export class Stage extends SpriteBase { right: number; top: number; bottom: number; - } + }; public constructor(initialConditions: StageInitialConditions, vars = {}) { super(initialConditions, vars); @@ -993,7 +994,7 @@ export class Stage extends SpriteBase { left: -this.width / 2, right: this.width / 2, top: this.height / 2, - bottom: -this.height / 2 + bottom: -this.height / 2, }; // For obsolete counter blocks. diff --git a/src/Watcher.ts b/src/Watcher.ts index 389d82f..2e15a38 100644 --- a/src/Watcher.ts +++ b/src/Watcher.ts @@ -29,7 +29,7 @@ type WatcherOptions = { export default class Watcher { public value: () => WatcherValue; public setValue: (value: number) => void; - private _previousValue: unknown | symbol; + private _previousValue: unknown; private color: Color; private _label!: string; private _x!: number; From e1140942b00c77f32248f9d22ca0990a127bcbdb Mon Sep 17 00:00:00 2001 From: adroitwhiz Date: Tue, 16 Jul 2024 09:10:52 -0400 Subject: [PATCH 2/3] Add todo for _layerOrder --- src/Sprite.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Sprite.ts b/src/Sprite.ts index 08a0a05..809cd82 100644 --- a/src/Sprite.ts +++ b/src/Sprite.ts @@ -101,6 +101,7 @@ abstract class SpriteBase { public _project!: Project; protected _costumeNumber: number; + // TODO: remove this and just store the sprites in layer order, as Scratch does. public _layerOrder: number; public triggers: Trigger[]; public watchers: Partial>; From 6f8e928341676c02762066595d95b6be1c4f7472 Mon Sep 17 00:00:00 2001 From: adroitwhiz Date: Tue, 16 Jul 2024 09:14:34 -0400 Subject: [PATCH 3/3] Oops, actually lint all the files --- package.json | 2 +- src/renderer/Drawable.ts | 4 +++- src/renderer/ShaderManager.ts | 7 +------ src/renderer/Skin.ts | 4 +--- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 1414194..da478a9 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "scripts": { "build": "rollup -c", "dev": "rollup -c --watch", - "lint": "eslint \"./src/**.ts\"", + "lint": "eslint \"./src/**/*.ts\"", "prepare": "npm run build" }, "devDependencies": { diff --git a/src/renderer/Drawable.ts b/src/renderer/Drawable.ts index e1be5bd..96ee474 100644 --- a/src/renderer/Drawable.ts +++ b/src/renderer/Drawable.ts @@ -410,7 +410,9 @@ export default class Drawable { private _warnBadSize(description: string, treating: string): void { if (!this._warnedBadSize) { const { name } = this._sprite.constructor; - console.warn(`Expected a number, sprite ${name} size is ${description}. Treating as ${treating}.`); + console.warn( + `Expected a number, sprite ${name} size is ${description}. Treating as ${treating}.` + ); this._warnedBadSize = true; } } diff --git a/src/renderer/ShaderManager.ts b/src/renderer/ShaderManager.ts index 8ed6849..89dd3d1 100644 --- a/src/renderer/ShaderManager.ts +++ b/src/renderer/ShaderManager.ts @@ -59,12 +59,7 @@ class ShaderManager { } // Creates and compiles a vertex or fragment shader from the given source code. - private _createShader( - source: string, - type: - | WebGLRenderingContext["FRAGMENT_SHADER"] - | WebGLRenderingContext["VERTEX_SHADER"] - ): WebGLShader { + private _createShader(source: string, type: number): WebGLShader { const gl = this.gl; const shader = gl.createShader(type); if (!shader) throw new Error("Could not create shader."); diff --git a/src/renderer/Skin.ts b/src/renderer/Skin.ts index 0f29528..17e3e0f 100644 --- a/src/renderer/Skin.ts +++ b/src/renderer/Skin.ts @@ -28,9 +28,7 @@ export default abstract class Skin { // Helper function to create a texture from an image and handle all the boilerplate. protected _makeTexture( image: HTMLImageElement | HTMLCanvasElement | null, - filtering: - | WebGLRenderingContext["NEAREST"] - | WebGLRenderingContext["LINEAR"] + filtering: number ): WebGLTexture { const gl = this.gl; const glTexture = gl.createTexture();