Skip to content

Commit

Permalink
Enable more linting rules
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdubbelboer committed Dec 17, 2023
1 parent 1a496a5 commit 3da99e8
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 48 deletions.
14 changes: 14 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
"env": {
"browser": true
},
"rules": {
"eqeqeq": 1,
"no-else-return": 1,
"no-invalid-this": 1,
"no-redeclare": 1,
"no-sequences": 1,
"no-undef-init": 1,
"no-unmodified-loop-condition": 1,
"no-unneeded-ternary": 1,
"no-unused-expressions": 1,
"no-use-before-define": 1,
"no-var": 1,
"prefer-const": 1
},
"globals": {
"PokiSDK": "readonly"
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"watch": "rollup -c -w --sourcemap",
"build": "rm -rf dist && rollup -c",
"format": "prettier --write .",
"lint": "eslint . && stylelint public/css/*.css"
"lint": "eslint --fix . && stylelint public/css/*.css"
},
"dependencies": {
"@pixi/assets": "7.3.2",
Expand Down
6 changes: 3 additions & 3 deletions src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ export class Game extends EventEmitter {
}

resize() {
let width = window.innerWidth;
let height = window.innerHeight;
const width = window.innerWidth;
const height = window.innerHeight;

const m = 1200 / Math.max(width, height);

Expand Down Expand Up @@ -407,7 +407,7 @@ export class Game extends EventEmitter {
}

let next = ms;
let rm;
let rm = () => {};
const cb = () => {
if (this.destroyed) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function init(extension) {

window.game = new Game(loader).once('done', () => {
gameStarted = false;
window.game = null;

canvas.style.display = 'none';

Expand Down
17 changes: 12 additions & 5 deletions src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,22 @@ export class Loader extends EventEmitter {
const p = Math.max(progress, 0.1) * 80;
this.loadingBar.style.width = p + '%';
},
).then(() => {
this.postload();
});
)
.then(() => {
this.postload();
})
.catch((err) => {
console.error(err);

// Hope for the best and continue.
this.postload();
});
});
}

postload() {
let width = window.innerWidth * 1.2;
let height = window.innerHeight * 1.2;
const width = window.innerWidth * 1.2;
const height = window.innerHeight * 1.2;

this.app = new PIXI.Application({
width,
Expand Down
78 changes: 39 additions & 39 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,34 @@ export function easeOutSine(x) {
// Distances

export function linePointDistance(p1, p2, c) {
var ac = { x: c.x - p1.x, y: c.y - p1.y };
var ab = { x: p2.x - p1.x, y: p2.y - p1.y };
var ab2 = dot(ab, ab);
var acab = dot(ac, ab);
var t = acab / ab2;
const ac = { x: c.x - p1.x, y: c.y - p1.y };
const ab = { x: p2.x - p1.x, y: p2.y - p1.y };
const ab2 = dot(ab, ab);
const acab = dot(ac, ab);
let t = acab / ab2;
t = t < 0 ? 0 : t;
t = t > 1 ? 1 : t;
var h = { x: ab.x * t + p1.x - c.x, y: ab.y * t + p1.y - c.y };
var h2 = dot(h, h);
const h = { x: ab.x * t + p1.x - c.x, y: ab.y * t + p1.y - c.y };
const h2 = dot(h, h);
return Math.sqrt(h2);
}

// Functions related to colors

// lerpColor lerps between two colors in 0xrrggbb format.
export function lerpColor(a, b, t) {
const ar = (a >> 16) & 0xff;
const ag = (a >> 8) & 0xff;
const ab = a & 0xff;
const br = (b >> 16) & 0xff;
const bg = (b >> 8) & 0xff;
const bb = b & 0xff;
const rr = ar + (br - ar) * t;
const rg = ag + (bg - ag) * t;
const rb = ab + (bb - ab) * t;
return (rr << 16) | (rg << 8) | rb;
}

// Lines

// smoothLine draws a line from from to to with a smooth transition from fromSize to toSize and fromColor to toColor.
Expand Down Expand Up @@ -60,12 +76,12 @@ export function smoothLine(g, from, to, fromSize, toSize, fromColor, toColor, fr

// lineLineIntersection returns true if the lines intersect, false otherwise.
export function lineLineIntersection(p1, p2, p3, p4) {
var s1_x = p2.x - p1.x;
var s1_y = p2.y - p1.y;
var s2_x = p4.x - p3.x;
var s2_y = p4.y - p3.y;
var s = (-s1_y * (p1.x - p3.x) + s1_x * (p1.y - p3.y)) / (-s2_x * s1_y + s1_x * s2_y);
var t = (s2_x * (p1.y - p3.y) - s2_y * (p1.x - p3.x)) / (-s2_x * s1_y + s1_x * s2_y);
const s1_x = p2.x - p1.x;
const s1_y = p2.y - p1.y;
const s2_x = p4.x - p3.x;
const s2_y = p4.y - p3.y;
const s = (-s1_y * (p1.x - p3.x) + s1_x * (p1.y - p3.y)) / (-s2_x * s1_y + s1_x * s2_y);
const t = (s2_x * (p1.y - p3.y) - s2_y * (p1.x - p3.x)) / (-s2_x * s1_y + s1_x * s2_y);
return s >= 0 && s <= 1 && t >= 0 && t <= 1;
}

Expand Down Expand Up @@ -125,15 +141,15 @@ export function lineBoxIntersection(v1, v2, box) {

// polygonPolygonIntersection returns true if the polygons intersect, false otherwise.
export function polygonPolygonIntersection(points1, points2) {
var a = points1;
var b = points2;
var polygons = [a, b];
var minA, maxA, projected, minB, maxB, j;
for (var i = 0; i < polygons.length; i++) {
var polygon = polygons[i];
for (var i1 = 0; i1 < polygon.length; i1 += 2) {
var i2 = (i1 + 2) % polygon.length;
var normal = { x: polygon[i2 + 1] - polygon[i1 + 1], y: polygon[i1] - polygon[i2] };
const a = points1;
const b = points2;
const polygons = [a, b];
let minA, maxA, projected, minB, maxB, j;
for (let i = 0; i < polygons.length; i++) {
const polygon = polygons[i];
for (let i1 = 0; i1 < polygon.length; i1 += 2) {
const i2 = (i1 + 2) % polygon.length;
const normal = { x: polygon[i2 + 1] - polygon[i1 + 1], y: polygon[i1] - polygon[i2] };
minA = maxA = null;
for (j = 0; j < a.length; j += 2) {
projected = normal.x * a[j] + normal.y * a[j + 1];
Expand Down Expand Up @@ -228,22 +244,6 @@ export function rotateXY(p, angle) {
};
}

// Functions related to colors

// lerpColor lerps between two colors in 0xrrggbb format.
export function lerpColor(a, b, t) {
const ar = (a >> 16) & 0xff;
const ag = (a >> 8) & 0xff;
const ab = a & 0xff;
const br = (b >> 16) & 0xff;
const bg = (b >> 8) & 0xff;
const bb = b & 0xff;
const rr = ar + (br - ar) * t;
const rg = ag + (bg - ag) * t;
const rb = ab + (bb - ab) * t;
return (rr << 16) | (rg << 8) | rb;
}

// Randomness functions

// mulberry32 is a fast deterministic random number generator.
Expand All @@ -263,7 +263,7 @@ export function mulberry32(a) {
export function shuffle(array) {
for (let i = array.length - 1; i > 0; i--) {
// Generate a random index between 0 and i
let j = Math.floor(Math.random() * (i + 1));
const j = Math.floor(Math.random() * (i + 1));

// Swap elements at index i and j
[array[i], array[j]] = [array[j], array[i]];
Expand Down

0 comments on commit 3da99e8

Please sign in to comment.