feat: preferred game

this needs more testing
v1-dev
Raymond 2025-02-26 22:36:04 -05:00 committed by Azalea
parent b23385ba28
commit d28b9bf5a8
3 changed files with 20 additions and 4 deletions

View File

@ -42,6 +42,7 @@ export interface CardSummary {
ongeki: CardSummaryGame | null
diva: CardSummaryGame | null
wacca: CardSummaryGame | null
auto: CardSummaryGame | null // let's pretend this just doesn't exist
}

View File

@ -1,7 +1,7 @@
import { DATA_HOST } from "./config"
import type { MusicMeta } from "./generalTypes"
export type GameName = 'mai2' | 'chu3' | 'ongeki' | 'wacca'
export type GameName = 'mai2' | 'chu3' | 'ongeki' | 'wacca' | 'auto'
const multTable = {
'mai2': [
@ -67,7 +67,9 @@ const multTable = {
[ 60.0, 0, 'B' ],
[ 1.0, 0, 'C' ],
[ 0.0, 0, 'D' ]
]
],
'auto': []
}
export function getMult(achievement: number, game: GameName) {

View File

@ -30,7 +30,7 @@
registerChart()
export let username: string;
export let game: GameName = "mai2"
export let game: GameName = "auto"
let calElement: HTMLElement
let error: string;
let me: AquaNetUser
@ -57,6 +57,19 @@
USER.isLoggedIn() && USER.me().then(u => me = u)
CARD.userGames(username).then(games => {
if (game == "auto") {
let targetGames = Object.entries(games)
.map(d => {
if (d[1])
d[1].lastLogin = d[1].lastLogin ? new Date(d[1].lastLogin) : new Date(0);
return d;
}).sort((a,b) => {
return b[1]?.lastLogin - a[1]?.lastLogin;
});
if (targetGames[0])
window.location.href = `/u/${username}/${targetGames[0][0]}`
return;
}
if (!games[game]) {
// Find a valid game
const valid = Object.entries(games).filter(([g, valid]) => valid)
@ -105,7 +118,7 @@
}).catch((e) => { error = e.message; console.error(e) } );
}
if (Object.keys(GAME_TITLE).includes(game)) init()
if (Object.keys(GAME_TITLE).includes(game) || game == "auto") init()
else error = t("UserHome.InvalidGame", {game})
const setRival = (isAdd: boolean) => {