Animations
This commit is contained in:
parent
903bc35bd3
commit
ba01bba5dc
|
@ -1,5 +1,5 @@
|
||||||
<script setup lang="ts"></script>
|
<script setup lang="ts"></script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<RouterView class="container mx-auto h-full" />
|
<RouterView class="container mx-auto h-full px-2" />
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -1,61 +1,68 @@
|
||||||
<template>
|
<template>
|
||||||
<TransitionGroup name="slide_up">
|
<div>
|
||||||
<div
|
<TransitionGroup name="slide_up">
|
||||||
class="mb-2 text-center"
|
<div
|
||||||
v-for="(op, i) in operations"
|
class="mb-2 text-center"
|
||||||
:style="{ transitionDelay: `${transDelay * (operations.length - i)}ms` }"
|
v-for="(op, i) in operations"
|
||||||
:key="i">
|
:style="{
|
||||||
<div class="inline-block relative text-xl">
|
transitionDelay: `${transDelay * (operations.length - i)}ms`,
|
||||||
<!-- OPERATION -->
|
}"
|
||||||
<div
|
:key="i">
|
||||||
class="flex items-center"
|
<div class="inline-block relative text-xl">
|
||||||
:class="{ 'text-red-600': isOperationInvalid(op) }">
|
<!-- OPERATION -->
|
||||||
<!-- LEFT -->
|
<div
|
||||||
<div class="w-[2.5em] border-b border-stone-600 transition-all">
|
class="flex items-center"
|
||||||
{{ op.left?.value ?? ' ' }}
|
:class="{ 'text-red-600': isOperationInvalid(op) }">
|
||||||
</div>
|
<!-- LEFT -->
|
||||||
<!-- RIGHT -->
|
<div class="w-[2.5em] border-b border-stone-600 transition-all">
|
||||||
<div class="w-[2.5em] border-b border-stone-600 transition-all">
|
{{ op.left?.value ?? ' ' }}
|
||||||
{{ op.operator ?? ' ' }}
|
</div>
|
||||||
</div>
|
<!-- RIGHT -->
|
||||||
|
<div class="w-[2.5em] border-b border-stone-600 transition-all">
|
||||||
|
{{ op.operator ?? ' ' }}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="w-[2.5em] border-b border-stone-600 transition-all">
|
<div class="w-[2.5em] border-b border-stone-600 transition-all">
|
||||||
{{ op.right?.value ?? ' ' }}
|
{{ op.right?.value ?? ' ' }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- EQUALS -->
|
||||||
|
<div class="mx-4 border-none">
|
||||||
|
=
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- RESULT -->
|
||||||
|
<PlaquetteBox
|
||||||
|
:dynamic-size="true"
|
||||||
|
class="w-[3.2em] h-8 border-none">
|
||||||
|
<IconSad v-if="isOperationInvalid(op)" />
|
||||||
|
<span
|
||||||
|
v-else-if="
|
||||||
|
op.operator &&
|
||||||
|
op.left &&
|
||||||
|
op.right &&
|
||||||
|
isOperationResultValid(op)
|
||||||
|
">
|
||||||
|
{{ operate(op.operator, op.left.value, op.right.value) }}
|
||||||
|
</span>
|
||||||
|
<span v-else>?</span>
|
||||||
|
</PlaquetteBox>
|
||||||
|
|
||||||
|
<!-- UNDO -->
|
||||||
|
<button
|
||||||
|
class="ml-8"
|
||||||
|
@click="undoOperation(i)">
|
||||||
|
<IconUndo
|
||||||
|
class="text-stone-400"
|
||||||
|
:class="{
|
||||||
|
invisible: !canOperationBeDeleted(op),
|
||||||
|
}" />
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- EQUALS -->
|
|
||||||
<div class="mx-4 border-none">
|
|
||||||
=
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- RESULT -->
|
|
||||||
<PlaquetteBox
|
|
||||||
:dynamic-size="true"
|
|
||||||
class="w-[3.2em] h-8 border-none">
|
|
||||||
<IconSad v-if="isOperationInvalid(op)" />
|
|
||||||
<span
|
|
||||||
v-else-if="
|
|
||||||
op.operator && op.left && op.right && isOperationResultValid(op)
|
|
||||||
">
|
|
||||||
{{ operate(op.operator, op.left.value, op.right.value) }}
|
|
||||||
</span>
|
|
||||||
<span v-else>?</span>
|
|
||||||
</PlaquetteBox>
|
|
||||||
|
|
||||||
<!-- UNDO -->
|
|
||||||
<button
|
|
||||||
class="ml-8"
|
|
||||||
@click="undoOperation(i)">
|
|
||||||
<IconUndo
|
|
||||||
class="text-stone-400"
|
|
||||||
:class="{
|
|
||||||
invisible: !canOperationBeDeleted(op),
|
|
||||||
}" />
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</TransitionGroup>
|
||||||
</TransitionGroup>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
|
|
@ -8,9 +8,8 @@ export const pool = [
|
||||||
export enum GameState {
|
export enum GameState {
|
||||||
Undefined = 0,
|
Undefined = 0,
|
||||||
Waiting = 1,
|
Waiting = 1,
|
||||||
Playing = 2,
|
Loading = 2,
|
||||||
Lost = 3,
|
Playing = 3,
|
||||||
Won = 4,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const gameState = ref(GameState.Undefined)
|
export const gameState = ref(GameState.Undefined)
|
||||||
|
|
|
@ -66,3 +66,13 @@
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
transform: translateY(30px);
|
transform: translateY(30px);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.zero_height-enter-active,
|
||||||
|
.zero_height-leave-active {
|
||||||
|
transition: all 0.5s ease;
|
||||||
|
}
|
||||||
|
.zero_height-enter-from,
|
||||||
|
.zero_height-leave-to {
|
||||||
|
height: 0;
|
||||||
|
opacity: 0;
|
||||||
|
}
|
|
@ -6,6 +6,8 @@ import { Operation, Plaquette } from './types'
|
||||||
export const operations = reactive<Operation[]>([])
|
export const operations = reactive<Operation[]>([])
|
||||||
export const plaquettes = ref<Plaquette[]>([])
|
export const plaquettes = ref<Plaquette[]>([])
|
||||||
|
|
||||||
|
export const result = ref(0)
|
||||||
|
|
||||||
export const currentOperation = computed(
|
export const currentOperation = computed(
|
||||||
() => operations[operations.length - 1],
|
() => operations[operations.length - 1],
|
||||||
)
|
)
|
||||||
|
@ -13,3 +15,7 @@ export const currentOperation = computed(
|
||||||
export const isEndGame = computed(
|
export const isEndGame = computed(
|
||||||
() => operations.length === 5 && isOperationReady(currentOperation.value),
|
() => operations.length === 5 && isOperationReady(currentOperation.value),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
export const isResultPerfect = computed(
|
||||||
|
() => currentOperation.value.result!.value === result.value,
|
||||||
|
)
|
||||||
|
|
|
@ -16,13 +16,21 @@
|
||||||
</NumberBox>
|
</NumberBox>
|
||||||
|
|
||||||
<!-- Start button -->
|
<!-- Start button -->
|
||||||
<Transition name="slide_up">
|
<!-- TODO: fix animation -->
|
||||||
<!-- TODO: fix animation -->
|
<Transition name="zero_height">
|
||||||
<div class="text-center">
|
<div
|
||||||
|
class="text-center"
|
||||||
|
v-if="gameState === GameState.Waiting">
|
||||||
|
<div>
|
||||||
|
Combinez les nombres imposés afin de trouver le résultat ci-dessus, ou
|
||||||
|
de vous en approcher le plus possible.<br>
|
||||||
|
Le compteur démarre quand vous cliquez sur le bouton.<br>Partagez vos
|
||||||
|
meilleurs temps !
|
||||||
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
v-if="!gameIsRunning"
|
|
||||||
@click="startGame"
|
@click="startGame"
|
||||||
class="py-2 px-4 bg-stone-800 rounded border">
|
class="py-2 px-4 mt-4 bg-stone-800 rounded border">
|
||||||
{{ t('startGame') }}
|
{{ t('startGame') }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -71,9 +79,7 @@
|
||||||
<div
|
<div
|
||||||
v-if="isEndGame"
|
v-if="isEndGame"
|
||||||
class="flex flex-row justify-evenly items-center mt-8">
|
class="flex flex-row justify-evenly items-center mt-8">
|
||||||
<span v-if="gameState === GameState.Won">{{
|
<span v-if="isResultPerfect">{{ t('endGame.victoryLabel') }}</span>
|
||||||
t('endGame.victoryLabel')
|
|
||||||
}}</span>
|
|
||||||
<span v-else>{{ t('endGame.failureLabel') }}</span>
|
<span v-else>{{ t('endGame.failureLabel') }}</span>
|
||||||
<button
|
<button
|
||||||
class="p-2 rounded border"
|
class="p-2 rounded border"
|
||||||
|
@ -100,20 +106,26 @@ import NumberBox from '@/components/common/NumberBox.vue'
|
||||||
import PlaquetteBox from '@/components/common/PlaquetteBox.vue'
|
import PlaquetteBox from '@/components/common/PlaquetteBox.vue'
|
||||||
import OperationsList from '@/components/OperationsList.vue'
|
import OperationsList from '@/components/OperationsList.vue'
|
||||||
import { GameState, gameState, operators, pool } from '@/globals'
|
import { GameState, gameState, operators, pool } from '@/globals'
|
||||||
import { currentOperation, isEndGame, operations, plaquettes } from '@/store'
|
import {
|
||||||
|
currentOperation,
|
||||||
|
isEndGame,
|
||||||
|
isResultPerfect,
|
||||||
|
operations,
|
||||||
|
plaquettes,
|
||||||
|
result,
|
||||||
|
} from '@/store'
|
||||||
import { OperatorType, Plaquette } from '@/types'
|
import { OperatorType, Plaquette } from '@/types'
|
||||||
import { randItem, randRange } from '@/utils'
|
import { randItem, randRange } from '@/utils'
|
||||||
|
|
||||||
const { t } = useI18n() // call `useI18n`, and spread `t` from `useI18n` returning
|
const { t } = useI18n() // call `useI18n`, and spread `t` from `useI18n` returning
|
||||||
|
|
||||||
const result = ref(0)
|
|
||||||
const initDelay = ref(100)
|
const initDelay = ref(100)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Computed
|
* Computed
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const gameIsRunning = computed(() => gameState.value > GameState.Waiting)
|
const gameIsRunning = computed(() => gameState.value > GameState.Loading)
|
||||||
const shownPlaquettes = computed(() =>
|
const shownPlaquettes = computed(() =>
|
||||||
gameIsRunning.value ? plaquettes.value : [],
|
gameIsRunning.value ? plaquettes.value : [],
|
||||||
)
|
)
|
||||||
|
@ -130,11 +142,7 @@ watch(
|
||||||
free: true,
|
free: true,
|
||||||
value: operate(op.operator!, op.left!.value, op.right!.value),
|
value: operate(op.operator!, op.left!.value, op.right!.value),
|
||||||
}
|
}
|
||||||
if (op.result.value === result.value) {
|
if (operations.length < 5) {
|
||||||
// Winner
|
|
||||||
gameState.value = GameState.Won
|
|
||||||
}
|
|
||||||
else if (operations.length < 5) {
|
|
||||||
plaquettes.value.push(op.result)
|
plaquettes.value.push(op.result)
|
||||||
operations.push(getEmptyOperation())
|
operations.push(getEmptyOperation())
|
||||||
}
|
}
|
||||||
|
@ -144,7 +152,8 @@ watch(
|
||||||
)
|
)
|
||||||
|
|
||||||
function startGame(): void {
|
function startGame(): void {
|
||||||
gameState.value = GameState.Playing
|
gameState.value = GameState.Loading
|
||||||
|
setTimeout(() => (gameState.value = GameState.Playing), 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectNumber(p: Plaquette): void {
|
function selectNumber(p: Plaquette): void {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user