[F] Fix score display

matching
Azalea 2024-12-26 23:08:12 -05:00
parent cb6bf00236
commit 42d94b43b1
4 changed files with 19 additions and 27 deletions

View File

@ -73,8 +73,4 @@
.desc .desc
opacity: 0.6 opacity: 0.6
input[type="text"]
flex: 1
width: 100%
</style> </style>

View File

@ -2,24 +2,14 @@
<script lang="ts"> <script lang="ts">
import { slide } from "svelte/transition"; import { slide } from "svelte/transition";
import { DATA_HOST } from "../libs/config";
import { t } from "../libs/i18n"; import { t } from "../libs/i18n";
import { type GameName, getMult, parseComposition, roundFloor } from "../libs/scoring"; import { type GameName, type ParsedComposition, roundFloor } from "../libs/scoring";
import { coverNotFound } from "../libs/ui"; import { coverNotFound } from "../libs/ui";
import type { MusicMeta } from "../libs/generalTypes";
import { tooltip } from "../libs/ui"; import { tooltip } from "../libs/ui";
import useLocalStorage from "../libs/hooks/useLocalStorage.svelte"; import useLocalStorage from "../libs/hooks/useLocalStorage.svelte";
export let g: string
export let meta: MusicMeta
export let game: GameName export let game: GameName
export let p: ParsedComposition
// // mapData: [id, difficulty, score, rank]
// let mapData = g.split(":").map(Number)
// // mult: [score cutoff, rank multiplier, rank text]
// let mult = getMult(mapData[3], game)
// let mapRank: number | undefined = meta?.notes?.[mapData[1] === 10 ? 0 : mapData[1]]?.lv
const p = parseComposition(g, meta, game)
const rounding = useLocalStorage("rounding", true) const rounding = useLocalStorage("rounding", true)
</script> </script>
@ -29,7 +19,7 @@
<img src={p.img} alt="" on:error={coverNotFound} /> <img src={p.img} alt="" on:error={coverNotFound} />
<div class="info"> <div class="info">
<div class="first-line"> <div class="first-line">
<div class="song-title">{meta?.name ?? t("UserHome.UnknownSong")}</div> <div class="song-title">{p.name ?? t("UserHome.UnknownSong")}</div>
<span class={`lv level-${p.diffId === 10 ? 3 : p.diffId}`}> <span class={`lv level-${p.diffId === 10 ? 3 : p.diffId}`}>
{ p.difficulty ?? '-' } { p.difficulty ?? '-' }
</span> </span>
@ -42,7 +32,7 @@
</span> </span>
</span> </span>
{#if p.ratingChange !== undefined} {#if p.ratingChange !== undefined}
<span class="dx-change">{ p.ratingChange.toFixed(1) }</span> <span class="dx-change">{ p.ratingChange }</span>
{/if} {/if}
</div> </div>
</div> </div>

View File

@ -2,22 +2,26 @@
<script lang="ts"> <script lang="ts">
import RatingCompSong from "./RatingCompSong.svelte"; import RatingCompSong from "./RatingCompSong.svelte";
import { type GameName } from "../libs/scoring"; import { parseComposition, type GameName } from "../libs/scoring";
import { type MusicMeta } from "../libs/generalTypes"; import { type MusicMeta } from "../libs/generalTypes";
export let title: string; export let title: string;
export let comp: string | undefined; export let comp: string | undefined;
export let allMusics: Record<string, MusicMeta>; export let allMusics: Record<string, MusicMeta>;
export let game: GameName; export let game: GameName;
const split = comp?.split(",")?.filter(it => it.split(":")[0] !== '0')
?.map(it => parseComposition(it, allMusics[it.split(":")[0]], game))
if (split) console.log("Split", split)
</script> </script>
{#if comp} {#if split}
<div> <div>
<h2>{title}</h2> <h2>{title}</h2>
<div class="rating-composition"> <div class="rating-composition">
{#each comp.split(",").filter(it => it.split(":")[0] !== '0') as map} {#each split as p}
<div> <div>
<RatingCompSong g={map} meta={allMusics[map.split(":")[0]]} game={game}/> <RatingCompSong {p} {game}/>
</div> </div>
{/each} {/each}
</div> </div>

View File

@ -102,7 +102,8 @@ export function chusanRating(lv: number, score: number) {
return 0; // C return 0; // C
} }
interface ParsedComposition { export interface ParsedComposition {
name?: string
musicId: number musicId: number
diffId: number // ID of the difficulty diffId: number // ID of the difficulty
score: number score: number
@ -111,7 +112,7 @@ interface ParsedComposition {
rank: string // e.g. 'SSS+' rank: string // e.g. 'SSS+'
difficulty?: number // Actual difficulty of the map difficulty?: number // Actual difficulty of the map
img: string img: string
ratingChange?: number // Rating change after playing this map ratingChange?: string // Rating change after playing this map
} }
@ -127,17 +128,18 @@ export function parseComposition(item: string, meta: MusicMeta, game: GameName):
const [ cutoff, mult ] = [ +tup[0], +tup[1] ] const [ cutoff, mult ] = [ +tup[0], +tup[1] ]
const rank = tup[2] as string const rank = tup[2] as string
let diff = meta?.notes?.[mapData[1] === 10 ? 0 : mapData[1]]?.lv let diff = meta?.notes?.[diffId === 10 ? 0 : diffId]?.lv
function calcDxChange() { function calcDxChange() {
if (!diff) return if (!diff) return
if (game === 'mai2') if (game === 'mai2')
return Math.floor(diff * +mult * (Math.min(100.5, mapData[3] / 10000) / 100)) return Math.floor(diff * mult * (Math.min(100.5, score / 10000) / 100)).toFixed(0)
if (game === 'chu3') if (game === 'chu3')
return chusanRating(diff, score) / 100 return (chusanRating(diff, score) / 100).toFixed(1)
} }
return { return {
name: meta?.name,
musicId, musicId,
diffId, diffId,
score, score,