fix service header

This commit is contained in:
2026-01-25 18:02:58 +09:00
parent 570dce37e1
commit af22446c47
2 changed files with 18 additions and 15 deletions

View File

@@ -5,6 +5,7 @@ export interface UserCard {
cp: number cp: number
rare: number rare: number
cid: string cid: string
unique: boolean
} }
export interface CardCollection { export interface CardCollection {
@@ -14,19 +15,17 @@ export interface CardCollection {
} }
// Get rarity class name // Get rarity class name
function getRarityClass(rare: number): string { function getRarityClass(card: UserCard): string {
switch (rare) { if (card.unique) return 'unique'
case 1: return 'rare' if (card.rare >= 4) return 'shiny' // first(5), second(4)
case 2: return 'shiny' if (card.rare >= 1) return 'rare' // third(3), fourth(2), fifth(1)
case 3: return 'unique' return ''
default: return ''
}
} }
// Render single card with optional count badge // Render single card with optional count badge
export function renderCard(card: UserCard, baseUrl: string = '/card', count?: number): string { export function renderCard(card: UserCard, baseUrl: string = '/card', count?: number): string {
const rarityClass = getRarityClass(card.rare) const rarityClass = getRarityClass(card)
const imageUrl = `${baseUrl}/${card.id}.webp` const imageUrl = `${baseUrl}/${card.id}.webp`
const effectsHtml = rarityClass ? ` const effectsHtml = rarityClass ? `
@@ -89,10 +88,10 @@ export function renderCardPage(
// Count by rarity // Count by rarity
const rarityCount = { const rarityCount = {
normal: cards.filter(c => c.rare === 0).length, normal: cards.filter(c => !c.unique && c.rare === 0).length,
rare: cards.filter(c => c.rare === 1).length, rare: cards.filter(c => !c.unique && c.rare >= 1 && c.rare < 4).length,
shiny: cards.filter(c => c.rare === 2).length, shiny: cards.filter(c => !c.unique && c.rare >= 4).length,
unique: cards.filter(c => c.rare === 3).length, unique: cards.filter(c => c.unique).length,
} }
// Group cards by id and count // Group cards by id and count
@@ -101,8 +100,10 @@ export function renderCardPage(
const existing = cardGroups.get(card.id) const existing = cardGroups.get(card.id)
if (existing) { if (existing) {
existing.count++ existing.count++
// Keep the highest CP/rarity version // Keep the unique/highest rarity/CP version
if (card.cp > existing.card.cp || card.rare > existing.card.rare) { if (card.unique && !existing.card.unique ||
card.rare > existing.card.rare ||
card.cp > existing.card.cp) {
existing.card = card existing.card = card
} }
} else { } else {
@@ -110,9 +111,10 @@ export function renderCardPage(
} }
} }
// Sort by rarity (desc), then by id // Sort by unique first, then rarity (desc), then by id
const sortedGroups = Array.from(cardGroups.values()) const sortedGroups = Array.from(cardGroups.values())
.sort((a, b) => { .sort((a, b) => {
if (a.card.unique !== b.card.unique) return a.card.unique ? -1 : 1
if (b.card.rare !== a.card.rare) return b.card.rare - a.card.rare if (b.card.rare !== a.card.rare) return b.card.rare - a.card.rare
return a.card.id - b.card.id return a.card.id - b.card.id
}) })

View File

@@ -100,6 +100,7 @@ export interface UserCard {
cp: number cp: number
rare: number rare: number
cid: string cid: string
unique: boolean
} }
export interface CardCollection { export interface CardCollection {