Refactor battlesuits data
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
/** @jsxImportSource theme-ui */
|
||||
import { Box, Card, Text, Flex } from '@theme-ui/components'
|
||||
import { useRouter } from 'next/router'
|
||||
import { assetsBucketBaseUrl } from '../../lib/consts'
|
||||
import { BattlesuitData } from '../../lib/honkai3rd/battlesuits'
|
||||
import { translate } from '../../lib/i18n'
|
||||
import PageLink from '../atoms/PageLink'
|
||||
import SquareImageBox from '../atoms/SquareImageBox'
|
||||
|
||||
interface BattlesuitCardProps {
|
||||
battlesuit: Pick<BattlesuitData, 'id' | 'name' | 'krName'>
|
||||
battlesuit: Pick<BattlesuitData, 'id' | 'name'>
|
||||
hidden?: boolean
|
||||
size?: 'sm' | 'default'
|
||||
href?: string
|
||||
@@ -22,14 +20,6 @@ const BattlesuitCard = ({
|
||||
href,
|
||||
m,
|
||||
}: BattlesuitCardProps) => {
|
||||
const { locale } = useRouter()
|
||||
|
||||
const battlesuitName = translate(
|
||||
locale,
|
||||
{ 'ko-KR': battlesuit.krName },
|
||||
battlesuit.name
|
||||
)
|
||||
|
||||
if (href == null) {
|
||||
href = `/honkai3rd/battlesuits/${battlesuit.id}`
|
||||
}
|
||||
@@ -50,7 +40,7 @@ const BattlesuitCard = ({
|
||||
<Flex sx={{ alignItems: 'center' }}>
|
||||
<SquareImageBox
|
||||
mr={2}
|
||||
alt={battlesuitName}
|
||||
alt={battlesuit.name}
|
||||
src={`${assetsBucketBaseUrl}/honkai3rd/battlesuits/portrait-${battlesuit.id}.png`}
|
||||
size={30}
|
||||
/>
|
||||
@@ -62,7 +52,7 @@ const BattlesuitCard = ({
|
||||
whiteSpace: 'nowrap',
|
||||
}}
|
||||
>
|
||||
{battlesuitName}
|
||||
{battlesuit.name}
|
||||
</Text>
|
||||
</Flex>
|
||||
</PageLink>
|
||||
@@ -84,7 +74,7 @@ const BattlesuitCard = ({
|
||||
>
|
||||
<PageLink href={href}>
|
||||
<SquareImageBox
|
||||
alt={battlesuitName}
|
||||
alt={battlesuit.name}
|
||||
src={`${assetsBucketBaseUrl}/honkai3rd/battlesuits/portrait-${battlesuit.id}.png`}
|
||||
size={100}
|
||||
/>
|
||||
@@ -97,7 +87,7 @@ const BattlesuitCard = ({
|
||||
textAlign: 'center',
|
||||
}}
|
||||
>
|
||||
<Text>{battlesuitName}</Text>
|
||||
<Text>{battlesuit.name}</Text>
|
||||
</Box>
|
||||
</PageLink>
|
||||
</Card>
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
export interface BattlesuitSkill {
|
||||
name: string
|
||||
krName?: string
|
||||
description: string
|
||||
krDescription?: string
|
||||
requiredRank?: string
|
||||
}
|
||||
|
||||
@@ -23,7 +21,6 @@ export interface BattlesuitData {
|
||||
id: string
|
||||
version?: string
|
||||
name: string
|
||||
krName?: string
|
||||
type: string
|
||||
valkyrie: string
|
||||
features: string[]
|
||||
|
||||
@@ -59,12 +59,6 @@ const BattlesuitShowPage = ({
|
||||
const { t } = useTranslation()
|
||||
const { locale } = useRouter()
|
||||
|
||||
const battlesuitName = translate(
|
||||
locale,
|
||||
{ ['ko-KR']: battlesuit.krName },
|
||||
battlesuit.name
|
||||
)
|
||||
|
||||
const { label: valkyrieLabel, krLabel } = valkyries.find(
|
||||
(aValkyrie) => aValkyrie.value === battlesuit.valkyrie
|
||||
) || { label: battlesuit.valkyrie, krLabel: battlesuit.valkyrie }
|
||||
@@ -85,7 +79,7 @@ const BattlesuitShowPage = ({
|
||||
return (
|
||||
<Honkai3rdLayout>
|
||||
<Head
|
||||
title={`${battlesuitName} - ${t('common.honkai-3rd')} - ${t(
|
||||
title={`${battlesuit.name} - ${t('common.honkai-3rd')} - ${t(
|
||||
'common.abyss-lab'
|
||||
)}`}
|
||||
description={`${t('common.honkai-3rd')} ${t(
|
||||
@@ -116,12 +110,12 @@ const BattlesuitShowPage = ({
|
||||
},
|
||||
{
|
||||
href: `/honkai3rd/battlesuits/${battlesuit.id}`,
|
||||
label: battlesuitName,
|
||||
label: battlesuit.name,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
<Heading as='h1'>{battlesuitName}</Heading>
|
||||
<Heading as='h1'>{battlesuit.name}</Heading>
|
||||
|
||||
<Box mb={3}>
|
||||
<Box
|
||||
@@ -133,7 +127,7 @@ const BattlesuitShowPage = ({
|
||||
}}
|
||||
>
|
||||
<Image
|
||||
alt={battlesuitName}
|
||||
alt={battlesuit.name}
|
||||
src={`${assetsBucketBaseUrl}/honkai3rd/battlesuits/${battlesuit.id}.png`}
|
||||
width={400}
|
||||
height={400}
|
||||
@@ -239,44 +233,37 @@ const BattlesuitShowPage = ({
|
||||
<BattlesuitSkillGroupCard
|
||||
heading={t('battlesuit-show.leader')}
|
||||
skillGroup={battlesuit.leader}
|
||||
locale={locale}
|
||||
/>
|
||||
|
||||
<BattlesuitSkillGroupCard
|
||||
heading={t('battlesuit-show.passive')}
|
||||
skillGroup={battlesuit.passive}
|
||||
locale={locale}
|
||||
/>
|
||||
|
||||
<BattlesuitSkillGroupCard
|
||||
heading={t('battlesuit-show.evasion')}
|
||||
skillGroup={battlesuit.evasion}
|
||||
locale={locale}
|
||||
/>
|
||||
|
||||
<BattlesuitSkillGroupCard
|
||||
heading={t('battlesuit-show.special-attack')}
|
||||
skillGroup={battlesuit.special}
|
||||
locale={locale}
|
||||
/>
|
||||
|
||||
<BattlesuitSkillGroupCard
|
||||
heading={t('battlesuit-show.ultimate')}
|
||||
skillGroup={battlesuit.ultimate}
|
||||
locale={locale}
|
||||
/>
|
||||
|
||||
<BattlesuitSkillGroupCard
|
||||
heading={t('battlesuit-show.basic-attack')}
|
||||
skillGroup={battlesuit.basic}
|
||||
locale={locale}
|
||||
/>
|
||||
|
||||
{battlesuit.sp != null && (
|
||||
<BattlesuitSkillGroupCard
|
||||
heading={t('battlesuit-show.sp-skill')}
|
||||
skillGroup={battlesuit.sp}
|
||||
locale={locale}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
@@ -290,7 +277,7 @@ export async function getStaticProps({
|
||||
params,
|
||||
locale,
|
||||
}: NextPageContext & { params: { battlesuitId: string } }) {
|
||||
const battlesuit = getBattlesuitById(params.battlesuitId)!
|
||||
const battlesuit = getBattlesuitById(params.battlesuitId, locale)!
|
||||
const { weaponIds, stigmataIds } = (battlesuit.equipment || []).reduce<{
|
||||
weaponIds: string[]
|
||||
stigmataIds: string[]
|
||||
@@ -336,13 +323,11 @@ export async function getStaticPaths() {
|
||||
interface BattlesuitSkillGroupCardProps {
|
||||
heading: string
|
||||
skillGroup: BattlesuitSkillGroup
|
||||
locale?: string
|
||||
}
|
||||
|
||||
const BattlesuitSkillGroupCard = ({
|
||||
heading,
|
||||
skillGroup,
|
||||
locale,
|
||||
}: BattlesuitSkillGroupCardProps) => {
|
||||
return (
|
||||
<Card mb={3}>
|
||||
@@ -353,39 +338,21 @@ const BattlesuitSkillGroupCard = ({
|
||||
}}
|
||||
>
|
||||
<Heading as='h2' mb={1}>
|
||||
{translate(
|
||||
locale,
|
||||
{ 'ko-KR': skillGroup.core.krName },
|
||||
skillGroup.core.name
|
||||
)}
|
||||
{skillGroup.core.name}
|
||||
</Heading>
|
||||
<SecondaryLabel>{heading}</SecondaryLabel>
|
||||
</Box>
|
||||
|
||||
<Paragraph p={2} sx={{ whiteSpace: 'pre-wrap', borderBottom: 'default' }}>
|
||||
{translate(
|
||||
locale,
|
||||
{ 'ko-KR': skillGroup.core.krDescription },
|
||||
skillGroup.core.description
|
||||
)}
|
||||
{skillGroup.core.description}
|
||||
</Paragraph>
|
||||
|
||||
{skillGroup.subskills.map((subskill) => {
|
||||
const skillName = translate(
|
||||
locale,
|
||||
{ 'ko-KR': subskill.krName },
|
||||
subskill.name
|
||||
)
|
||||
const skillDescription = translate(
|
||||
locale,
|
||||
{ 'ko-KR': subskill.krDescription },
|
||||
subskill.description
|
||||
)
|
||||
return (
|
||||
<React.Fragment key={subskill.name}>
|
||||
<Heading as='h3' p={2} m={0} sx={{ borderBottom: 'default' }}>
|
||||
<Flex sx={{ alignItems: 'center' }}>
|
||||
<Text>{skillName}</Text>
|
||||
<Text>{subskill.name}</Text>
|
||||
{subskill.requiredRank != null ? (
|
||||
/^[0-9]/.test(subskill.requiredRank) ? (
|
||||
<Box
|
||||
@@ -415,7 +382,7 @@ const BattlesuitSkillGroupCard = ({
|
||||
'&:last-child': { borderBottom: 'none' },
|
||||
}}
|
||||
>
|
||||
{skillDescription}
|
||||
{subskill.description}
|
||||
</Paragraph>
|
||||
</React.Fragment>
|
||||
)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/** @jsxImportSource theme-ui */
|
||||
import { Box, Heading, Flex, Button } from '@theme-ui/components'
|
||||
import { pick } from 'ramda'
|
||||
import { useCallback, useMemo, useState } from 'react'
|
||||
import FilterButton from '../../../components/atoms/FilterButton'
|
||||
import Breadcrumb from '../../../components/organisms/Breadcrumb'
|
||||
@@ -21,7 +20,7 @@ import Honkai3rdLayout from '../../../components/layouts/Honkai3rdLayout'
|
||||
|
||||
type BattlesuitListItemData = Pick<
|
||||
BattlesuitData,
|
||||
'id' | 'name' | 'krName' | 'features' | 'type' | 'valkyrie'
|
||||
'id' | 'name' | 'features' | 'type' | 'valkyrie'
|
||||
>
|
||||
|
||||
interface BattlesuitListPageProps {
|
||||
@@ -171,12 +170,15 @@ export default BattlesuitListPage
|
||||
export async function getStaticProps({ locale }: NextPageContext) {
|
||||
return {
|
||||
props: {
|
||||
battlesuits: listBattlesuits().map((battlesuit) =>
|
||||
pick(
|
||||
['id', 'name', 'krName', 'features', 'type', 'valkyrie'],
|
||||
battlesuit
|
||||
)
|
||||
),
|
||||
battlesuits: listBattlesuits().map((battlesuit) => {
|
||||
return {
|
||||
id: battlesuit.id,
|
||||
name: battlesuit.name,
|
||||
features: battlesuit.features,
|
||||
type: battlesuit.type,
|
||||
valikyrie: battlesuit.valkyrie,
|
||||
}
|
||||
}),
|
||||
...(await getI18NProps(locale)),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -5,8 +5,7 @@ import Breadcrumb from '../../../../components/organisms/Breadcrumb'
|
||||
import { BattlesuitData } from '../../../../lib/honkai3rd/battlesuits'
|
||||
import { generateI18NPaths, getI18NProps } from '../../../../server/i18n'
|
||||
import { getBattlesuitById } from '../../../../server/data/honkai3rd/battlesuits'
|
||||
import { translate, useTranslation } from '../../../../lib/i18n'
|
||||
import { useRouter } from 'next/router'
|
||||
import { useTranslation } from '../../../../lib/i18n'
|
||||
import Head from '../../../../components/atoms/Head'
|
||||
import { assetsBucketBaseUrl } from '../../../../lib/consts'
|
||||
import Honkai3rdLayout from '../../../../components/layouts/Honkai3rdLayout'
|
||||
@@ -38,18 +37,10 @@ const BattlesuitShowPage = ({
|
||||
signetSet,
|
||||
}: BattlesuitShowPageProps) => {
|
||||
const { t } = useTranslation()
|
||||
const { locale } = useRouter()
|
||||
|
||||
const battlesuitName = translate(
|
||||
locale,
|
||||
{ ['ko-KR']: battlesuit.krName },
|
||||
battlesuit.name
|
||||
)
|
||||
|
||||
return (
|
||||
<Honkai3rdLayout>
|
||||
<Head
|
||||
title={`${battlesuitName} (${t('common.elysian-realm')}) - ${t(
|
||||
title={`${battlesuit.name} (${t('common.elysian-realm')}) - ${t(
|
||||
'common.honkai-3rd'
|
||||
)} - ${t('common.abyss-lab')}`}
|
||||
description={`${t('common.honkai-3rd')} ${t(
|
||||
@@ -67,12 +58,12 @@ const BattlesuitShowPage = ({
|
||||
},
|
||||
{
|
||||
href: `/honkai3rd/elysian-realm/battlesuits/${battlesuit.id}`,
|
||||
label: battlesuitName,
|
||||
label: battlesuit.name,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
<Heading as='h1'>{battlesuitName}</Heading>
|
||||
<Heading as='h1'>{battlesuit.name}</Heading>
|
||||
|
||||
<Box mb={3}>
|
||||
<Box
|
||||
@@ -84,7 +75,7 @@ const BattlesuitShowPage = ({
|
||||
}}
|
||||
>
|
||||
<Image
|
||||
alt={battlesuitName}
|
||||
alt={battlesuit.name}
|
||||
src={`${assetsBucketBaseUrl}/honkai3rd/battlesuits/${battlesuit.id}.png`}
|
||||
width={400}
|
||||
height={400}
|
||||
@@ -111,7 +102,7 @@ export async function getStaticProps({
|
||||
locale,
|
||||
}: NextPageContext & { params: { battlesuitId: string } }) {
|
||||
try {
|
||||
const battlesuit = getBattlesuitById(params.battlesuitId)!
|
||||
const battlesuit = getBattlesuitById(params.battlesuitId, locale)!
|
||||
const { weaponIds, stigmataIds } = (battlesuit.equipment || []).reduce<{
|
||||
weaponIds: string[]
|
||||
stigmataIds: string[]
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
|
||||
type BattlesuitListItemData = Pick<
|
||||
BattlesuitData,
|
||||
'id' | 'name' | 'krName' | 'features' | 'type' | 'valkyrie'
|
||||
'id' | 'name' | 'features' | 'type' | 'valkyrie'
|
||||
>
|
||||
|
||||
interface BattlesuitListPageProps {
|
||||
@@ -182,7 +182,7 @@ export async function getStaticProps({ locale }: NextPageContext) {
|
||||
})
|
||||
return {
|
||||
props: {
|
||||
battlesuitMap: getBattlesuitMapByIds(erBattlesuitIds),
|
||||
battlesuitMap: getBattlesuitMapByIds(erBattlesuitIds, locale),
|
||||
supportBattlesuits,
|
||||
remembranceSigils,
|
||||
...(await getI18NProps(locale)),
|
||||
|
||||
@@ -25,8 +25,7 @@ import {
|
||||
getBattlesuitById,
|
||||
listBattlesuits,
|
||||
} from '../../../../server/data/honkai3rd/battlesuits'
|
||||
import { translate, useTranslation } from '../../../../lib/i18n'
|
||||
import { useRouter } from 'next/router'
|
||||
import { useTranslation } from '../../../../lib/i18n'
|
||||
import { assetsBucketBaseUrl } from '../../../../lib/consts'
|
||||
import { WeaponData } from '../../../../lib/honkai3rd/weapons'
|
||||
import { getWeaponMapByIds } from '../../../../server/data/honkai3rd/weapons'
|
||||
@@ -50,17 +49,10 @@ const BattlesuitShowPage = ({
|
||||
stigmataMap,
|
||||
}: BattlesuitShowPageProps) => {
|
||||
const { t } = useTranslation()
|
||||
const { locale } = useRouter()
|
||||
|
||||
const battlesuitName = translate(
|
||||
locale,
|
||||
{ ['ko-KR']: battlesuit.krName },
|
||||
battlesuit.name
|
||||
)
|
||||
|
||||
return (
|
||||
<Box p={3}>
|
||||
<Heading as='h1'>{battlesuitName}</Heading>
|
||||
<Heading as='h1'>{battlesuit.name}</Heading>
|
||||
|
||||
<Box mb={3}>
|
||||
<Box
|
||||
@@ -72,7 +64,7 @@ const BattlesuitShowPage = ({
|
||||
}}
|
||||
>
|
||||
<Image
|
||||
alt={battlesuitName}
|
||||
alt={battlesuit.name}
|
||||
src={`${assetsBucketBaseUrl}/honkai3rd/battlesuits/${battlesuit.id}.png`}
|
||||
width={400}
|
||||
height={400}
|
||||
@@ -178,44 +170,37 @@ const BattlesuitShowPage = ({
|
||||
<BattlesuitSkillGroupCard
|
||||
heading={t('battlesuit-show.leader')}
|
||||
skillGroup={battlesuit.leader}
|
||||
locale={locale}
|
||||
/>
|
||||
|
||||
<BattlesuitSkillGroupCard
|
||||
heading={t('battlesuit-show.passive')}
|
||||
skillGroup={battlesuit.passive}
|
||||
locale={locale}
|
||||
/>
|
||||
|
||||
<BattlesuitSkillGroupCard
|
||||
heading={t('battlesuit-show.evasion')}
|
||||
skillGroup={battlesuit.evasion}
|
||||
locale={locale}
|
||||
/>
|
||||
|
||||
<BattlesuitSkillGroupCard
|
||||
heading={t('battlesuit-show.special-attack')}
|
||||
skillGroup={battlesuit.special}
|
||||
locale={locale}
|
||||
/>
|
||||
|
||||
<BattlesuitSkillGroupCard
|
||||
heading={t('battlesuit-show.ultimate')}
|
||||
skillGroup={battlesuit.ultimate}
|
||||
locale={locale}
|
||||
/>
|
||||
|
||||
<BattlesuitSkillGroupCard
|
||||
heading={t('battlesuit-show.basic-attack')}
|
||||
skillGroup={battlesuit.basic}
|
||||
locale={locale}
|
||||
/>
|
||||
|
||||
{battlesuit.sp != null && (
|
||||
<BattlesuitSkillGroupCard
|
||||
heading={t('battlesuit-show.sp-skill')}
|
||||
skillGroup={battlesuit.sp}
|
||||
locale={locale}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
@@ -228,7 +213,7 @@ export async function getStaticProps({
|
||||
params,
|
||||
locale,
|
||||
}: NextPageContext & { params: { battlesuitId: string } }) {
|
||||
const battlesuit = getBattlesuitById(params.battlesuitId)!
|
||||
const battlesuit = getBattlesuitById(params.battlesuitId, locale)!
|
||||
const { weaponIds, stigmataIds } = (battlesuit.equipment || []).reduce<{
|
||||
weaponIds: string[]
|
||||
stigmataIds: string[]
|
||||
@@ -274,13 +259,11 @@ export async function getStaticPaths() {
|
||||
interface BattlesuitSkillGroupCardProps {
|
||||
heading: string
|
||||
skillGroup: BattlesuitSkillGroup
|
||||
locale?: string
|
||||
}
|
||||
|
||||
const BattlesuitSkillGroupCard = ({
|
||||
heading,
|
||||
skillGroup,
|
||||
locale,
|
||||
}: BattlesuitSkillGroupCardProps) => {
|
||||
return (
|
||||
<Card mb={3}>
|
||||
@@ -291,39 +274,21 @@ const BattlesuitSkillGroupCard = ({
|
||||
}}
|
||||
>
|
||||
<Heading as='h2' mb={1}>
|
||||
{translate(
|
||||
locale,
|
||||
{ 'ko-KR': skillGroup.core.krName },
|
||||
skillGroup.core.name
|
||||
)}
|
||||
{skillGroup.core.name}
|
||||
</Heading>
|
||||
<SecondaryLabel>{heading}</SecondaryLabel>
|
||||
</Box>
|
||||
|
||||
<Paragraph p={2} sx={{ whiteSpace: 'pre-wrap', borderBottom: 'default' }}>
|
||||
{translate(
|
||||
locale,
|
||||
{ 'ko-KR': skillGroup.core.krDescription },
|
||||
skillGroup.core.description
|
||||
)}
|
||||
{skillGroup.core.description}
|
||||
</Paragraph>
|
||||
|
||||
{skillGroup.subskills.map((subskill) => {
|
||||
const skillName = translate(
|
||||
locale,
|
||||
{ 'ko-KR': subskill.krName },
|
||||
subskill.name
|
||||
)
|
||||
const skillDescription = translate(
|
||||
locale,
|
||||
{ 'ko-KR': subskill.krDescription },
|
||||
subskill.description
|
||||
)
|
||||
return (
|
||||
<React.Fragment key={subskill.name}>
|
||||
<Heading as='h3' p={2} m={0} sx={{ borderBottom: 'default' }}>
|
||||
<Flex sx={{ alignItems: 'center' }}>
|
||||
<Text>{skillName}</Text>
|
||||
<Text>{subskill.name}</Text>
|
||||
{subskill.requiredRank != null ? (
|
||||
/^[0-9]/.test(subskill.requiredRank) ? (
|
||||
<Box
|
||||
@@ -353,7 +318,7 @@ const BattlesuitSkillGroupCard = ({
|
||||
'&:last-child': { borderBottom: 'none' },
|
||||
}}
|
||||
>
|
||||
{skillDescription}
|
||||
{subskill.description}
|
||||
</Paragraph>
|
||||
</React.Fragment>
|
||||
)
|
||||
|
||||
@@ -147,7 +147,8 @@ export async function getStaticProps({
|
||||
const battlesuitMap = getBattlesuitMapByIds(
|
||||
weapon != null && weapon.battlesuits != null
|
||||
? weapon.battlesuits.map(({ id }) => id)
|
||||
: []
|
||||
: [],
|
||||
locale
|
||||
)
|
||||
|
||||
const weaponIds = []
|
||||
|
||||
@@ -57,11 +57,7 @@ const VersionShowPage = ({
|
||||
'versions.version'
|
||||
)} ${versionName} / ${t('versions.new-battlesuits')}: ${battlesuits
|
||||
.map((battlesuit) => {
|
||||
return translate(
|
||||
locale,
|
||||
{ 'ko-KR': battlesuit.krName },
|
||||
battlesuit.name
|
||||
)
|
||||
return battlesuit.name
|
||||
})
|
||||
.join(',')} / ${t('versions.new-weapons')}: ${weapons
|
||||
.map((weapon) => {
|
||||
@@ -113,12 +109,6 @@ const VersionShowPage = ({
|
||||
</Heading>
|
||||
<Box mb={3} sx={{ display: 'inline-block' }}>
|
||||
{battlesuits.map((battlesuit) => {
|
||||
const battlesuitName = translate(
|
||||
locale,
|
||||
{ 'ko-KR': battlesuit.krName },
|
||||
battlesuit.name
|
||||
)
|
||||
|
||||
return (
|
||||
<NextLink
|
||||
key={battlesuit.id}
|
||||
@@ -130,10 +120,10 @@ const VersionShowPage = ({
|
||||
<SquareImageBox
|
||||
size={40}
|
||||
src={`${assetsBucketBaseUrl}/honkai3rd/battlesuits/portrait-${battlesuit.id}.png`}
|
||||
alt={`${battlesuitName}`}
|
||||
alt={`${battlesuit.name}`}
|
||||
mr={2}
|
||||
/>
|
||||
<Text>{battlesuitName}</Text>
|
||||
<Text>{battlesuit.name}</Text>
|
||||
</Flex>
|
||||
</Link>
|
||||
</NextLink>
|
||||
@@ -232,7 +222,7 @@ export async function getStaticProps({
|
||||
const versionData = getVersion(params.versionId)!
|
||||
|
||||
const battlesuits = versionData.newBattlesuits.map((battlesuitId) => {
|
||||
return getBattlesuitById(battlesuitId)
|
||||
return getBattlesuitById(battlesuitId, locale)
|
||||
})
|
||||
const weapons = versionData.newWeapons.map((weaponId) => {
|
||||
return getWeaponById(weaponId)
|
||||
|
||||
@@ -103,12 +103,6 @@ const VersionIndexPage = ({
|
||||
</Heading>
|
||||
<Box mb={3} sx={{ display: 'inline-block' }}>
|
||||
{currentVersionNewBattlesuits.map((battlesuit) => {
|
||||
const battlesuitName = translate(
|
||||
locale,
|
||||
{ 'ko-KR': battlesuit.krName },
|
||||
battlesuit.name
|
||||
)
|
||||
|
||||
return (
|
||||
<NextLink
|
||||
key={battlesuit.id}
|
||||
@@ -120,10 +114,10 @@ const VersionIndexPage = ({
|
||||
<SquareImageBox
|
||||
size={40}
|
||||
src={`${assetsBucketBaseUrl}/honkai3rd/battlesuits/portrait-${battlesuit.id}.png`}
|
||||
alt={`${battlesuitName}`}
|
||||
alt={`${battlesuit.name}`}
|
||||
mr={2}
|
||||
/>
|
||||
<Text>{battlesuitName}</Text>
|
||||
<Text>{battlesuit.name}</Text>
|
||||
</Flex>
|
||||
</Link>
|
||||
</NextLink>
|
||||
|
||||
@@ -22,6 +22,7 @@ const order = [
|
||||
'basic',
|
||||
'sp',
|
||||
'core',
|
||||
'subskills',
|
||||
'description',
|
||||
'krDescription',
|
||||
'requiredRank',
|
||||
|
||||
@@ -1,152 +1,67 @@
|
||||
import { readdirSync, readFileSync, readJsonFileSync } from '../fs'
|
||||
import { compareVersion } from '../../../lib/string'
|
||||
import {
|
||||
BattlesuitData,
|
||||
BattlesuitSkillGroup,
|
||||
} from '../../../lib/honkai3rd/battlesuits'
|
||||
import { BattlesuitData } from '../../../lib/honkai3rd/battlesuits'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import yaml from 'yaml'
|
||||
import { omit } from 'ramda'
|
||||
|
||||
const battlesuitsFileNameList = readdirSync('honkai3rd/battlesuits')
|
||||
const battlesuitDataList = battlesuitsFileNameList
|
||||
.map((fileName) => {
|
||||
const filePathname = 'honkai3rd/battlesuits/' + fileName
|
||||
const data = readJsonFileSync(filePathname) as BattlesuitData
|
||||
let parsedData: any = null
|
||||
|
||||
const krDataFilePath = `honkai3rd/ko-KR/battlesuits/${data.id}.md`
|
||||
try {
|
||||
const krData = parseSkillData(readFileSync(krDataFilePath).toString())
|
||||
|
||||
data.krName = krData.name
|
||||
assignKrDataToSkill(data.leader, krData.leader)
|
||||
assignKrDataToSkill(data.passive, krData.passive)
|
||||
assignKrDataToSkill(data.evasion, krData.evasion)
|
||||
assignKrDataToSkill(data.special, krData.special)
|
||||
assignKrDataToSkill(data.ultimate, krData.ultimate)
|
||||
assignKrDataToSkill(data.basic, krData.basic)
|
||||
if (data.sp != null && krData.sp != null) {
|
||||
assignKrDataToSkill(data.sp, krData.sp)
|
||||
export function listBattlesuits(locale?: string): BattlesuitData[] {
|
||||
if (parsedData == null) {
|
||||
parsedData = yaml.parse(
|
||||
fs
|
||||
.readFileSync(
|
||||
path.join(process.cwd(), 'data/honkai3rd/battlesuits.yaml')
|
||||
)
|
||||
.toString('utf-8')
|
||||
)
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Failed to read', krDataFilePath)
|
||||
console.warn(error)
|
||||
}
|
||||
return data
|
||||
const battlesuits = parsedData
|
||||
|
||||
const localized = (battlesuits as any[]).map((battlesuit) => {
|
||||
return {
|
||||
...omit(['krName', 'krDescription'], battlesuit),
|
||||
name: locale === 'ko-KR' ? battlesuit.krName : battlesuit.name,
|
||||
leader: localizeSkillGroup(battlesuit.leader),
|
||||
passive: localizeSkillGroup(battlesuit.passive),
|
||||
evasion: localizeSkillGroup(battlesuit.evasion),
|
||||
special: localizeSkillGroup(battlesuit.special),
|
||||
ultimate: localizeSkillGroup(battlesuit.ultimate),
|
||||
basic: localizeSkillGroup(battlesuit.basic),
|
||||
sp: battlesuit.sp != null ? localizeSkillGroup(battlesuit.sp) : null,
|
||||
} as any
|
||||
})
|
||||
.sort((a, b) => {
|
||||
let compareResult = compareVersion(b.version || '0.0', a.version || '0.0')
|
||||
if (compareResult !== 0) {
|
||||
return compareResult
|
||||
|
||||
return localized
|
||||
|
||||
function localizeSkillGroup(skillGroup: any) {
|
||||
return {
|
||||
core: localizeSkill(skillGroup.core),
|
||||
subskills: skillGroup.subskills.map((subskill: any) =>
|
||||
localizeSkill(subskill)
|
||||
),
|
||||
}
|
||||
compareResult = a.name
|
||||
.replace(/ \(.\)/, '')
|
||||
.localeCompare(b.name.replace(/ \(.\)/, ''))
|
||||
|
||||
return compareResult
|
||||
})
|
||||
const battlesuitMap = battlesuitDataList.reduce((map, stigmata) => {
|
||||
map.set(stigmata.id, stigmata)
|
||||
return map
|
||||
}, new Map<string, BattlesuitData>())
|
||||
|
||||
export function listBattlesuits() {
|
||||
return battlesuitDataList
|
||||
}
|
||||
|
||||
export function getBattlesuitById(id: string) {
|
||||
return battlesuitMap.get(id)
|
||||
function localizeSkill(skill: any) {
|
||||
return {
|
||||
...omit(['krName', 'krDescription'], skill),
|
||||
name: locale === 'ko-KR' ? skill.krName : skill.name,
|
||||
description: locale === 'ko-KR' ? skill.krDescription : skill.description,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function getBattlesuitMapByIds(idList: string[]) {
|
||||
export function getBattlesuitById(id: string, locale?: string) {
|
||||
return listBattlesuits(locale).find((battlesuit) => battlesuit.id === id)
|
||||
}
|
||||
|
||||
export function getBattlesuitMapByIds(idList: string[], locale?: string) {
|
||||
return idList.reduce<{ [key: string]: BattlesuitData }>((map, id) => {
|
||||
const battlesuit = getBattlesuitById(id)
|
||||
const battlesuit = getBattlesuitById(id, locale)
|
||||
if (battlesuit != null) {
|
||||
map[id] = battlesuit
|
||||
}
|
||||
return map
|
||||
}, {})
|
||||
}
|
||||
|
||||
function parseSkillData(rawData: string) {
|
||||
const [
|
||||
nameSection,
|
||||
leaderSection,
|
||||
passiveSection,
|
||||
evasionSection,
|
||||
specialSection,
|
||||
ultimateSection,
|
||||
basicSection,
|
||||
spSection,
|
||||
] = rawData.split('\n## ')
|
||||
|
||||
const name = nameSection.replace('#', '').trim()
|
||||
|
||||
return {
|
||||
name,
|
||||
leader: parseSkillSection(leaderSection),
|
||||
passive: parseSkillSection(passiveSection),
|
||||
evasion: parseSkillSection(evasionSection),
|
||||
special: parseSkillSection(specialSection),
|
||||
ultimate: parseSkillSection(ultimateSection),
|
||||
basic: parseSkillSection(basicSection),
|
||||
sp: spSection != null ? parseSkillSection(spSection) : undefined,
|
||||
}
|
||||
}
|
||||
|
||||
function parseSkillSection(rawData: string) {
|
||||
const [coreSection, ...subskillSections] = rawData.split('\n### ')
|
||||
|
||||
const [coreName, ...descriptionLines] = coreSection.trim().split('\n')
|
||||
|
||||
return {
|
||||
core: {
|
||||
name: coreName,
|
||||
description: descriptionLines.join('\n').trim(),
|
||||
},
|
||||
subskills: subskillSections.map((subskillSection) => {
|
||||
const [subskillName, ...subskillDescriptionLines] = subskillSection
|
||||
.trim()
|
||||
.split('\n')
|
||||
|
||||
return {
|
||||
name: subskillName,
|
||||
description: subskillDescriptionLines.join('\n').trim(),
|
||||
}
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
function assignKrDataToSkill(
|
||||
skillGroup: BattlesuitSkillGroup,
|
||||
krDataSkillGroup: BattlesuitSkillGroup
|
||||
) {
|
||||
if (krDataSkillGroup == null || krDataSkillGroup.core == null) {
|
||||
throw new Error(`No translation for ${skillGroup.core.name}`)
|
||||
}
|
||||
try {
|
||||
skillGroup.core.krName = krDataSkillGroup.core.name
|
||||
skillGroup.core.krDescription = krDataSkillGroup.core.description.replace(
|
||||
/\\\*/g,
|
||||
'*'
|
||||
)
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
`Failed to assign ${skillGroup.core.name}(${(error as Error).message})`
|
||||
)
|
||||
}
|
||||
skillGroup.subskills.forEach((subskill, index) => {
|
||||
try {
|
||||
subskill.krName = krDataSkillGroup.subskills[index].name
|
||||
subskill.krDescription = krDataSkillGroup.subskills[
|
||||
index
|
||||
].description.replace(/\\\*/g, '*')
|
||||
} catch (error) {
|
||||
if (krDataSkillGroup.subskills[index] == null) {
|
||||
throw new Error(
|
||||
`No translation for ${skillGroup.core.name} / ${subskill.name}`
|
||||
)
|
||||
}
|
||||
throw new Error(
|
||||
`Failed to assign ${skillGroup.core.name}(${(error as Error).message})`
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ export const krSignetGroupMap = signetGroups.reduce<{
|
||||
|
||||
const name =
|
||||
group.id === 'elysia'
|
||||
? `${getBattlesuitById(setType)!.krName} 전용 각인`
|
||||
? `${getBattlesuitById(setType, 'ko-KR')!.name} 전용 각인`
|
||||
: `${setType === 'nexus' ? '증폭 각인' : '일반 각인'}${
|
||||
setIndex != null ? ` ${setIndex}` : ''
|
||||
}`
|
||||
@@ -115,7 +115,7 @@ export function getSignetGroupById(id: string, locale = 'en-US') {
|
||||
|
||||
export function getSupportBattlesuits(locale?: string) {
|
||||
return supportBattlesuitIds.map<SupportBattlesuit>((battlesuitId) => {
|
||||
const battlesuit = getBattlesuitById(battlesuitId)!
|
||||
const battlesuit = getBattlesuitById(battlesuitId, locale)!
|
||||
const {
|
||||
skillName,
|
||||
description,
|
||||
@@ -138,7 +138,6 @@ export function getSupportBattlesuits(locale?: string) {
|
||||
.slice(2)
|
||||
.split('\n\n')
|
||||
|
||||
localizedName = battlesuit.krName!
|
||||
localizedSkillName = krSkillName
|
||||
localizedDescription = krDescriptionLines.join('\n').trim()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user