Skip to content

Commit

Permalink
chore: clean extracted data and remove html from it
Browse files Browse the repository at this point in the history
  • Loading branch information
Nagarian committed Dec 21, 2024
1 parent 8408b7d commit bea52f8
Show file tree
Hide file tree
Showing 12 changed files with 786 additions and 482 deletions.
829 changes: 594 additions & 235 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-markdown": "^9.0.1",
"rehype-raw": "^7.0.0",
"remark-gfm": "^4.0.0",
"styled-system": "^5.1.5",
"uuid": "^11.0.3"
},
Expand Down
6 changes: 3 additions & 3 deletions src/components/DescriptionHighlighter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import styled from '@emotion/styled'
import { diffWords } from 'diff'
import { memo, ReactNode } from 'react'
import ReactMarkdown, { Components } from 'react-markdown'
import rehypeRaw from 'rehype-raw'
import remarkGfm from 'remark-gfm'
import { ReactMarkdownRenderers } from 'styles/react-markdown'
import { OrbColor } from 'styles/theme-definition'

Expand Down Expand Up @@ -46,7 +46,7 @@ function BaseDescriptionHighlighter({
)

return (
<ReactMarkdown rehypePlugins={[rehypeRaw]} components={renderers}>
<ReactMarkdown remarkPlugins={[remarkGfm]} components={renderers}>
{parts}
</ReactMarkdown>
)
Expand Down Expand Up @@ -82,7 +82,7 @@ const renderers: Components = {
p: p => <FakeParagraph {...p} />,
h3: p => <Header3 {...p} />,
a: ({ href, ...p }) => {
const orb = href?.replace(/\[|\]/g, '') as keyof OrbColor
const orb = (href as string)?.replace(/\[|\]/g, '') as keyof OrbColor
return (
<Orb orb={orb} {...p}>
{orb}
Expand Down
76 changes: 5 additions & 71 deletions src/models/old-units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ export type BaseUnit = {
rcv: number
}
number: number
limitStats: {
limitStats?: {
hp: number[]
atk: number[]
rcv: number[]
sailors: number[]
captains: number[]
}
llimitStats: {
llimitStats?: {
sailors1: number[]
sailors2: number[]
captains: number[]
Expand Down Expand Up @@ -174,75 +174,9 @@ export type UnitFestGPBurst = {

export type UnitCooldown = [number, number]

export type SimpleUnitSpecial =
| string
| {
cooldown: UnitCooldown
description: string
}[]

export type LLBSimpleUnitSpecial = {
base: SimpleUnitSpecial
llbbase?: SimpleUnitSpecial
llblevel1?: SimpleUnitSpecial
llblevel2?: SimpleUnitSpecial
llbcombined: undefined
}
export type UnitSpecial = string

export type VersusUnitSpecial = {
character1: SimpleUnitSpecial
llbcharacter1?: SimpleUnitSpecial
character2: SimpleUnitSpecial
llbcharacter2?: SimpleUnitSpecial
}

export type DualUnitV1Special = {
base: SimpleUnitSpecial
llbbase?: SimpleUnitSpecial
combined: SimpleUnitSpecial
llbcombined?: SimpleUnitSpecial
}

export type DualUnitV2Special = {
character1: SimpleUnitSpecial
character2: SimpleUnitSpecial
combined: SimpleUnitSpecial
}

export type UnitSpecial =
| SimpleUnitSpecial
| LLBSimpleUnitSpecial
| DualUnitV1Special
| DualUnitV2Special
| VersusUnitSpecial

export type UnitCaptain =
| string
| undefined
| {
character1: string
character2: string
combined: string
llbcharacter1?: string
llbcharacter2?: string
llbcombined?: string
}
| {
base: string
level1?: string
level2?: string
level3?: string
level4?: string
level5?: string
level6?: string
llbbase?: string
llblevel1?: string
llblevel2?: string
llblevel3?: string
llblevel4?: string
llblevel5?: string
llblevel6?: string
}
export type UnitCaptain = string

export type UnitSailor =
| string
Expand Down Expand Up @@ -288,7 +222,7 @@ export type UnitLevelLimitBreak = null | Partial<{
}>

export type UnitDetail = {
captain: UnitCaptain
captain?: UnitCaptain
captainNotes?: string
special?: UnitSpecial
specialNotes?: string
Expand Down
81 changes: 2 additions & 79 deletions src/models/units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,6 @@ export type BaseUnit = {
rcv: number
}
number: number
limitStats: {
hp: number[]
atk: number[]
rcv: number[]
sailors: number[]
captains: number[]
}
llimitStats: {
sailors1: number[]
sailors2: number[]
captains: number[]
specials: number[]
}
pirateFest: {
class?: UnitPirateFestStyle
DEF: number
Expand Down Expand Up @@ -158,73 +145,9 @@ export type UnitFestGPBurst = {

export type UnitCooldown = [number, number]

export type SimpleUnitSpecial =
| string
| {
cooldown: UnitCooldown
description: string
}[]

export type LLBSimpleUnitSpecial = {
base: SimpleUnitSpecial
llbbase?: SimpleUnitSpecial
llbcombined: undefined
}

export type VersusUnitSpecial = {
character1: SimpleUnitSpecial
llbcharacter1?: SimpleUnitSpecial
character2: SimpleUnitSpecial
llbcharacter2?: SimpleUnitSpecial
}
export type UnitSpecial = string

export type DualUnitV1Special = {
base: SimpleUnitSpecial
llbbase?: SimpleUnitSpecial
combined: SimpleUnitSpecial
llbcombined?: SimpleUnitSpecial
}

export type DualUnitV2Special = {
character1: SimpleUnitSpecial
character2: SimpleUnitSpecial
combined: SimpleUnitSpecial
}

export type UnitSpecial =
| SimpleUnitSpecial
| LLBSimpleUnitSpecial
| DualUnitV1Special
| DualUnitV2Special
| VersusUnitSpecial

export type UnitCaptain =
| string
| undefined
| {
character1: string
character2: string
combined: string
llbcharacter1?: string
llbcharacter2?: string
llbcombined?: string
}
| {
base: string
level1?: string
level2?: string
level3?: string
level4?: string
level5?: string
level6?: string
llbbase?: string
llblevel1?: string
llblevel2?: string
llblevel3?: string
llblevel4?: string
llblevel5?: string
llblevel6?: string
}
export type UnitCaptain = string

export type UnitSailor =
| string
Expand Down
12 changes: 1 addition & 11 deletions src/pages/Detail/components/LimitBreakEdit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,5 @@ function SailorDescription(lockedCount: number, sailor: UnitSailor) {
function CaptainDescription(captain: UnitCaptain) {
if (!captain) return []

if (typeof captain === 'string') {
return captain === 'None' ? [] : [captain]
}

return [
'combined' in captain ? captain.combined : undefined,
'base' in captain ? captain.base : undefined,
...Object.entries(captain)
.filter(([key, value]) => key.startsWith('level'))
.map(([key, value]) => value),
].filter(v => v)
return captain === 'None' ? [] : [captain]
}
38 changes: 1 addition & 37 deletions src/pages/Detail/components/SpecialLvlEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,6 @@ type SpecialLvlEditProps = {
onChange: (special: UserUnitSpecial) => void
}

function MultiStageSpecial(special: UnitSpecial): ReactNode {
if (typeof special === 'string') {
return <DescriptionHighlighter value={special} />
}

if (typeof special !== 'object') {
return undefined
}

if (Array.isArray(special)) {
return (
<Box as="ul" display="grid" gridAutoFlow="row" gap="2">
{special.map(({ description }, i) => (
<li key={i}>
<strong>Stage {i + 1}: </strong>
<DescriptionHighlighter value={description} />
</li>
))}
</Box>
)
}

return (
<Box as="ul" display="grid" gridAutoFlow="row" gap="2">
{Object.entries(special)
.filter(([key, value]) => !!value)
.map(([key, value], i) => (
<li key={i}>
<strong>{key}: </strong>
{value && MultiStageSpecial(value)}
</li>
))}
</Box>
)
}

export function SpecialLvlEdit({
special,
detail,
Expand All @@ -65,7 +29,7 @@ export function SpecialLvlEdit({
value={lvl}
max={lvlMax}
name={detail.specialName}
descriptions={[MultiStageSpecial(detail.special)]}
descriptions={[detail.special]}
>
{special.lvlMax > 1 && (
<SpecialLevelInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ const CaptainRcvFinder = (captain: UnitCaptain) => {
}

const SpecialRcvFinder = (special: UnitSpecial) => {
if (Array.isArray(special)) {
return special.some(spe => RcvRegex.test(spe.description))
}
if (typeof special === 'string') {
return RcvRegex.test(special)
}

return false
return RcvRegex.test(special)
}

export const ByRcvFinderFilter = (criteria: ByRcvFinderCriteria) =>
Expand Down
7 changes: 2 additions & 5 deletions src/scripts/extract-optcdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { DB } from './unitExtracter.js'
import { writeFileSync } from 'fs'
import { createGenerator } from 'ts-json-schema-generator'
import Ajv from 'ajv'
import { fixupVersusUnit } from './fixup.js'

/** @type {import('ts-json-schema-generator/dist/src/Config').Config} */
const config = {
Expand Down Expand Up @@ -120,13 +119,11 @@ function getErrors(db) {
return errors
}

const DBFixed = DB.map(fixupVersusUnit)

writeFileSync(
'./public/db-old.json',
prettify ? JSON.stringify(DBFixed, null, 2) : JSON.stringify(DBFixed),
prettify ? JSON.stringify(DB, null, 2) : JSON.stringify(DB),
)
const isValide = validate(DBFixed)
const isValide = validate(DB)

if (!isValide) {
throw new Error('some validation errors occured')
Expand Down
10 changes: 10 additions & 0 deletions src/scripts/extract-shipdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ function cleanDescription(value: string) {
.replace(/\[ATK_UP\]/, 'attack up')
.replace(/\[EOT_HEAL\]/, 'end of turn heal')
.replace(/\[EOT_HEAL_TO_DAMAGE\]/, 'eot heal slot to damage')

.replaceAll(/\<hr\/?\>/gi, '\n---\n')
.replaceAll(/\<br\/?\>/gi, '\n\n')
.replaceAll(/\<\/?[uo]l\>/gi, '\n\n')
.replaceAll(/\<li\>/gi, '- ')
.replaceAll(/\<\/li\>/gi, '\n')
.replaceAll(/(\s?)\<b\>(\s?)/gi, ' **')
.replaceAll(/(\s?)\<\/b\>(\s?)/gi, '** ')
.replaceAll(/(\s?)\<i\>(\s?)/gi, ' *')
.replaceAll(/(\s?)\<\/em\>(\s?)/gi, '* ')
}

const shipImagesHost = 'https://optc-ships.vercel.app'
Expand Down
Loading

0 comments on commit bea52f8

Please sign in to comment.