diff --git a/src/lib/ActionInputStateMachine.svelte.ts b/src/lib/ActionInputStateMachine.svelte.ts index 6875221..bf65756 100644 --- a/src/lib/ActionInputStateMachine.svelte.ts +++ b/src/lib/ActionInputStateMachine.svelte.ts @@ -1,14 +1,13 @@ -import type { AutoAction, AutoInputState } from '$lib/types'; +import type { AutoAction, AutoActionData, AutoInputState } from '$lib/types'; export class ActionInputStateMachine { actionState: AutoInputState = $state('None') as AutoInputState; held_bunnies: number = 0; - held_balloons: number = $state(0); - held_totes: number = $state(0); - held_scorables: number = $derived(this.held_balloons + this.held_bunnies); - held_ejectables: number = $derived(this.held_scorables + this.held_totes); + held_balloons: number = 0; + held_totes: number = 0; + /// Methods for adjusting the state (checked by user) intake_piece() { this.actionState = this.actionState === 'None' ? 'Intake' : this.actionState; } @@ -27,20 +26,39 @@ export class ActionInputStateMachine { } complete_action(success: boolean): AutoAction { + const action_data: AutoActionData = { + action: this.actionState as AutoAction, + success, + ok: true + }; + + if (this.new_action(action_data)) { + const ret = this.actionState.slice(); + this.actionState = 'None'; + return ret as AutoAction; + } else { + console.error('Illegal action, this is a bug'); + // UB aqfter contract of state machine has been broken + return {} as unknown as AutoAction; + } + } + + // Takes an action and returns if it's a legal one + public new_action(action_data: AutoActionData): boolean { + const success = action_data.success; + const action = action_data.action; if (success) { - if (this.actionState.includes('IntakeBalloon')) this.held_balloons++; - else if (this.actionState.includes('IntakeBunny')) this.held_bunnies++; - else if (this.actionState.includes('IntakeTote')) this.held_totes++; - else if (this.actionState.includes('EjectBalloon')) this.held_balloons--; - else if (this.actionState.includes('EjectBunny')) this.held_bunnies--; - else if (this.actionState.includes('EjectTote')) this.held_totes--; + 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('EjectBalloon')) this.held_balloons--; + else if (action.includes('EjectBunny')) this.held_bunnies--; + else if (action.includes('EjectTote')) this.held_totes--; } - // Assume failed scoring is still ejecting - if (this.actionState.includes('ScoreBalloon')) this.held_balloons--; - else if (this.actionState.includes('ScoreBunny')) this.held_bunnies--; + if (action.includes('ScoreBalloon')) this.held_balloons--; + else if (action.includes('ScoreBunny')) this.held_bunnies--; - const ret = this.actionState.slice(); - this.actionState = 'None'; - return ret as AutoAction; + if (action.includes('Intake')) return true; + return this.held_balloons >= 0 && this.held_bunnies >= 0 && this.held_totes >= 0; } } diff --git a/src/lib/components/Action.svelte b/src/lib/components/Action.svelte index 103f0fb..ea61e37 100644 --- a/src/lib/components/Action.svelte +++ b/src/lib/components/Action.svelte @@ -26,15 +26,18 @@ > {action_data.action}
+ {#if !action_data.ok} + Warning + {/if} diff --git a/src/lib/components/Timeline.svelte b/src/lib/components/Timeline.svelte index bc891d1..e07f81d 100644 --- a/src/lib/components/Timeline.svelte +++ b/src/lib/components/Timeline.svelte @@ -1,4 +1,5 @@ @@ -37,7 +40,12 @@ id="timeline" > {#each actions as _, i} - + {/each} {#if actions.length === 0}

No actions yet :3

diff --git a/src/lib/types.ts b/src/lib/types.ts index 74be898..bba036e 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -12,20 +12,6 @@ export type User = { }; /// Counts -export type AutoActionsTM = ActionsTM & { - bunny_intake_success: number; - bunny_intake_failure: number; - bunny_tote_success: number; - bunny_tote_failure: number; - bunny_low_success: number; - bunny_low_failure: number; - actions: AutoActionData[]; -}; - -export type TeleActionsTM = ActionsTM & { - actions: TeleActionData[]; -}; - export type ActionsTM = { id: number; tote_intake_success: number; @@ -44,6 +30,20 @@ export type ActionsTM = { score_other_robot_failure: number; }; +export type AutoActionsTM = ActionsTM & { + bunny_intake_success: number; + bunny_intake_failure: number; + bunny_tote_success: number; + bunny_tote_failure: number; + bunny_low_success: number; + bunny_low_failure: number; + actions: AutoActionData[]; +}; + +export type TeleActionsTM = ActionsTM & { + actions: TeleActionData[]; +}; + export type TeamMatch = { id: number; scout_id: string; @@ -57,14 +57,16 @@ export type TeamMatch = { tele_actions: TeleActionData[]; }; -export type AutoActionData = { - action: AutoAction; +export type TeleActionData = { + action: TeleAction; success: boolean; + ok: boolean; }; -export type TeleActionData = { - action: TeleAction; +export type AutoActionData = { + action: AutoAction; success: boolean; + ok: boolean; }; // Action Types diff --git a/src/routes/scout/ActionInputs.svelte b/src/routes/scout/ActionInputs.svelte index 704f98c..1f3150e 100644 --- a/src/routes/scout/ActionInputs.svelte +++ b/src/routes/scout/ActionInputs.svelte @@ -1,27 +1,60 @@