refactor: extract signals filter builder, add ESLint 10 config, fix low-hanging issues

This commit is contained in:
Sebastian Seedorf
2026-06-04 14:09:12 +02:00
parent cf9bb33ecb
commit 4b05f2968e
34 changed files with 2145 additions and 188 deletions

View File

@@ -2,7 +2,7 @@ import { readFileSync, writeFileSync } from 'fs';
const CSV = 'public/factorio_item_colors.csv';
function hexToHsl(h: string): [number, number, number] {
let r = parseInt(h.slice(1, 3), 16) / 255,
const r = parseInt(h.slice(1, 3), 16) / 255,
g = parseInt(h.slice(3, 5), 16) / 255,
b = parseInt(h.slice(5, 7), 16) / 255;
const mx = Math.max(r, g, b),
@@ -11,7 +11,7 @@ function hexToHsl(h: string): [number, number, number] {
if (mx === mn) return [0, 0, Math.round(l * 100)];
const d = mx - mn,
s = l > 0.5 ? d / (2 - mx - mn) : d / (mx + mn);
let hue = 0;
let hue: number;
if (mx === r) hue = ((g - b) / d + (g < b ? 6 : 0)) * 60;
else if (mx === g) hue = ((b - r) / d + 2) * 60;
else hue = ((r - g) / d + 4) * 60;
@@ -61,7 +61,14 @@ function hueDist(a: number, b: number): number {
return Math.min(d, 360 - d);
}
const lines = readFileSync(CSV, 'utf-8').trim().split('\n');
let rawText: string;
try {
rawText = readFileSync(CSV, 'utf-8');
} catch (e) {
console.error('Failed to read CSV:', e);
process.exit(1);
}
const lines = rawText.trim().split('\n');
const header = lines[0];
const raw = lines
.slice(1)
@@ -108,8 +115,9 @@ for (let i = 0; i < n; i++) {
const groups = new Map<number, typeof hsl>();
for (let i = 0; i < n; i++) {
const root = find(i);
if (!groups.has(root)) groups.set(root, []);
groups.get(root)!.push(hsl[i]);
const group = groups.get(root) ?? [];
if (!groups.has(root)) groups.set(root, group);
group.push(hsl[i]);
}
let fixed = 0;