taiko: implement taiko arcade score view

This commit is contained in:
Pinapelz
2025-11-07 21:14:27 -08:00
parent 88566d8161
commit 8bbac6ec12
7 changed files with 580 additions and 7 deletions
+5
View File
@@ -35,6 +35,11 @@ async function main() {
internalName: "reflecbeat",
formattedName: "REFLEC BEAT",
description: "A touchscreen rhythm game from KONAMI",
},
{
internalName: "taiko",
formattedName: "Taiko no Tatsujin Arcade",
description: "A drum-based rhythm game"
}
],
});
@@ -0,0 +1,533 @@
import React from "react";
import SHA1 from "crypto-js/sha1";
import { Link } from "react-router";
import { globalSkipKeys } from "../../types/constants";
import clearImg from "../../assets/games/taiko/clear.webp";
import donderfulImg from "../../assets/games/taiko/donderful_combo.webp";
import easyImg from "../../assets/games/taiko/easy.webp";
import normalImg from "../../assets/games/taiko/normal.webp";
import full_comboImg from "../../assets/games/taiko/full_combo.webp";
import hardImg from "../../assets/games/taiko/hard.webp";
import iki_1 from "../../assets/games/taiko/iki_1.webp";
import iki_2 from "../../assets/games/taiko/iki_2.webp";
import iki_3 from "../../assets/games/taiko/iki_3.webp";
import kiwami from "../../assets/games/taiko/kiwami.webp";
import miyabi_1 from "../../assets/games/taiko/miyabi_1.webp";
import miyabi_2 from "../../assets/games/taiko/miyabi_2.webp";
import miyabi_3 from "../../assets/games/taiko/miyabi_3.webp";
import oni from "../../assets/games/taiko/oni.webp";
import ura_oni from "../../assets/games/taiko/ura_oni.webp";
import type {Score, ScoreDisplayProps} from "../../types/game";
const TaikoScoreDisplay: React.FC<ScoreDisplayProps> = ({
scores,
viewMode,
sortField,
sortDirection,
onSort,
onDelete,
showUsername = false,
hideTitleArtist = false,
}) => {
// Key mappings for better display names. Hit or miss
const keyDisplayNames: Record<string, string> = {
title: "Title",
artist: "Artist",
score: "Score",
difficulty: "Difficulty",
level: "Level",
score_rank: "Score Rank",
crown_rank: "Crown Rank",
timestamp: "Date",
judgements: "Judgements",
good: "Good/良",
ok: "Ok/可",
bad: "Bad/不可 ",
max_combo: "Combo",
pound: "Drumrolls",
date: "Date",
username: "Username",
};
const mainStatKeys = [
"score",
"difficulty",
"lamp",
"score_rank",
"crown_rank",
"diff_lamp",
"percent",
"rating",
"grade",
];
const expandableKeys = ["judgements", "optional"];
const gameParam = new URLSearchParams(window.location.search).get("game") || "taiko";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const formatValue = (value: any, key: string): string => {
if (value === null || value === undefined) return "N/A";
// Handle timestamps
if (key === "timestamp" || key === "date") {
const date = new Date(typeof value === "number" ? value : value);
return date.toLocaleDateString();
}
if (typeof value === "number") {
if (key === "score" || key === "maxCombo" || key === "combo") {
return value.toLocaleString();
}
return value.toString();
}
if (typeof value === "boolean") {
return value ? "Yes" : "No";
}
if (Array.isArray(value)) {
return value.join(", ");
}
return String(value);
};
const getDisplayName = (key: string): string => {
return keyDisplayNames[key] || key.charAt(0).toUpperCase() + key.slice(1);
};
const renderValue = (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value: any,
key: string,
compact: boolean = false,
): React.ReactElement => {
if (value === null || value === undefined)
return <span className="text-slate-500">N/A</span>;
if(key === "difficulty"){
let imgSrc = null;
switch (value) {
case "EASY":
imgSrc = easyImg;
break;
case "NORMAL":
imgSrc = normalImg;
break;
case "HARD":
imgSrc = hardImg;
break;
case "ONI":
imgSrc = oni;
break;
case "URA_ONI":
imgSrc = ura_oni;
break;
default:
imgSrc = easyImg;
break;
}
return <span>
<img className="w-4/5" src={imgSrc} alt={value} />
</span>;
}
if(key === "score_rank"){
let imgSrc = null;
switch (value) {
case "IKI 1":
imgSrc = iki_1;
break;
case "IKI 2":
imgSrc = iki_2;
break;
case "IKI 3":
imgSrc = iki_3;
break;
case "MIYABI 1":
imgSrc = miyabi_1;
break;
case "MIYABI 2":
imgSrc = miyabi_2;
break;
case "MIYABI 3":
imgSrc = miyabi_3;
break;
case "KIWAMI":
imgSrc = kiwami;
break;
default:
imgSrc = easyImg;
break;
}
return <span>
<img className="w-3/4" src={imgSrc} alt={value} />
</span>;
}
if(key === "crown_rank"){
let imgSrc = null;
switch (value) {
case "CLEAR":
imgSrc = clearImg;
break;
case "FULL COMBO":
imgSrc = full_comboImg;
break;
case "DONDERFUL COMBO":
imgSrc = donderfulImg;
break;
default:
imgSrc = easyImg;
break;
}
return <span>
<img src={imgSrc} alt={value} />
</span>;
}
// Handle judgements specially
if (key === "judgements" && typeof value === "object") {
const judgementEntries = Object.entries(value);
if (compact) {
return (
<div className="text-xs text-slate-300 space-y-1">
{judgementEntries.map(([jKey, jValue]) => (
<div key={jKey} className="flex justify-between">
<span className="text-slate-400 capitalize">
{getDisplayName(jKey)}:
</span>
<span className="font-medium">{formatValue(jValue, jKey)}</span>
</div>
))}
</div>
);
}
return (
<div className="flex flex-wrap gap-1 text-xs">
{judgementEntries.map(([jKey, jValue]) => (
<span
key={jKey}
className="bg-slate-700/50 text-slate-200 px-2 py-1 rounded-full border border-slate-600"
>
<span className="capitalize">{getDisplayName(jKey)}</span>:{" "}
{formatValue(jValue, jKey)}
</span>
))}
</div>
);
}
if (typeof value === "object" && !Array.isArray(value)) {
return (
<div className="space-y-1">
{Object.entries(value).map(([subKey, subValue]) => (
<div key={subKey} className="flex justify-between text-xs">
<span className="text-slate-400">{getDisplayName(subKey)}:</span>
<span className="font-medium">
{formatValue(subValue, subKey)}
</span>
</div>
))}
</div>
);
}
return <span>{formatValue(value, key)}</span>;
};
const getScoreEntries = (score: Score) => {
const entries = Object.entries(score).filter(
([key]) => !globalSkipKeys.includes(key),
);
const mainStats = entries.filter(([key]) => mainStatKeys.includes(key));
const expandable = entries.filter(([key]) => expandableKeys.includes(key));
return {
mainStats,
expandable,
timestamp: score.timestamp,
};
};
const SortIcon = ({ field }: { field: string }) => {
if (sortField !== field) {
return <span className="text-slate-500">↕</span>;
}
return sortDirection === "asc" ? (
<span className="text-violet-400">↑</span>
) : (
<span className="text-violet-400">↓</span>
);
};
const sortedScores = [...scores].sort((a, b) => {
const aVal = a[sortField];
const bVal = b[sortField];
if (aVal === undefined || aVal === null) return 1;
if (bVal === undefined || bVal === null) return -1;
let comparison = 0;
if (typeof aVal === "string" && typeof bVal === "string") {
comparison = aVal.localeCompare(bVal);
} else if (typeof aVal === "number" && typeof bVal === "number") {
comparison = aVal - bVal;
} else if (aVal instanceof Date && bVal instanceof Date) {
comparison = aVal.getTime() - bVal.getTime();
} else {
comparison = String(aVal).localeCompare(String(bVal));
}
return sortDirection === "asc" ? comparison : -comparison;
});
// Get all possible keys for table headers
const allKeys = Array.from(
new Set(scores.flatMap((score) => Object.keys(score))),
).filter((key) => !globalSkipKeys.includes(key));
// Prioritize important keys for table display
const tableKeys = [
...(hideTitleArtist ? [] : ["title", "song", "artist"]),
...(showUsername ? ["username"] : []),
"score",
"difficulty",
"lamp",
"diff_lamp",
"rating",
"percent",
"grade",
"score_rank",
"crown_rank",
"level",
"judgements",
"combo",
"timestamp",
].filter((key) => allKeys.includes(key));
// Add actions column if delete function is provided
const showActions = onDelete && viewMode === "table";
if (scores.length === 0) {
return (
<div className="text-center py-16">
<div className="w-24 h-24 bg-slate-800 rounded-full flex items-center justify-center mx-auto mb-6">
<span className="text-slate-400 text-2xl">🎵</span>
</div>
<h3 className="text-xl font-semibold text-slate-300 mb-2">
No scores found
</h3>
<p className="text-slate-500">Import some score data to get started!</p>
</div>
);
}
if (viewMode === "cards") {
return (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-2 xl:grid-cols-3 gap-4 sm:gap-6">
{sortedScores.map((score, index) => {
const chartIdHash = SHA1(`${gameParam}${score.title}${score.artist}`).toString();
const { mainStats, expandable, timestamp } =
getScoreEntries(score);
return (
<div
key={score.id || index}
className="bg-slate-900/50 backdrop-blur-sm border border-slate-800/50 rounded-lg sm:rounded-xl p-4 sm:p-6 hover:border-violet-500/30 transition-all duration-300 hover:shadow-lg hover:shadow-violet-500/10"
>
{/* Primary Info */}
<div className="flex items-start justify-between mb-4">
<div className="flex-1 min-w-0">
{!hideTitleArtist && (
<Link to={`/chart?chartId=${chartIdHash}&game=${gameParam}`}>
<h3 className="text-base sm:text-lg font-semibold text-white mb-1 break-words leading-tight">
{score.title || score.song || "Unknown Title"}
</h3>
{score.artist && (
<p className="text-slate-400 text-xs sm:text-sm break-words leading-tight">
{score.artist}
</p>
)}
</Link>
)}
{showUsername && score.username && (
<p className="text-slate-500 text-xs break-words leading-tight">
by {score.username}
</p>
)}
</div>
</div>
{/* Main Stats */}
{mainStats.length > 0 && (
<div className="grid grid-cols-2 gap-2 sm:gap-4 mb-4">
{mainStats.slice(0, 4).map(([key, value]) => (
<div key={key} className="bg-slate-800/50 rounded-lg p-2 sm:p-3">
<p className="text-slate-400 text-[10px] sm:text-xs uppercase tracking-wide mb-1">
{getDisplayName(key)}
</p>
<p className="text-white font-semibold text-sm sm:text-lg">
{renderValue(value, key)}
</p>
</div>
))}
</div>
)}
{/* Level */}
{score.level && (
<div className="mb-4">
<div className="bg-gradient-to-br from-violet-500/20 to-purple-600/20 border border-violet-500/30 rounded-lg p-3 sm:p-4 shadow-lg shadow-violet-500/10">
<div className="flex items-center justify-between">
<div className="flex items-center space-x-2">
<div className="w-2 h-2 bg-violet-400 rounded-full animate-pulse"></div>
<p className="text-violet-300 text-xs sm:text-sm font-medium uppercase tracking-wider">
Level
</p>
</div>
<div className="bg-violet-500/20 px-3 py-1 rounded-full border border-violet-400/40">
<p className="text-violet-100 font-bold text-lg sm:text-xl">
{score.level}
</p>
</div>
</div>
</div>
</div>
)}
{/* Expandable sections (judgements, optional) */}
{expandable.map(([key, value]) => (
<div key={key} className="mb-4">
<p className="text-slate-400 text-xs uppercase tracking-wide mb-2">
{getDisplayName(key)}
</p>
{renderValue(value, key)}
</div>
))}
{/* Timestamp */}
<div className="pt-4 border-t border-slate-800/50">
<p className="text-slate-500 text-[10px] sm:text-xs">
{new Date(
typeof timestamp === "number" ? timestamp : timestamp,
).toLocaleDateString()}{" "}
•{" "}
{new Date(
typeof timestamp === "number" ? timestamp : timestamp,
).toLocaleTimeString([], {
hour: "2-digit",
minute: "2-digit",
})}
</p>
</div>
</div>
);
})}
</div>
);
}
return (
<div className="bg-slate-900/50 backdrop-blur-sm border border-slate-800/50 rounded-xl overflow-hidden">
<div className="overflow-x-auto relative">
<div className="md:hidden absolute right-0 top-0 bottom-0 w-8 bg-linear-to-l from-slate-900/80 to-transparent pointer-events-none z-10"></div>
<table className="w-full text-sm min-w-[800px] md:min-w-[1000px]">
<thead className="bg-slate-800/50 border-b border-slate-700/50">
<tr>
{tableKeys.map((key) => (
<th
key={key}
className="px-2 sm:px-4 py-2 sm:py-3 text-left text-slate-300 font-medium text-xs sm:text-sm"
>
{key === "judgements" ? (
<span>{getDisplayName(key)}</span>
) : (
<button
onClick={() => onSort(key)}
className="flex items-center space-x-1 sm:space-x-2 hover:text-white transition-colors"
>
<span>{getDisplayName(key)}</span>
<SortIcon field={key} />
</button>
)}
</th>
))}
{showActions && (
<th className="px-2 sm:px-4 py-2 sm:py-3 text-left text-slate-300 font-medium w-16 text-xs sm:text-sm">
Actions
</th>
)}
</tr>
</thead>
<tbody className="divide-y divide-slate-800/50">
{sortedScores.map((score, index) => (
<tr
key={score.id || index}
className="hover:bg-slate-800/30 transition-colors group"
>
{tableKeys.map((key) => (
<td key={key} className="px-2 sm:px-4 py-2 sm:py-3 text-xs sm:text-sm">
{key === "lamp" || key === "diff_lamp" ? (
<div className="flex items-center space-x-2">
<span className="inline-block bg-slate-800/50 text-slate-200 px-1 sm:px-2 py-0.5 sm:py-1 rounded text-[10px] sm:text-xs border border-slate-600 whitespace-nowrap">
{score[key] || "No Clear"}
</span>
</div>
) : key === "judgements" ? (
<div className="w-32">
{renderValue(score[key], key, true)}
</div>
) : key === "timestamp" ? (
<span className="text-slate-400 text-[10px] sm:text-xs whitespace-nowrap">
{new Date(
typeof score[key] === "number"
? score[key]
: score[key],
).toLocaleDateString()}
</span>
) : key === "username" ? (
<span className="text-violet-400 text-xs sm:text-sm font-medium">
{score[key] || "Unknown"}
</span>
) : key === "level" || key === "crown_rank" || key === "score_rank" ? (
<div className="flex items-center justify-center">
{renderValue(score[key], key)}
</div>
) : (
<span
className={`${(key === "title" || key === "song") && !hideTitleArtist ? "text-white font-medium" : key === "score" ? "text-white font-medium" : "text-slate-300"}`}
>
{renderValue(score[key], key)}
</span>
)}
</td>
))}
{showActions && (
<td className="px-2 sm:px-4 py-2 sm:py-3">
<button
onClick={() => onDelete(score.id)}
className="text-red-400 hover:text-red-300 opacity-100 transition-opacity duration-200 p-1 rounded bg-red-500/10"
title="Delete score"
>
<svg className="w-3 h-3 sm:w-4 sm:h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
</svg>
</button>
</td>
)}
</tr>
))}
</tbody>
</table>
</div>
</div>
);
};
export default TaikoScoreDisplay;
+12 -6
View File
@@ -11,6 +11,7 @@ import DivaScoreDisplay from "../components/displays/DivaScoreDisplay";
import MusicDiverScoreDisplay from "../components/displays/MusicDiverScoreDisplay";
import NostalgiaScoreDisplay from "../components/displays/NostalgiaScoreDisplay";
import ReflecBeatScoreDisplay from "../components/displays/ReflecBeatScoreDisplay";
import TaikoScoreDisplay from "../components/displays/TaikoScoreDisplay";
type SortField = string;
type SortDirection = "asc" | "desc";
@@ -297,7 +298,6 @@ const AllScores = () => {
showUsername={true}
/>
);
break;
case "dancearound":
return (
<DancearoundScoreDisplay
@@ -309,7 +309,6 @@ const AllScores = () => {
showUsername={true}
/>
);
break;
case "diva":
return (
<DivaScoreDisplay
@@ -321,7 +320,6 @@ const AllScores = () => {
showUsername={true}
/>
);
break;
case "musicdiver":
return (
<MusicDiverScoreDisplay
@@ -333,7 +331,6 @@ const AllScores = () => {
showUsername={true}
/>
);
break;
case "nostalgia":
return (
<NostalgiaScoreDisplay
@@ -345,7 +342,6 @@ const AllScores = () => {
showUsername={true}
/>
);
break;
case "reflecbeat":
return (
<ReflecBeatScoreDisplay
@@ -357,7 +353,17 @@ const AllScores = () => {
showUsername={true}
/>
);
break;
case "taiko":
return (
<TaikoScoreDisplay
scores={scores}
viewMode={viewMode}
sortField={sortField}
sortDirection={sortDirection}
onSort={handleSort}
showUsername={true}
/>
);
default:
return (
<ScoreDisplay
+13
View File
@@ -12,6 +12,7 @@ import SongInfoDisplay from "../components/modals/SongInfoDisplay";
import DancearoundScoreDisplay from "../components/displays/DancearoundScoreDisplay";
import NostalgiaScoreDisplay from "../components/displays/NostalgiaScoreDisplay";
import ReflecBeatScoreDisplay from "../components/displays/ReflecBeatScoreDisplay";
import TaikoScoreDisplay from "../components/displays/TaikoScoreDisplay";
type SortField = string;
type SortDirection = "asc" | "desc";
@@ -261,6 +262,18 @@ const Chart = () => {
hideTitleArtist={true}
/>
);
case "taiko":
return (
<TaikoScoreDisplay
scores={scores}
viewMode={viewMode}
sortField={sortField}
sortDirection={sortDirection}
onSort={handleSort}
showUsername={true}
hideTitleArtist={true}
/>
);
default:
return (
<ScoreDisplay
+4
View File
@@ -12,6 +12,7 @@ import divaImage from "../assets/games/diva.webp";
import musicdiverImage from "../assets/games/music_diver.webp";
import reflecbeatImage from "../assets/games/reflecbeat.webp";
import nostalgiaImage from "../assets/games/nostalgia.webp";
import taikoImage from "../assets/games/taiko.webp";
const Home = () => {
const { user, isLoading, logout } = useAuth();
@@ -49,6 +50,9 @@ const Home = () => {
case "nostalgia": {
return nostalgiaImage;
}
case "taiko": {
return taikoImage;
}
default: {
return null;
}
+12
View File
@@ -12,6 +12,7 @@ import DivaScoreDisplay from "../components/displays/DivaScoreDisplay";
import MusicDiverDisplay from "../components/displays/MusicDiverScoreDisplay";
import ReflecBeatScoreDisplay from "../components/displays/ReflecBeatScoreDisplay";
import NostalgiaScoreDisplay from "../components/displays/NostalgiaScoreDisplay";
import TaikoScoreDisplay from "../components/displays/TaikoScoreDisplay";
type SortField = string;
type SortDirection = "asc" | "desc";
@@ -292,6 +293,17 @@ const Score = () => {
onDelete={handleDeleteScore}
/>
);
case "taiko":
return (
<TaikoScoreDisplay
scores={scores}
viewMode={viewMode}
sortField={sortField}
sortDirection={sortDirection}
onSort={handleSort}
onDelete={handleDeleteScore}
/>
);
default:
return (
<ScoreDisplay
+1 -1
View File
@@ -165,8 +165,8 @@ def get_play_hist(token: str, chart_data):
"crown_rank": crown,
"score_rank": lamp,
"score": int(total_score) if total_score and total_score.isdigit() else total_score,
"judgements": judgements,
"optional": {
"judgements": judgements,
"combo": combo,
"pound": pound
}