Skip to content

Commit

Permalink
Fix worker import
Browse files Browse the repository at this point in the history
  • Loading branch information
xpdota committed Sep 23, 2024
1 parent ce386a4 commit 3d35234
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions packages/frontend/src/scripts/components/meld_solver_bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class MeldSolverSettingsExport {
targetGcd?: number;
}


export class MeldSolverDialog extends BaseModal {
private _sheet: GearPlanSheetGui;

Expand All @@ -43,9 +44,7 @@ export class MeldSolverDialog extends BaseModal {
this.headerText = 'Meld Solver';
const form = document.createElement("form");
form.method = 'dialog';
this.solveWorker = new Worker(new URL(
'./src_scripts_components_meld_solver_worker_ts.js', document.location.toString())
);
this.solveWorker = this.makeActualWorker();

this.classList.add('meld-solver-area');
//this._solver = new MeldSolver(sheet);
Expand All @@ -72,18 +71,32 @@ export class MeldSolverDialog extends BaseModal {

this.cancelButton = makeActionButton("Cancel", async () => {
this.solveWorker.terminate();
this.solveWorker = new Worker(new URL(
'./src_scripts_components_meld_solver_worker_ts.js', document.location.toString())
);
this.solveWorker = this.makeActualWorker();
this.buttonArea.removeChild(this.cancelButton);
this.solveMeldsButton.disabled = false;
})
});

this.addButton(this.solveMeldsButton);
form.replaceChildren( this.settingsDiv);
this.contentArea.append(form);
}

// Webpack sees this and it causes it to generate a separate js file for the worker.
// import.meta.url doesn't actually work for this - we need to use document.location as shown in the ctor.
// TODO: make sure the worker JS is not also ending up in the main JS
makeUselessWorker() {
this.solveWorker = new Worker(new URL(
// @ts-expect-error idk
'../workers/meld_solver_worker.ts', import.meta.url)
);
}

makeActualWorker(): Worker {
return new Worker(new URL(
'./src_scripts_workers_meld_solver_worker_ts.js', document.location.toString())
);
}

public refresh(set: CharacterGearSet) {
this.settingsDiv.settings.gearset = set;
}
Expand All @@ -109,7 +122,7 @@ class MeldSolverSettingsMenu extends HTMLDivElement {
private useTargetGcdCheckBox: FieldBoundCheckBox<MeldSolverSettings>;
private targetGcdInput: FieldBoundFloatField<MeldSolverSettings>;
private checkboxContainer: HTMLDivElement;
private simDropdown: FieldBoundDataSelect<MeldSolverSettings, Simulation<any, any, any>>
private simDropdown: FieldBoundDataSelect<MeldSolverSettings, Simulation<SimResult, unknown, unknown>>;

constructor(sheet: GearPlanSheetGui, set: CharacterGearSet) {
super();
Expand Down Expand Up @@ -159,7 +172,7 @@ class MeldSolverSettingsMenu extends HTMLDivElement {
simText.textContent = "Sim: ";
simText.classList.add('meld-solver-settings');

this.simDropdown = new FieldBoundDataSelect<typeof this.settings, Simulation<any, any, any>>(
this.simDropdown = new FieldBoundDataSelect<typeof this.settings, Simulation<SimResult, unknown, unknown>>(
this.settings,
'sim',
value => {
Expand Down

0 comments on commit 3d35234

Please sign in to comment.