aboutsummaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-05-28 16:26:47 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-05-28 16:26:47 +0200
commit9df6811626d11ecb6b0cb15cb3a4be6d7ad479a1 (patch)
tree93459f5edd5b015c6c1b6832c559d0c36aa17df3 /web
parent2e122bdffbe7524f5ed6f7cb704bbd1b778a6b41 (diff)
downloadnissy-core-9df6811626d11ecb6b0cb15cb3a4be6d7ad479a1.tar.gz
nissy-core-9df6811626d11ecb6b0cb15cb3a4be6d7ad479a1.zip
Revert memory64 and improve frontend for web version
Diffstat (limited to 'web')
-rw-r--r--web/adapter.cpp3
-rw-r--r--web/http/index.html9
-rw-r--r--web/http/nissyapp.mjs26
-rw-r--r--web/worker.mjs16
4 files changed, 46 insertions, 8 deletions
diff --git a/web/adapter.cpp b/web/adapter.cpp
index 676390c..31d00fe 100644
--- a/web/adapter.cpp
+++ b/web/adapter.cpp
@@ -23,7 +23,8 @@ const std::set<std::string> available_solvers
23 "h48h1k2", 23 "h48h1k2",
24 "h48h2k2", 24 "h48h2k2",
25 "h48h3k2", 25 "h48h3k2",
26 "h48h7k2", 26 "h48h4k2",
27 "h48h5k2",
27}; 28};
28 29
29std::map<std::string, nissy::solver> loaded_solvers; 30std::map<std::string, nissy::solver> loaded_solvers;
diff --git a/web/http/index.html b/web/http/index.html
index 47ccc0d..04ddf4c 100644
--- a/web/http/index.html
+++ b/web/http/index.html
@@ -9,9 +9,12 @@
9 <body> 9 <body>
10 <input id="scrambleText" placeholder="Type the scramble here..."> 10 <input id="scrambleText" placeholder="Type the scramble here...">
11 <select id="solverSelector"> 11 <select id="solverSelector">
12 <option value="h48h0k4">h48 h=0 k=4 (59Mb)</option> 12 <option value="h48h3k2" selected="selected">
13 <option value="h48h3k2" selected="selected">h48 h=3 k=2 (283Mb)</option> 13 h48 h=4 k=2 (300 Mb) - light
14 <option value="h48h7k2">h48 h=7 k=2 (3.6Gb)</option> 14 </option>
15 <option value="h48h5k2" selected="selected">
16 h48 h=5 k=2 (1 Gb) - fastest
17 </option>
15 </select> 18 </select>
16 <button id="solveButton">Solve</button> 19 <button id="solveButton">Solve</button>
17 <div id="confirmDownload" style="display:none"> 20 <div id="confirmDownload" style="display:none">
diff --git a/web/http/nissyapp.mjs b/web/http/nissyapp.mjs
index 55ca198..1f9fa72 100644
--- a/web/http/nissyapp.mjs
+++ b/web/http/nissyapp.mjs
@@ -30,8 +30,8 @@ worker.onmessage = (event) => {
30function updateResults(label, results, enable) { 30function updateResults(label, results, enable) {
31 resultsLabel.innerText = label; 31 resultsLabel.innerText = label;
32 resultsText.innerText = results; 32 resultsText.innerText = results;
33 solveButton.disable = !enable; 33 solveButton.disabled = !enable;
34 solverSelector.disable = !enable; 34 solverSelector.disabled = !enable;
35} 35}
36 36
37var logVisible = false; 37var logVisible = false;
@@ -49,7 +49,27 @@ toggleLog.addEventListener("click", () => {
49solveButton.addEventListener("click", () => { 49solveButton.addEventListener("click", () => {
50 const solver = solverSelector.options[solverSelector.selectedIndex].value; 50 const solver = solverSelector.options[solverSelector.selectedIndex].value;
51 const scramble = scrField.value; 51 const scramble = scrField.value;
52 loadDataThenSolve(solver, scramble); 52
53 const callbackId = ++lastCallbackId;
54 callbacks.set(callbackId, {
55 f: (callbackArg, validateResult) => {
56 if (validateResult) {
57 loadDataThenSolve(callbackArg.solver, callbackArg.scramble);
58 } else {
59 updateResults("Scramble is invalid", "", true);
60 }
61 },
62 arg: {
63 solver: solver,
64 scramble: scramble
65 }
66 });
67
68 worker.postMessage({
69 command: "validate scramble",
70 id: lastCallbackId,
71 arg: scramble
72 });
53}); 73});
54 74
55function loadDataThenSolve(solver, scramble) { 75function loadDataThenSolve(solver, scramble) {
diff --git a/web/worker.mjs b/web/worker.mjs
index 0cb618b..12de1dc 100644
--- a/web/worker.mjs
+++ b/web/worker.mjs
@@ -8,6 +8,7 @@ const commands = [
8 { name: "load solver data", exec: loadSolverDataFromStorage }, 8 { name: "load solver data", exec: loadSolverDataFromStorage },
9 { name: "download solver data", exec: downloadSolverData }, 9 { name: "download solver data", exec: downloadSolverData },
10 { name: "generate solver data", exec: generateSolverData }, 10 { name: "generate solver data", exec: generateSolverData },
11 { name: "validate scramble", exec: validateScramble },
11 { name: "solve", exec: solve }, 12 { name: "solve", exec: solve },
12]; 13];
13 14
@@ -45,7 +46,7 @@ async function loadSolverDataFromStorage(id, solver) {
45 }); 46 });
46 47
47 if (!(await nissy.isSolverAvailable(solver))) { 48 if (!(await nissy.isSolverAvailable(solver))) {
48 async_return(false, "Error: solver " + arg.solver + 49 async_return(false, "Error: solver " + solver +
49 " is not available in this version of nissy."); 50 " is not available in this version of nissy.");
50 return; 51 return;
51 } 52 }
@@ -113,6 +114,19 @@ async function generateSolverData(id, solver) {
113 } 114 }
114} 115}
115 116
117// Check if the scramble is valid.
118// Argument: string (the scramble).
119async function validateScramble(id, arg) {
120 const async_return = (success) => postMessage({
121 command: "validate scramble",
122 id: id,
123 arg: success
124 });
125
126 var cube = new nissy.Cube();
127 async_return(cube.move(arg).ok());
128}
129
116// Solve the cube with the given options. 130// Solve the cube with the given options.
117// Argument: { 131// Argument: {
118// solver: string 132// solver: string

Generated with cgit - Back to sebastiano.tronto.net