diff --git a/src/data/honkai3rd/weapons.ts b/src/data/honkai3rd/weapons.ts new file mode 100644 index 00000000..e22d3708 --- /dev/null +++ b/src/data/honkai3rd/weapons.ts @@ -0,0 +1,66 @@ +import { readdirSync, readJsonFileSync } from '../../lib/data' + +export interface WeaponSkill { + name: string + description: string +} + +export interface WeaponData { + id: string + name: string + atk: number + crt: number + category: + | 'pistol' + | 'cannon' + | 'katana' + | 'cross' + | 'greatsword' + | 'scythe' + | 'lance' + | 'gauntlet' + | 'bow' + rarity: number + skills: WeaponSkill[] + version?: number +} + +const weaponsFileNameList = readdirSync('weapons') +const weaponDataList = weaponsFileNameList + .map((fileName) => { + const filePathname = 'weapons/' + fileName + const data = readJsonFileSync(filePathname) as WeaponData + + return data + }) + .sort((a, b) => { + let compareResult = 0 + + compareResult = b.rarity - a.rarity + if (compareResult !== 0) { + return compareResult + } + + compareResult = (b.version || 0) - (a.version || 0) + if (compareResult !== 0) { + return compareResult + } + + compareResult = a.name + .replace(/ \(.\)/, '') + .localeCompare(b.name.replace(/ \(.\)/, '')) + + return compareResult + }) +const weaponMap = weaponDataList.reduce((map, weapon) => { + map.set(weapon.id, weapon) + return map +}, new Map()) + +export function listWeapons() { + return weaponDataList +} + +export function getWeaponById(id: string) { + return weaponMap.get(id) +} diff --git a/src/pages/honkai3rd/index.tsx b/src/pages/honkai3rd/index.tsx index 2f071d3a..8ded88d9 100644 --- a/src/pages/honkai3rd/index.tsx +++ b/src/pages/honkai3rd/index.tsx @@ -49,6 +49,11 @@ const Honkai3rdIndexPage = () => { Stigmata + + + Weapons + + Updates diff --git a/src/pages/honkai3rd/weapons/index.tsx b/src/pages/honkai3rd/weapons/index.tsx new file mode 100644 index 00000000..414a623e --- /dev/null +++ b/src/pages/honkai3rd/weapons/index.tsx @@ -0,0 +1,114 @@ +/** @jsxImportSource theme-ui */ +import { Text, Box, Heading, Flex, Link } from '@theme-ui/components' +import NextLink from 'next/link' +import Breadcrumb from '../../../components/organisms/Breadcrumb' +import Honkai3rdNavigator from '../../../components/organisms/Honkai3rdNavigator' +import { listWeapons, WeaponData } from '../../../data/honkai3rd/weapons' + +interface WeaponListPageProps { + weaponDataList: WeaponData[] +} + +const WeaponListPage = ({ weaponDataList }: WeaponListPageProps) => { + return ( + + + + + + + Weapons + + + {weaponDataList.map((weapon) => { + return ( + + + + +
+ +
+
+ + {weapon.name} + + + {'⭐'.repeat(weapon.rarity)} + + +
+
+ ) + })} +
+
+
+ ) +} + +export default WeaponListPage + +export async function getStaticProps() { + return { + props: { + weaponDataList: listWeapons(), + }, + } +}