This commit is contained in:
syuilo 2023-01-08 20:30:19 +09:00
parent 5d13e2744f
commit 7ed905f76b

View file

@ -1,6 +1,7 @@
<template> <template>
<div> <div>
<div v-if="game.ready" :class="$style.game"> <div v-if="game.ready" :class="$style.game">
<div :class="$style.cps" class="">{{ number(cps) }}cps</div>
<div :class="$style.count" class=""><i class="ti ti-cookie" style="font-size: 70%;"></i> {{ number(cookies) }}</div> <div :class="$style.count" class=""><i class="ti ti-cookie" style="font-size: 70%;"></i> {{ number(cookies) }}</div>
<button v-click-anime class="_button" :class="$style.button" @click="onClick"> <button v-click-anime class="_button" :class="$style.button" @click="onClick">
<img src="/client-assets/cookie.png" :class="$style.img"> <img src="/client-assets/cookie.png" :class="$style.img">
@ -25,6 +26,8 @@ defineProps<{
const saveData = game.saveData; const saveData = game.saveData;
const cookies = computed(() => saveData.value?.cookies); const cookies = computed(() => saveData.value?.cookies);
let cps = $ref(0);
let prevCookies = $ref(0);
function onClick(ev: MouseEvent) { function onClick(ev: MouseEvent) {
saveData.value!.cookies++; saveData.value!.cookies++;
@ -35,6 +38,15 @@ function onClick(ev: MouseEvent) {
os.popup(MkPlusOneEffect, { x, y }, {}, 'end'); os.popup(MkPlusOneEffect, { x, y }, {}, 'end');
} }
useInterval(() => {
const diff = saveData.value!.cookies - prevCookies;
cps = diff;
prevCookies = saveData.value!.cookies;
}, 1000, {
immediate: false,
afterMounted: true,
});
useInterval(game.save, 1000 * 5, { useInterval(game.save, 1000 * 5, {
immediate: false, immediate: false,
afterMounted: true, afterMounted: true,
@ -42,6 +54,7 @@ useInterval(game.save, 1000 * 5, {
onMounted(async () => { onMounted(async () => {
await game.load(); await game.load();
prevCookies = saveData.value!.cookies;
}); });
onUnmounted(() => { onUnmounted(() => {
@ -55,6 +68,13 @@ onUnmounted(() => {
text-align: center; text-align: center;
} }
.cps {
position: absolute;
top: 12px;
left: 12px;
opacity: 0.5;
}
.count { .count {
font-size: 1.3em; font-size: 1.3em;
margin-bottom: 6px; margin-bottom: 6px;