Skip to content

Commit

Permalink
Merge branch 'azalea/input-grid' of github.com:flamingchickens1540/in…
Browse files Browse the repository at this point in the history
…flatedchickens into azalea/input-grid
  • Loading branch information
awwpotato committed Nov 14, 2024
2 parents b91cc3c + 1ba1b6a commit b8b501b
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 38 deletions.
23 changes: 16 additions & 7 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,28 @@ export type TeleActionData = {
};

// Action Types
// Naming Convention: action_type + game_piece + where
export type TeleAction =
| 'IntakeTote'
| 'IntakeBalloon'
| 'IntakeCoral'
| 'ScoreYourHeldTote'
| 'ScoreOtherHeldTote'
| 'ScoreExternalTote'
| 'ScoreBalloonLow';
| 'IntakeBalloonCoral'
| 'ScoreBalloonInternalTote' // Held by scorer
| 'ScoreBalloonExternalTote' // Held by alliance member
| 'ScoreBalloonUncontrolledTote'
| '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' | 'ScoreBunnyTote' | 'ScoreBunnyLow';
export type BunnyAction =
| 'IntakeBunny'
| 'ScoreBunnyInternalTote'
| 'ScoreBunnyExternalTote'
| 'ScoreBunnyUncontrolledTote'
| 'ScoreBunnyLow';
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;
136 changes: 105 additions & 31 deletions src/routes/scout/ActionInputs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,39 @@
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_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}`;
}
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--;
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 @@ -30,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 All @@ -50,7 +76,9 @@
<button class="bg-zinc-500 p-2 rounded" onclick={() => (actionState = 'IntakeBalloon')}
>Intake Balloon From Ground</button
>
<button class="bg-zinc-500 p-2 rounded" onclick={() => (actionState = 'IntakeCoral')}
<button
class="bg-zinc-500 p-2 rounded"
onclick={() => (actionState = 'IntakeBalloonCoral')}
>Intake Ballon From Coral</button
>
<button
Expand All @@ -60,31 +88,71 @@
</div>
{:else if is_score_state}
<div class="grid gap-2 grid-cols-2 grid-rows-4">
<button class="bg-zinc-500 p-2 rounded" onclick={() => (actionState = 'ScoreBunnyLow')}
>Score Bunny in Low Zone</button
>
<button class="bg-zinc-500 p-2 rounded" onclick={() => (actionState = 'ScoreBunnyTote')}
>Score Bunny in Tote</button
>
<button
class="bg-zinc-500 p-2 rounded"
onclick={() => (actionState = 'ScoreBalloonLow')}>Score Ballon in Low Zone</button
>
{#if held_bunnies > 0}
<button class="bg-zinc-500 p-2 rounded" onclick={() => score_bunny('Low')}
>Score Bunny in Low Zone</button
>
<button
class="bg-zinc-500 p-2 rounded"
onclick={() => score_bunny('UncontrolledTote')}
>Score Bunny in Uncontrolled Tote</button
>
{#if held_totes > 0}
<button
class="bg-zinc-500 p-2 rounded"
onclick={() => score_bunny('InternalTote')}
>Score Bunny in Internal Held Tote</button
>
{/if}
<button class="bg-zinc-500 p-2 rounded" onclick={() => score_bunny('ExternalTote')}
>Score Bunny in External Held Tote</button
>
{/if}
{#if held_balloons > 0}
<button class="bg-zinc-500 p-2 rounded" onclick={() => score_balloon('Low')}
>Score Ballon in Low Zone</button
>
<button
class="bg-zinc-500 p-2 rounded"
onclick={() => score_balloon('UncontrolledTote')}
>Score Bunny in Uncontrolled Tote</button
>
{#if held_totes > 0}
<button
class="bg-zinc-500 p-2 rounded"
onclick={() => score_balloon('InternalTote')}
>Score Balloon in Internal Held Tote</button
>
{/if}
<button
class="bg-zinc-500 p-2 rounded"
onclick={() => score_balloon('ExternalTote')}
>Score Balloon in External Held Tote
</button>
{/if}
<button
class="bg-zinc-500 p-2 rounded"
onclick={() => (actionState = 'ScoreExternalTote')}
>Score Bunny in Uncontrolled Tote</button
>
<button
class="bg-zinc-500 p-2 rounded"
onclick={() => (actionState = 'ScoreYourHeldTote')}
>Score Bunny in Your Held Tote</button
>
<button
class="bg-zinc-500 p-2 rounded"
onclick={() => (actionState = 'ScoreOtherHeldTote')}
>Score Bunny in Tote Held by Other Robot</button
class="bg-zinc-500 col-span-2 p-2 rounded"
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
Expand All @@ -93,7 +161,13 @@
{: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 b8b501b

Please sign in to comment.