From a91ad8398d8ff9bdcc8ca03dce05645cc7dbc6d1 Mon Sep 17 00:00:00 2001 From: Francesco Minnocci Date: Thu, 29 Feb 2024 00:37:10 +0100 Subject: [PATCH] add prettier, fix TS stuff --- .prettierrc | 9 +++++++++ src/scripts/circuits-art.ts | 31 ++++++++++++++++++++++++------- tsconfig.json | 12 ++++++------ 3 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..6f80c3f --- /dev/null +++ b/.prettierrc @@ -0,0 +1,9 @@ +{ + "printWidth": 110, + "singleQuote": true, + "quoteProps": "consistent", + "tabWidth": 4, + "useTabs": false, + "semi": false, + "arrowParens": "avoid" +} diff --git a/src/scripts/circuits-art.ts b/src/scripts/circuits-art.ts index 5b4e8c6..fc76d7f 100644 --- a/src/scripts/circuits-art.ts +++ b/src/scripts/circuits-art.ts @@ -68,7 +68,7 @@ function setup() { const startTime = new Date() - const handle = setInterval(() => { + const handle = window.setInterval(() => { const time = new Date().getTime() - startTime.getTime() update(state, g.canvas.width, g.canvas.height, time) @@ -264,16 +264,26 @@ const DIR_AVAILABLE_PREDICATE: Record grid.get([x - 1, y]) !== 'down-right') && implies(grid.has([x + 1, y]), () => grid.get([x + 1, y]) !== 'down-left'), - ['down-left']: ([x, y], grid) => !grid.has([x - 1, y + 1]) && implies(grid.has([x - 1, y]), () => grid.get([x - 1, y]) === 'down-left'), + ['down-left']: ([x, y], grid) => + !grid.has([x - 1, y + 1]) && + implies(grid.has([x - 1, y]), () => grid.get([x - 1, y]) === 'down-left'), ['down-right']: ([x, y], grid) => - !grid.has([x + 1, y + 1]) && implies(grid.has([x + 1, y]), () => grid.get([x + 1, y]) === 'down-right'), + !grid.has([x + 1, y + 1]) && + implies(grid.has([x + 1, y]), () => grid.get([x + 1, y]) === 'down-right'), } -function pruneDirections(grid: Grid, position: Point2, directions: WireDirection[]): WireDirection[] { +function pruneDirections( + grid: Grid, + position: Point2, + directions: WireDirection[] +): WireDirection[] { return directions.filter(dir => DIR_AVAILABLE_PREDICATE[dir](position, grid)) } -function generateWire(grid: Grid, startingPoint: Point2): { position: Point2; direction: WireCell }[] { +function generateWire( + grid: Grid, + startingPoint: Point2 +): { position: Point2; direction: WireCell }[] { const segmentLength = Math.floor(1 - Math.random() ** 2) * 10 + 30 let currentPosition = startingPoint let currentDirection: WireDirection = randomChoice(['down', 'down', 'down', 'down-left', 'down-right']) @@ -281,7 +291,11 @@ function generateWire(grid: Grid, startingPoint: Point2): { position: const steps: { position: Point2; direction: WireCell }[] = [] for (let i = 0; i < segmentLength; i++) { - const availableDirections = pruneDirections(grid, currentPosition, ['down', 'down-left', 'down-right']) + const availableDirections = pruneDirections(grid, currentPosition, [ + 'down', + 'down-left', + 'down-right', + ]) if (availableDirections.length === 0) { break } else { @@ -290,7 +304,10 @@ function generateWire(grid: Grid, startingPoint: Point2): { position: ? currentDirection : randomChoice(availableDirections) - if ((currentDirection === 'down-left' && dir === 'down-right') || (currentDirection === 'down-right' && dir === 'down-left')) { + if ( + (currentDirection === 'down-left' && dir === 'down-right') || + (currentDirection === 'down-right' && dir === 'down-left') + ) { break } diff --git a/tsconfig.json b/tsconfig.json index e90c686..560c357 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { - "extends": "astro/tsconfigs/strict", - "compilerOptions": { - "jsx": "react-jsx", - "jsxImportSource": "preact" - } -} \ No newline at end of file + "extends": "astro/tsconfigs/strict", + "compilerOptions": { + "jsx": "react-jsx", + "jsxImportSource": "preact" + } +}