Skip to content

Commit

Permalink
feat: ejectables!
Browse files Browse the repository at this point in the history
  • Loading branch information
Azalea Colburn committed Nov 14, 2024
1 parent 7662583 commit 1ba1b6a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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;
52 changes: 47 additions & 5 deletions src/routes/scout/ActionInputs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
Expand All @@ -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,
Expand All @@ -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');
</script>

<h1>Number of pieces currently held: {held_pieces}</h1>
<h1>Number of pieces currently held: {held_scorables}</h1>
<div class="grid gap-2 grid-cols-1 grid-rows-2 place-items-center">
{#if is_none_state}
<div class="grid gap-2 grid-cols-2">
<button class="bg-zinc-500 p-2 rounded" onclick={intake_piece}>Intake</button>
<button class="bg-zinc-500 p-2 rounded" onclick={score_piece}>Score</button>
{#if held_scorables > 0}
<button class="bg-zinc-500 p-2 rounded" onclick={score_piece}>Score</button>
{/if}
{#if held_ejectables > 0}
<button class="bg-zinc-500 p-2 rounded" onclick={eject_piece}>Eject</button>
{/if}
</div>
{:else if is_intake_state}
<div class="grid gap-3 grid-cols-2 grid-rows-2 flex-grow">
Expand Down Expand Up @@ -122,10 +135,39 @@
onclick={() => (actionState = 'None')}>Cancel</button
>
</div>
{:else if is_eject_state}
<div class="grid gap-2 grid-cols-2 grid-rows-4">
{#if held_bunnies > 0}
<button class="bg-zinc-500 p-2 rounded" onclick={() => (actionState = 'EjectBunny')}
>Eject Bunny</button
>
{/if}
{#if held_balloons > 0}
<button
class="bg-zinc-500 p-2 rounded"
onclick={() => (actionState = 'EjectBalloon')}>Eject Ballon</button
>
{/if}
{#if held_totes > 0}
<button class="bg-zinc-500 p-2 rounded" onclick={() => (actionState = 'EjectTote')}
>Eject Tote</button
>
{/if}
<button
class="bg-zinc-500 col-span-2 p-2 rounded"
onclick={() => (actionState = 'None')}>Cancel</button
>
</div>
{:else}
<SuccessFail
{complete}
cancel={() => (actionState = actionState.substring(0, 1) === 'S' ? 'Score' : 'Intake')}
cancel={() =>
(actionState =
actionState.substring(0, 1) === 'S'
? 'Score'
: actionState.substring(0, 1) === 'E'
? 'Eject'
: 'Intake')}
/>
{/if}
</div>

0 comments on commit 1ba1b6a

Please sign in to comment.