From 724260b515a52a5d88d1a56c3b280d7d5428cd49 Mon Sep 17 00:00:00 2001 From: NuclearRedeye Date: Tue, 26 Nov 2024 15:21:37 +0000 Subject: [PATCH] fix: linting issues --- src/ts/data/levels/level00.ts | 2 +- src/ts/index.ts | 9 ++++----- src/ts/interfaces/circle.ts | 2 +- src/ts/objects/entity.ts | 10 +++++----- src/ts/raycaster.ts | 2 +- src/ts/types.ts | 4 ++-- src/ts/utils/math-utils.ts | 4 ++-- src/ts/utils/vector-utils.ts | 19 +++++++++---------- 8 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/ts/data/levels/level00.ts b/src/ts/data/levels/level00.ts index 3028563..aa7cfd7 100644 --- a/src/ts/data/levels/level00.ts +++ b/src/ts/data/levels/level00.ts @@ -42,5 +42,5 @@ export const level00: Level = { [sw(1), sw(1), sw(5), sw(1), sst(4), sw(2), tw(2), sw(2), sw(2), sw(2)] ], entities: [], - sprites: [sbnt(4.5, 5.5, 11, 0.25, SpriteProperties.ALIGN_BOTTOM), sb(5.5, 5.5, 5, 1), sb(6.5, 5.5, 11, 0.25, SpriteProperties.ALIGN_BOTTOM | SpriteProperties.STATIC), sb(7.5, 5.5, 5, 0.25, SpriteProperties.ALIGN_TOP)], + sprites: [sbnt(4.5, 5.5, 11, 0.25, SpriteProperties.ALIGN_BOTTOM), sb(5.5, 5.5, 5, 1), sb(6.5, 5.5, 11, 0.25, SpriteProperties.ALIGN_BOTTOM | SpriteProperties.STATIC), sb(7.5, 5.5, 5, 0.25, SpriteProperties.ALIGN_TOP)] }; diff --git a/src/ts/index.ts b/src/ts/index.ts index 89d786a..dad3b2d 100644 --- a/src/ts/index.ts +++ b/src/ts/index.ts @@ -125,14 +125,14 @@ function onTick(timestamp: number): void { // If enabled, draw the minimap if (minimap) { const player = getPlayer(); - frontBuffer.fillStyle = "green"; + frontBuffer.fillStyle = 'green'; frontBuffer.fillRect(frontBufferProps.x + 10, frontBufferProps.y + 10, frontBufferProps.width * 0.2, frontBufferProps.height * 0.2); // Draw the direction Vector const directionStart = { - x: frontBufferProps.x + 10 + ((frontBufferProps.width * 0.2) / 2), - y: frontBufferProps.y + 10 + ((frontBufferProps.height * 0.2) / 2) - } + x: frontBufferProps.x + 10 + (frontBufferProps.width * 0.2) / 2, + y: frontBufferProps.y + 10 + (frontBufferProps.height * 0.2) / 2 + }; const directionEnd = vu.add(directionStart, vu.scale(player.direction, 20)); @@ -174,7 +174,6 @@ function onTick(timestamp: number): void { frontBuffer.fillText(`Angle: ${player.getAngle().toFixed(2)} Degrees`, 15, 15); frontBuffer.fillText(`FOV: ${player.getFOV().toFixed(2)} Degrees`, 15, 30); } - } window.requestAnimationFrame(onTick); diff --git a/src/ts/interfaces/circle.ts b/src/ts/interfaces/circle.ts index 9430a7c..ce6e4fa 100644 --- a/src/ts/interfaces/circle.ts +++ b/src/ts/interfaces/circle.ts @@ -1,4 +1,4 @@ -import type { Vector } from "./vector"; +import type { Vector } from './vector'; export interface Circle { position: Vector; diff --git a/src/ts/objects/entity.ts b/src/ts/objects/entity.ts index dbf80d1..da52d44 100644 --- a/src/ts/objects/entity.ts +++ b/src/ts/objects/entity.ts @@ -5,10 +5,10 @@ import type { Level } from '../interfaces/level'; import * as vu from '../utils/vector-utils.js'; import { radiansToDegrees } from '../utils/math-utils.js'; -import { isBlocked, isInteractive, isSolid } from '../utils/cell-utils.js'; +import { isBlocked, isSolid } from '../utils/cell-utils.js'; import { getCell } from '../utils/level-utils.js'; -export class Entity implements Dynamic{ +export class Entity implements Dynamic { position: Vector; direction: Vector; camera: Vector; @@ -44,12 +44,12 @@ export class Entity implements Dynamic{ update(elapsed: number): void {} rotate(amount: Radian): void { - this.direction = vu.rotate(this.direction, amount) - this.camera = vu.rotate(this.camera, amount) + this.direction = vu.rotate(this.direction, amount); + this.camera = vu.rotate(this.camera, amount); } move(amount: number, level: Level): void { - const position = vu.add(this.position, vu.scale(this.direction, amount)) + const position = vu.add(this.position, vu.scale(this.direction, amount)); // Check for a collision on the X Axis const xCell = getCell(level, Math.floor(position.x), Math.floor(this.position.y)); diff --git a/src/ts/raycaster.ts b/src/ts/raycaster.ts index a15053f..36c0be8 100644 --- a/src/ts/raycaster.ts +++ b/src/ts/raycaster.ts @@ -14,7 +14,7 @@ import { getAnimationFrame } from './utils/time-utils.js'; import { applyEffectTint, getTextureById, isTextureAnimated, isTextureStateful } from './utils/texture-utils.js'; import { isSpriteAlignedBottom, isSpriteAlignedTop, isSpriteStatic, isSpriteTinted } from './utils/sprite-utils.js'; import { radiansToDegrees } from './utils/math-utils.js'; -import * as vu from './utils/vector-utils.js' +import * as vu from './utils/vector-utils.js'; // Derived from https://lodev.org/cgtutor/raycasting.html. // Casts a ray from the specified point at the specified angle and returns the first Wall the ray impacts. diff --git a/src/ts/types.ts b/src/ts/types.ts index 4051ae8..7c8d285 100644 --- a/src/ts/types.ts +++ b/src/ts/types.ts @@ -1,4 +1,4 @@ -import { Vector } from "./interfaces/vector"; +import { Vector } from './interfaces/vector'; export type Radian = number; -export type Scaler = Vector; \ No newline at end of file +export type Scaler = Vector; diff --git a/src/ts/utils/math-utils.ts b/src/ts/utils/math-utils.ts index 62adda3..af4477b 100644 --- a/src/ts/utils/math-utils.ts +++ b/src/ts/utils/math-utils.ts @@ -10,7 +10,7 @@ export function degreesToRadians(degrees: number): number { // Converts a value from Radians to Degrees. export function radiansToDegrees(radians: number): number { - let theta = radians * 180 / Math.PI; + let theta = (radians * 180) / Math.PI; if (theta < 0) theta += 360; return theta; -} \ No newline at end of file +} diff --git a/src/ts/utils/vector-utils.ts b/src/ts/utils/vector-utils.ts index 4fd1e71..25360ac 100644 --- a/src/ts/utils/vector-utils.ts +++ b/src/ts/utils/vector-utils.ts @@ -1,4 +1,4 @@ -import { Vector } from "../interfaces/vector"; +import { Vector } from '../interfaces/vector'; export type Scaler = number; export type Radian = number; @@ -9,15 +9,15 @@ export function create(x: number = 0, y: number = 0): Vector { return { x, y - } + }; } export function normalise(v: Vector): Vector { - const magnitude = Math.sqrt((v.x * v.x) + (v.y * v.y)); + const magnitude = Math.sqrt(v.x * v.x + v.y * v.y); return { x: v.x / magnitude, y: v.y / magnitude - } + }; } export function add(a: Vector, b: Vector): Vector { @@ -38,31 +38,30 @@ export function multiply(a: Vector, b: Vector): Vector { return { x: a.x * b.x, y: a.y * b.y - } + }; } export function scale(a: Vector, factor: number): Vector { return { x: a.x * factor, y: a.y * factor - } + }; } export function rotate(v: Vector, radians: Radian): Vector { return { x: v.x * Math.cos(radians) - v.y * Math.sin(radians), y: v.x * Math.sin(radians) + v.y * Math.cos(radians) - } + }; } export function dot(a: Vector, b: Vector): Scaler { - return (a.x * b.x) + (a.y * b.y); + return a.x * b.x + a.y * b.y; } export function angle(a: Vector, b?: Vector): Radian { if (b !== undefined) { - return Math.acos(dot(a,b)); + return Math.acos(dot(a, b)); } return Math.atan2(a.y, a.x); } -