From 3d35234abb9f2b028f9b5c24a31a2db065abc92a Mon Sep 17 00:00:00 2001 From: XP Date: Sun, 22 Sep 2024 18:04:28 -0700 Subject: [PATCH] Fix worker import --- .../src/scripts/components/meld_solver_bar.ts | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/packages/frontend/src/scripts/components/meld_solver_bar.ts b/packages/frontend/src/scripts/components/meld_solver_bar.ts index 33851328..b9ca824a 100644 --- a/packages/frontend/src/scripts/components/meld_solver_bar.ts +++ b/packages/frontend/src/scripts/components/meld_solver_bar.ts @@ -27,6 +27,7 @@ export class MeldSolverSettingsExport { targetGcd?: number; } + export class MeldSolverDialog extends BaseModal { private _sheet: GearPlanSheetGui; @@ -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); @@ -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; } @@ -109,7 +122,7 @@ class MeldSolverSettingsMenu extends HTMLDivElement { private useTargetGcdCheckBox: FieldBoundCheckBox; private targetGcdInput: FieldBoundFloatField; private checkboxContainer: HTMLDivElement; - private simDropdown: FieldBoundDataSelect> + private simDropdown: FieldBoundDataSelect>; constructor(sheet: GearPlanSheetGui, set: CharacterGearSet) { super(); @@ -159,7 +172,7 @@ class MeldSolverSettingsMenu extends HTMLDivElement { simText.textContent = "Sim: "; simText.classList.add('meld-solver-settings'); - this.simDropdown = new FieldBoundDataSelect>( + this.simDropdown = new FieldBoundDataSelect>( this.settings, 'sim', value => {