Add formatting to frontend (#27)

This commit is contained in:
lucas authored and GitHub committed 2026-01-05 19:25:41 +01:00
1 parent f3143c7b88
commit d4bb9b195f
14 files changed
+169 -82

No files matched your search

+1
View File
@@ -1 +1,2 @@
.DS_Store
.vscode
+5
View File
@@ -0,0 +1,5 @@
{
"singleQuote": false,
"semi": true,
"endOfLine": "auto"
}
+15 -4
View File
@@ -1,10 +1,21 @@
// @ts-check
import eslint from '@eslint/js';
import { defineConfig } from 'eslint/config';
import tseslint from 'typescript-eslint';
import eslint from "@eslint/js";
import { defineConfig } from "eslint/config";
import tseslint from "typescript-eslint";
import prettierConfig from "eslint-config-prettier";
import prettierPlugin from "eslint-plugin-prettier";
export default defineConfig(
eslint.configs.recommended,
tseslint.configs.recommended,
...tseslint.configs.recommended,
// disables ESLint rules that conflict with Prettier (must be near the end)
prettierConfig,
{
plugins: { prettier: prettierPlugin },
rules: {
"prettier/prettier": "error",
},
},
);
+5 -5
View File
@@ -1,13 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="/style.css">
<link rel="stylesheet" href="/style.css" />
<title>Auto Beer Pong</title>
</head>
</head>
<body>
<body>
<script type="module" src="/src/main.ts"></script>
</body>
</body>
</html>
+6 -6
View File
@@ -13,9 +13,9 @@
"devDependencies": {
"@eslint/js": "^9.39.1",
"eslint": "^9.39.1",
"eslint-config-prettier": "^10.1.2",
"eslint-plugin-prettier": "^5.2.6",
"prettier": "^3.5.3",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.4",
"prettier": "^3.7.4",
"typescript": "~5.7.3",
"typescript-eslint": "^8.48.0",
"vite": "^6.2.0"
@@ -2135,9 +2135,9 @@
}
},
"node_modules/prettier": {
"version": "3.6.2",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.6.2.tgz",
"integrity": "sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==",
"version": "3.7.4",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.7.4.tgz",
"integrity": "sha512-v6UNi1+3hSlVvv8fSaoUbggEM5VErKmmpGA7Pl3HF8V6uKY7rvClBOJlH6yNwQtfTueNkGVpOv/mtWL9L4bgRA==",
"dev": true,
"license": "MIT",
"bin": {
+5 -3
View File
@@ -7,6 +7,8 @@
"start": "npm run dev",
"build": "npm run lint && tsc && vite build",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"format": "prettier . --write",
"dev": "vite"
},
"dependencies": {
@@ -15,9 +17,9 @@
"devDependencies": {
"@eslint/js": "^9.39.1",
"eslint": "^9.39.1",
"eslint-config-prettier": "^10.1.2",
"eslint-plugin-prettier": "^5.2.6",
"prettier": "^3.5.3",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.4",
"prettier": "^3.7.4",
"typescript": "~5.7.3",
"typescript-eslint": "^8.48.0",
"vite": "^6.2.0"
+32 -20
View File
@@ -1,12 +1,22 @@
import { Actor, ActorArgs, Circle, Color, Engine, Graphic, GraphicsGroup, Random, vec, Vector } from "excalibur";
import {
Actor,
ActorArgs,
Circle,
Color,
Engine,
Graphic,
GraphicsGroup,
Random,
vec,
Vector,
} from "excalibur";
import { assertNotNull, assertNull } from "../utils/assertUtils";
import { gravitationalConstant, groundHeight } from "../utils/physicsConstant";
export const defaultBallConfiguration: BallConfiguration = {
color: Color.Orange,
radius: 5,
}
};
export interface BallConfiguration {
readonly color: Color;
@@ -19,11 +29,13 @@ export class Ball extends Actor {
private _graphic: Graphic = null!;
private _animation: BallAnimation = new BallAnimation(this);
constructor(actorArgs: ActorArgs, public readonly configuration: BallConfiguration) {
constructor(
actorArgs: ActorArgs,
public readonly configuration: BallConfiguration,
) {
super(actorArgs);
}
onInitialize(engine: Engine): void {
const { configuration } = this;
const { radius } = configuration;
@@ -40,10 +52,10 @@ export class Ball extends Actor {
this._graphic = new GraphicsGroup({
members: [
{ graphic: ballGraphic, offset: vec(0, 0)},
{ graphic:specularGraphic, offset: vec(radius / 2, radius / 2)}
{ graphic: ballGraphic, offset: vec(0, 0) },
{ graphic: specularGraphic, offset: vec(radius / 2, radius / 2) },
],
})
});
this.graphics.add(this._graphic);
@@ -51,12 +63,14 @@ export class Ball extends Actor {
this.pos = start;
engine.input.pointers.primary.on("down", () => {
const randomVelocity = vec(random.integer(100, 400), random.integer(0, -400));
const randomVelocity = vec(
random.integer(100, 400),
random.integer(0, -400),
);
this.startParabolaAnimation(new Parabola(start, randomVelocity));
})
});
}
public update(engine: Engine, elapsed: number): void {
super.update(engine, elapsed);
this._animation.update(elapsed);
@@ -72,9 +86,7 @@ class BallAnimation {
private _parabola: Parabola | null = null;
private _elapsedTime: number | null = null;
constructor(private _ball: Ball) {
}
constructor(private _ball: Ball) {}
get running(): boolean {
return this._running;
@@ -116,23 +128,23 @@ class BallAnimation {
this._ball.pos = newPosition;
}
}
export class Parabola {
constructor(
readonly startPos: Vector,
readonly startVelocity: Vector
) { }
readonly startVelocity: Vector,
) {}
position(time: number): Vector {
const timeSeconds = time / 1000;
const x = this.startPos.x + this.startVelocity.x * timeSeconds;
const y = this.startVelocity.y * timeSeconds + gravitationalConstant / 2 * timeSeconds ** 2 + this.startPos.y;
const y =
this.startVelocity.y * timeSeconds +
(gravitationalConstant / 2) * timeSeconds ** 2 +
this.startPos.y;
return new Vector(x, y);
}
}
+34 -16
View File
@@ -1,4 +1,14 @@
import { Actor, ActorArgs, Color, Engine, Graphic, GraphicsGroup, Line, Polygon,vec } from "excalibur";
import {
Actor,
ActorArgs,
Color,
Engine,
Graphic,
GraphicsGroup,
Line,
Polygon,
vec,
} from "excalibur";
import { pixelsPerMeter } from "../utils/physicsConstant";
import { jitterVector, randomInteger } from "../utils/randomUtils";
@@ -61,19 +71,28 @@ export class Champion extends Actor {
this.anchor = vec(0.5, 1);
this._graphic = new GraphicsGroup({
members: [
{ graphic: leftLeg , offset: vec(0, -waistHeight)},
{ graphic: rightLeg , offset: vec(0, -waistHeight)},
{ graphic: leftLeg, offset: vec(0, -waistHeight) },
{ graphic: rightLeg, offset: vec(0, -waistHeight) },
{ graphic: bodyGraphic, offset: vec(-width / 2, -height) },
{ graphic: headGraphic, offset: vec(-headSize / 2, -height - headSize / 2) },
{ graphic: smileEyeGraphic.clone(), offset: vec(-headSize / 4, -height) },
{ graphic: smileEyeGraphic.clone(), offset: vec(headSize / 4, -height) },
{
graphic: headGraphic,
offset: vec(-headSize / 2, -height - headSize / 2),
},
{
graphic: smileEyeGraphic.clone(),
offset: vec(-headSize / 4, -height),
},
{
graphic: smileEyeGraphic.clone(),
offset: vec(headSize / 4, -height),
},
],
useAnchor: false,
})
});
this.graphics.add(this._graphic);
this.rotation = Math.PI / 180 * 5;
this.rotation = (Math.PI / 180) * 5;
}
update(_engine: Engine, elapsed: number): void {
@@ -84,9 +103,8 @@ export class Champion extends Actor {
this._jiggleTimer += elapsed;
if (this._jiggleTimer > jiggleTime) {
this._jiggleTimer -= jiggleTime;
this.rotation = -this.rotation
this.rotation = -this.rotation;
}
}
}
@@ -104,9 +122,9 @@ const _crossEyeGraphic = new GraphicsGroup({
end: vec(-5, 5),
color: Color.Black,
thickness: 3,
})
]
});
}),
],
});
const smileEyeGraphic = new GraphicsGroup({
members: [
@@ -121,6 +139,6 @@ const smileEyeGraphic = new GraphicsGroup({
end: vec(10, 5),
color: Color.Black,
thickness: 3,
})
]
});
}),
],
});
+17 -6
View File
@@ -1,5 +1,14 @@
import { Actor, ActorArgs, Color, Engine, Graphic, GraphicsGroup, Line, Polygon,vec } from "excalibur";
import {
Actor,
ActorArgs,
Color,
Engine,
Graphic,
GraphicsGroup,
Line,
Polygon,
vec,
} from "excalibur";
import { pixelsPerMeter } from "../utils/physicsConstant";
export const defaultCupConfiguration = {
@@ -9,7 +18,7 @@ export const defaultCupConfiguration = {
widthBottom: 0.12 * pixelsPerMeter,
height: 0.2 * pixelsPerMeter,
rimThickness: 0.02 * pixelsPerMeter,
}
};
export interface CupConfiguration {
readonly cupColor: Color;
@@ -23,15 +32,17 @@ export interface CupConfiguration {
export class Cup extends Actor {
private _graphic: Graphic = null!;
constructor(actorArgs: ActorArgs, public readonly configuration: CupConfiguration) {
constructor(
actorArgs: ActorArgs,
public readonly configuration: CupConfiguration,
) {
super(actorArgs);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onInitialize(_engine: Engine): void {
const { configuration } = this;
const { height, widthRim, widthBottom, } = configuration;
const { height, widthRim, widthBottom } = configuration;
const halfWidthBottom = widthBottom / 2;
const halfWidthRim = widthRim / 2;
+2 -2
View File
@@ -7,13 +7,13 @@ export class Ground extends Actor {
private _graphic: Graphic = null!;
onInitialize(engine: Engine): void {
const { width, height} = engine.screen;
const { width, height } = engine.screen;
this._graphic = new Rectangle({
width,
height: height / 2,
color: groundColor,
})
});
this.graphics.add(this._graphic);
this.pos.setTo(0, groundHeight);
+16 -4
View File
@@ -1,4 +1,12 @@
import { Actor, ActorArgs, Color, Engine, Graphic, Polygon,vec } from "excalibur";
import {
Actor,
ActorArgs,
Color,
Engine,
Graphic,
Polygon,
vec,
} from "excalibur";
import { pixelsPerMeter } from "../utils/physicsConstant";
export const defaultTableConfiguration = {
@@ -8,7 +16,7 @@ export const defaultTableConfiguration = {
thickness: 0.15 * pixelsPerMeter,
legOffset: 0.15 * pixelsPerMeter,
legThickness: 0.15 * pixelsPerMeter,
}
};
export interface TableConfiguration {
readonly color: Color;
@@ -22,13 +30,17 @@ export interface TableConfiguration {
export class Table extends Actor {
private _graphic: Graphic = null!;
constructor(actorArgs: ActorArgs, public readonly configuration: TableConfiguration) {
constructor(
actorArgs: ActorArgs,
public readonly configuration: TableConfiguration,
) {
super(actorArgs);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onInitialize(_engine: Engine): void {
const { width, height, thickness, legOffset, legThickness } = this.configuration;
const { width, height, thickness, legOffset, legThickness } =
this.configuration;
const halfWidth = width / 2;
const points = [
+19 -12
View File
@@ -18,7 +18,6 @@ export class GameScene extends GameStateScene {
private _cups: Cup[] = [];
private _champions: Champion[] = [];
// eslint-disable-next-line @typescript-eslint/no-unused-vars
constructor(private _connection: Connection) {
super();
@@ -31,33 +30,41 @@ export class GameScene extends GameStateScene {
this._ground = new Ground();
this.add(this._ground);
this._table = new Table({pos: vec(0, groundHeight)}, defaultTableConfiguration);
this._table = new Table(
{ pos: vec(0, groundHeight) },
defaultTableConfiguration,
);
this.add(this._table);
const tableHalfWidth = this._table.configuration.width / 2;
const tableHeight = this._table.configuration.height;
const cupPositions = [
...[10, 32, 54].map(v => v - tableHalfWidth),
...[10, 32, 54].map(v => -v + tableHalfWidth),
...[10, 32, 54].map((v) => v - tableHalfWidth),
...[10, 32, 54].map((v) => -v + tableHalfWidth),
];
cupPositions.forEach(offsetX => {
const cup = new Cup({
cupPositions.forEach((offsetX) => {
const cup = new Cup(
{
pos: vec(offsetX, groundHeight - tableHeight),
color: Color.Red,
}, defaultCupConfiguration)
},
defaultCupConfiguration,
);
this.add(cup);
this._cups.push(cup);
});
const championPositions = [
...[50, 150, 250].map(v => -v - tableHalfWidth),
...[50, 150, 250].map(v => v + tableHalfWidth)
...[50, 150, 250].map((v) => -v - tableHalfWidth),
...[50, 150, 250].map((v) => v + tableHalfWidth),
];
championPositions.forEach(offsetX => {
const champion = new Champion({color: randomNonGroundColor(), pos: vec(offsetX, groundHeight)});
championPositions.forEach((offsetX) => {
const champion = new Champion({
color: randomNonGroundColor(),
pos: vec(offsetX, groundHeight),
});
this.add(champion);
this._champions.push(champion);
});
+5 -1
View File
@@ -1,5 +1,9 @@
import { Color } from "excalibur";
export function colorDistance(color1: Color, color2: Color): number {
return Math.abs(color1.r - color2.r) + Math.abs(color1.g - color2.g) + Math.abs(color1.b - color2.b);
return (
Math.abs(color1.r - color2.r) +
Math.abs(color1.g - color2.g) +
Math.abs(color1.b - color2.b)
);
}
+7 -3
View File
@@ -3,7 +3,11 @@ import { Color, Random, vec, Vector } from "excalibur";
const rand = new Random();
export function randomColor(): Color {
return new Color(rand.integer(0, 255), rand.integer(0, 255), rand.integer(0, 255));
return new Color(
rand.integer(0, 255),
rand.integer(0, 255),
rand.integer(0, 255),
);
}
/** Jitter given vector by at most the given magnitude. The random offset is [-magnitude / 2, magnitude / 2] */
@@ -13,6 +17,6 @@ export function jitterVector(v: Vector, magnitude: number): Vector {
return vec(x, y);
}
export function randomInteger(min: number, max:number): number {
return rand.integer(min, max -1);
export function randomInteger(min: number, max: number): number {
return rand.integer(min, max - 1);
}