-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
345c217
commit eab1087
Showing
21 changed files
with
219 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<template> | ||
<div class="relative h-full tg-section-bg aspect-square p-4 rounded-2xl cursor-pointer active:scale-90 duration-200" @click="handleClick()"> | ||
<slot /> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { hapticFeedback } from '@telegram-apps/sdk-vue' | ||
function handleClick() { | ||
if (hapticFeedback.impactOccurred.isAvailable()) { | ||
hapticFeedback.impactOccurred('light') | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<template> | ||
<button class="p-3 tg-button w-full rounded-2xl font-medium cursor-pointer active:scale-95 duration-200" @click="handleClick()"> | ||
<slot /> | ||
</button> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { hapticFeedback } from '@telegram-apps/sdk-vue' | ||
function handleClick() { | ||
if (hapticFeedback.impactOccurred.isAvailable()) { | ||
hapticFeedback.impactOccurred('light') | ||
} | ||
} | ||
</script> |
28 changes: 28 additions & 0 deletions
28
apps/telegram-game/src/components/CharacterActivationBlock.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<template> | ||
<div v-if="isActive" class="px-8 tg-hint text-center font-medium leading-tight"> | ||
Это твой активный персонаж | ||
</div> | ||
<Button v-else class="mt-3" @click="activateCharacter()"> | ||
Активировать | ||
</Button> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { useFetch } from '@vueuse/core' | ||
const { characterId } = defineProps<{ | ||
characterId: string | ||
}>() | ||
const { characters, refreshCharacters } = useCharacters() | ||
const { profile, refreshProfile } = useTelegramProfile() | ||
const character = computed(() => characters.value?.find(({ id }) => id === characterId)) | ||
const isActive = computed(() => profile.value.profile?.activeEditionId === character.value?.editions?.find(({ profileId }) => profileId === profile.value?.profile.id)?.id) | ||
async function activateCharacter() { | ||
await useFetch(`https://chatgame.space/api/telegram/profile/${profile.value.id}/character/${characterId}/activate`).get().json<{ ok: boolean }>() | ||
await refreshProfile() | ||
await refreshCharacters() | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<template> | ||
<h2 class="mb-2 tg-section-header-text text-2xl"> | ||
{{ text }} | ||
</h2> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
defineProps<{ text: string }>() | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { CharacterWithEditions } from '@chat-game/types' | ||
import { useFetch } from '@vueuse/core' | ||
|
||
const { data, execute: refreshCharacters } = useFetch('https://chatgame.space/api/character').get().json<CharacterWithEditions[]>() | ||
|
||
export function useCharacters() { | ||
return { characters: data, refreshCharacters } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
import { initData } from '@telegram-apps/sdk-vue' | ||
import { useFetch } from '@vueuse/core' | ||
|
||
export function useTelegramProfile() { | ||
const user = initData.user() | ||
|
||
const { data } = useFetch(`https://chatgame.space/api/telegram/${user?.id}?username=${user?.username}`, { | ||
async onFetchError(ctx) { | ||
return ctx | ||
}, | ||
}).get().json() | ||
const { data, execute: refreshProfile } = useFetch(`https://chatgame.space/api/telegram/`, { | ||
async beforeFetch() { | ||
const user = initData.user() | ||
if (user) { | ||
return { | ||
url: `https://chatgame.space/api/telegram/${user.id}?username=${user.username}`, | ||
} | ||
} | ||
}, | ||
}).get().json() | ||
|
||
return { profile: data } | ||
export function useTelegramProfile() { | ||
return { profile: data, refreshProfile } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,71 @@ | ||
<template> | ||
<PageContainer> | ||
<ComingSoon /> | ||
<div class="tg-section-bg mb-4 px-3 py-3 flex flex-row gap-2 items-center rounded-2xl"> | ||
<img src="/coin.png" alt="" class="w-14 h-14"> | ||
<div> | ||
<div class="text-2xl font-medium"> | ||
{{ profile?.profile?.coins }} | ||
</div> | ||
<div class="tg-hint text-sm"> | ||
Монеты | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<SectionHeader text="Коллекция персонажей 2024" /> | ||
|
||
<div class="grid grid-cols-2 gap-2"> | ||
<ActiveCard v-for="char in characters" :key="char?.id" @click="() => { isCharacterOpened = true; selectedCharacterId = char?.id }"> | ||
<div v-if="!char?.editions?.find(({ profileId }) => profileId === profile?.profile.id)" class="z-10 absolute top-0 left-0 right-0 bottom-0 tg-secondary-bg opacity-40" /> | ||
|
||
<div v-if="profile?.profile?.activeEditionId === char?.editions?.find(({ profileId }) => profileId === profile?.profile.id)?.id" class="tg-accent-text text-base font-medium leading-tight"> | ||
Активный | ||
</div> | ||
<p class="font-medium text-lg"> | ||
{{ char?.nickname }} | ||
</p> | ||
<div v-if="char?.price && !char?.editions?.find(({ profileId }) => profileId === profile?.profile.id)" class="flex flex-row gap-1 items-center"> | ||
<img src="/coin-small.png" alt="" class="w-5 h-5 grayscale-100"> | ||
<p>{{ char?.price }}</p> | ||
</div> | ||
|
||
<img :src="`/units/${char?.codename}/128.png`" alt="" class="absolute bottom-0 right-0 w-32 h-auto" :class="{ 'grayscale-100 opacity-70': !char?.editions?.find(({ profileId }) => profileId === profile?.profile.id) }"> | ||
</ActiveCard> | ||
</div> | ||
</PageContainer> | ||
|
||
<Modal :title="`«${selectedCharacter?.nickname}» ${selectedCharacter?.name}`" :is-opened="isCharacterOpened" @close="isCharacterOpened = false"> | ||
<img :src="`/units/${selectedCharacter?.codename}/idle.gif`" alt="" class="absolute -top-24 left-0 w-28 h-28"> | ||
|
||
<p class="text-sm"> | ||
{{ selectedCharacter?.description }} | ||
</p> | ||
|
||
<div v-if="selectedCharacter?.editions?.find(({ profileId }) => profileId === profile?.profile.id)"> | ||
<CharacterActivationBlock :character-id="selectedCharacterId" /> | ||
</div> | ||
<div v-else> | ||
<Button v-if="selectedCharacter?.price" class="mt-3 flex flex-row gap-2 items-center justify-center" @click="() => {}"> | ||
<p>Разблокировать за</p> | ||
<div class="flex flex-row gap-2 items-center text-xl"> | ||
<p>{{ selectedCharacter?.price }}</p> | ||
<img src="/coin-small.png" alt="" class="w-8 h-8"> | ||
</div> | ||
</Button> | ||
<div v-else class="px-8 tg-hint text-center font-medium leading-tight"> | ||
Персонажа нельзя разблокировать за Монеты | ||
</div> | ||
</div> | ||
</Modal> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import ComingSoon from '@/components/ComingSoon.vue' | ||
import CharacterActivationBlock from '@/components/CharacterActivationBlock.vue' | ||
const { profile } = useTelegramProfile() | ||
const { characters } = useCharacters() | ||
const isCharacterOpened = ref(false) | ||
const selectedCharacterId = ref() | ||
const selectedCharacter = computed(() => characters.value?.find(({ id }) => id === selectedCharacterId.value)) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
apps/website/server/api/telegram/profile/[profileId]/character/[characterId]/activate.get.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
export default defineEventHandler(async (event) => { | ||
const telegramId = getRouterParam(event, 'telegramId') | ||
const characterId = getRouterParam(event, 'characterId') | ||
|
||
const telegramProfile = await prisma.telegramProfile.findFirst({ | ||
where: { id: telegramId }, | ||
include: { | ||
profile: { | ||
include: { | ||
characterEditions: true, | ||
}, | ||
}, | ||
}, | ||
}) | ||
if (!telegramProfile || !telegramProfile?.profile) { | ||
throw createError({ | ||
status: 404, | ||
}) | ||
} | ||
|
||
const edition = telegramProfile.profile.characterEditions.find((e) => e.characterId === characterId) | ||
if (!edition) { | ||
throw createError({ | ||
status: 400, | ||
message: 'You do not have this character', | ||
}) | ||
} | ||
|
||
await prisma.profile.update({ | ||
where: { id: telegramProfile.profile.id }, | ||
data: { | ||
activeEditionId: edition.id, | ||
}, | ||
}) | ||
|
||
return { ok: true } | ||
}) |
File renamed without changes.
Oops, something went wrong.