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 @@ (actionState = 'IntakeBalloon')} >Intake Balloon From Ground - (actionState = 'IntakeCoral')} + (actionState = 'IntakeBalloonCoral')} >Intake Ballon From Coral {:else if is_score_state} - (actionState = 'ScoreBunnyLow')} - >Score Bunny in Low Zone - (actionState = 'ScoreBunnyTote')} - >Score Bunny in Tote - (actionState = 'ScoreBalloonLow')}>Score Ballon in Low Zone - (actionState = 'ScoreExternalTote')} - >Score Bunny in Uncontrolled Tote - (actionState = 'ScoreYourHeldTote')} - >Score Bunny in Your Held Tote - (actionState = 'ScoreOtherHeldTote')} - >Score Bunny in Tote Held by Other Robot + {#if held_bunnies > 0} + score_bunny('Low')} + >Score Bunny in Low Zone + score_bunny('UncontrolledTote')} + >Score Bunny in Uncontrolled Tote + {#if held_totes > 0} + score_bunny('InternalTote')} + >Score Bunny in Internal Held Tote + {/if} + score_bunny('ExternalTote')} + >Score Bunny in External Held Tote + {/if} + {#if held_balloons > 0} + score_balloon('Low')} + >Score Ballon in Low Zone + score_balloon('UncontrolledTote')} + >Score Bunny in Uncontrolled Tote + {#if held_totes > 0} + score_balloon('InternalTote')} + >Score Balloon in Internal Held Tote + {/if} + score_balloon('ExternalTote')} + >Score Balloon in External Held Tote + + {/if} (actionState = 'None')}>Cancel