1+ import { getPlayer , getUnits } from "./requestMaker.ts" ;
2+ import type { PlayerResp , UnitsResp } from "./requestMaker.ts" ;
3+ import { profileStatMappings , playerMappings , galacticPowerMappings , speedModMappings , pipMappings , relicMappings , gearMappings , rarityMappings } from "./listBuilderMappings.ts" ;
4+ import { getSpeedModCount , getPipCount , countOffensePercentRolls } from "./mods.ts" ;
5+ import { ULLocation , relicChart , gearChart , starChart , activeChart } from "./locations.ts"
6+
7+ function handleProfileStat ( player : PlayerResp ) : void {
8+ profileStatMappings . forEach ( stat => {
9+ const playerStat = player . profileStat . find ( ps => ps . index === stat . index ) ;
10+ if ( playerStat ) {
11+ ULLocation ( "profileStatList" , `${ stat . displayName } : ${ playerStat . value } ` ) ;
12+ }
13+ } ) ;
14+ }
15+
16+ function handleGP ( player : PlayerResp ) : void {
17+ galacticPowerMappings . forEach ( stat => {
18+ const playerStat = player . profileStat . find ( ps => ps . index === stat . index )
19+ if ( playerStat ) {
20+ ULLocation ( "GPList" , `${ stat . displayName } : ${ playerStat . value } ` ) ;
21+ }
22+ } ) ;
23+ }
24+
25+ function handleGear ( player : PlayerResp , units : UnitsResp [ ] ) : void {
26+ let tracker : number [ ] = [ ] ;
27+ for ( let key in gearMappings ) {
28+ let counter = 0 ;
29+ player . rosterUnit . forEach ( unit => {
30+ if ( unit . currentTier && ! checkIfShip ( units , unit . definitionId ) ) {
31+ if ( unit . currentTier === Number ( key ) ) {
32+ counter ++ ;
33+ }
34+ }
35+ } ) ;
36+ tracker . push ( counter ) ;
37+ }
38+
39+ gearChart ( tracker ) ;
40+ }
41+
42+ function handleRelics ( player : PlayerResp , units : UnitsResp [ ] ) : void {
43+ let tracker : number [ ] = [ ] ;
44+ for ( let key in relicMappings ) {
45+ let counter = 0 ;
46+ player . rosterUnit . forEach ( unit => {
47+ if ( checkIfShip ( units , unit . definitionId ) ) {
48+ return ;
49+ }
50+ if ( unit . relic && unit . relic . currentTier ) {
51+ if ( unit . relic . currentTier === Number ( key ) ) {
52+ counter ++ ;
53+ }
54+ }
55+ } ) ;
56+ tracker . push ( counter ) ;
57+ }
58+ relicChart ( tracker ) ;
59+ }
60+
61+ function handleActivated ( player : PlayerResp , units : UnitsResp [ ] ) : void {
62+ let activated = 0 , notActivated = 0 ;
63+ units . forEach ( unit => {
64+ if ( ! unit . id . endsWith ( ":SEVEN_STAR" ) ) {
65+ return ;
66+ }
67+ if ( ! unit . obtainable || unit . obtainableTime != 0 ) {
68+ return ;
69+ }
70+ const trimmed = unit . id . split ( ":" ) [ 0 ] ;
71+ let found = false ;
72+ for ( const pUnit of player . rosterUnit ) {
73+ if ( pUnit . definitionId . split ( ":" ) [ 0 ] === trimmed ) {
74+ found = true ;
75+ activated ++ ;
76+ break ;
77+ }
78+ }
79+ if ( ! found ) {
80+ notActivated ++ ;
81+ //console.log(`${trimmed} not activated`);
82+ }
83+ } ) ;
84+
85+ activeChart ( activated , notActivated ) ;
86+ }
87+
88+ function handleSpeedMods ( player : PlayerResp ) : void {
89+ speedModMappings . forEach ( stat => {
90+ ULLocation ( "modsList" , `${ stat . displayName } : ${ getSpeedModCount ( player , stat . min , stat . max ) } ` ) ;
91+ } ) ;
92+ }
93+
94+ function handleOffenseMods ( player : PlayerResp ) : void {
95+ const offenseStats = countOffensePercentRolls ( player )
96+ for ( const key in offenseStats ) {
97+ ULLocation ( "offenseModsList" , `${ key } : ${ offenseStats [ key ] } ` )
98+ }
99+ }
100+
101+ function handlePips ( player : PlayerResp ) : void {
102+ const { sixDot, fiveDot, other } = getPipCount ( player ) ;
103+
104+ ULLocation ( "pipList" , `${ pipMappings . sixDot } : ${ sixDot } ` ) ;
105+ ULLocation ( "pipList" , `${ pipMappings . fiveDot } : ${ fiveDot } ` ) ;
106+ ULLocation ( "pipList" , `${ pipMappings . other } : ${ other } ` ) ;
107+ }
108+
109+ function handleStars ( player : PlayerResp ) : void {
110+ let tracker : number [ ] = [ ] ;
111+ for ( let rarity in rarityMappings ) {
112+ let counter = 0 ;
113+ player . rosterUnit . forEach ( unit => {
114+ if ( unit . currentRarity === Number ( rarity ) ) {
115+ counter ++ ;
116+ }
117+ } ) ;
118+ tracker . push ( counter ) ;
119+ }
120+ starChart ( tracker ) ;
121+ }
122+
123+ function checkIfShip ( units : UnitsResp [ ] , defId : string ) : boolean {
124+ for ( const unit of units ) {
125+ if ( unit . id === defId ) {
126+ return unit . combatType === 2 ;
127+ }
128+ }
129+
130+ console . log ( `Unit not found: ${ defId } ` ) ;
131+ return false ;
132+ }
133+
134+ export async function FillList ( allyCode : string ) {
135+ const units = await getUnits ( ) ;
136+ if ( ! units ) {
137+ console . error ( `Failed to get units` )
138+ return
139+ }
140+
141+ const player : PlayerResp = await getPlayer ( allyCode ) ;
142+
143+ for ( const playerKey in playerMappings ) {
144+ const key = playerKey as keyof PlayerResp ;
145+ if ( ! ( key in playerMappings ) ) {
146+ console . error ( `Missing ${ key } in playerMappings` )
147+ continue
148+ }
149+
150+ switch ( playerMappings [ key ] . displayType ) {
151+ case 0 :
152+ ULLocation ( "mainList" , `${ playerMappings [ key ] . displayName } : ${ player [ key ] } ` ) ;
153+ break ;
154+ case 1 :
155+ handleProfileStat ( player ) ;
156+ break ;
157+ case 2 :
158+ handleGP ( player ) ;
159+ break ;
160+ case 3 :
161+ handleSpeedMods ( player ) ;
162+ break ;
163+ case 4 :
164+ handlePips ( player ) ;
165+ break ;
166+ case 5 :
167+ handleRelics ( player , units ) ;
168+ break ;
169+ case 6 :
170+ handleGear ( player , units ) ;
171+ break ;
172+ case 7 :
173+ handleStars ( player ) ;
174+ break ;
175+ case 8 :
176+ handleActivated ( player , units ) ;
177+ break ;
178+ case 9 :
179+ handleOffenseMods ( player )
180+ break ;
181+ default :
182+ console . error ( `Found unknown playerMappings key: ${ key } ` )
183+ }
184+ }
185+ }
0 commit comments