Restructure data modules
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import { readdirSync, readJsonFileSync } from '../../../lib/data'
|
||||
import { compareVersion } from '../../../lib/string'
|
||||
|
||||
export interface BattlesuitSkill {
|
||||
name: string
|
||||
description: string
|
||||
requiredRank: string
|
||||
}
|
||||
export interface BattlesuitSkillGroup {
|
||||
core: BattlesuitSkill
|
||||
subskills: BattlesuitSkill[]
|
||||
}
|
||||
|
||||
export interface BattlesuitData {
|
||||
id: string
|
||||
version?: string
|
||||
name: string
|
||||
type: string
|
||||
valkyrie: string
|
||||
strengths: string[]
|
||||
leader: BattlesuitSkillGroup
|
||||
special: BattlesuitSkillGroup
|
||||
evasion: BattlesuitSkillGroup
|
||||
passive: BattlesuitSkillGroup
|
||||
ultimate: BattlesuitSkillGroup
|
||||
basic: BattlesuitSkillGroup
|
||||
sp?: BattlesuitSkillGroup
|
||||
}
|
||||
|
||||
const battlesuitsFileNameList = readdirSync('honkai3rd/battlesuits')
|
||||
const battlesuitDataList = battlesuitsFileNameList
|
||||
.map((fileName) => {
|
||||
const filePathname = 'honkai3rd/battlesuits/' + fileName
|
||||
const data = readJsonFileSync(filePathname) as BattlesuitData
|
||||
|
||||
return data
|
||||
})
|
||||
.sort((a, b) => {
|
||||
let compareResult = compareVersion(b.version || '0.0', a.version || '0.0')
|
||||
if (compareResult !== 0) {
|
||||
return compareResult
|
||||
}
|
||||
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)
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { readdirSync, readJsonFileSync } from '../../../lib/data'
|
||||
import { compareVersion } from '../../../lib/string'
|
||||
|
||||
export interface ElfSkill {
|
||||
type: 'passive' | 'basic' | 'ultimate' | 'team'
|
||||
name: string
|
||||
requiredRank: number
|
||||
description: string
|
||||
}
|
||||
|
||||
export interface ElfData {
|
||||
id: string
|
||||
name: string
|
||||
baseRank: number
|
||||
strengths: string[]
|
||||
skillRows: [ElfSkill[], ElfSkill[], ElfSkill[], ElfSkill[]]
|
||||
version: string
|
||||
}
|
||||
|
||||
const elfFileNameList = readdirSync('honkai3rd/elfs')
|
||||
const elfDataList = elfFileNameList
|
||||
.map((fileName) => {
|
||||
const filePathname = 'honkai3rd/elfs/' + fileName
|
||||
const data = readJsonFileSync(filePathname) as ElfData
|
||||
|
||||
return data
|
||||
})
|
||||
.sort((a, b) => {
|
||||
let compareResult = 0
|
||||
|
||||
compareResult = compareVersion(b.version, a.version)
|
||||
|
||||
if (compareResult !== 0) {
|
||||
return compareResult
|
||||
}
|
||||
compareResult = a.name
|
||||
.replace(/ \(.\)/, '')
|
||||
.localeCompare(b.name.replace(/ \(.\)/, ''))
|
||||
|
||||
return compareResult
|
||||
})
|
||||
|
||||
const elfMap = elfDataList.reduce((map, elf) => {
|
||||
map.set(elf.id, elf)
|
||||
return map
|
||||
}, new Map<string, ElfData>())
|
||||
|
||||
export function listElfs() {
|
||||
return elfDataList
|
||||
}
|
||||
|
||||
export function getElfById(id: string) {
|
||||
return elfMap.get(id)
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
import { readdirSync, readJsonFileSync } from '../../../lib/data'
|
||||
import { compareVersion } from '../../../lib/string'
|
||||
|
||||
export interface StigmataSkill {
|
||||
name: string
|
||||
description: string
|
||||
}
|
||||
|
||||
export interface StigmataData {
|
||||
id: string
|
||||
name: string
|
||||
skill: StigmataSkill
|
||||
ttk: number
|
||||
def: number
|
||||
crt: number
|
||||
set?: string
|
||||
type: 'top' | 'mid' | 'bot'
|
||||
hp: number
|
||||
rarity: 3 | 4 | 5
|
||||
version?: string
|
||||
hidden?: boolean
|
||||
}
|
||||
|
||||
export interface StigmataSet {
|
||||
id: string
|
||||
name: string
|
||||
altName: string
|
||||
twoSetSkill: StigmataSkill
|
||||
threeSetSkill: StigmataSkill
|
||||
version?: string
|
||||
}
|
||||
|
||||
const stigmataDataFileNameList = readdirSync('honkai3rd/stigmata')
|
||||
const stigmataList = stigmataDataFileNameList
|
||||
.map((fileName) => {
|
||||
const filePathname = 'honkai3rd/stigmata/' + fileName
|
||||
const data = readJsonFileSync(filePathname) as StigmataData
|
||||
|
||||
return data
|
||||
})
|
||||
.filter((stigmataData) => !stigmataData.hidden)
|
||||
.sort((a, b) => {
|
||||
let compareResult = b.rarity - a.rarity
|
||||
if (compareResult !== 0) {
|
||||
return compareResult
|
||||
}
|
||||
compareResult = compareVersion(b.version || '0.0', a.version || '0.0')
|
||||
if (compareResult !== 0) {
|
||||
return compareResult
|
||||
}
|
||||
compareResult = (a.set || 'ZZZZZ').localeCompare(b.set || 'ZZZZZ')
|
||||
if (compareResult !== 0) {
|
||||
return compareResult
|
||||
}
|
||||
compareResult = -a.type.localeCompare(b.type)
|
||||
if (compareResult !== 0) {
|
||||
return compareResult
|
||||
}
|
||||
compareResult = a.name
|
||||
.replace(/ \(.\)/, '')
|
||||
.localeCompare(b.name.replace(/ \(.\)/, ''))
|
||||
|
||||
return compareResult
|
||||
})
|
||||
const stigmataMap = stigmataList.reduce((map, stigmata) => {
|
||||
map.set(stigmata.id, stigmata)
|
||||
return map
|
||||
}, new Map<string, StigmataData>())
|
||||
|
||||
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)
|
||||
}
|
||||
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
|
||||
|
||||
return data
|
||||
})
|
||||
|
||||
const stigmataSetMap = stigmataSetList.reduce((map, stigmataSet) => {
|
||||
map.set(stigmataSet.id, stigmataSet)
|
||||
return map
|
||||
}, new Map<string, StigmataSet>())
|
||||
|
||||
export function listStigmata() {
|
||||
return stigmataList
|
||||
}
|
||||
|
||||
export function getStigmataById(id: string) {
|
||||
return stigmataMap.get(id)
|
||||
}
|
||||
|
||||
export function getStigmataListBySetId(setId: string) {
|
||||
return stigmataSetStigmataDataListMap.get(setId) || []
|
||||
}
|
||||
|
||||
export function getStigmataSetBySetId(setId: string) {
|
||||
return stigmataSetMap.get(setId)
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { readdirSync, readJsonFileSync } from '../../../lib/data'
|
||||
|
||||
export interface SupplyEventData {
|
||||
id: string
|
||||
verified: boolean
|
||||
track: number
|
||||
name: string
|
||||
type: string
|
||||
token: string
|
||||
featured: {
|
||||
type: string
|
||||
id: string
|
||||
}[]
|
||||
extra: string[]
|
||||
version: number
|
||||
duration: [string, string]
|
||||
guarantees: {
|
||||
count: number
|
||||
recurring: boolean
|
||||
rewards: { type: string; id: string; amount: number | [number, number] }[]
|
||||
}[]
|
||||
mileages: {
|
||||
count: number
|
||||
rewardOptions: {
|
||||
type: string
|
||||
id: string
|
||||
amount: number
|
||||
}[]
|
||||
}[]
|
||||
drops: {
|
||||
type: string
|
||||
id: string
|
||||
rate: number
|
||||
amount: number | [number, number]
|
||||
}[]
|
||||
}
|
||||
|
||||
export function listSupplyEventsByVersion(version: string) {
|
||||
const supplyEventsDirectoryPathname = `honkai3rd/versions/${version}/supply-events`
|
||||
|
||||
const supplyEventFileNameList = readdirSync(supplyEventsDirectoryPathname)
|
||||
const supplyEventList = supplyEventFileNameList
|
||||
.map((fileName) => {
|
||||
const filePathname = `${supplyEventsDirectoryPathname}/` + fileName
|
||||
const data = readJsonFileSync(filePathname)
|
||||
|
||||
return { ...data, id: fileName.replace(/\.json/, '') } as SupplyEventData
|
||||
})
|
||||
.sort((a, b) => {
|
||||
return -a.id.localeCompare(b.id)
|
||||
})
|
||||
|
||||
return supplyEventList
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { format } from 'date-fns'
|
||||
import { readdirSync, readFileSync, readJsonFileSync } from '../../../lib/data'
|
||||
import { compareVersion } from '../../../lib/string'
|
||||
|
||||
export interface VersionData {
|
||||
version: string
|
||||
previousVersion?: string
|
||||
nextVersion?: string
|
||||
name: string
|
||||
duration: [string, string]
|
||||
verified: boolean
|
||||
newBattlesuits: string[]
|
||||
newWeapons: string[]
|
||||
description: string
|
||||
}
|
||||
|
||||
const versionDirectoryList = readdirSync('honkai3rd/versions')
|
||||
|
||||
const versionDataList = versionDirectoryList
|
||||
.map((directoryName) => {
|
||||
const directoryPathname = 'honkai3rd/versions/' + directoryName
|
||||
const data: VersionData = {
|
||||
version: directoryName,
|
||||
...readJsonFileSync(directoryPathname + '/version-data.json'),
|
||||
description: readFileSync(
|
||||
directoryPathname + '/description.md'
|
||||
).toString(),
|
||||
}
|
||||
|
||||
return data
|
||||
})
|
||||
.sort((a, b) => {
|
||||
return compareVersion(b.version, a.version)
|
||||
})
|
||||
|
||||
export function listVersionData() {
|
||||
return versionDataList
|
||||
}
|
||||
|
||||
export function getVersion(version: number | string) {
|
||||
return versionDataList.find((versionData) => {
|
||||
return versionData.version.toString() === version.toString()
|
||||
})
|
||||
}
|
||||
|
||||
export function getCurrentVersion() {
|
||||
const todayDateString = format(new Date(), 'yyyy-MM-dd')
|
||||
|
||||
return versionDataList.find((versionData) => {
|
||||
const [startDateString] = versionData.duration
|
||||
|
||||
return startDateString.localeCompare(todayDateString) < 0
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import { readdirSync, readJsonFileSync } from '../../../lib/data'
|
||||
import { compareVersion } from '../../../lib/string'
|
||||
|
||||
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?: string
|
||||
}
|
||||
|
||||
const weaponsFileNameList = readdirSync('honkai3rd/weapons')
|
||||
const weaponDataList = weaponsFileNameList
|
||||
.map((fileName) => {
|
||||
const filePathname = 'honkai3rd/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 = compareVersion(b.version || '0.0', a.version || '0.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<string, WeaponData>())
|
||||
|
||||
export function listWeapons() {
|
||||
return weaponDataList
|
||||
}
|
||||
|
||||
export function getWeaponById(id: string) {
|
||||
return weaponMap.get(id)
|
||||
}
|
||||
Reference in New Issue
Block a user