Skip to content

Commit c5d4d48

Browse files
committed
add: spreadsheet servant row script
1 parent e045610 commit c5d4d48

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed

src/spreadsheet/servant.ts

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import { stdin, stdout } from "process";
2+
import { createInterface } from "readline/promises";
3+
import { parseArgs } from "util";
4+
import type { MatchData } from "fast-fuzzy";
5+
import { servantsCache } from "~/cache";
6+
import { log, logger, createTimer, col } from "~/utils/logger";
7+
import {
8+
createServantSearcher,
9+
prettyPrintMatch
10+
} from "~/utils/ServantSearcher";
11+
import { describeServantClass } from "~/utils/describeServantClass";
12+
13+
const timer = createTimer();
14+
const args = parseArgs({
15+
args: process.argv.slice(2),
16+
options: {
17+
verbose: { type: "boolean", short: "v", default: false }
18+
},
19+
allowPositionals: true
20+
});
21+
const rl = createInterface({ input: stdin, output: stdout });
22+
23+
async function proposeOption(
24+
candidate: Servant,
25+
matchData?: MatchData<Servant>
26+
) {
27+
const input = await rl.question(
28+
`Found Servant '${matchData ? prettyPrintMatch(matchData) : candidate.name}'. Add to list? [Y/n]:`
29+
);
30+
if (input.toLowerCase() == "n") return false;
31+
32+
// Name Picker
33+
const nameIdx = Number(
34+
await rl.question(
35+
`Pick Name:\n [0] ${candidate.name} (default)\n${candidate.names
36+
.map((name, idx) => ` [${idx + 1}] ${name}\n`)
37+
.join("")} [${
38+
candidate.names.length + 1
39+
}] ${col.italic("New Name")}\n\nSelect Option [0-${
40+
candidate.names.length + 1
41+
}]: `
42+
)
43+
);
44+
45+
// pre-defined name
46+
if (isNaN(nameIdx) || nameIdx == 0) return candidate.name;
47+
if (candidate.names.length >= nameIdx) return candidate.names[nameIdx - 1];
48+
49+
// custom name
50+
const customName = await rl.question(
51+
`Enter new Name (leave empty to use default name): `
52+
);
53+
return customName || candidate.name;
54+
}
55+
56+
async function main() {
57+
// DEBUG
58+
if (args.values.verbose) logger.setLogLevel("Debug");
59+
log.debug(args);
60+
61+
const servants = new Array<[Servant, string]>();
62+
const [searcher, servantsList] = await Promise.all([
63+
createServantSearcher(),
64+
servantsCache.read()
65+
]);
66+
for (const value of args.positionals) {
67+
// handle adding by ID
68+
const id = Number(value);
69+
if (!isNaN(id)) {
70+
const candidate = servantsList.find(
71+
servant => servant.id == id || servant.collectionNo == id
72+
);
73+
if (!candidate) {
74+
log.warn(`Found no Servant for id '${id}'`);
75+
continue;
76+
}
77+
const proposal = await proposeOption(candidate);
78+
if (proposal) servants.push([candidate, proposal]);
79+
continue;
80+
}
81+
82+
// handle adding by name search
83+
const candidates = searcher.search(value);
84+
if (candidates.length < 1) {
85+
log.warn(`Found no Servant for search '${value}'`);
86+
continue;
87+
}
88+
for (const match of candidates) {
89+
const proposal = await proposeOption(match.item, match);
90+
if (proposal) servants.push([match.item, proposal]);
91+
}
92+
}
93+
94+
// generate table rows
95+
console.log(""); // just put an empty line to make copying easier
96+
servants.sort((a, b) => a[0].id - b[0].id);
97+
for (const [servant, servantName] of servants) {
98+
// ID and Name
99+
stdout.write(`${servant.collectionNo}\t${servantName}\t`);
100+
// icon
101+
stdout.write(
102+
`=IMAGE("https://static.atlasacademy.io/JP/Faces/f_${servant.id}3.png")\t`
103+
);
104+
// bond CE
105+
if (servant.bondCE) {
106+
stdout.write(
107+
`=IMAGE("https://static.atlasacademy.io/JP/Faces/f_${servant.bondCE}0.png")\t`
108+
);
109+
stdout.write(
110+
`=IMAGE("https://static.atlasacademy.io/JP/EquipFaces/f_${servant.bondCE}0.png")\t`
111+
);
112+
} else {
113+
stdout.write(`N/A\tN/A\t`);
114+
}
115+
// rarity, cost, class
116+
stdout.write(
117+
`${servant.rarity}\t${servant.cost}\t${describeServantClass(servant.className)}\n`
118+
);
119+
}
120+
console.log(""); // just put an empty line to make copying easier
121+
}
122+
123+
main()
124+
.then(() => log.success(`Completed in ${timer()}`))
125+
.catch(e => log.fatal(e))
126+
.finally(() => rl.close());

0 commit comments

Comments
 (0)