add prettier, fix TS stuff

website-ng
Francesco Minnocci 3 months ago
parent ff3a44e23c
commit a91ad8398d
No known key found for this signature in database
GPG Key ID: 76DA3AF9BAED1A32

@ -0,0 +1,9 @@
{
"printWidth": 110,
"singleQuote": true,
"quoteProps": "consistent",
"tabWidth": 4,
"useTabs": false,
"semi": false,
"arrowParens": "avoid"
}

@ -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<WireDirection, (pos: Point2, grid: Grid<Wi
!grid.has([x, y + 1]) &&
implies(grid.has([x - 1, y]), () => 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<WireCell>, position: Point2, directions: WireDirection[]): WireDirection[] {
function pruneDirections(
grid: Grid<WireCell>,
position: Point2,
directions: WireDirection[]
): WireDirection[] {
return directions.filter(dir => DIR_AVAILABLE_PREDICATE[dir](position, grid))
}
function generateWire(grid: Grid<WireCell>, startingPoint: Point2): { position: Point2; direction: WireCell }[] {
function generateWire(
grid: Grid<WireCell>,
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<WireCell>, 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<WireCell>, 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
}

@ -1,7 +1,7 @@
{
"extends": "astro/tsconfigs/strict",
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact"
}
}
"extends": "astro/tsconfigs/strict",
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact"
}
}

Loading…
Cancel
Save