diff --git a/src/app/main/game/berrydash/leaderboards/page.tsx b/src/app/main/game/berrydash/leaderboards/page.tsx deleted file mode 100644 index a341efe..0000000 --- a/src/app/main/game/berrydash/leaderboards/page.tsx +++ /dev/null @@ -1,358 +0,0 @@ -'use client' - -import './styles.css' -import { useCallback, useEffect, useState } from 'react' -import { BirdColor } from '@/types/BerryDash/BirdColor' -import { GetIconForUser } from '@/lib/berrydashutil' -import Image from 'next/image' -import { useRouter } from 'next/navigation' -import { arch, platform } from '@tauri-apps/plugin-os' -import { fetch } from '@tauri-apps/plugin-http' -import { verifySignature } from '@/lib/util' -import Dropdown from '@/components/Dropdown' -import { app } from '@tauri-apps/api' - -interface BaseEntry { - id: number - username: string - value: number - icon: number - overlay: number - birdColor: BirdColor - overlayColor: BirdColor - customIcon: string | null -} - -interface Stats { - highScore: string - totalNormalBerries: string - totalPoisonBerries: string - totalSlowBerries: string - totalUltraBerries: string - totalSpeedyBerries: string - totalCoinBerries: string - totalRandomBerries: string - totalAntiBerries: string - totalGoldenBerries: string - coins: string -} - -interface LeaderboardEntry extends BaseEntry { - type: 'leaderboard' - value: number -} - -interface Account extends BaseEntry { - type: 'account' - stats: Stats - xp: bigint -} - -export function calculateXP ( - normalBerries: bigint, - poisonBerries: bigint, - slowBerries: bigint, - ultraBerries: bigint, - speedyBerries: bigint, - coinBerries: bigint, - randomBerries: bigint, - antiBerries: bigint, - goldenBerries: bigint -): bigint { - let totalXp = 0n - totalXp += normalBerries - totalXp -= poisonBerries - totalXp -= slowBerries - totalXp += ultraBerries * 5n - totalXp += speedyBerries * 10n - totalXp += coinBerries * 10n - totalXp += randomBerries - totalXp -= antiBerries - totalXp += goldenBerries * 4n - - if (totalXp < 0n) totalXp = 0n - return totalXp -} - -export function calculateLevel (xp: bigint): number { - const levelDivisor = 50.0 - - const xpNumber = Number(xp) - const discriminant = 95 * 95 + levelDivisor * 2 * xpNumber - const level = (-95 + Math.sqrt(discriminant)) / levelDivisor - return Math.floor(level) + 1 -} - -export default function BerryDashLeaderboards () { - const [selected, setSelected] = useState(-1) - const [selectedBerryOption, setSelectedBerryOption] = useState(0) - const [entries, setEntries] = useState<(LeaderboardEntry | Account)[]>([]) - const [loading, setLoading] = useState(false) - - const router = useRouter() - - const Refresh = useCallback(async () => { - setLoading(true) - try { - if (selected == 3 || selected == 4) { - const response = await fetch( - 'https://games.lncvrt.xyz/api/berrydash/account?username=', - { - headers: { - Requester: 'LncvrtGamesLauncherClient', - ClientVersion: await app.getVersion(), - ClientPlatform: platform() + '-' + arch() - } - } - ) - const signature = response.headers.get('x-signature') ?? '' - const data = await response.json() - if ( - (await verifySignature(JSON.stringify(data), signature)) && - data.success - ) { - let accounts = data.data as Account[] - - accounts = accounts.map(acc => { - const xp = calculateXP( - BigInt(acc.stats.totalNormalBerries), - BigInt(acc.stats.totalPoisonBerries), - BigInt(acc.stats.totalSlowBerries), - BigInt(acc.stats.totalUltraBerries), - BigInt(acc.stats.totalSpeedyBerries), - BigInt(acc.stats.totalCoinBerries), - BigInt(acc.stats.totalRandomBerries), - BigInt(acc.stats.totalAntiBerries), - BigInt(acc.stats.totalGoldenBerries) - ) - return { ...acc, xp } - }) - - accounts.sort((a, b) => (b.xp > a.xp ? 1 : b.xp < a.xp ? -1 : 0)) - - setEntries(accounts) - } else console.log('Failed') - } else { - const response = await fetch( - 'https://games.lncvrt.xyz/api/berrydash/leaderboard/' + - (selected == 0 - ? 'score' - : selected == 1 - ? 'berry?berry=' + selectedBerryOption - : selected == 2 - ? 'coin' - : selected == 5 - ? 'legacy' - : 'total'), - { - headers: { - Requester: 'LncvrtGamesLauncherClient', - ClientVersion: await app.getVersion(), - ClientPlatform: platform() + '-' + arch() - } - } - ) - const signature = response.headers.get('x-signature') ?? '' - const data = await response.json() - if ( - (await verifySignature(JSON.stringify(data), signature)) && - data.success - ) - setEntries(data.data as LeaderboardEntry[]) - } - } catch { - setEntries([]) - } - setLoading(false) - }, [selected, selectedBerryOption]) - - useEffect(() => { - document.title = 'Lncvrt Games - Berry Dash Leaderboards' - }, []) - - useEffect(() => { - if (selected != -1) setTimeout(() => Refresh(), 0) - }, [selected, Refresh]) - - return ( -
-
-

Berry Dash Leaderboards

-
- {selected == 1 && ( -
- setSelectedBerryOption(Number(e))} - /> -
- )} - - -
-
-
- {selected == -1 ? ( - <> -

Select a Leaderboard

-
- - - - - - - -
- - ) : loading ? ( -

- Loading -

- ) : ( - <> -
- {entries.map((item, index) => { - const isAccount = 'stats' in item - const isLeaderboard = 'value' in item && !isAccount - - return ( -
-
- -

- {item.username} (#{index + 1}) -

-
- - {isLeaderboard ? ( -

- {selected === 1 || selected === 6 - ? 'Berries' - : selected === 2 - ? 'Coins' - : 'Score'} - : {item.value.toLocaleString()} -

- ) : isAccount ? ( -

- {selected === 3 ? 'Level' : 'XP'}:{' '} - {selected === 3 - ? calculateLevel(item.xp).toLocaleString() - : item.xp.toLocaleString()} -

- ) : null} -
- ) - })} -
- - )} -
-
- ) -} diff --git a/src/app/main/game/berrydash/leaderboards/styles.css b/src/app/main/game/berrydash/leaderboards/styles.css deleted file mode 100644 index c585e91..0000000 --- a/src/app/main/game/berrydash/leaderboards/styles.css +++ /dev/null @@ -1,13 +0,0 @@ -@import "tailwindcss"; - -.box { - @apply bg-(--col1) border border-(--col3) rounded-lg w-auto p-1; -} - -.leaderboard-button { - @apply bg-(--col2) hover:bg-(--col4) border border-(--col4) hover:border-(--col6) rounded-lg px-4 py-2 inline-block transition-all cursor-pointer; -} - -.leaderboard-entry { - @apply rounded-lg text-gray-200 text-lg px-1 py-0.5 transition-colors bg-(--col2) hover:bg-(--col3) border border-(--col4) hover:border-(--col5) cursor-pointer; -} diff --git a/src/app/main/game/page.tsx b/src/app/main/game/page.tsx index 8952e11..c5b9500 100644 --- a/src/app/main/game/page.tsx +++ b/src/app/main/game/page.tsx @@ -4,7 +4,7 @@ import '../Installs.css' import { useEffect } from 'react' import { invoke } from '@tauri-apps/api/core' import { useGlobal } from '@/providers/GlobalProvider' -import { useRouter, useSearchParams } from 'next/navigation' +import { useSearchParams } from 'next/navigation' import { platform } from '@tauri-apps/plugin-os' import { faWarning } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' @@ -30,11 +30,11 @@ export default function Installs () { customDataLocation, needsRevisionUpdate, launchGame, - developerMode + developerMode, + theme } = useGlobal() const params = useSearchParams() - const router = useRouter() const id = Number(params.get('id') || 0) const game = serverVersionList?.games.find(g => g.id === id) @@ -73,9 +73,17 @@ export default function Installs () {