Skip to content

Commit 9bf01b9

Browse files
committed
Merge branch 'Gemini2035-guan/temp1' into dev
2 parents 44d7791 + ec3e811 commit 9bf01b9

34 files changed

+4388
-2336
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
"lint:fix": "npm-run-all --parallel lint:fix:eslint lint:fix:prettier",
1515
"lint:fix:eslint": "eslint --fix src/**/*",
1616
"lint:fix:prettier": "prettier --write src/**/*",
17-
"scripts:update": "yarn install && npm-run-all --parallel scripts:update-operators scripts:update-operator-avatars",
17+
"scripts:update": "yarn install && npm-run-all --parallel scripts:update-operators scripts:update-operator-avatars scripts:update-prof-icons",
1818
"scripts:update-operators": "esno scripts/update-operators.ts",
19-
"scripts:update-operator-avatars": "esno scripts/update-operator-avatars.ts"
19+
"scripts:update-operator-avatars": "esno scripts/update-operator-avatars.ts",
20+
"scripts:update-prof-icons": "yarn install && esno scripts/update-prof-icons.ts"
2021
},
2122
"dependencies": {
2223
"@blueprintjs/core": "^4.15.1",
446 Bytes
Loading

public/assets/prof-icons/MEDIC.png

594 Bytes
Loading
492 Bytes
Loading
594 Bytes
Loading
457 Bytes
Loading
445 Bytes
Loading

public/assets/prof-icons/TANK.png

544 Bytes
Loading
388 Bytes
Loading

scripts/shared.ts

Lines changed: 75 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1+
import { access } from 'fs/promises'
12
import { uniq, uniqBy } from 'lodash-es'
23
import fetch from 'node-fetch'
3-
import pinyin from 'pinyin'
4+
import { pinyin } from 'pinyin'
45
import simplebig from 'simplebig'
56

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+
619
function pinyinify(name: string) {
720
return [
821
pinyin(name, {
@@ -19,14 +32,15 @@ function pinyinify(name: string) {
1932
}
2033

2134
function transformOperatorName(name: string) {
22-
const cleanedSimplifiedName = name.replace(/["]/g, '')
35+
const cleanedName = name.replace(/["]/g, '')
2336

2437
const traditional = simplebig.s2t(name) as string
2538
const cleanedTraditional = traditional.replace(/["]/g, '')
39+
2640
return {
2741
name,
2842
alias: uniq([
29-
...pinyinify(cleanedSimplifiedName),
43+
...pinyinify(cleanedName),
3044
traditional,
3145
cleanedTraditional,
3246
...pinyinify(cleanedTraditional),
@@ -36,23 +50,69 @@ function transformOperatorName(name: string) {
3650

3751
const CHARACTER_TABLE_JSON_URL =
3852
'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'
3955

4056
const CHARACTER_BLOCKLIST = [
57+
'char_512_aprot', // 暮落(集成战略):It's just not gonna be there.
4158
'token_10012_rosmon_shield', // 迷迭香的战术装备:It's just not gonna be there.
4259
]
4360

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 = []
4986
const result = uniqBy(
50-
ids.flatMap((el) => {
51-
const op = resp[el]
87+
opIds.flatMap((id) => {
88+
const op = charTable[id]
5289
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+
53112
return [
54113
{
55-
id: el,
114+
id: id,
115+
subProf: op.subProfessionId,
56116
...transformOperatorName(op.name),
57117
alt_name: op.appellation,
58118
},
@@ -62,5 +122,8 @@ export async function getOperatorNames() {
62122
).sort((a, b) => {
63123
return pinyin.compare(a.name, b.name)
64124
})
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+
}
66129
}

0 commit comments

Comments
 (0)