From 7662583a55331e22c33a54b210b93174a2924fb4 Mon Sep 17 00:00:00 2001 From: Azalea Colburn Date: Wed, 13 Nov 2024 18:51:23 -0800 Subject: [PATCH 1/2] feat: piece specific error prevention --- src/lib/types.ts | 16 +++-- src/routes/scout/ActionInputs.svelte | 90 +++++++++++++++++++--------- 2 files changed, 72 insertions(+), 34 deletions(-) diff --git a/src/lib/types.ts b/src/lib/types.ts index b8e462e..14bef75 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -68,16 +68,22 @@ export type TeleActionData = { }; // Action Types +// Naming Convention: action_type + game_piece + where export type TeleAction = | 'IntakeTote' | 'IntakeBalloon' - | 'IntakeCoral' - | 'ScoreYourHeldTote' - | 'ScoreOtherHeldTote' - | 'ScoreExternalTote' + | 'IntakeBalloonCoral' + | 'ScoreBalloonInternalTote' // Held by scorer + | 'ScoreBalloonExternalTote' // Held by alliance member + | 'ScoreBalloonUncontrolledTote' | 'ScoreBalloonLow'; -export type BunnyAction = 'IntakeBunny' | 'ScoreBunnyTote' | 'ScoreBunnyLow'; +export type BunnyAction = + | 'IntakeBunny' + | 'ScoreBunnyInternalTote' + | 'ScoreBunnyExternalTote' + | 'ScoreBunnyUncontrolledTote' + | 'ScoreBunnyLow'; export type AutoAction = TeleAction | BunnyAction; // For state machine diff --git a/src/routes/scout/ActionInputs.svelte b/src/routes/scout/ActionInputs.svelte index 5b8bba3..8bf785b 100644 --- a/src/routes/scout/ActionInputs.svelte +++ b/src/routes/scout/ActionInputs.svelte @@ -5,7 +5,11 @@ const { actions = $bindable() }: { actions: AutoActionData[] } = $props(); let actionState: AutoInputState = $state('None') as AutoInputState; - let held_pieces: number = $state(0); + + let held_bunnies: number = $state(0); + let held_balloons: number = $state(0); + let held_totes: number = $state(0); + let held_pieces: number = $derived(held_balloons + held_bunnies); function intake_piece() { actionState = actionState === 'None' ? 'Intake' : actionState; @@ -14,10 +18,19 @@ if (held_pieces < 1) return; actionState = actionState === 'None' ? 'Score' : actionState; } + function score_bunny(where: 'Low' | 'ExternalTote' | 'InternalTote' | 'UncontrolledTote') { + actionState = `ScoreBunny${where}`; + } + function score_balloon(where: 'Low' | 'InternalTote' | 'ExternalTote' | 'UncontrolledTote') { + actionState = `ScoreBalloon${where}`; + } function complete(success: boolean) { // Assume that the robot ejects even if they fail to score - if (actionState.substring(0, 5) === 'Score') held_pieces--; - else if (actionState.substring(0, 6) === 'Intake' && success) held_pieces++; + if (actionState.includes('IntakeBalloon')) held_balloons++; + else if (actionState.includes('IntakeBunny')) held_bunnies++; + else if (actionState.includes('IntakeTote')) held_totes++; + else if (actionState.includes('ScoreBalloon')) held_balloons--; + else if (actionState.includes('ScoreBunny')) held_bunnies--; const action: AutoActionData = { action: actionState as AutoAction, @@ -50,7 +63,9 @@ - - - - - - + {#if held_bunnies > 0} + + + {#if held_totes > 0} + + {/if} + + {/if} + {#if held_balloons > 0} + + + {#if held_totes > 0} + + {/if} + + {/if} Date: Wed, 13 Nov 2024 19:14:26 -0800 Subject: [PATCH 2/2] feat: ejectables! --- src/lib/types.ts | 7 ++-- src/routes/scout/ActionInputs.svelte | 52 +++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/src/lib/types.ts b/src/lib/types.ts index 14bef75..74be898 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -76,7 +76,10 @@ export type TeleAction = | 'ScoreBalloonInternalTote' // Held by scorer | 'ScoreBalloonExternalTote' // Held by alliance member | 'ScoreBalloonUncontrolledTote' - | 'ScoreBalloonLow'; + | 'ScoreBalloonLow' + | 'EjectBalloon' + | 'EjectBunny' // Could happen in Tele; we could instead move this to BunnyAction and reset held_bunnies to 0 after Auto + | 'EjectTote'; export type BunnyAction = | 'IntakeBunny' @@ -87,6 +90,6 @@ export type BunnyAction = export type AutoAction = TeleAction | BunnyAction; // For state machine -export type ItemInputState = 'Intake' | 'Score' | 'None'; +export type ItemInputState = 'Intake' | 'Score' | 'Eject' | 'None'; export type TeleInputState = TeleAction | ItemInputState; export type AutoInputState = TeleInputState | BunnyAction; diff --git a/src/routes/scout/ActionInputs.svelte b/src/routes/scout/ActionInputs.svelte index 8bf785b..eadb514 100644 --- a/src/routes/scout/ActionInputs.svelte +++ b/src/routes/scout/ActionInputs.svelte @@ -9,15 +9,19 @@ let held_bunnies: number = $state(0); let held_balloons: number = $state(0); let held_totes: number = $state(0); - let held_pieces: number = $derived(held_balloons + held_bunnies); + let held_scorables: number = $derived(held_balloons + held_bunnies); + let held_ejectables: number = $derived(held_scorables + held_totes); function intake_piece() { actionState = actionState === 'None' ? 'Intake' : actionState; } function score_piece() { - if (held_pieces < 1) return; actionState = actionState === 'None' ? 'Score' : actionState; } + function eject_piece() { + actionState = actionState === 'None' ? 'Eject' : actionState; + } + function score_bunny(where: 'Low' | 'ExternalTote' | 'InternalTote' | 'UncontrolledTote') { actionState = `ScoreBunny${where}`; } @@ -31,6 +35,9 @@ else if (actionState.includes('IntakeTote')) held_totes++; else if (actionState.includes('ScoreBalloon')) held_balloons--; else if (actionState.includes('ScoreBunny')) held_bunnies--; + else if (actionState.includes('EjectBalloon')) held_balloons--; + else if (actionState.includes('EjectBunny')) held_bunnies--; + else if (actionState.includes('EjectTote')) held_totes--; const action: AutoActionData = { action: actionState as AutoAction, @@ -43,14 +50,20 @@ const is_none_state = $derived(actionState === 'None'); const is_intake_state = $derived(actionState === 'Intake'); const is_score_state = $derived(actionState === 'Score'); + const is_eject_state = $derived(actionState === 'Eject'); -

Number of pieces currently held: {held_pieces}

+

Number of pieces currently held: {held_scorables}

{#if is_none_state}
- + {#if held_scorables > 0} + + {/if} + {#if held_ejectables > 0} + + {/if}
{:else if is_intake_state}
@@ -122,10 +135,39 @@ onclick={() => (actionState = 'None')}>Cancel
+ {:else if is_eject_state} +
+ {#if held_bunnies > 0} + + {/if} + {#if held_balloons > 0} + + {/if} + {#if held_totes > 0} + + {/if} + +
{:else} (actionState = actionState.substring(0, 1) === 'S' ? 'Score' : 'Intake')} + cancel={() => + (actionState = + actionState.substring(0, 1) === 'S' + ? 'Score' + : actionState.substring(0, 1) === 'E' + ? 'Eject' + : 'Intake')} /> {/if}