Skip to content

Commit

Permalink
Merge pull request #354 from Junie-774/meld-solver-wip
Browse files Browse the repository at this point in the history
Some meld solver fixes
  • Loading branch information
xpdota authored Oct 16, 2024
2 parents fc85c2d + a2005c4 commit 6be0a79
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 28 deletions.
60 changes: 36 additions & 24 deletions packages/frontend/src/scripts/components/meld_solver_modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { recordEvent } from "@xivgear/core/analytics/analytics";
export class MeldSolverDialog extends BaseModal {
private _sheet: GearPlanSheetGui;

private form: HTMLFormElement;
private descriptionText: HTMLDivElement;
private setNameText: HTMLDivElement;
readonly tempSettings: MeldSolverSettings;
Expand All @@ -28,8 +29,8 @@ export class MeldSolverDialog extends BaseModal {
this._sheet = sheet;
this.id = 'meld-solver-dialog';
this.headerText = 'Meld Solver';
const form = document.createElement("form");
form.method = 'dialog';
this.form = document.createElement("form");
this.form.method = 'dialog';
this.inner.style.maxWidth = "25%"; // idk why this doesn't work in common-css but it don't.

this.classList.add('meld-solver-area');
Expand All @@ -49,13 +50,9 @@ export class MeldSolverDialog extends BaseModal {
this.solver = new MeldSolver(sheet);
meld_solve_start = Date.now();

this.closeButton.disabled = true;
this.settingsDiv.setEnabled(false);

this.buttonArea.removeChild(this.solveMeldsButton);
this.addButton(this.cancelButton);
this.progressDisplay = new MeldSolverProgressDisplay;
form.replaceChildren(this.progressDisplay);
this.showProgress();

const solverPromise = this.solver.solveMelds(
this.settingsDiv.gearsetGenSettings,
this.settingsDiv.simSettings,
Expand All @@ -64,7 +61,7 @@ export class MeldSolverDialog extends BaseModal {
this.progressDisplay.text.textContent = "Simulating...";

});
solverPromise.then((set) => this.messageReceived(set));
solverPromise.then((set) => this.solveResultReceived(set));
recordEvent("SolveMelds", {
"Total Time Taken: ": Date.now() - (meld_solve_start ?? Date.now()),
});
Expand All @@ -73,36 +70,28 @@ export class MeldSolverDialog extends BaseModal {

this.cancelButton = makeActionButton("Cancel", async () => {
await this.solver.cancel();

this.closeButton.disabled = false;
this.settingsDiv.setEnabled(true);

this.buttonArea.removeChild(this.cancelButton);
form.replaceChildren(this.settingsDiv);
this.addButton(this.solveMeldsButton);
});

this.addButton(this.solveMeldsButton);
this.showSettings();
});

form.replaceChildren(
this.descriptionText, document.createElement('br'),
this.setNameText, document.createElement('br'),
this.settingsDiv);
this.contentArea.append(form);
this.showSettings();
this.contentArea.append(this.form);
}

public refresh(set: CharacterGearSet) {
this.settingsDiv.gearsetGenSettings.gearset = set;
}

messageReceived(set: CharacterGearSet) {

solveResultReceived(set: CharacterGearSet) {
if (set) {
this.applyResult(set);
this.settingsDiv.gearsetGenSettings.gearset.forceRecalc();
this._sheet.refreshMateria();
this.close();
return;
}
this.showSettings();
}

applyResult(newSet: CharacterGearSet) {
Expand All @@ -115,6 +104,29 @@ export class MeldSolverDialog extends BaseModal {
this.settingsDiv.gearsetGenSettings.gearset.equipment[slotKey].melds = newSet.equipment[slotKey].melds;
}
}

showSettings() {

this.closeButton.disabled = false;
this.settingsDiv.setEnabled(true);

this.form.replaceChildren(
this.descriptionText, document.createElement('br'),
this.setNameText, document.createElement('br'),
this.settingsDiv
);
this.addButton(this.solveMeldsButton);
}

showProgress() {

this.closeButton.disabled = true;
this.settingsDiv.setEnabled(false);

this.progressDisplay = new MeldSolverProgressDisplay;
this.form.replaceChildren(this.progressDisplay);
this.addButton(this.cancelButton);
}
}

class LoadBar extends HTMLDivElement {
Expand Down
5 changes: 4 additions & 1 deletion packages/frontend/src/scripts/components/meldsolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@ export class MeldSolver {
sheet: this._sheet.exportSheet(),
data: GearsetGenerationSettings.export(gearsetGenSettings, this._sheet)
};
console.log("n: ", workerPool.numFreeWorkers);

const gearGenJob = workerPool.requestWork(gearsetGenRequest);
this.jobs.push(gearGenJob)

let sets: SetExport[] = await (gearGenJob.promise as Promise<SetExport[]>);
if (sets.length === 0) {
return null;
}
this.jobs = [];

const nSimJobs = workerPool.numFreeWorkers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class GearsetGenerationWorker extends WorkerBehavior<GearsetGenerationJob
const setGenerator = new GearsetGenerator(this.sheet, gearsetGenSettings);
const allGearsets = setGenerator.getMeldPossibilitiesForGearset(gearsetGenSettings);

const setsToExport: SetExport[] = allGearsets.map(set => this.sheet.exportGearSet(set));
const setsToExport: SetExport[] = allGearsets.map(set => this.sheet.exportGearSet(set)).filter(set => Object.keys(set).length !== 0);

this.postResult(setsToExport);
}
Expand Down
1 change: 0 additions & 1 deletion packages/frontend/src/scripts/workers/worker_main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ onmessage = async function (event) {
data: null,
};
this.postMessage(response);
console.log("Done Init!");
return;
}
const sheet = HEADLESS_SHEET_PROVIDER.fromExport(request.sheet);
Expand Down
1 change: 0 additions & 1 deletion packages/frontend/src/scripts/workers/worker_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ export class WorkerPool {
);
worker.onmessage = (event) => {
const id = this.activeJobIds.get(worker);
console.log("Done init?");
this.onWorkerMessage(worker, id, event.data);
}

Expand Down

0 comments on commit 6be0a79

Please sign in to comment.