Skip to content

Commit

Permalink
fix/feat: all the fixes and features from bunnybots and the days lead…
Browse files Browse the repository at this point in the history
…ing up to it
  • Loading branch information
azaleacolburn committed Dec 15, 2024
1 parent d67d64f commit 9532421
Show file tree
Hide file tree
Showing 14 changed files with 693 additions and 217 deletions.
13 changes: 9 additions & 4 deletions 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,19 +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('EjectBalloon') && this.held_balloons <= 0) return false;
else if (action.includes('EjectBunny') && this.held_bunnies <= 0) return false;
else if (action.includes('EjectTote') && this.held_totes <= 0) return false;
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 9532421

Please sign in to comment.