@@ -2,8 +2,8 @@ import jsonData from "../Data/data.json" assert { type: "json" };
22import { convertTime , formatNumber , isMainTheory , logToExp } from "../Utils/helpers" ;
33import { qs , qsa , ce , event , removeAllChilds } from "../Utils/DOMhelpers" ;
44
5- // Other
6- const sigmaInput = qs < HTMLInputElement > ( ".sigma " ) ;
5+ // Settings
6+ const generateTotalPurchaseList = qs < HTMLInputElement > ( ".totalPurchaseList " ) ;
77
88// Outputs
99const table = qs ( ".simTable" ) ;
@@ -18,6 +18,8 @@ const varBuyListCloseBtn = qs<HTMLButtonElement>(".boughtVarsCloseBtn");
1818const tau = `<span style="font-size:0.9rem; font-style:italics">τ</span>` ;
1919const rho = `<span style="font-size:0.9rem; font-style:italics">ρ</span>` ;
2020
21+ let totalBuys : varBuy [ ] = [ ] ;
22+
2123// Utils
2224function clearTable ( ) {
2325 removeAllChilds ( tbody ) ;
@@ -62,13 +64,13 @@ function fillTableRow(row: HTMLTableRowElement, count: number) {
6264 for ( let i = 0 ; i < count ; i ++ ) addTableCell ( row , "" ) ;
6365}
6466
65- let totalBuys : varBuy [ ] = [ ] ;
66-
6767/** Binds a var buy list to the last cell of a result row */
68- const bindVarBuy = ( row : HTMLTableRowElement , buys : varBuy [ ] ) => {
68+ const bindVarBuy = ( row : HTMLTableRowElement , buys : varBuy [ ] , addToTotal = true ) => {
6969 if ( row . lastChild == null ) return ;
70- totalBuys . push ( ...buys ) ;
71- totalBuys . push ( { variable : "---" , level : 0 , cost : 0 , timeStamp : 0 } ) ;
70+ if ( addToTotal && generateTotalPurchaseList . checked ) {
71+ totalBuys . push ( ...buys ) ;
72+ totalBuys . push ( { variable : "---" , level : 0 , cost : 0 , timeStamp : 0 } ) ;
73+ }
7274 const lastChild = row . lastChild as HTMLElement ;
7375 lastChild . onclick = ( ) => {
7476 openVarModal ( buys ) ;
@@ -102,10 +104,6 @@ function highlightResetCells() {
102104
103105/** Generates and open the var buy list */
104106function openVarModal ( arr : varBuy [ ] ) {
105- if ( sigmaInput . value === "hax" ) {
106- console . log ( "HAX" ) ;
107- arr = totalBuys ;
108- }
109107 document . body . style . overflow = "hidden" ;
110108 varBuyDialog . showModal ( ) ;
111109 removeAllChilds ( varBuyTable ) ;
@@ -120,10 +118,9 @@ function openVarModal(arr: varBuy[]) {
120118 highlightResetCells ( ) ;
121119}
122120
123- event ( varBuyListCloseBtn , "pointerdown" , ( ) => {
124- varBuyDialog . close ( ) ;
125- document . body . style . overflow = "auto" ;
126- } ) ;
121+ event ( varBuyListCloseBtn , "pointerdown" , ( ) => varBuyDialog . close ( ) ) ;
122+
123+ event ( varBuyDialog , "close" , ( ) => document . body . style . overflow = "auto" ) ;
127124
128125// Response writers
129126
@@ -164,13 +161,23 @@ function writeChainSimResponse(response: ChainSimResponse) {
164161
165162 tbody . append ( labelRow ) ;
166163 tbody . append ( resRow ) ;
164+ if ( generateTotalPurchaseList . checked ) {
165+ bindVarBuy ( resRow , totalBuys , false ) ;
166+ }
167167}
168168
169169function writeStepSimResponse ( response : StepSimResponse ) {
170170 response . results . forEach ( res => writeSingleSimResponse ( {
171171 responseType : "single" ,
172172 result : res
173173 } ) ) ;
174+ if ( generateTotalPurchaseList . checked ) {
175+ const resRow = ce < HTMLTableRowElement > ( "tr" ) ;
176+ fillTableRow ( resRow , 8 ) ;
177+ addTableCell ( resRow , "Total" ) ;
178+ bindVarBuy ( resRow , totalBuys , false ) ;
179+ tbody . append ( resRow ) ;
180+ }
174181}
175182
176183function writeSimAllResponse ( response : SimAllResponse ) {
0 commit comments