From 5b0b2226cc45982bd6a400d319362e23fef451a5 Mon Sep 17 00:00:00 2001 From: alexay7 <43906716+alexay7@users.noreply.github.com> Date: Sun, 28 Jul 2024 03:46:18 +0200 Subject: [PATCH 1/2] Add favorite songs in recent plays (chunithm) --- AquaNet/src/libs/generalTypes.ts | 1 + AquaNet/src/libs/i18n/en_ref.ts | 1 + AquaNet/src/libs/sdk.ts | 11 ++-- AquaNet/src/pages/UserHome.svelte | 54 ++++++++++++++++++- .../aqua/net/games/GameApiController.kt | 5 +- .../java/icu/samnyan/aqua/net/games/Models.kt | 1 + .../icu/samnyan/aqua/net/games/chu3/Chusan.kt | 4 +- 7 files changed, 69 insertions(+), 8 deletions(-) diff --git a/AquaNet/src/libs/generalTypes.ts b/AquaNet/src/libs/generalTypes.ts index 2fa0ad28..66bf4a24 100644 --- a/AquaNet/src/libs/generalTypes.ts +++ b/AquaNet/src/libs/generalTypes.ts @@ -97,6 +97,7 @@ export interface GenericGameSummary { lastSeen: string lastVersion: string ratingComposition: { [key: string]: any } + favSongs: number[] recent: GenericGamePlaylog[] } diff --git a/AquaNet/src/libs/i18n/en_ref.ts b/AquaNet/src/libs/i18n/en_ref.ts index 13d75e88..c128e9c0 100644 --- a/AquaNet/src/libs/i18n/en_ref.ts +++ b/AquaNet/src/libs/i18n/en_ref.ts @@ -109,6 +109,7 @@ export const EN_REF_HOME = { 'home.setup.ask': 'If you have any questions, please ask in our', 'home.setup.support': 'server', 'home.setup.keychip-tips': 'This is your unique keychip, do not share it with anyone', + 'home.favlimit': 'You have reached the limit of favorite songs', } export const EN_REF_SETTINGS = { diff --git a/AquaNet/src/libs/sdk.ts b/AquaNet/src/libs/sdk.ts index d9da5612..b35ba6b7 100644 --- a/AquaNet/src/libs/sdk.ts +++ b/AquaNet/src/libs/sdk.ts @@ -178,10 +178,13 @@ export async function put(endpoint: string, params: any, init?: RequestInitWithP if (json.error) throw new Error(json.error) } - const ret = res.json() - cache[endpoint + JSON.stringify(params) + JSON.stringify(init)] = ret + // Json the response only if body is not empty + if (res.headers.get('content-length') !== '0') { + const ret = res.json() + cache[endpoint + JSON.stringify(params) + JSON.stringify(init)] = ret - return ret + return ret + } } export async function realPost(endpoint: string, params: any, init?: RequestInitWithParams): Promise { @@ -262,7 +265,7 @@ export const USER = { } export const USERBOX = { - getAimeId:(cardId:string):Promise<{luid:string}|null> =>realPost('/api/sega/aime/getByAccessCode',{ accessCode:cardId }), + toggleFavSong:(aimeId:string, songId:number) =>put(`/api/game/chuni/v2/song/${songId}/favorite?aimeId=${aimeId}`,{}, { params:{ aimeId } }), getProfile:(aimeId:string):Promise =>get('/api/game/chuni/v2/profile',{ aimeId }), getUnlockedItems:(aimeId:string, itemId: UserBoxItemKind):Promise<{itemKind:number, itemId:number,stock:number,isValid:boolean}[]> => get(`/api/game/chuni/v2/item/${itemId}`,{ aimeId }), diff --git a/AquaNet/src/pages/UserHome.svelte b/AquaNet/src/pages/UserHome.svelte index 6bc62509..576d1bda 100644 --- a/AquaNet/src/pages/UserHome.svelte +++ b/AquaNet/src/pages/UserHome.svelte @@ -15,7 +15,7 @@ import { Line } from 'svelte-chartjs'; import moment from "moment"; import 'chartjs-adapter-moment'; - import { CARD, DATA, GAME, USER } from "../libs/sdk"; + import { CARD, DATA, GAME, USER, USERBOX } from "../libs/sdk"; import { type GameName, getMult, roundFloor } from "../libs/scoring"; import StatusOverlays from "../components/StatusOverlays.svelte"; import Icon from "@iconify/svelte"; @@ -90,6 +90,32 @@ }) }).catch((e) => error = e.message); }).catch((e) => { error = e.message; console.error(e) } ); + + // Function to add to favorites + async function toggleFavSong(musicId: number) { + if(!d || !me) return + + const card = me.cards.length > 0 ? me.cards[0].luid : ""; + + if (d.user.favSongs.includes(musicId)) { + + await USERBOX.toggleFavSong(card, musicId) + + d.user.favSongs = d.user.favSongs.filter(id => id !== musicId) + } else { + // If there are 20 fav songs, cancel the request + if (d.user.favSongs.length >= 20){ + error = t("home.favlimit") + return + } + + await USERBOX.toggleFavSong(card, musicId) + + const newFav = [...d.user.favSongs, musicId] + + d.user.favSongs = newFav + } + }
@@ -254,6 +280,17 @@ {roundFloor(r.achievement, game, 1)}% + {#if r.musicId !== 0} + + + + {/if} {#if game === 'mai2' || game === 'wacca'} 0} class="dx-change"> {r.afterRating === r.beforeRating ? '-' : (r.afterRating - r.beforeRating).toFixed(0)} @@ -314,6 +351,16 @@ border-radius: $border-radius object-fit: cover + .fav-button + background: none + border: none + cursor: pointer + padding: 0 + color: $c-main + font-size: 1.5rem + display: flex + margin-left: .5rem + @media (max-width: $w-mobile) .user-pfp margin-top: -68px @@ -457,6 +504,11 @@ display: flex justify-content: space-between overflow: hidden + align-items: center + + > div + align-items: center + display: flex // Limit song name to one line > div:first-child diff --git a/src/main/java/icu/samnyan/aqua/net/games/GameApiController.kt b/src/main/java/icu/samnyan/aqua/net/games/GameApiController.kt index 3a6f9218..6ffc1298 100644 --- a/src/main/java/icu/samnyan/aqua/net/games/GameApiController.kt +++ b/src/main/java/icu/samnyan/aqua/net/games/GameApiController.kt @@ -93,7 +93,7 @@ abstract class GameApiController(name: String, userDataClass: KCl } } - fun genericUserSummary(card: Card, ratingComp: Map): GenericGameSummary { + fun genericUserSummary(card: Card, ratingComp: Map, favSongs: List? = null): GenericGameSummary { // Summary values: total plays, player rating, server-wide ranking // number of each rank, max combo, number of full combo, number of all perfect val user = userDataRepo.findByCard(card) ?: (404 - "Game data not found") @@ -137,8 +137,9 @@ abstract class GameApiController(name: String, userDataClass: KCl lastSeen = user.lastPlayDate.toString(), lastVersion = user.lastRomVersion, ratingComposition = ratingComp, + favSongs = favSongs, recent = plays.sortedBy { it.userPlayDate.toString() }.takeLast(15).reversed(), - lastPlayedHost = us.userRepo.findByKeychip(user.lastClientId)?.username + lastPlayedHost = us.userRepo.findByKeychip(user.lastClientId)?.username, ) } } \ No newline at end of file diff --git a/src/main/java/icu/samnyan/aqua/net/games/Models.kt b/src/main/java/icu/samnyan/aqua/net/games/Models.kt index 095fb6e3..7ffe632f 100644 --- a/src/main/java/icu/samnyan/aqua/net/games/Models.kt +++ b/src/main/java/icu/samnyan/aqua/net/games/Models.kt @@ -44,6 +44,7 @@ data class GenericGameSummary( val lastPlayedHost: String? = null, val ratingComposition: Map, + val favSongs: List?, val recent: List ) diff --git a/src/main/java/icu/samnyan/aqua/net/games/chu3/Chusan.kt b/src/main/java/icu/samnyan/aqua/net/games/chu3/Chusan.kt index e6debddb..2097911e 100644 --- a/src/main/java/icu/samnyan/aqua/net/games/chu3/Chusan.kt +++ b/src/main/java/icu/samnyan/aqua/net/games/chu3/Chusan.kt @@ -39,6 +39,8 @@ class Chusan( "recent" to (extra["recent_rating_list"] ?: ""), ) - genericUserSummary(card, ratingComposition) + val favoriteSongs = extra["favorite_music"]?.split(",")?.mapNotNull { it.toIntOrNull() } ?: emptyList() + + genericUserSummary(card, ratingComposition, favoriteSongs) } } \ No newline at end of file From 6a851dc70d734156d4bfaab974e88af576bb4930 Mon Sep 17 00:00:00 2001 From: alexay7 <43906716+alexay7@users.noreply.github.com> Date: Sun, 28 Jul 2024 15:59:12 +0200 Subject: [PATCH 2/2] Add favorite song selector --- AquaNet/src/components/SongSelector.svelte | 200 +++++++++++++++++++ AquaNet/src/components/StatusOverlays.svelte | 3 + AquaNet/src/libs/generalTypes.ts | 2 +- AquaNet/src/libs/i18n/en_ref.ts | 9 + AquaNet/src/pages/UserHome.svelte | 70 ++++++- 5 files changed, 274 insertions(+), 10 deletions(-) create mode 100644 AquaNet/src/components/SongSelector.svelte diff --git a/AquaNet/src/components/SongSelector.svelte b/AquaNet/src/components/SongSelector.svelte new file mode 100644 index 00000000..cb9b25c1 --- /dev/null +++ b/AquaNet/src/components/SongSelector.svelte @@ -0,0 +1,200 @@ + + + + +
+
+

{t("home.songlist")}

+ +
+ { + page=0; + renderPage(); + }}/> + +
+ + {#each matchedSongs as { id, name },i} +
+ +
+
{name ?? t("UserHome.UnknownSong")}
+
+ {#if parseInt(id) !== 0} + + + + {/if} +
+ {/each} +
+ +
+
+ + +
+ {page + 1} / {pages} +
+ + +
+
+
+ + +
+
+ + \ No newline at end of file diff --git a/AquaNet/src/components/StatusOverlays.svelte b/AquaNet/src/components/StatusOverlays.svelte index 2b6d2024..b0a55387 100644 --- a/AquaNet/src/components/StatusOverlays.svelte +++ b/AquaNet/src/components/StatusOverlays.svelte @@ -59,6 +59,9 @@ {/if}