From 86f3f52dd9fba48db2d95f7ed88bf3e89e5ecf32 Mon Sep 17 00:00:00 2001 From: Trenton Zimmer <66042448+trmazi@users.noreply.github.com> Date: Sun, 31 May 2026 16:06:04 -0400 Subject: [PATCH] Add personal scores to song overview --- src/helpers/score/index.js | 7 ++- src/stores/api/music.js | 47 +++++++++++++++--- src/views/Game/SongView.vue | 98 +++++++++++++++++++++++++++++++++++-- 3 files changed, 140 insertions(+), 12 deletions(-) diff --git a/src/helpers/score/index.js b/src/helpers/score/index.js index 31798d1..a0236ba 100644 --- a/src/helpers/score/index.js +++ b/src/helpers/score/index.js @@ -11,8 +11,11 @@ export function hydrateScoreData(thisGame, data) { for (const chartId in songData.charts) { var chart = songData.charts[chartId]; const maxScore = (chart.data.notecount ?? 5730) * 2; - chart.records = chart?.records.map((v) => ({ ...v, maxScore: maxScore })); - for (const recordIndex in chart.records) { + chart.records = chart?.records?.map((v) => ({ + ...v, + maxScore: maxScore, + })); + for (const recordIndex in chart?.records) { var record = chart.records[recordIndex]; record = formatIIDXScore(record.maxScore, record); chart.records[recordIndex] = record; diff --git a/src/stores/api/music.js b/src/stores/api/music.js index 0edf517..bf54940 100644 --- a/src/stores/api/music.js +++ b/src/stores/api/music.js @@ -1,4 +1,5 @@ import { useMainStore } from "@/stores/main"; + const mainStore = useMainStore(); export async function APIGetMusicData( @@ -8,13 +9,25 @@ export async function APIGetMusicData( oneChart = false, ) { try { + const params = new URLSearchParams({ + game, + version, + }); + + if (oneChart) { + params.append("oneChart", "true"); + } + + if (songIds?.length) { + params.append("songIds", songIds.join(",")); + } + const data = await mainStore.callApi( - `/music?game=${game}&version=${version}` + - (oneChart ? "&oneChart=true" : ""), + `/music?${params.toString()}`, "GET", null, - { songIds: songIds.toString() }, ); + return data.data; } catch (error) { console.log("Error fetching music data:", error); @@ -24,11 +37,20 @@ export async function APIGetMusicData( export async function getAttemptData(game, userId = null) { try { + const params = new URLSearchParams(); + + if (userId) { + params.append("userId", userId); + } + + const query = params.toString(); + const data = await mainStore.callApi( - `/attempts/${game}` + (userId ? `?userId=${userId}` : ""), + `/attempts/${game}${query ? `?${query}` : ""}`, "GET", null, ); + return data.data; } catch (error) { console.log("Error fetching attempt data:", error); @@ -36,13 +58,26 @@ export async function getAttemptData(game, userId = null) { } } -export async function APIGetRecordData(game, userId = null) { +export async function APIGetRecordData(game, userId = null, songId = null) { try { + const params = new URLSearchParams(); + + if (userId) { + params.append("userId", userId); + } + + if (songId) { + params.append("songId", songId); + } + + const query = params.toString(); + const data = await mainStore.callApi( - `/records/${game}` + (userId ? `?userId=${userId}` : ""), + `/records/${game}${query ? `?${query}` : ""}`, "GET", null, ); + return data.data; } catch (error) { console.log("Error fetching record data:", error); diff --git a/src/views/Game/SongView.vue b/src/views/Game/SongView.vue index eb5fbdb..17618a3 100644 --- a/src/views/Game/SongView.vue +++ b/src/views/Game/SongView.vue @@ -1,7 +1,12 @@