From 9380b50c2635fb7b5c31db386cb779e64d7d1438 Mon Sep 17 00:00:00 2001 From: Azalea Colburn <62953415+azaleacolburn@users.noreply.github.com> Date: Tue, 19 Nov 2024 16:27:03 -0800 Subject: [PATCH] Timeline Modification Verification (#11) * feat(wip): started action input state machine class * style: format files * feat: basic timeline warning system * style: format files * fix: move action arrows * feat: user cannot close invalid timeline --------- Co-authored-by: azaleacolburn --- src/lib/ActionInputStateMachine.svelte.ts | 32 +++++++++++++++++++ src/lib/components/Action.svelte | 3 ++ src/lib/components/Timeline.svelte | 29 ++++++++++++----- src/lib/types.ts | 38 ++++++++++++----------- src/routes/scout/ActionInputs.svelte | 6 ++-- 5 files changed, 80 insertions(+), 28 deletions(-) create mode 100644 src/lib/ActionInputStateMachine.svelte.ts diff --git a/src/lib/ActionInputStateMachine.svelte.ts b/src/lib/ActionInputStateMachine.svelte.ts new file mode 100644 index 0000000..ef2ebd6 --- /dev/null +++ b/src/lib/ActionInputStateMachine.svelte.ts @@ -0,0 +1,32 @@ +import type { AutoActionData } from '$lib/types'; + +export class ActionInputVerifier { + private held_bunnies: number = 0; + private held_balloons: number = 0; + private held_totes: number = 0; + + public verify_actions(action_data: AutoActionData[]) { + action_data + .reverse() + .forEach((action_data) => (action_data.ok = this.verify_new_action(action_data))); + } + + // Takes an action and returns if it's a legal one + verify_new_action(action_data: AutoActionData): boolean { + const success = action_data.success; + const action = action_data.action; + if (success) { + 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--; + } + if (action.includes('ScoreBalloon')) this.held_balloons--; + else if (action.includes('ScoreBunny')) this.held_bunnies--; + + 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..cd2caf7 100644 --- a/src/lib/components/Action.svelte +++ b/src/lib/components/Action.svelte @@ -26,6 +26,9 @@ > {action_data.action}
+ {#if !action_data.ok} + Warning + {/if}