aboutsummaryrefslogtreecommitdiff
path: root/web/http/worker.mjs
blob: 7ce107008b756538850a94bd13ec5d8013dcbec0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import Nissy from "./nissy_web_module.mjs"

const nissy = await Nissy();
nissy.setLogger(nissy._addCallbackFunction(console.log));

onmessage = (e) => {
//TODO: try to load from storage first, then download
  nissy.initSolverDownload(e.data.solver, "/tables").then(
  (download_result) => {
    if (!download_result) {
      postMessage("Error retrieving the solver data");
    } else {
      var cube = new nissy.Cube();
      cube.move(e.data.scramble);

      nissy.solve(e.data.solver, cube, nissy.NissFlag.normal,
        0, 17, 1, 99, 4, -1).then(
      (solve_result) => {
        if (!solve_result.err.ok())
          postMessage("Error while solving (solve returned " +
            solve_result.err.value + ")");
        else
          postMessage(solve_result.solutions)
      });
    }
  });
};

Generated with cgit - Back to sebastiano.tronto.net