Skip to content

Commit

Permalink
BunnyBots Fixes and Features (#27)
Browse files Browse the repository at this point in the history
* fix: a 502 error and some other stuff adley found

* feat: clear robots button

* style: clear robots button

* chore: remove old tailwind config file

* fix: failing to eject an unheld item is an illegal state

* fix: icon displays and doesn't error

* fix/feat: all the fixes and features from bunnybots and the days leading up to it

* style: format files

---------

Co-authored-by: azaleacolburn <[email protected]>
  • Loading branch information
azaleacolburn and azaleacolburn authored Dec 17, 2024
1 parent 4b4936a commit d27c276
Show file tree
Hide file tree
Showing 19 changed files with 715 additions and 250 deletions.
Binary file modified bun.lockb
Binary file not shown.
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.1",
"type": "module",
"scripts": {
"dev": "vite dev",
"dev": "vite dev --port 3020",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
Expand Down Expand Up @@ -35,14 +35,12 @@
},
"dependencies": {
"autoprefixer": "^10.4.20",
"mysql2": "^3.11.4",
"lucide-svelte": "^0.460.1",
"pg": "^8.13.1",
"postgresql": "^0.0.1",
"socket.io": "^4.8.1",
"socket.io-client": "^4.8.1",
"tailwindcss": "^3.4.14",
"typescript-eslint": "^8.14.0",
"vite": "^5.4.11",
"lucide-svelte": "^0.460.1",
"socket.io": "^4.8.1",
"socket.io-client": "^4.8.1"
"vite": "^5.4.11"
}
}
7 changes: 5 additions & 2 deletions src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="flamingChicken.png" />
<meta name="viewport" content="width=device-width" />
<link rel="icon" href="./flamingChicken.png" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
Expand Down
11 changes: 10 additions & 1 deletion src/lib/ActionInputStateMachine.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export class ActionInputVerifier {
};
}

public actions_are_ok(action_data: AutoActionData[]): boolean {
return action_data.every((action) => action.ok);
}

public verify_actions(action_data: AutoActionData[]) {
action_data.forEach((action) => {
action.ok = this.verify_new_action(action);
Expand All @@ -32,15 +36,20 @@ export class ActionInputVerifier {
verify_new_action(action_data: AutoActionData): boolean {
const success = action_data.success;
const action = action_data.action;
console.log(action);
if (action.includes('InternalTote') && this.held_totes === 0) return false;
if (success) {
if (action.includes('IntakeBalloon')) this.held_balloons++;
else if (action.includes('IntakeBunny')) this.held_bunnies++;
else if (action.includes('IntakeTote')) this.held_totes++;
else if (action.includes('PreloadBunny')) this.held_bunnies++;
else if (action.includes('PreloadBalloon')) this.held_balloons++;
else if (action.includes('EjectBalloon')) this.held_balloons--;
else if (action.includes('EjectBunny')) this.held_bunnies--;
else if (action.includes('EjectTote')) this.held_totes--;
} else {
if (action.includes('EjectBunny') && this.held_bunnies === 0) return false;
else if (action.includes('EjectBalloon') && this.held_balloons === 0) return false;
else if (action.includes('EjectTote') && this.held_totes === 0) return false;
}
if (action.includes('ScoreBalloon')) this.held_balloons--;
else if (action.includes('ScoreBunny')) this.held_bunnies--;
Expand Down
31 changes: 31 additions & 0 deletions src/lib/localStore.svelte.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { browser } from '$app/environment';

export class LocalStore<T> {
value = $state<T[]>() as T[];
key = '';

constructor(key: string, value: T[]) {
this.value = value;
this.key = key;

if (browser) {
const item = localStorage.getItem(key);
if (item) this.value = this.deserialize(item);
}

$effect(() => {
if (this.value.length > 12) {
this.value.splice(0, 1);
}
localStorage.setItem(this.key, this.serialize(this.value));
});
}

serialize(value: T[]): string {
return JSON.stringify(value);
}

deserialize(item: string): T[] {
return JSON.parse(item);
}
}
15 changes: 13 additions & 2 deletions src/lib/server-assets/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ const event_key = 'orbb2024';
// Whether or not the database is currently being used
const use_db: boolean = USE_DB === 'true';

console.log(Number.parseInt(DB_PORT));

const db = new Client({
user: DB_USER,
password: DB_PASSWORD,
Expand Down Expand Up @@ -234,6 +232,19 @@ export async function insertUser(name: string): Promise<boolean> {
}
}

export async function delete_team_match(
match_key: string,
team_key: string
): Promise<number | null> {
if (!use_db) return null;

const response = await db.query(
'DELETE FROM "TeamMatches" WHERE "match_key" = $1 AND "team_key" = $2',
[match_key, team_key]
);
return response.rowCount;
}

export async function select(matchkey: string, teamkey: string) {
if (!use_db) return null;

Expand Down
4 changes: 3 additions & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ export type BunnyAction =
| 'ScoreBunnyExternalTote'
| 'ScoreBunnyUncontrolledTote'
| 'ScoreBunnyLow';
export type AutoAction = TeleAction | BunnyAction;

export type PreAction = 'PreloadBunny' | 'PreloadBalloon';
export type AutoAction = TeleAction | BunnyAction | PreAction;

export type TeleHeldItems = {
balloons: number;
Expand Down
Loading

0 comments on commit d27c276

Please sign in to comment.