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}