-
Notifications
You must be signed in to change notification settings - Fork 0
/
mika_regional_dialogue_demo.html
60 lines (54 loc) · 2.54 KB
/
mika_regional_dialogue_demo.html
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/pyodide/v0.19.0/full/pyodide.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
<style>
.game-screen {
font-family: monospace;
}
</style>
</head>
<body>
Some text.<br>
<script type="text/javascript">
async function main(){
let pyodide = await loadPyodide({
indexURL : "https://cdn.jsdelivr.net/pyodide/v0.19.0/full/"
});
await pyodide.loadPackage(["attrs", "pyyaml"]);
await pyodide.runPythonAsync(`
from pyodide.http import pyfetch
from asyncio import gather
from random import random
import os
def safe_open_wb(path):
''' Open "path" for writing, creating any parent directories as needed.
'''
p = os.path.dirname(path)
if p:
os.makedirs(p, exist_ok=True)
return open(path, 'wb')
async def fetch_py(filename):
print(f"fetching py file {filename}")
response = await pyfetch(filename + "?rnd=" + str(random()))
with safe_open_wb(filename) as f:
f.write(await response.bytes())
py_files = "mika_yaml_dialogue.py, mika_regional_dialogue.py, styleml_glyph_exts.py, mika_modules.py, mika_dialogue.py, mika_screen.py, mika_svgui.py, styleml_mika_exts.py, utilities.py, ./styleml/convenient_argument.py, ./styleml/core.py, ./styleml/macro_ext.py, ./styleml/portal_ext.py"
py_files = py_files.split(", ")
await gather(*[fetch_py(fn) for fn in py_files])
# load characters and scenes
import json
await fetch_py("walk_modules.json")
with open("walk_modules.json") as f:
modules = json.load(f)
all_module_files = modules.values()
await gather(*[fetch_py(os.path.join("./resources/modules", fn)) for fn in all_module_files])
await gather(*[fetch_py("./resources/predefined_macros.txt")])
`)
pyodide.runPython(await (await fetch("mika_regional_dialogue_demo.py" + "?rnd=" + Math.random())).text());
}
main();
</script>
</body>
</html>