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,9 +1,12 @@
|
||||||
<template>
|
<template>
|
||||||
|
<div>
|
||||||
<TransitionGroup name="slide_up">
|
<TransitionGroup name="slide_up">
|
||||||
<div
|
<div
|
||||||
class="mb-2 text-center"
|
class="mb-2 text-center"
|
||||||
v-for="(op, i) in operations"
|
v-for="(op, i) in operations"
|
||||||
:style="{ transitionDelay: `${transDelay * (operations.length - i)}ms` }"
|
:style="{
|
||||||
|
transitionDelay: `${transDelay * (operations.length - i)}ms`,
|
||||||
|
}"
|
||||||
:key="i">
|
:key="i">
|
||||||
<div class="inline-block relative text-xl">
|
<div class="inline-block relative text-xl">
|
||||||
<!-- OPERATION -->
|
<!-- OPERATION -->
|
||||||
|
@ -35,7 +38,10 @@
|
||||||
<IconSad v-if="isOperationInvalid(op)" />
|
<IconSad v-if="isOperationInvalid(op)" />
|
||||||
<span
|
<span
|
||||||
v-else-if="
|
v-else-if="
|
||||||
op.operator && op.left && op.right && isOperationResultValid(op)
|
op.operator &&
|
||||||
|
op.left &&
|
||||||
|
op.right &&
|
||||||
|
isOperationResultValid(op)
|
||||||
">
|
">
|
||||||
{{ operate(op.operator, op.left.value, op.right.value) }}
|
{{ operate(op.operator, op.left.value, op.right.value) }}
|
||||||
</span>
|
</span>
|
||||||
|
@ -56,6 +62,7 @@
|
||||||
</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 -->
|
||||||
<div class="text-center">
|
<Transition name="zero_height">
|
||||||
|
<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