Initial
This commit is contained in:
commit
2ca7a264b3
53 files changed
+7113
No files matched your search
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
importScripts("/vendor/pyodide.js");
|
||||
const ready = (async () => {
|
||||
const py = await loadPyodide({indexURL: "/vendor/", fullStdLib:false});
|
||||
const response = await fetch("/rules.json", {credentials:"omit"});
|
||||
if (!response.ok) throw Error("Файлы движка недоступны");
|
||||
const files = await response.json();
|
||||
for (const file of ["catalog.json","engine.py","strategy.py","local_game.py"]) {
|
||||
py.FS.writeFile("/home/pyodide/"+file, files[file]);
|
||||
}
|
||||
return py.runPython("from local_game import dispatch\ndispatch");
|
||||
})();
|
||||
onmessage = async ({data}) => {
|
||||
try {
|
||||
const dispatch = await ready;
|
||||
postMessage({result:JSON.parse(dispatch(JSON.stringify(data)))});
|
||||
} catch {
|
||||
postMessage({error:"Не удалось открыть позицию. Попробуйте начать новую партию."});
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user