Refactor stigmata data
This commit is contained in:
@@ -1,25 +1,16 @@
|
||||
/** @jsxImportSource theme-ui */
|
||||
import { Box, Card, Text, Flex } from '@theme-ui/components'
|
||||
import { useRouter } from 'next/router'
|
||||
import { assetsBucketBaseUrl } from '../../lib/consts'
|
||||
import { StigmataData } from '../../lib/honkai3rd/stigmata'
|
||||
import { translate } from '../../lib/i18n'
|
||||
import PageLink from '../atoms/PageLink'
|
||||
import SquareImageBox from '../atoms/SquareImageBox'
|
||||
|
||||
interface StigmataCardProps {
|
||||
stigmata: Pick<StigmataData, 'id' | 'name' | 'rarity' | 'krName'>
|
||||
stigmata: Pick<StigmataData, 'id' | 'name' | 'rarity'>
|
||||
size?: 'sm' | 'default'
|
||||
}
|
||||
|
||||
const StigmataCard = ({ stigmata, size }: StigmataCardProps) => {
|
||||
const { locale } = useRouter()
|
||||
const stigmataName = translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmata.krName },
|
||||
stigmata.name
|
||||
)
|
||||
|
||||
if (size === 'sm') {
|
||||
return (
|
||||
<Card
|
||||
@@ -36,7 +27,7 @@ const StigmataCard = ({ stigmata, size }: StigmataCardProps) => {
|
||||
<Flex>
|
||||
<SquareImageBox
|
||||
mr={2}
|
||||
alt={stigmataName}
|
||||
alt={stigmata.name}
|
||||
src={`${assetsBucketBaseUrl}/honkai3rd/stigmata/icon-${stigmata.id}.png`}
|
||||
size={30}
|
||||
/>
|
||||
@@ -49,7 +40,7 @@ const StigmataCard = ({ stigmata, size }: StigmataCardProps) => {
|
||||
textAlign: 'center',
|
||||
}}
|
||||
>
|
||||
<Text sx={{ lineHeight: '30px' }}>{stigmataName}</Text>
|
||||
<Text sx={{ lineHeight: '30px' }}>{stigmata.name}</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
</PageLink>
|
||||
@@ -68,7 +59,7 @@ const StigmataCard = ({ stigmata, size }: StigmataCardProps) => {
|
||||
<PageLink href={`/honkai3rd/stigmata/${stigmata.id}`}>
|
||||
<SquareImageBox
|
||||
size={[75, 100]}
|
||||
alt={stigmataName}
|
||||
alt={stigmata.name}
|
||||
src={`${assetsBucketBaseUrl}/honkai3rd/stigmata/icon-${stigmata.id}.png`}
|
||||
/>
|
||||
<Box
|
||||
@@ -80,7 +71,7 @@ const StigmataCard = ({ stigmata, size }: StigmataCardProps) => {
|
||||
textAlign: 'center',
|
||||
}}
|
||||
>
|
||||
<Text>{stigmataName}</Text>
|
||||
<Text>{stigmata.name}</Text>
|
||||
</Box>
|
||||
<Box sx={{ fontSize: 1, textAlign: 'center' }}>
|
||||
{'⭐'.repeat(stigmata.rarity)}
|
||||
|
||||
@@ -1,24 +1,15 @@
|
||||
/** @jsxImportSource theme-ui */
|
||||
import { Box, Card, Flex, Text } from '@theme-ui/components'
|
||||
import { useRouter } from 'next/router'
|
||||
import { assetsBucketBaseUrl } from '../../lib/consts'
|
||||
import { StigmataSet } from '../../lib/honkai3rd/stigmata'
|
||||
import { translate } from '../../lib/i18n'
|
||||
import PageLink from '../atoms/PageLink'
|
||||
import SquareImageBox from '../atoms/SquareImageBox'
|
||||
|
||||
interface StigmataSetCardProps {
|
||||
stigmataSet: Pick<StigmataSet, 'id' | 'name' | 'krName' | 'rarity'>
|
||||
stigmataSet: Pick<StigmataSet, 'id' | 'name' | 'rarity'>
|
||||
}
|
||||
|
||||
const StigmataSetCard = ({ stigmataSet }: StigmataSetCardProps) => {
|
||||
const { locale } = useRouter()
|
||||
const stigmataSetName = translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmataSet.krName },
|
||||
stigmataSet.name
|
||||
)
|
||||
|
||||
return (
|
||||
<Card
|
||||
sx={{
|
||||
@@ -31,17 +22,17 @@ const StigmataSetCard = ({ stigmataSet }: StigmataSetCardProps) => {
|
||||
<Flex sx={{ justifyContent: 'space-around' }}>
|
||||
<SquareImageBox
|
||||
size={[80, 100]}
|
||||
alt={`${stigmataSet.id} Top`}
|
||||
alt={`${stigmataSet.name} Top`}
|
||||
src={`${assetsBucketBaseUrl}/honkai3rd/stigmata/icon-${stigmataSet.id}-top.png`}
|
||||
/>
|
||||
<SquareImageBox
|
||||
size={[80, 100]}
|
||||
alt={`${stigmataSet.id} Mid`}
|
||||
alt={`${stigmataSet.name} Mid`}
|
||||
src={`${assetsBucketBaseUrl}/honkai3rd/stigmata/icon-${stigmataSet.id}-mid.png`}
|
||||
/>
|
||||
<SquareImageBox
|
||||
size={[80, 100]}
|
||||
alt={`${stigmataSet.id} Bottom`}
|
||||
alt={`${stigmataSet.name} Bottom`}
|
||||
src={`${assetsBucketBaseUrl}/honkai3rd/stigmata/icon-${stigmataSet.id}-bot.png`}
|
||||
/>
|
||||
</Flex>
|
||||
@@ -54,7 +45,7 @@ const StigmataSetCard = ({ stigmataSet }: StigmataSetCardProps) => {
|
||||
textAlign: 'center',
|
||||
}}
|
||||
>
|
||||
<Text>{stigmataSetName}</Text>
|
||||
<Text>{stigmataSet.name}</Text>
|
||||
</Box>
|
||||
<Box sx={{ fontSize: 1, textAlign: 'center' }}>
|
||||
{'⭐'.repeat(stigmataSet.rarity)}
|
||||
|
||||
@@ -12,8 +12,7 @@ import PageLink from '../../components/atoms/PageLink'
|
||||
import StigmataCard from '../../components/molecules/StigmataCard'
|
||||
import Breadcrumb from '../../components/organisms/Breadcrumb'
|
||||
import SecondaryLabel from '../atoms/SecondaryLabel'
|
||||
import { useRouter } from 'next/router'
|
||||
import { translate, useTranslation } from '../../lib/i18n'
|
||||
import { useTranslation } from '../../lib/i18n'
|
||||
import Head from '../atoms/Head'
|
||||
import { assetsBucketBaseUrl } from '../../lib/consts'
|
||||
import Honkai3rdLayout from '../layouts/Honkai3rdLayout'
|
||||
@@ -30,27 +29,12 @@ const SingleStigmataPage = ({
|
||||
stigmataSet,
|
||||
stigmataSetList,
|
||||
}: SingleStigmataPageProps) => {
|
||||
const { locale } = useRouter()
|
||||
const { t } = useTranslation()
|
||||
|
||||
const stigmataName = translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmataData.krName },
|
||||
stigmataData.name
|
||||
)
|
||||
|
||||
const stigmataSkillDescription = translate(
|
||||
locale,
|
||||
{
|
||||
'ko-KR': stigmataData.skill.krDescription,
|
||||
},
|
||||
stigmataData.skill.description
|
||||
)
|
||||
|
||||
return (
|
||||
<Honkai3rdLayout>
|
||||
<Head
|
||||
title={`${stigmataName} - ${t('common.honkai-3rd')} - ${t(
|
||||
title={`${stigmataData.name} - ${t('common.honkai-3rd')} - ${t(
|
||||
'common.abyss-lab'
|
||||
)}`}
|
||||
description={`${t('common.honkai-3rd')} ${t('stigmata-show.stigmata')} /
|
||||
@@ -67,12 +51,12 @@ const SingleStigmataPage = ({
|
||||
{ href: '/honkai3rd/stigmata', label: t('common.stigmata') },
|
||||
{
|
||||
href: `/honkai3rd/stigmata/${stigmataData.id}`,
|
||||
label: stigmataName,
|
||||
label: stigmataData.name,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
<Heading as='h1'>{stigmataName}</Heading>
|
||||
<Heading as='h1'>{stigmataData.name}</Heading>
|
||||
|
||||
<Box
|
||||
mb={3}
|
||||
@@ -85,7 +69,7 @@ const SingleStigmataPage = ({
|
||||
}}
|
||||
>
|
||||
<Image
|
||||
alt={stigmataName}
|
||||
alt={stigmataData.name}
|
||||
src={`${assetsBucketBaseUrl}/honkai3rd/stigmata/${stigmataData.id}.png`}
|
||||
width={400}
|
||||
height={400}
|
||||
@@ -103,7 +87,7 @@ const SingleStigmataPage = ({
|
||||
HP : {stigmataData.hp} / ATK : {stigmataData.atk} / DEF :{' '}
|
||||
{stigmataData.def} / CRT : {stigmataData.crt}
|
||||
</Box>
|
||||
<Paragraph p={2}>{stigmataSkillDescription}</Paragraph>
|
||||
<Paragraph p={2}>{stigmataData.skill.description}</Paragraph>
|
||||
</Card>
|
||||
|
||||
{stigmataSet != null && (
|
||||
@@ -111,20 +95,10 @@ const SingleStigmataPage = ({
|
||||
<Box sx={{ p: 2, borderBottom: 'default' }}>
|
||||
<Heading as='h2' mb={1}>
|
||||
<PageLink href={`/honkai3rd/stigmata/${stigmataSet.id}-set`}>
|
||||
{translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmataSet.krName },
|
||||
stigmataSet.name
|
||||
)}
|
||||
{stigmataSet.name}
|
||||
</PageLink>
|
||||
</Heading>
|
||||
<SecondaryLabel>
|
||||
{translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmataSet.krAltName },
|
||||
stigmataSet.altName
|
||||
)}
|
||||
</SecondaryLabel>
|
||||
<SecondaryLabel>{stigmataSet.altName}</SecondaryLabel>
|
||||
</Box>
|
||||
|
||||
<Flex
|
||||
@@ -146,32 +120,16 @@ const SingleStigmataPage = ({
|
||||
</Flex>
|
||||
|
||||
<Heading as='h3' m={0} p={2} sx={{ borderBottom: 'default' }}>
|
||||
{translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmataSet.twoSetSkill.krName },
|
||||
stigmataSet.twoSetSkill.name
|
||||
)}
|
||||
{stigmataSet.twoSetSkill.name}
|
||||
</Heading>
|
||||
<Paragraph m={0} p={2} sx={{ borderBottom: 'default' }}>
|
||||
{translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmataSet.twoSetSkill.krDescription },
|
||||
stigmataSet.twoSetSkill.description
|
||||
)}
|
||||
{stigmataSet.twoSetSkill.description}
|
||||
</Paragraph>
|
||||
<Heading as='h3' m={0} p={2} sx={{ borderBottom: 'default' }}>
|
||||
{translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmataSet.threeSetSkill.krName },
|
||||
stigmataSet.threeSetSkill.name
|
||||
)}
|
||||
{stigmataSet.threeSetSkill.name}
|
||||
</Heading>
|
||||
<Paragraph m={0} p={2}>
|
||||
{translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmataSet.threeSetSkill.krDescription },
|
||||
stigmataSet.threeSetSkill.description
|
||||
)}
|
||||
{stigmataSet.threeSetSkill.description}
|
||||
</Paragraph>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
@@ -6,8 +6,7 @@ import StigmataCard from '../../components/molecules/StigmataCard'
|
||||
import Breadcrumb from '../../components/organisms/Breadcrumb'
|
||||
import { StigmataData, StigmataSet } from '../../lib/honkai3rd/stigmata'
|
||||
import SecondaryLabel from '../atoms/SecondaryLabel'
|
||||
import { translate, useTranslation } from '../../lib/i18n'
|
||||
import { useRouter } from 'next/router'
|
||||
import { useTranslation } from '../../lib/i18n'
|
||||
import Head from '../atoms/Head'
|
||||
import Honkai3rdLayout from '../layouts/Honkai3rdLayout'
|
||||
|
||||
@@ -22,28 +21,16 @@ const StigmataSetPage = ({
|
||||
stigmataSetList,
|
||||
}: StigmataSetProps) => {
|
||||
const { t } = useTranslation()
|
||||
const { locale } = useRouter()
|
||||
|
||||
const stigmataSetName = translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmataSet.krName },
|
||||
stigmataSet.name
|
||||
)
|
||||
const stigmataSetAltName = translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmataSet.krAltName },
|
||||
stigmataSet.altName
|
||||
)
|
||||
|
||||
return (
|
||||
<Honkai3rdLayout>
|
||||
<Head
|
||||
title={`${stigmataSetName} ${t('stigmata-show.stigmata-set')} - ${t(
|
||||
title={`${stigmataSet.name} ${t('stigmata-show.stigmata-set')} - ${t(
|
||||
'common.honkai-3rd'
|
||||
)} - ${t('common.abyss-lab')}`}
|
||||
description={`${t('common.honkai-3rd')} ${t(
|
||||
'stigmata-show.stigmata-set'
|
||||
)} / ${'⭐'.repeat(stigmataSet.rarity)} / ${stigmataSetAltName}`}
|
||||
)} / ${'⭐'.repeat(stigmataSet.rarity)} / ${stigmataSet.altName}`}
|
||||
/>
|
||||
|
||||
<Box p={3}>
|
||||
@@ -59,16 +46,16 @@ const StigmataSetPage = ({
|
||||
},
|
||||
{
|
||||
href: `/honkai3rd/stigmata/${stigmataSet.id}-set`,
|
||||
label: stigmataSetName,
|
||||
label: stigmataSet.name,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
<Box mb={3}>
|
||||
<Heading as='h1' mb={0}>
|
||||
{stigmataSetName}
|
||||
{stigmataSet.name}
|
||||
</Heading>
|
||||
<SecondaryLabel>{stigmataSetAltName}</SecondaryLabel>
|
||||
<SecondaryLabel>{stigmataSet.altName}</SecondaryLabel>
|
||||
</Box>
|
||||
|
||||
<Card mb={3}>
|
||||
@@ -90,16 +77,6 @@ const StigmataSetPage = ({
|
||||
})}
|
||||
</Flex>
|
||||
{stigmataSetList.map((stigmataSetItem) => {
|
||||
const stigmataName = translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmataSetItem.krName },
|
||||
stigmataSetItem.name
|
||||
)
|
||||
const stigmataSkillDescrpition = translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmataSetItem.skill.krDescription },
|
||||
stigmataSetItem.skill.description
|
||||
)
|
||||
return (
|
||||
<React.Fragment key={stigmataSetItem.id}>
|
||||
<Box sx={{ p: 2, borderBottom: 'default' }}>
|
||||
@@ -107,7 +84,7 @@ const StigmataSetPage = ({
|
||||
<PageLink
|
||||
href={`/honkai3rd/stigmata/${stigmataSetItem.id}`}
|
||||
>
|
||||
{stigmataName}
|
||||
{stigmataSetItem.name}
|
||||
</PageLink>
|
||||
</Heading>
|
||||
<SecondaryLabel>
|
||||
@@ -126,7 +103,7 @@ const StigmataSetPage = ({
|
||||
'&:last-child': { borderBottom: 'none' },
|
||||
}}
|
||||
>
|
||||
{stigmataSkillDescrpition}
|
||||
{stigmataSetItem.skill.description}
|
||||
</Paragraph>
|
||||
</React.Fragment>
|
||||
)
|
||||
@@ -135,34 +112,16 @@ const StigmataSetPage = ({
|
||||
|
||||
<Card>
|
||||
<Heading as='h2' m={0} p={2} sx={{ borderBottom: 'default' }}>
|
||||
{translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmataSet.twoSetSkill.krName },
|
||||
stigmataSet.twoSetSkill.name
|
||||
)}
|
||||
{stigmataSet.twoSetSkill.name}
|
||||
</Heading>
|
||||
<Paragraph m={0} p={2} sx={{ borderBottom: 'default' }}>
|
||||
{translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmataSet.twoSetSkill.krDescription },
|
||||
stigmataSet.twoSetSkill.description
|
||||
)}
|
||||
{stigmataSet.twoSetSkill.description}
|
||||
</Paragraph>
|
||||
<Heading as='h2' m={0} p={2} sx={{ borderBottom: 'default' }}>
|
||||
{translate(
|
||||
locale,
|
||||
{
|
||||
'ko-KR': stigmataSet.threeSetSkill.krName,
|
||||
},
|
||||
stigmataSet.threeSetSkill.name
|
||||
)}
|
||||
{stigmataSet.threeSetSkill.name}
|
||||
</Heading>
|
||||
<Paragraph m={0} p={2}>
|
||||
{translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmataSet.threeSetSkill.krDescription },
|
||||
stigmataSet.threeSetSkill.description
|
||||
)}
|
||||
{stigmataSet.threeSetSkill.description}
|
||||
</Paragraph>
|
||||
</Card>
|
||||
</Box>
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
export interface StigmataSkill {
|
||||
name: string
|
||||
krName?: string
|
||||
description: string
|
||||
krDescription?: string
|
||||
}
|
||||
|
||||
export interface StigmataData {
|
||||
id: string
|
||||
name: string
|
||||
krName?: string
|
||||
skill: StigmataSkill
|
||||
atk: number
|
||||
def: number
|
||||
@@ -24,9 +21,7 @@ export interface StigmataData {
|
||||
export interface StigmataSet {
|
||||
id: string
|
||||
name: string
|
||||
krName?: string
|
||||
altName: string
|
||||
krAltName?: string
|
||||
twoSetSkill: StigmataSkill
|
||||
threeSetSkill: StigmataSkill
|
||||
rarity: 3 | 4 | 5
|
||||
|
||||
@@ -295,7 +295,7 @@ export async function getStaticProps({
|
||||
)
|
||||
const weaponMap = getWeaponMapByIds(weaponIds, locale)
|
||||
|
||||
const stigmataMap = getStigmataMapByIds(stigmataIds)
|
||||
const stigmataMap = getStigmataMapByIds(stigmataIds, locale)
|
||||
|
||||
return {
|
||||
props: {
|
||||
|
||||
@@ -229,9 +229,9 @@ export async function getStaticProps({
|
||||
},
|
||||
{ weaponIds: [], stigmataIds: [] }
|
||||
)
|
||||
const weaponMap = getWeaponMapByIds(weaponIds)
|
||||
const weaponMap = getWeaponMapByIds(weaponIds, locale)
|
||||
|
||||
const stigmataMap = getStigmataMapByIds(stigmataIds)
|
||||
const stigmataMap = getStigmataMapByIds(stigmataIds, locale)
|
||||
|
||||
return {
|
||||
props: {
|
||||
|
||||
@@ -6,47 +6,35 @@ import { StigmataSetProps } from '../../../../components/pages/StigmataSetPage'
|
||||
import { generateI18NPaths, getI18NProps } from '../../../../server/i18n'
|
||||
import {
|
||||
listStigmata,
|
||||
getStigmataById,
|
||||
getStigmataListBySetId,
|
||||
getStigmataSetBySetId,
|
||||
listStigmataSet,
|
||||
getStigmaById,
|
||||
} from '../../../../server/data/honkai3rd/stigmata'
|
||||
import { Box, Card, Flex, Heading, Paragraph } from 'theme-ui'
|
||||
import SecondaryLabel from '../../../../components/atoms/SecondaryLabel'
|
||||
import StigmataCard from '../../../../components/molecules/StigmataCard'
|
||||
import { translate, useTranslation } from '../../../../lib/i18n'
|
||||
import { useRouter } from 'next/router'
|
||||
import { useTranslation } from '../../../../lib/i18n'
|
||||
import { SingleStigmataPageProps } from '../../../../components/pages/SingleStigmataPage'
|
||||
|
||||
type StigmataShowPageProps = StigmataSetProps | SingleStigmataPageProps
|
||||
|
||||
const StigmataListPage = (props: StigmataShowPageProps) => {
|
||||
const { t } = useTranslation()
|
||||
const { locale } = useRouter()
|
||||
|
||||
if (props.type === 'single') {
|
||||
return null
|
||||
}
|
||||
|
||||
const { stigmataSet, stigmataSetList } = props
|
||||
const stigmataSetName = translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmataSet.krName },
|
||||
stigmataSet.name
|
||||
)
|
||||
const stigmataSetAltName = translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmataSet.krAltName },
|
||||
stigmataSet.altName
|
||||
)
|
||||
|
||||
return (
|
||||
<Box p={3}>
|
||||
<Box mb={3}>
|
||||
<Heading as='h1' mb={0}>
|
||||
{stigmataSetName}
|
||||
{stigmataSet.name}
|
||||
</Heading>
|
||||
<SecondaryLabel>{stigmataSetAltName}</SecondaryLabel>
|
||||
<SecondaryLabel>{stigmataSet.altName}</SecondaryLabel>
|
||||
</Box>
|
||||
|
||||
<Card mb={3}>
|
||||
@@ -68,22 +56,12 @@ const StigmataListPage = (props: StigmataShowPageProps) => {
|
||||
})}
|
||||
</Flex>
|
||||
{stigmataSetList.map((stigmataSetItem) => {
|
||||
const stigmataName = translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmataSetItem.krName },
|
||||
stigmataSetItem.name
|
||||
)
|
||||
const stigmataSkillDescrpition = translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmataSetItem.skill.krDescription },
|
||||
stigmataSetItem.skill.description
|
||||
)
|
||||
return (
|
||||
<React.Fragment key={stigmataSetItem.id}>
|
||||
<Box sx={{ p: 2, borderBottom: 'default' }}>
|
||||
<Heading as='h2' mb={1}>
|
||||
<PageLink href={`/honkai3rd/stigmata/${stigmataSetItem.id}`}>
|
||||
{stigmataName}
|
||||
{stigmataSetItem.name}
|
||||
</PageLink>
|
||||
</Heading>
|
||||
<SecondaryLabel>
|
||||
@@ -102,7 +80,7 @@ const StigmataListPage = (props: StigmataShowPageProps) => {
|
||||
'&:last-child': { borderBottom: 'none' },
|
||||
}}
|
||||
>
|
||||
{stigmataSkillDescrpition}
|
||||
{stigmataSetItem.skill.description}
|
||||
</Paragraph>
|
||||
</React.Fragment>
|
||||
)
|
||||
@@ -111,34 +89,16 @@ const StigmataListPage = (props: StigmataShowPageProps) => {
|
||||
|
||||
<Card>
|
||||
<Heading as='h2' m={0} p={2} sx={{ borderBottom: 'default' }}>
|
||||
{translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmataSet.twoSetSkill.krName },
|
||||
stigmataSet.twoSetSkill.name
|
||||
)}
|
||||
{stigmataSet.twoSetSkill.name}
|
||||
</Heading>
|
||||
<Paragraph m={0} p={2} sx={{ borderBottom: 'default' }}>
|
||||
{translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmataSet.twoSetSkill.krDescription },
|
||||
stigmataSet.twoSetSkill.description
|
||||
)}
|
||||
{stigmataSet.twoSetSkill.description}
|
||||
</Paragraph>
|
||||
<Heading as='h2' m={0} p={2} sx={{ borderBottom: 'default' }}>
|
||||
{translate(
|
||||
locale,
|
||||
{
|
||||
'ko-KR': stigmataSet.threeSetSkill.krName,
|
||||
},
|
||||
stigmataSet.threeSetSkill.name
|
||||
)}
|
||||
{stigmataSet.threeSetSkill.name}
|
||||
</Heading>
|
||||
<Paragraph m={0} p={2}>
|
||||
{translate(
|
||||
locale,
|
||||
{ 'ko-KR': stigmataSet.threeSetSkill.krDescription },
|
||||
stigmataSet.threeSetSkill.description
|
||||
)}
|
||||
{stigmataSet.threeSetSkill.description}
|
||||
</Paragraph>
|
||||
</Card>
|
||||
</Box>
|
||||
@@ -151,29 +111,29 @@ export async function getStaticProps({
|
||||
params,
|
||||
locale,
|
||||
}: NextPageContext & { params: { stigmataId: string } }) {
|
||||
const stigmataData = getStigmataById(params.stigmataId)!
|
||||
const stigmataData = getStigmaById(params.stigmataId, locale)!
|
||||
if (stigmataData != null) {
|
||||
return {
|
||||
props: {
|
||||
type: 'single',
|
||||
stigmataData: stigmataData,
|
||||
stigmataSetList: (getStigmataListBySetId(stigmataData.set!) || []).sort(
|
||||
(a, b) => -a.type.localeCompare(b.type)
|
||||
),
|
||||
stigmataSet: getStigmataSetBySetId(stigmataData.set!) || null,
|
||||
stigmataSetList: (
|
||||
getStigmataListBySetId(stigmataData.set!, locale) || []
|
||||
).sort((a, b) => -a.type.localeCompare(b.type)),
|
||||
stigmataSet: getStigmataSetBySetId(stigmataData.set!, locale) || null,
|
||||
...(await getI18NProps(locale)),
|
||||
},
|
||||
}
|
||||
}
|
||||
const [stigmataSetId] = params.stigmataId.split('-set')
|
||||
const stigmataSet = getStigmataSetBySetId(stigmataSetId)!
|
||||
const stigmataSet = getStigmataSetBySetId(stigmataSetId, locale)!
|
||||
return {
|
||||
props: {
|
||||
type: 'set',
|
||||
stigmataSet,
|
||||
stigmataSetList: (getStigmataListBySetId(stigmataSet.id) || []).sort(
|
||||
(a, b) => -a.type.localeCompare(b.type)
|
||||
),
|
||||
stigmataSetList: (
|
||||
getStigmataListBySetId(stigmataSet.id, locale) || []
|
||||
).sort((a, b) => -a.type.localeCompare(b.type)),
|
||||
...(await getI18NProps(locale)),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import StigmataSetPage, {
|
||||
import { generateI18NPaths, getI18NProps } from '../../../server/i18n'
|
||||
import {
|
||||
listStigmata,
|
||||
getStigmataById,
|
||||
getStigmaById,
|
||||
getStigmataListBySetId,
|
||||
getStigmataSetBySetId,
|
||||
listStigmataSet,
|
||||
@@ -31,29 +31,29 @@ export async function getStaticProps({
|
||||
params,
|
||||
locale,
|
||||
}: NextPageContext & { params: { stigmataId: string } }) {
|
||||
const stigmataData = getStigmataById(params.stigmataId)!
|
||||
const stigmataData = getStigmaById(params.stigmataId, locale)!
|
||||
if (stigmataData != null) {
|
||||
return {
|
||||
props: {
|
||||
type: 'single',
|
||||
stigmataData: stigmataData,
|
||||
stigmataSetList: (getStigmataListBySetId(stigmataData.set!) || []).sort(
|
||||
(a, b) => -a.type.localeCompare(b.type)
|
||||
),
|
||||
stigmataSet: getStigmataSetBySetId(stigmataData.set!) || null,
|
||||
stigmataSetList: (
|
||||
getStigmataListBySetId(stigmataData.set!, locale) || []
|
||||
).sort((a, b) => -a.type.localeCompare(b.type)),
|
||||
stigmataSet: getStigmataSetBySetId(stigmataData.set!, locale) || null,
|
||||
...(await getI18NProps(locale)),
|
||||
},
|
||||
}
|
||||
}
|
||||
const [stigmataSetId] = params.stigmataId.split('-set')
|
||||
const stigmataSet = getStigmataSetBySetId(stigmataSetId)!
|
||||
const stigmataSet = getStigmataSetBySetId(stigmataSetId, locale)!
|
||||
return {
|
||||
props: {
|
||||
type: 'set',
|
||||
stigmataSet,
|
||||
stigmataSetList: (getStigmataListBySetId(stigmataSet.id) || []).sort(
|
||||
(a, b) => -a.type.localeCompare(b.type)
|
||||
),
|
||||
stigmataSetList: (
|
||||
getStigmataListBySetId(stigmataSet.id, locale) || []
|
||||
).sort((a, b) => -a.type.localeCompare(b.type)),
|
||||
...(await getI18NProps(locale)),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ import Head from '../../../components/atoms/Head'
|
||||
import Honkai3rdLayout from '../../../components/layouts/Honkai3rdLayout'
|
||||
|
||||
interface StigmataListPageProps {
|
||||
stigmataDataList: Pick<StigmataData, 'id' | 'name' | 'rarity' | 'krName'>[]
|
||||
stigmataSetList: Pick<StigmataSet, 'id' | 'name' | 'rarity' | 'krName'>[]
|
||||
stigmataDataList: Pick<StigmataData, 'id' | 'name' | 'rarity'>[]
|
||||
stigmataSetList: Pick<StigmataSet, 'id' | 'name' | 'rarity'>[]
|
||||
}
|
||||
|
||||
const StigmataListPage = ({
|
||||
@@ -102,11 +102,11 @@ export default StigmataListPage
|
||||
export async function getStaticProps({ locale }: NextPageContext) {
|
||||
return {
|
||||
props: {
|
||||
stigmataDataList: listStigmata().map((stigmata) =>
|
||||
pick(['id', 'name', 'rarity', 'krName'], stigmata)
|
||||
stigmataDataList: listStigmata(locale).map((stigmata) =>
|
||||
pick(['id', 'name', 'rarity'], stigmata)
|
||||
),
|
||||
stigmataSetList: listStigmataSet().map((stigmataSet) =>
|
||||
pick(['id', 'name', 'rarity', 'krName'], stigmataSet)
|
||||
stigmataSetList: listStigmataSet(locale).map((stigmataSet) =>
|
||||
pick(['id', 'name', 'rarity'], stigmataSet)
|
||||
),
|
||||
...(await getI18NProps(locale)),
|
||||
},
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
import { runScript } from '../lib/utils'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import yaml from 'yaml'
|
||||
import { listStigmataSet } from '../../server/data/honkai3rd/stigmata'
|
||||
import sortKeys from 'sort-keys'
|
||||
|
||||
const order = [
|
||||
'id',
|
||||
'version',
|
||||
'name',
|
||||
'krName',
|
||||
'altName',
|
||||
'krAltName',
|
||||
'type',
|
||||
'rarity',
|
||||
'twoSetSkill',
|
||||
'threeSetSkill',
|
||||
'description',
|
||||
'krDescription',
|
||||
]
|
||||
|
||||
async function migrateStigmataSets() {
|
||||
const stigmataSetList = listStigmataSet()
|
||||
const newDataDir = path.join(__dirname, '../../../data/honkai3rd')
|
||||
|
||||
const sortedData = sortKeys(stigmataSetList, {
|
||||
deep: true,
|
||||
compare: (a, b) => {
|
||||
return order.indexOf(a) - order.indexOf(b)
|
||||
},
|
||||
})
|
||||
fs.writeFileSync(
|
||||
path.join(newDataDir, 'stigmata-sets.yaml'),
|
||||
yaml.stringify(sortedData)
|
||||
)
|
||||
}
|
||||
|
||||
runScript(migrateStigmataSets)
|
||||
@@ -1,41 +0,0 @@
|
||||
import { runScript } from '../lib/utils'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import yaml from 'yaml'
|
||||
import { listStigmata } from '../../server/data/honkai3rd/stigmata'
|
||||
import sortKeys from 'sort-keys'
|
||||
|
||||
const order = [
|
||||
'id',
|
||||
'version',
|
||||
'name',
|
||||
'krName',
|
||||
'type',
|
||||
'rarity',
|
||||
'hp',
|
||||
'atk',
|
||||
'def',
|
||||
'crt',
|
||||
'set',
|
||||
'skill',
|
||||
'description',
|
||||
'krDescription',
|
||||
]
|
||||
|
||||
async function migrateStigmata() {
|
||||
const stigmataList = listStigmata()
|
||||
const newDataDir = path.join(__dirname, '../../../data/honkai3rd')
|
||||
|
||||
const sortedData = sortKeys(stigmataList, {
|
||||
deep: true,
|
||||
compare: (a, b) => {
|
||||
return order.indexOf(a) - order.indexOf(b)
|
||||
},
|
||||
})
|
||||
fs.writeFileSync(
|
||||
path.join(newDataDir, 'stigmata.yaml'),
|
||||
yaml.stringify(sortedData)
|
||||
)
|
||||
}
|
||||
|
||||
runScript(migrateStigmata)
|
||||
@@ -1,26 +1,29 @@
|
||||
import { readdirSync, readFileSync, readJsonFileSync } from '../fs'
|
||||
import { compareVersion } from '../../../lib/string'
|
||||
import { StigmataData, StigmataSet } from '../../../lib/honkai3rd/stigmata'
|
||||
import { StigmataData } from '../../../lib/honkai3rd/stigmata'
|
||||
import yaml from 'yaml'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { omit } from 'ramda'
|
||||
|
||||
const stigmataDataFileNameList = readdirSync('honkai3rd/stigmata')
|
||||
const stigmataList = stigmataDataFileNameList
|
||||
.map((fileName) => {
|
||||
const filePathname = 'honkai3rd/stigmata/' + fileName
|
||||
const data = readJsonFileSync(filePathname) as StigmataData
|
||||
let cachedStigmataData: any = null
|
||||
|
||||
const krDataFilePath = `honkai3rd/ko-KR/stigmata/${data.id}.md`
|
||||
try {
|
||||
const krData = parseStigmataData(readFileSync(krDataFilePath).toString())
|
||||
|
||||
data.krName = krData.name
|
||||
data.skill.krName = krData.skill.name
|
||||
data.skill.krDescription = krData.skill.description
|
||||
} catch (error) {
|
||||
// console.warn('Failed to read', krDataFilePath)
|
||||
// console.warn(error)
|
||||
export function listStigmata(locale?: string): StigmataData[] {
|
||||
if (cachedStigmataData == null) {
|
||||
cachedStigmataData = yaml.parse(
|
||||
fs
|
||||
.readFileSync(path.join(process.cwd(), 'data/honkai3rd/stigmata.yaml'))
|
||||
.toString('utf-8')
|
||||
)
|
||||
}
|
||||
const stigmata = cachedStigmataData
|
||||
|
||||
return data
|
||||
const localized = (stigmata as any[])
|
||||
.map((stigma) => {
|
||||
return {
|
||||
...omit(['krName', 'krDescription'], stigma),
|
||||
name: locale === 'ko-KR' ? stigma.krName : stigma.name,
|
||||
skill: localizeSkill(stigma.skill),
|
||||
} as any
|
||||
})
|
||||
.filter((stigmataData) => !stigmataData.hidden)
|
||||
.sort((a, b) => {
|
||||
@@ -46,47 +49,44 @@ const stigmataList = stigmataDataFileNameList
|
||||
|
||||
return compareResult
|
||||
})
|
||||
const stigmataMap = stigmataList.reduce((map, stigmata) => {
|
||||
map.set(stigmata.id, stigmata)
|
||||
return map
|
||||
}, new Map<string, StigmataData>())
|
||||
return localized
|
||||
|
||||
const stigmataSetStigmataDataListMap = stigmataList.reduce((map, stigmata) => {
|
||||
if (stigmata.set != null) {
|
||||
let stigmataList = map.get(stigmata.set)
|
||||
if (stigmataList == null) {
|
||||
stigmataList = []
|
||||
map.set(stigmata.set, stigmataList)
|
||||
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,
|
||||
}
|
||||
}
|
||||
stigmataList.push(stigmata)
|
||||
}
|
||||
return map
|
||||
}, new Map<string, StigmataData[]>())
|
||||
|
||||
const stigmataSetFileNameList = readdirSync('honkai3rd/stigmata-sets')
|
||||
const stigmataSetList = stigmataSetFileNameList
|
||||
.map((fileName) => {
|
||||
const filePathname = 'honkai3rd/stigmata-sets/' + fileName
|
||||
const data = readJsonFileSync(filePathname) as StigmataSet
|
||||
export function getStigmaById(id: string, locale?: string) {
|
||||
return listStigmata(locale).find((stigma) => stigma.id === id, locale)
|
||||
}
|
||||
|
||||
const krDataFilePath = `honkai3rd/ko-KR/stigmata-sets/${data.id}.md`
|
||||
try {
|
||||
const krData = parseStigmataSetData(
|
||||
readFileSync(krDataFilePath).toString()
|
||||
let cachedStigmataSetsData: any = null
|
||||
|
||||
export function listStigmataSet(locale?: string): StigmataData[] {
|
||||
if (cachedStigmataSetsData == null) {
|
||||
cachedStigmataSetsData = yaml.parse(
|
||||
fs
|
||||
.readFileSync(
|
||||
path.join(process.cwd(), 'data/honkai3rd/stigmata-sets.yaml')
|
||||
)
|
||||
.toString('utf-8')
|
||||
)
|
||||
|
||||
data.krName = krData.name
|
||||
data.krAltName = krData.altName
|
||||
data.twoSetSkill.krName = krData.twoSetSkill.name
|
||||
data.twoSetSkill.krDescription = krData.twoSetSkill.description
|
||||
data.threeSetSkill.krName = krData.threeSetSkill.name
|
||||
data.threeSetSkill.krDescription = krData.threeSetSkill.description
|
||||
} catch (error) {
|
||||
// console.warn('Failed to read', krDataFilePath)
|
||||
// console.warn(error)
|
||||
}
|
||||
|
||||
return data
|
||||
const stigmataSets = cachedStigmataSetsData as any[]
|
||||
const localized = stigmataSets
|
||||
.map((stigmataSet) => {
|
||||
return {
|
||||
...omit(['krName', 'krDescription'], stigmataSet),
|
||||
name: locale === 'ko-KR' ? stigmataSet.krName : stigmataSet.name,
|
||||
altName:
|
||||
locale === 'ko-KR' ? stigmataSet.krAltName : stigmataSet.altName,
|
||||
twoSetSkill: localizeSkill(stigmataSet.twoSetSkill),
|
||||
threeSetSkill: localizeSkill(stigmataSet.threeSetSkill),
|
||||
} as any
|
||||
})
|
||||
.filter((stigmataSet) => !stigmataSet.hidden)
|
||||
.sort((a, b) => {
|
||||
@@ -104,80 +104,33 @@ const stigmataSetList = stigmataSetFileNameList
|
||||
|
||||
return compareResult
|
||||
})
|
||||
return localized
|
||||
|
||||
const stigmataSetMap = stigmataSetList.reduce((map, stigmataSet) => {
|
||||
map.set(stigmataSet.id, stigmataSet)
|
||||
return map
|
||||
}, new Map<string, StigmataSet>())
|
||||
|
||||
export function listStigmata() {
|
||||
return stigmataList
|
||||
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 getStigmataById(id: string) {
|
||||
return stigmataMap.get(id)
|
||||
export function getStigmataSetBySetId(setId: string, locale?: string) {
|
||||
return listStigmataSet(locale).find((set) => set.id === setId, locale)
|
||||
}
|
||||
|
||||
export function listStigmataSet() {
|
||||
return stigmataSetList
|
||||
export function getStigmataListBySetId(setId: string, locale?: string) {
|
||||
return ['top', 'mid', 'bot'].map((type) => {
|
||||
return getStigmaById(setId + '-' + type, locale)!
|
||||
})
|
||||
}
|
||||
|
||||
export function getStigmataListBySetId(setId: string) {
|
||||
return stigmataSetStigmataDataListMap.get(setId) || []
|
||||
}
|
||||
|
||||
export function getStigmataSetBySetId(setId: string) {
|
||||
return stigmataSetMap.get(setId)
|
||||
}
|
||||
|
||||
export function getStigmataMapByIds(idList: string[]) {
|
||||
export function getStigmataMapByIds(idList: string[], locale?: string) {
|
||||
return idList.reduce<{ [key: string]: StigmataData }>((map, id) => {
|
||||
const stigmata = getStigmataById(id)
|
||||
const stigmata = getStigmaById(id, locale)
|
||||
if (stigmata != null) {
|
||||
map[id] = stigmata
|
||||
}
|
||||
return map
|
||||
}, {})
|
||||
}
|
||||
|
||||
function parseStigmataData(rawData: string) {
|
||||
const [name, skillName, skillDescription] = rawData
|
||||
.replace(/\\\*/g, '*')
|
||||
.split('\n\n')
|
||||
.map((data) => data.replace(/#+\s/, '').trim())
|
||||
|
||||
return {
|
||||
name,
|
||||
skill: {
|
||||
name: skillName,
|
||||
description: skillDescription,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function parseStigmataSetData(rawData: string) {
|
||||
const [
|
||||
name,
|
||||
altName,
|
||||
twoSetSkillName,
|
||||
twoSetSkillDescription,
|
||||
threeSetSkillName,
|
||||
threeSetSkillDescription,
|
||||
] = rawData
|
||||
.replace(/\\\*/g, '*')
|
||||
.split('\n\n')
|
||||
.map((data) => data.replace(/#+\s/, '').trim())
|
||||
|
||||
return {
|
||||
name,
|
||||
altName,
|
||||
twoSetSkill: {
|
||||
name: twoSetSkillName,
|
||||
description: twoSetSkillDescription,
|
||||
},
|
||||
threeSetSkill: {
|
||||
name: threeSetSkillName,
|
||||
description: threeSetSkillDescription,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user