File tree Expand file tree Collapse file tree 4 files changed +114
-0
lines changed
Expand file tree Collapse file tree 4 files changed +114
-0
lines changed Original file line number Diff line number Diff line change 1+ import type { Interface } from "readline/promises" ;
2+
3+ /**
4+ * User-choice menu for picking Class/Grand Score
5+ * @param scoresList read cachefile
6+ * @param rl Readline Interface
7+ * @returns idx in scoresList
8+ */
9+ export async function chooseScore ( scoresList : ClassScore [ ] , rl : Interface ) {
10+ const n = scoresList . length . toString ( ) . length ;
11+ const choice = await rl . question (
12+ `Pick Class Score:\n${ scoresList
13+ . map (
14+ ( score , idx ) =>
15+ ` ${ " " . repeat ( n - ( idx + 1 ) . toString ( ) . length ) } [${ idx + 1 } ] ${ score . name } ${
16+ score . en ? "" : " (JP only)"
17+ } \n`
18+ )
19+ . join ( "" ) } \nChoice (1-${ scoresList . length } ): `
20+ ) ;
21+
22+ // parse input
23+ const choiceParsed = parseInt ( choice ) - 1 ;
24+ if (
25+ isNaN ( choiceParsed ) ||
26+ choiceParsed < 0 ||
27+ choiceParsed >= scoresList . length
28+ ) {
29+ return ;
30+ }
31+
32+ return choiceParsed ;
33+ }
Original file line number Diff line number Diff line change 1+ import type { UserClassScore } from "./types" ;
2+
3+ export function createBlankUserScore ( id : number ) {
4+ const score : UserClassScore = {
5+ id,
6+ unlockedNodes : [ ]
7+ } ;
8+
9+ return score ;
10+ }
Original file line number Diff line number Diff line change 1+ import type { Interface } from "readline/promises" ;
2+ import { scoresCache } from "~/cache" ;
3+ import { describeServantClass } from "~/utils/describeServantClass" ;
4+ import { chooseScore } from "./chooseScore" ;
5+ import { loadUserScore } from "./loadUserScores" ;
6+ import { createBlankUserScore } from "./createBlankUserScore" ;
7+
8+ export async function scoresManager ( rl : Interface ) {
9+ const scoresList = await scoresCache . read ( ) ;
10+ let current : undefined | number = undefined ;
11+
12+ while ( true ) {
13+ current ??= await chooseScore ( scoresList , rl ) ;
14+ if ( current === undefined ) return ;
15+ const scoreData = scoresList [ current ] ;
16+ const userScoreFile = await loadUserScore ( scoreData . id ) ;
17+ const userScore = await userScoreFile . read ( ) ;
18+ const totalNodes = Object . values ( scoreData . nodes ) . length ;
19+ console . log (
20+ `\n${ scoreData . name } ${
21+ scoreData . classes . length > 1
22+ ? ` (${ scoreData . classes . map ( className => describeServantClass ( className ) ) . join ( ", " ) } )`
23+ : ""
24+ } \n${ userScore . unlockedNodes . length } /${ totalNodes } completed`
25+ ) ;
26+
27+ const opt = await rl . question (
28+ ` [1] Unlock Nodes\n [2] Check required Materials\n [3] Reset Class Score\nChoice (1-3): `
29+ ) ;
30+ switch ( opt ) {
31+ case "1" :
32+ case "2" :
33+ console . error ( "UNIMPLEMENTED" ) ;
34+ continue ; // TEMP
35+ case "3" :
36+ await userScoreFile . write ( createBlankUserScore ( scoreData . id ) ) ;
37+ continue ;
38+ default :
39+ current = undefined ;
40+ continue ;
41+ }
42+ }
43+ }
Original file line number Diff line number Diff line change 1+ import { parseArgs } from "util" ;
2+ import { createInterface } from "readline/promises" ;
3+ import { log , logger , createTimer } from "~/utils/logger" ;
4+
5+ const timer = createTimer ( ) ;
6+ const rl = createInterface ( { input : process . stdin , output : process . stdout } ) ;
7+ const { values : args } = parseArgs ( {
8+ args : process . argv . slice ( 2 ) ,
9+ options : {
10+ verbose : { type : "boolean" , short : "v" , default : false }
11+ }
12+ } ) ;
13+
14+ async function main ( ) {
15+ // DEBUG
16+ if ( args . verbose ) logger . setLogLevel ( "Debug" ) ;
17+ log . debug ( args ) ;
18+
19+ // CODE GOES HERE
20+ const { scoresManager } = await import ( "./scores" ) ;
21+ const res = await scoresManager ( rl ) ;
22+ log . debug ( res ) ;
23+ }
24+
25+ main ( )
26+ . then ( ( ) => log . success ( `Completed in ${ timer ( ) } ` ) )
27+ . catch ( e => log . fatal ( e ) )
28+ . finally ( ( ) => rl . close ( ) ) ;
You can’t perform that action at this time.
0 commit comments