feat: updated official_info structure

This commit is contained in:
Haoyu Xu
2025-05-06 14:51:13 +08:00
parent f3f84068da
commit 6644ab616e
7 changed files with 769 additions and 709 deletions

View File

@@ -21,7 +21,7 @@ const voiceOnAtom = atomWithStorage('voiceOn', false)
let lastVoiceState = 'ended' let lastVoiceState = 'ended'
export default function Home() { export default function Home() {
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line
const _trackEvt = useInsight() const _trackEvt = useInsight()
const { setTitle, setTabs, currentTab, setHeaderIcon, setFastNavigation } = const { setTitle, setTabs, currentTab, setHeaderIcon, setFastNavigation } =
useHeader() useHeader()
@@ -190,15 +190,14 @@ export default function Home() {
<section <section
className={`${classes['styled-selection']}`} className={`${classes['styled-selection']}`}
> >
{officialUpdate.dates {officialUpdate.info
.reduce((acc, cur) => { .filter(
const op = officialUpdate.info[cur] (e) =>
return [...acc, ...op] !operators.find(
}, []) (o) =>
.slice( o.official_id ===
0, e.id.toString()
officialUpdate.length - )
operators.length
) )
.map((entry, index) => { .map((entry, index) => {
return ( return (
@@ -251,12 +250,21 @@ export default function Home() {
classes.title classes.title
} }
> >
{ {language ===
'zh-CN'
? entry.type ===
'skin'
? `${
entry entry
.codename[ .skinName[
language 'zh-CN'
] ]
} } · ${entry.operatorName}`
: entry.operatorName
: entry
.skinName[
'en-US'
]}
</section> </section>
<section <section
className={ className={

File diff suppressed because it is too large Load Diff

View File

@@ -4,10 +4,10 @@ import { file } from '@aklive2d/libs'
import config from '@aklive2d/config' import config from '@aklive2d/config'
import type { import type {
OfficialArray, OfficialArray,
OfficialInfo, OfficialInfoV2,
OfficialOperatorInfo, OfficialOperatorInfo,
OfficialInfoMapping, OfficialInfoMapping,
OfficialInfoOperatorConfig, OfficialInfoOperatorConfigV2,
} from './types' } from './types'
const AUTO_UPDATE_FOLDER = path.resolve( const AUTO_UPDATE_FOLDER = path.resolve(
@@ -39,70 +39,64 @@ export const update = async () => {
if (!data) throw new Error('No data found') if (!data) throw new Error('No data found')
const rows = (data as OfficialArray)[0][3].initialData const rows = (data as OfficialArray)[0][3].initialData
const dict: OfficialInfo = { const dict: OfficialInfoV2 = {
length: rows.length, length: rows.length,
dates: [], dates: [],
info: {}, info: [],
} }
let current_displayTime = rows[0].displayTime let current_displayTime = rows[0].displayTime
let current_block = []
for (const row of rows) { for (const row of rows) {
const displayTime = row.displayTime const displayTime = row.displayTime
if (displayTime !== current_displayTime) { if (displayTime !== current_displayTime) {
dict.info[current_displayTime] = current_block
dict.dates.push(current_displayTime) dict.dates.push(current_displayTime)
current_displayTime = row.displayTime current_displayTime = row.displayTime
current_block = []
} }
current_block.push(get_row(row)) dict.info.push(get_row(row, current_displayTime))
} }
dict.info[current_displayTime] = current_block
dict.dates.push(current_displayTime) dict.dates.push(current_displayTime)
file.writeSync(JSON.stringify(dict, null, 4), OFFICIAL_INFO_JSON) file.writeSync(JSON.stringify(dict, null, 4), OFFICIAL_INFO_JSON)
} }
const get_row = (row: OfficialOperatorInfo): OfficialInfoOperatorConfig => { const get_row = (
row: OfficialOperatorInfo,
date: string
): OfficialInfoOperatorConfigV2 => {
const type = row.type const type = row.type
let codename_zhCN, item_type: 'operator' | 'skin' let item_type: 'operator' | 'skin'
switch (type) { switch (type) {
case 0: case 0:
codename_zhCN = row.charName
item_type = 'operator' item_type = 'operator'
break break
case 1: case 1:
codename_zhCN = row.suitName + ' · ' + row.charName
item_type = 'skin' item_type = 'skin'
break break
default: default:
throw 'unknown type' throw 'unknown type'
} }
return { return {
codename: { operatorName: row.charName,
'zh-CN': codename_zhCN, skinName: {
'zh-CN': row.suitName,
'en-US': row.codename, 'en-US': row.codename,
}, },
type: item_type, type: item_type,
link: `https://ak.hypergryph.com/archive/dynamicCompile/${row.cid}.html`, link: `https://ak.hypergryph.com/archive/dynamicCompile/${row.cid}.html`,
id: row.cid, id: Number(row.cid),
date,
} }
} }
const generateMapping = () => { const generateMapping = () => {
const mapping: OfficialInfoMapping = {} const mapping: OfficialInfoMapping = {}
const content = file.readSync(OFFICIAL_INFO_JSON) const content = file.readSync(OFFICIAL_INFO_JSON) as string
if (!content) throw new Error('Failed to read official info JSON') if (!content) throw new Error('Failed to read official info JSON')
const data: OfficialInfo = JSON.parse(content) const data: OfficialInfoV2 = JSON.parse(content)
if (!data) throw new Error('Failed to parse official info JSON') if (!data) throw new Error('Failed to parse official info JSON')
Object.keys(data.info).forEach((date) => { data.info.forEach((e) => {
data.info[date].forEach((operator) => { mapping[e.id] = e
mapping[operator.id] = {
date,
...operator,
}
})
}) })
return mapping return mapping
} }

View File

@@ -21,30 +21,8 @@ type UnrelatedDataArray = ['$', string, null, unknown]
export type OfficialArray = [OfficialDataArray, UnrelatedDataArray] export type OfficialArray = [OfficialDataArray, UnrelatedDataArray]
export type OfficialInfo = {
length: number
dates: string[]
info: {
[date: string]: OfficialInfoOperatorConfig[]
}
}
export interface OfficialInfoOperatorConfig {
codename: {
'zh-CN': string
'en-US': string
}
type: 'operator' | 'skin'
link: string
id: string
}
export interface OperatorConfig extends OfficialInfoOperatorConfig {
date: string
}
export type OfficialInfoMapping = { export type OfficialInfoMapping = {
[id: string]: OperatorConfig [id: string]: OfficialInfoOperatorConfigV2
} }
export type OfficialInfoV2 = { export type OfficialInfoV2 = {

View File

@@ -145,8 +145,8 @@ const generateMapping = () => {
const type = operatorInfo.type const type = operatorInfo.type
const name = const name =
type === 'skin' type === 'skin'
? operatorInfo.codename['zh-CN'].split(' · ')[0] ? operatorInfo.skinName['zh-CN']
: operatorInfo.codename['en-US'] : operatorInfo.skinName['en-US']
const skinEntry = findSkinEntry(skinTable, name, type) const skinEntry = findSkinEntry(skinTable, name, type)
operator.filename = skinEntry.dynIllustId.replace(/_2$/, '') operator.filename = skinEntry.dynIllustId.replace(/_2$/, '')
operator.fallback_name = operator.fallback_name =

View File

@@ -31,8 +31,8 @@ export const init = (name: string, id: string) => {
try { try {
const entryName = const entryName =
currentOpertor.type === 'skin' currentOpertor.type === 'skin'
? currentOpertor.codename['zh-CN'].split(' · ')[0] ? currentOpertor.skinName['zh-CN']
: currentOpertor.codename['en-US'] : currentOpertor.skinName['en-US']
const skinEntry = findSkinEntry( const skinEntry = findSkinEntry(
skinTable, skinTable,
entryName, entryName,
@@ -41,7 +41,16 @@ export const init = (name: string, id: string) => {
template.codename = findCodename(skinEntry, currentOpertor) template.codename = findCodename(skinEntry, currentOpertor)
} catch (e: unknown) { } catch (e: unknown) {
console.log(e as string) console.log(e as string)
template.codename = currentOpertor.codename template.codename =
currentOpertor.type === 'skin'
? {
'zh-CN': `${currentOpertor.skinName['zh-CN']} · ${currentOpertor.operatorName}`,
'en-US': `${currentOpertor.skinName['en-US']} / ${currentOpertor.operatorName}`,
}
: {
'zh-CN': `${currentOpertor.operatorName}`,
'en-US': `${currentOpertor.skinName['en-US']}`,
}
} }
file.writeSync( file.writeSync(

View File

@@ -10,7 +10,7 @@ import {
SkinTableJsonCharSkinEntry, SkinTableJsonCharSkinEntry,
Codename, Codename,
} from '../types.ts' } from '../types.ts'
import type { OfficialInfoOperatorConfig } from '@aklive2d/official-info/types' import type { OfficialInfoOperatorConfigV2 } from '@aklive2d/official-info/types'
export const getExtractedFolder = (name: string) => { export const getExtractedFolder = (name: string) => {
return path.join(OPERATOR_SOURCE_FOLDER, name, config.dir_name.extracted) return path.join(OPERATOR_SOURCE_FOLDER, name, config.dir_name.extracted)
@@ -111,7 +111,7 @@ export const findSkinEntry = (
*/ */
export const findCodename = ( export const findCodename = (
skinEntry: SkinTableJsonCharSkinEntry, skinEntry: SkinTableJsonCharSkinEntry,
officialInfo: OfficialInfoOperatorConfig officialInfo: OfficialInfoOperatorConfigV2
) => { ) => {
const UPPER_CASE_EXCEPTION_WORDS = [ const UPPER_CASE_EXCEPTION_WORDS = [
'the', 'the',
@@ -144,7 +144,7 @@ export const findCodename = (
modelNameNormalized = modelNameNormalizedArray.join(' ') modelNameNormalized = modelNameNormalizedArray.join(' ')
} }
if (skinEntry.displaySkin.skinName) { if (skinEntry.displaySkin.skinName) {
let engSkinName = officialInfo.codename['en-US'] let engSkinName = officialInfo.skinName['en-US']
const engkinNameArray = engSkinName.split(' ') const engkinNameArray = engSkinName.split(' ')
engkinNameArray.forEach((word, index) => { engkinNameArray.forEach((word, index) => {
if (/^[a-zA-Z]+$/.test(word)) { if (/^[a-zA-Z]+$/.test(word)) {
@@ -158,10 +158,11 @@ export const findCodename = (
} }
}) })
engSkinName = engkinNameArray.join(' ') engSkinName = engkinNameArray.join(' ')
codename['zh-CN'] = officialInfo.codename['zh-CN'].replace(/ +$/, '') codename['zh-CN'] =
`${officialInfo.skinName['zh-CN']} · ${officialInfo.operatorName}`
codename['en-US'] = `${engSkinName} / ${modelNameNormalized}` codename['en-US'] = `${engSkinName} / ${modelNameNormalized}`
} else { } else {
codename['zh-CN'] = officialInfo.codename['zh-CN'].replace(/ +$/, '') codename['zh-CN'] = officialInfo.operatorName
codename['en-US'] = modelNameNormalized codename['en-US'] = modelNameNormalized
} }
return codename return codename