1
+ import { access } from 'fs/promises'
1
2
import { uniq , uniqBy } from 'lodash-es'
2
3
import fetch from 'node-fetch'
3
- import pinyin from 'pinyin'
4
+ import { pinyin } from 'pinyin'
4
5
import simplebig from 'simplebig'
5
6
7
+ type Profession = { id : string ; name : string }
8
+ type Professions = ( Profession & { sub : Profession [ ] } ) [ ]
9
+
10
+ export async function fileExists ( file : string ) {
11
+ try {
12
+ await access ( file )
13
+ return true
14
+ } catch ( e ) {
15
+ return false
16
+ }
17
+ }
18
+
6
19
function pinyinify ( name : string ) {
7
20
return [
8
21
pinyin ( name , {
@@ -19,14 +32,15 @@ function pinyinify(name: string) {
19
32
}
20
33
21
34
function transformOperatorName ( name : string ) {
22
- const cleanedSimplifiedName = name . replace ( / [ ” “ " ] / g, '' )
35
+ const cleanedName = name . replace ( / [ ” “ " ] / g, '' )
23
36
24
37
const traditional = simplebig . s2t ( name ) as string
25
38
const cleanedTraditional = traditional . replace ( / [ ” “ " ] / g, '' )
39
+
26
40
return {
27
41
name,
28
42
alias : uniq ( [
29
- ...pinyinify ( cleanedSimplifiedName ) ,
43
+ ...pinyinify ( cleanedName ) ,
30
44
traditional ,
31
45
cleanedTraditional ,
32
46
...pinyinify ( cleanedTraditional ) ,
@@ -36,23 +50,69 @@ function transformOperatorName(name: string) {
36
50
37
51
const CHARACTER_TABLE_JSON_URL =
38
52
'https://raw.githubusercontent.com/Kengxxiao/ArknightsGameData/master/zh_CN/gamedata/excel/character_table.json'
53
+ const UNIEQUIP_TABLE_JSON_URL =
54
+ 'https://raw.githubusercontent.com/Kengxxiao/ArknightsGameData/master/zh_CN/gamedata/excel/uniequip_table.json'
39
55
40
56
const CHARACTER_BLOCKLIST = [
57
+ 'char_512_aprot' , // 暮落(集成战略):It's just not gonna be there.
41
58
'token_10012_rosmon_shield' , // 迷迭香的战术装备:It's just not gonna be there.
42
59
]
43
60
44
- export async function getOperatorNames ( ) {
45
- const resp = ( await fetch ( CHARACTER_TABLE_JSON_URL ) . then ( ( res ) =>
46
- res . json ( ) ,
47
- ) ) as any
48
- const ids = Object . keys ( resp )
61
+ const PROFESSION_NAMES = {
62
+ MEDIC : '医疗' ,
63
+ WARRIOR : '近卫' ,
64
+ SPECIAL : '特种' ,
65
+ SNIPER : '狙击' ,
66
+ PIONEER : '先锋' ,
67
+ TANK : '重装' ,
68
+ CASTER : '术师' ,
69
+ SUPPORT : '辅助' ,
70
+ }
71
+
72
+ async function json ( url : string ) {
73
+ return ( await ( await fetch ( url ) ) . json ( ) ) as any
74
+ }
75
+
76
+ export async function getOperators ( ) {
77
+ const [ charTable , uniequipTable ] = await Promise . all ( [
78
+ json ( CHARACTER_TABLE_JSON_URL ) ,
79
+ json ( UNIEQUIP_TABLE_JSON_URL ) ,
80
+ ] )
81
+
82
+ const { subProfDict } = uniequipTable
83
+
84
+ const opIds = Object . keys ( charTable )
85
+ const professions : Professions = [ ]
49
86
const result = uniqBy (
50
- ids . flatMap ( ( el ) => {
51
- const op = resp [ el ]
87
+ opIds . flatMap ( ( id ) => {
88
+ const op = charTable [ id ]
52
89
if ( [ 'TRAP' ] . includes ( op . profession ) ) return [ ]
90
+
91
+ if ( ! [ 'TOKEN' ] . includes ( op . profession ) ) {
92
+ const prof = professions . find ( ( p ) => p . id === op . profession )
93
+ if ( ! prof ) {
94
+ professions . push ( {
95
+ id : op . profession ,
96
+ name : PROFESSION_NAMES [ op . profession ] ,
97
+ sub : [
98
+ {
99
+ id : op . subProfessionId ,
100
+ name : subProfDict [ op . subProfessionId ] . subProfessionName ,
101
+ } ,
102
+ ] ,
103
+ } )
104
+ } else if ( ! prof . sub . find ( ( p ) => p . id === op . subProfessionId ) ) {
105
+ prof . sub . push ( {
106
+ id : op . subProfessionId ,
107
+ name : subProfDict [ op . subProfessionId ] . subProfessionName ,
108
+ } )
109
+ }
110
+ }
111
+
53
112
return [
54
113
{
55
- id : el ,
114
+ id : id ,
115
+ subProf : op . subProfessionId ,
56
116
...transformOperatorName ( op . name ) ,
57
117
alt_name : op . appellation ,
58
118
} ,
@@ -62,5 +122,8 @@ export async function getOperatorNames() {
62
122
) . sort ( ( a , b ) => {
63
123
return pinyin . compare ( a . name , b . name )
64
124
} )
65
- return result . filter ( ( el ) => ! CHARACTER_BLOCKLIST . includes ( el . id ) )
125
+ return {
126
+ professions,
127
+ operators : result . filter ( ( el ) => ! CHARACTER_BLOCKLIST . includes ( el . id ) ) ,
128
+ }
66
129
}
0 commit comments