UNPKG

@hhoangphuoc/escape-room-cli

Version:

A CLI for playing AI-generated escape room games. Install globally with: npm install -g @hhoangphuoc/escape-room-cli

75 lines (74 loc) 5.75 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { Box, Text } from 'ink'; const Leaderboard = ({ entries, count, showCostMetrics = false }) => { if (count === 0) { return (_jsxs(Box, { flexDirection: "column", padding: 1, children: [_jsx(Box, { marginBottom: 1, children: _jsx(Text, { bold: true, color: "yellow", children: "\uD83C\uDFC6 LEADERBOARD" }) }), _jsx(Box, { children: _jsx(Text, { color: "gray", children: "No completed games found yet. Be the first to complete a game!" }) })] })); } const getModeColor = (gameMode) => { switch (gameMode) { case 'single-room': return 'green'; case 'multi-room': return 'blue'; default: return 'white'; } }; const getRankColor = (rank) => { switch (rank) { case 1: return 'yellow'; case 2: return 'gray'; case 3: return 'red'; default: return 'white'; } }; const getRankEmoji = (rank) => { switch (rank) { case 1: return '🥇'; case 2: return '🥈'; case 3: return '🥉'; default: return ' '; } }; const formatCost = (cost) => { if (cost === undefined || cost === 0) return 'N/A'; return cost < 0.01 ? `$${cost.toFixed(5)}` : `$${cost.toFixed(3)}`; }; const getCostEfficiencyColor = (efficiency) => { if (efficiency === undefined) return 'gray'; if (efficiency > 80) return 'green'; if (efficiency > 60) return 'yellow'; return 'red'; }; const getCostEfficiencyEmoji = (efficiency) => { if (efficiency === undefined) return '❓'; if (efficiency > 80) return '🔥'; if (efficiency > 60) return '⚡'; return '🐌'; }; return (_jsxs(Box, { flexDirection: "column", padding: 1, children: [_jsx(Box, { marginBottom: 1, children: _jsxs(Text, { bold: true, color: "yellow", children: ["\uD83C\uDFC6 TOP 10 PLAYERS ", showCostMetrics ? '(with Cost Metrics)' : ''] }) }), _jsx(Box, { marginBottom: 1, children: _jsx(Text, { color: "gray", children: showCostMetrics ? 'Fastest, Smartest, and Most Cost-Efficient competitors!' : 'Fastest and Smartest competitors are here!' }) }), _jsxs(Box, { marginBottom: 1, children: [_jsx(Box, { width: 6, children: _jsx(Text, { bold: true, color: "cyan", children: "Rank" }) }), _jsx(Box, { width: 12, children: _jsx(Text, { bold: true, color: "cyan", children: "Player" }) }), _jsx(Box, { width: 10, children: _jsx(Text, { bold: true, color: "cyan", children: "Time" }) }), _jsx(Box, { width: 8, children: _jsx(Text, { bold: true, color: "cyan", children: "Hints" }) }), showCostMetrics && (_jsxs(_Fragment, { children: [_jsx(Box, { width: 10, children: _jsx(Text, { bold: true, color: "cyan", children: "Cost" }) }), _jsx(Box, { width: 12, children: _jsx(Text, { bold: true, color: "cyan", children: "Efficiency" }) })] })), _jsx(Box, { width: 12, children: _jsx(Text, { bold: true, color: "cyan", children: "Mode" }) })] }), _jsx(Box, { marginBottom: 1, children: _jsx(Text, { color: "gray", children: showCostMetrics ? '────┼───────────┼─────────┼──────┼─────────┼───────────┼────────────' : '────┼───────────┼─────────┼──────┼────────────' }) }), entries.map((entry) => (_jsxs(Box, { marginBottom: 0, children: [_jsx(Box, { width: 6, children: _jsxs(Text, { color: getRankColor(entry.rank), children: [getRankEmoji(entry.rank), " ", entry.rank.toString().padStart(2, ' ')] }) }), _jsx(Box, { width: 12, children: _jsx(Text, { bold: true, children: entry.userName.length > 10 ? entry.userName.substring(0, 10) + '...' : entry.userName.padEnd(12, ' ') }) }), _jsx(Box, { width: 10, children: _jsxs(Text, { color: "green", children: [entry.timeElapsed, "s"] }) }), _jsx(Box, { width: 8, children: _jsx(Text, { color: entry.hintsUsed > 0 ? 'yellow' : 'green', children: entry.hintsUsed }) }), showCostMetrics && (_jsxs(_Fragment, { children: [_jsx(Box, { width: 10, children: _jsx(Text, { color: entry.totalCost && entry.totalCost > 0.1 ? 'red' : 'green', children: formatCost(entry.totalCost).padStart(8, ' ') }) }), _jsx(Box, { width: 12, children: _jsxs(Text, { color: getCostEfficiencyColor(entry.costEfficiency), children: [getCostEfficiencyEmoji(entry.costEfficiency), " ", entry.costEfficiency ? `${entry.costEfficiency.toFixed(0)}%` : 'N/A'] }) })] })), _jsx(Box, { width: 12, children: _jsx(Text, { color: getModeColor(entry.gameMode), children: entry.gameMode }) })] }, entry.rank))), _jsx(Box, { marginTop: 1, padding: 1, children: _jsxs(Text, { color: "gray", children: ["\uD83D\uDCA1 ", showCostMetrics ? 'Lower time, fewer hints, and better cost efficiency = better ranking!' : 'Lower time and fewer hints = better ranking!'] }) }), showCostMetrics && (_jsx(Box, { padding: 1, children: _jsx(Text, { color: "gray", children: "\uD83D\uDD25 High efficiency (80%+) \u26A1 Good efficiency (60%+) \uD83D\uDC0C Low efficiency (<60%)" }) }))] })); }; export default Leaderboard;