2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
2024-02-12 03:37:45 +01:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2023-01-08 09:41:09 +01:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<div v-if="game.ready" :class="$style.game">
|
2023-01-08 12:30:19 +01:00
|
|
|
<div :class="$style.cps" class="">{{ number(cps) }}cps</div>
|
2023-01-08 09:41:09 +01:00
|
|
|
<div :class="$style.count" class=""><i class="ti ti-cookie" style="font-size: 70%;"></i> {{ number(cookies) }}</div>
|
2023-06-01 10:19:46 +02:00
|
|
|
<button v-click-anime class="_button" @click="onClick">
|
2023-01-08 09:41:09 +01:00
|
|
|
<img src="/client-assets/cookie.png" :class="$style.img">
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div v-else>
|
|
|
|
<MkLoading/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2023-12-07 06:42:09 +01:00
|
|
|
import { computed, onMounted, onUnmounted, ref } from 'vue';
|
2023-01-08 09:41:09 +01:00
|
|
|
import MkPlusOneEffect from '@/components/MkPlusOneEffect.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import * as os from '@/os.js';
|
|
|
|
import { useInterval } from '@/scripts/use-interval.js';
|
|
|
|
import * as game from '@/scripts/clicker-game.js';
|
|
|
|
import number from '@/filters/number.js';
|
|
|
|
import { claimAchievement } from '@/scripts/achievements.js';
|
2023-01-08 09:41:09 +01:00
|
|
|
|
|
|
|
const saveData = game.saveData;
|
|
|
|
const cookies = computed(() => saveData.value?.cookies);
|
2023-12-07 06:42:09 +01:00
|
|
|
const cps = ref(0);
|
|
|
|
const prevCookies = ref(0);
|
2023-01-08 09:41:09 +01:00
|
|
|
|
|
|
|
function onClick(ev: MouseEvent) {
|
2023-01-21 05:14:55 +01:00
|
|
|
const x = ev.clientX;
|
|
|
|
const y = ev.clientY;
|
|
|
|
os.popup(MkPlusOneEffect, { x, y }, {}, 'end');
|
|
|
|
|
2023-01-08 09:41:09 +01:00
|
|
|
saveData.value!.cookies++;
|
2023-01-08 12:42:45 +01:00
|
|
|
saveData.value!.totalCookies++;
|
|
|
|
saveData.value!.totalHandmadeCookies++;
|
2023-01-08 09:41:09 +01:00
|
|
|
saveData.value!.clicked++;
|
|
|
|
|
2023-01-21 05:14:55 +01:00
|
|
|
if (cookies.value === 1) {
|
|
|
|
claimAchievement('cookieClicked');
|
|
|
|
}
|
2023-01-08 09:41:09 +01:00
|
|
|
}
|
|
|
|
|
2023-01-08 12:30:19 +01:00
|
|
|
useInterval(() => {
|
2023-12-07 06:42:09 +01:00
|
|
|
const diff = saveData.value!.cookies - prevCookies.value;
|
|
|
|
cps.value = diff;
|
|
|
|
prevCookies.value = saveData.value!.cookies;
|
2023-01-08 12:30:19 +01:00
|
|
|
}, 1000, {
|
|
|
|
immediate: false,
|
|
|
|
afterMounted: true,
|
|
|
|
});
|
|
|
|
|
2023-01-08 09:41:09 +01:00
|
|
|
useInterval(game.save, 1000 * 5, {
|
|
|
|
immediate: false,
|
|
|
|
afterMounted: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
await game.load();
|
2023-12-07 06:42:09 +01:00
|
|
|
prevCookies.value = saveData.value!.cookies;
|
2023-01-08 09:41:09 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
game.save();
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.game {
|
|
|
|
padding: 16px;
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
2023-01-08 12:30:19 +01:00
|
|
|
.cps {
|
|
|
|
position: absolute;
|
|
|
|
top: 12px;
|
|
|
|
left: 12px;
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
|
2023-01-08 09:41:09 +01:00
|
|
|
.count {
|
|
|
|
font-size: 1.3em;
|
|
|
|
margin-bottom: 6px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.img {
|
|
|
|
max-width: 90px;
|
|
|
|
}
|
|
|
|
</style>
|