Skip to content

Commit 2a952ba

Browse files
committed
Properly added total purchase list + fixed bug when closing dialogs with esc
1 parent 022b059 commit 2a952ba

5 files changed

Lines changed: 34 additions & 23 deletions

File tree

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ <h1 style="margin-bottom: 1.5rem">Sim settings</h1>
140140
<!--span>Skip completed CTs in "all" mode: </span> <input type="checkbox" class="skipcompletedcts" /><br /><br /-->
141141
<span>Show a2 and a3 lvl in EFAI strat output: </span> <input type="checkbox" class="a23" /><br /><br />
142142
<span>Show unofficial CTs: </span> <input type="checkbox" class="unofficials" /><br /><br />
143+
<span>Generate a total purchase list: </span> <input type="checkbox" class="totalPurchaseList" /><br /><br />
143144
</dialog>
144145
<dialog class="boughtVars">
145146
<button class="boughtVarsCloseBtn">X</button>

src/Sim/parse.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const simAllStrats = qs<HTMLSelectElement>(".simallstrats");
2525
const completedCTs = qs<HTMLSelectElement>(".completedcts");
2626
const showA23 = qs<HTMLInputElement>(".a23");
2727
const showUnofficials = qs<HTMLInputElement>(".unofficials");
28+
const generateTotalPurchaseList = qs<HTMLInputElement>(".totalPurchaseList");
2829

2930
function parseSettings(): Settings {
3031
return {
@@ -36,7 +37,8 @@ function parseSettings(): Settings {
3637
simAllStrats: simAllStrats.value as SettingsSimAllStratsMode,
3738
completedCTs: completedCTs.value as SettingsCompletedCTsMode,
3839
showA23: showA23.checked,
39-
showUnofficials: showUnofficials.checked
40+
showUnofficials: showUnofficials.checked,
41+
totalPurchaseList: generateTotalPurchaseList.checked
4042
}
4143
}
4244

src/Sim/write.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import jsonData from "../Data/data.json" assert { type: "json" };
22
import { convertTime, formatNumber, isMainTheory, logToExp } from "../Utils/helpers";
33
import { 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
99
const table = qs(".simTable");
@@ -18,6 +18,8 @@ const varBuyListCloseBtn = qs<HTMLButtonElement>(".boughtVarsCloseBtn");
1818
const tau = `<span style="font-size:0.9rem; font-style:italics">&tau;</span>`;
1919
const rho = `<span style="font-size:0.9rem; font-style:italics">&rho;</span>`;
2020

21+
let totalBuys: varBuy[] = [];
22+
2123
// Utils
2224
function 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 */
104106
function 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

169169
function 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

176183
function writeSimAllResponse(response: SimAllResponse) {

src/UI/settings.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ event(settingsBtn, "pointerdown", () => {
1313
document.body.style.overflow = "hidden";
1414
});
1515

16-
event(settingsCloseBtn, "pointerdown", () => {
16+
event(settingsCloseBtn, "pointerdown", () => settingsModal.close());
17+
18+
event(settingsModal, "close", () => {
1719
setSimState();
18-
settingsModal.close();
1920
document.body.style.overflow = "auto";
20-
});
21+
})
2122

2223
// Instructions menu
2324

@@ -30,10 +31,9 @@ event(instructionsBtn, "pointerdown", () => {
3031
document.body.style.overflow = "hidden";
3132
});
3233

33-
event(instructionsCloseBtn, "pointerdown", () => {
34-
instructionsModal.close();
35-
document.body.style.overflow = "auto";
36-
});
34+
event(instructionsCloseBtn, "pointerdown", () => instructionsModal.close());
35+
36+
event(instructionsModal, "close", () => document.body.style.overflow = "auto");
3737

3838
// Settings inputs
3939

src/Utils/global.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ declare global {
123123
completedCTs: SettingsCompletedCTsMode;
124124
showA23: boolean;
125125
showUnofficials: boolean;
126+
totalPurchaseList: boolean;
126127
}
127128

128129
interface simResult {

0 commit comments

Comments
 (0)