From 4ce46bff4f7f67177110404fa91fe817faa16dd2 Mon Sep 17 00:00:00 2001 From: lgou2w Date: Sat, 13 Jul 2024 14:57:31 +0800 Subject: [PATCH] fix: icons for other languages can now be loaded --- src/components/gacha/GachaItemView.tsx | 51 ++++++++-------- .../gacha/ItemTypeCategoryMappings.ts | 60 +++++++++++++++++++ .../gacha/analysis/GachaAnalysisHistory.tsx | 5 +- .../gacha/overview/GachaOverviewGrid.tsx | 5 +- 4 files changed, 92 insertions(+), 29 deletions(-) create mode 100644 src/components/gacha/ItemTypeCategoryMappings.ts diff --git a/src/components/gacha/GachaItemView.tsx b/src/components/gacha/GachaItemView.tsx index 02cf69b..04988e4 100644 --- a/src/components/gacha/GachaItemView.tsx +++ b/src/components/gacha/GachaItemView.tsx @@ -6,13 +6,15 @@ import Typography from '@mui/material/Typography' import GenshinUIRarity3Background from '@/assets/images/genshin/UI_Rarity_3_Background.png' import GenshinUIRarity4Background from '@/assets/images/genshin/UI_Rarity_4_Background.png' import GenshinUIRarity5Background from '@/assets/images/genshin/UI_Rarity_5_Background.png' +import { ItemTypeCategoryMappings } from './ItemTypeCategoryMappings' import { lookupAssetIcon } from './icons' import dayjs from '@/utilities/dayjs' export interface GachaItemViewProps { facet: AccountFacet - name: string - id: string + lang: string + itemName: string + itemId: undefined | null | string itemType: string rank: 3 | 4 | 5 | '3' | '4' | '5' size: number @@ -22,19 +24,12 @@ export interface GachaItemViewProps { } export default function GachaItemView (props: GachaItemViewProps) { - const { facet, name, id, itemType, rank, size, usedPity, restricted, time } = props - - const category = ItemTypeCategoryMappings[itemType] - const icon = lookupAssetIcon(facet, category, id) - - let src = icon?.[1] - if (!src) { - src = getRemoteResourceSrc(facet, category, id) - } + const { facet, lang, itemName, itemId, itemType, rank, size, usedPity, restricted, time } = props + const iconSrc = resolveItemIconSrc(facet, lang, itemName, itemId, itemType) const title = !time - ? name - : name + '\n' + dayjs(time).format('LLLL') + ? itemName + : itemName + '\n' + dayjs(time).format('LLLL') return ( - {name} + {itemName} {usedPity && {usedPity}} {restricted && 限定} ) } -const ItemTypeCategoryMappings: Record = { - 角色: 'character', - 武器: 'weapon', - 光锥: 'weapon', - 代理人: 'character', - 音擎: 'weapon', - 邦布: 'bangboo' -} +function resolveItemIconSrc (facet: AccountFacet, lang: string, itemName: string, itemId: string | undefined | null, itemType: string): string | undefined { + const category = ItemTypeCategoryMappings[facet][lang]?.[itemType] + if (!category) { + console.error('Unable to resolve item icon category:', facet, lang, itemType, itemName, itemId) + return undefined + } + + // HACK: GenshinImpact embedded icons are only available for zh-cn language, go to Remote Loading + if (facet === AccountFacet.Genshin && lang !== 'zh-cn') { + return `https://hoyo-gacha.lgou2w.com/static/${facet}/${lang}/${category}/cutted/${itemName}.png` + } -function getRemoteResourceSrc (facet: AccountFacet, category: string, itemIdOrName: string) { - return `https://hoyo-gacha.lgou2w.com/static/${facet}/${category}/cutted/${itemIdOrName}.png` + const embedded = lookupAssetIcon(facet, category, itemId || itemName) + if (embedded) { + return embedded[1] + } else { + return `https://hoyo-gacha.lgou2w.com/static/${facet}/${category}/cutted/${itemId}.png` + } } const GachaItemViewCls = 'gacha-item-view' diff --git a/src/components/gacha/ItemTypeCategoryMappings.ts b/src/components/gacha/ItemTypeCategoryMappings.ts new file mode 100644 index 0000000..befae6b --- /dev/null +++ b/src/components/gacha/ItemTypeCategoryMappings.ts @@ -0,0 +1,60 @@ +/* eslint-disable object-shorthand */ +/* eslint-disable quote-props */ + +import { AccountFacet } from '@/interfaces/account' + +export const Character = 'character' +export const Weapon = 'weapon' +export const Bangboo = 'bangboo' + +export type Category = typeof Character | typeof Weapon | typeof Bangboo + +export const ItemTypeCategoryMappings: Record>> = { + [AccountFacet.Genshin]: { + 'de-de': { 'Figur': Character, 'Waffe': Weapon }, + 'en-us': { 'Character': Character, 'Weapon': Weapon }, + 'es-es': { 'Personaje': Character, 'Arma': Weapon }, + 'fr-fr': { 'Personnages': Character, 'Arme': Weapon }, + 'id-id': { 'Karakter': Character, 'Senjata': Weapon }, + 'it-it': { 'Personaggio': Character, 'Armi': Weapon }, + 'ja-jp': { 'キャラクター': Character, '武器': Weapon }, + 'ko-kr': { '캐릭터': Character, '무기': Weapon }, + 'pt-pt': { 'Personagem': Character, 'Arma': Weapon }, + 'ru-ru': { 'Персонаж': Character, 'Оружие': Weapon }, + 'th-th': { 'ตัวละคร': Character, 'อาวุธ': Weapon }, + 'tr-tr': { 'Karakter': Character, 'Silahlar': Weapon }, + 'vi-vn': { 'Nhân vật': Character, 'Vũ Khí': Weapon }, + 'zh-cn': { '角色': Character, '武器': Weapon }, + 'zh-tw': { '角色': Character, '武器': Weapon } + }, + [AccountFacet.StarRail]: { + 'de-de': { 'Figuren': Character, 'Lichtkegel': Weapon }, + 'en-us': { 'Character': Character, 'Light Cone': Weapon }, + 'es-es': { 'Personajes': Character, 'Conos de luz': Weapon }, + 'fr-fr': { 'Personnages': Character, 'Cônes de lumière': Weapon }, + 'id-id': { 'Karakter': Character, 'Light Cone': Weapon }, + 'ja-jp': { 'キャラクター': Character, '光円錐': Weapon }, + 'ko-kr': { '캐릭터': Character, '광추': Weapon }, + 'pt-pt': { 'Personagens': Character, 'Cones de Luz': Weapon }, + 'ru-ru': { 'Персонажи': Character, 'Световые конусы': Weapon }, + 'th-th': { 'ตัวละคร': Character, 'Light Cone': Weapon }, + 'vi-vn': { 'Nhân Vật': Character, 'Nón Ánh Sáng': Weapon }, + 'zh-cn': { '角色': Character, '光锥': Weapon }, + 'zh-tw': { '角色': Character, '光錐': Weapon } + }, + [AccountFacet.ZenlessZoneZero]: { + 'de-de': { 'Agenten': Character, 'W-Motoren': Weapon, 'Bangboos': Bangboo }, + 'en-us': { 'Agents': Character, 'W-Engines': Weapon, 'Bangboo': Bangboo }, + 'es-es': { 'Agentes': Character, 'Amplificadores': Weapon, 'Bangbús': Bangboo }, + 'fr-fr': { 'Agents': Character, 'Moteurs-amplis': Weapon, 'Bangbous': Bangboo }, + 'id-id': { 'Agen': Character, 'W-Engine': Weapon, 'Bangboo': Bangboo }, + 'ja-jp': { 'エージェント': Character, '音動機': Weapon, 'ボンプ': Bangboo }, + 'ko-kr': { '에이전트': Character, 'W-엔진': Weapon, '「Bangboo」': Bangboo }, + 'pt-pt': { 'Agentes': Character, 'Motores-W': Weapon, 'Bangboos': Bangboo }, + 'ru-ru': { 'Агенты': Character, 'Амплификаторы': Weapon, 'Банбу': Bangboo }, + 'th-th': { 'Agent': Character, 'W-Engine': Weapon, 'Bangboo': Bangboo }, + 'vi-vn': { 'Người Đại Diện': Character, 'W-Engine': Weapon, 'Bangboo': Bangboo }, + 'zh-cn': { '代理人': Character, '音擎': Weapon, '邦布': Bangboo }, + 'zh-tw': { '代理人': Character, '音擎': Weapon, '邦布': Bangboo } + } +} diff --git a/src/components/gacha/analysis/GachaAnalysisHistory.tsx b/src/components/gacha/analysis/GachaAnalysisHistory.tsx index 0e81425..8db9949 100644 --- a/src/components/gacha/analysis/GachaAnalysisHistory.tsx +++ b/src/components/gacha/analysis/GachaAnalysisHistory.tsx @@ -64,8 +64,9 @@ function GachaAnalysisHistoryList ({ facet, value }: {