Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lints and typechecking errors #207

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
5 changes: 3 additions & 2 deletions src/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
Expand Down
4 changes: 1 addition & 3 deletions src/Renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 10 additions & 8 deletions src/Sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ 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;
// TODO: remove this and just store the sprites in layer order, as Scratch does.
public _layerOrder: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way we could avoid making this underscore-public? I guess you just added a similar TODO above for _project, but it sounds like we should also avoid it for _layerOrder.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a TODO for removing _layerOrder entirely--we should just store sprites in-order as Scratch does.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we file that as an issue too LOL. Otherwise, again, awesome. Thanks!

public triggers: Trigger[];
public watchers: Partial<Record<string, Watcher>>;
protected costumes: Costume[];
Expand Down Expand Up @@ -701,7 +703,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);
Expand All @@ -725,7 +727,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);
Expand Down Expand Up @@ -869,7 +871,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);
Expand Down Expand Up @@ -953,7 +955,7 @@ export class Sprite extends SpriteBase {
BOTTOM: Symbol("BOTTOM"),
LEFT: Symbol("LEFT"),
RIGHT: Symbol("RIGHT"),
TOP: Symbol("TOP")
TOP: Symbol("TOP"),
});
}

Expand All @@ -971,7 +973,7 @@ export class Stage extends SpriteBase {
right: number;
top: number;
bottom: number;
}
};

public constructor(initialConditions: StageInitialConditions, vars = {}) {
super(initialConditions, vars);
Expand All @@ -993,7 +995,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.
Expand Down
2 changes: 1 addition & 1 deletion src/Watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/Drawable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/renderer/ShaderManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
4 changes: 1 addition & 3 deletions src/renderer/Skin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down