n0mbers/src/composables/game-state.ts
2022-02-17 22:20:09 +01:00

28 lines
825 B
TypeScript

import { computed, reactive, ref } from 'vue'
import { getEmptyOperation, isOperationReady } from '../algo'
import { GameState } from '../globals'
import { Operation, Plaquette } from '../types'
export const gameState = ref(GameState.Undefined)
export const operations = reactive<Operation[]>([getEmptyOperation()])
export const plaquettes = ref<Plaquette[]>([])
export const result = ref(0)
export const currentOperation = computed(
() => operations[operations.length - 1],
)
export const gameIsRunning = computed(() => gameState.value > GameState.Loading)
export const isEndGame = computed(
() =>
(operations.length === 5 && isOperationReady(currentOperation.value)) ||
isResultPerfect.value,
)
export const isResultPerfect = computed(
() => !!operations.some(o => o.result?.value === result.value),
)