-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_pyxel_fs.html
51 lines (48 loc) · 1.78 KB
/
test_pyxel_fs.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
<!-- Bootstrap HTML for running the unit tests. -->
<!DOCTYPE html>
<html>
<head>
<title>pyodide</title>
<script src="./pyodide.js"></script>
</head>
<body>
<button id="start" type="button" disabled>Loading...</button> <br>
<canvas id="canvas" oncontextmenu="event.preventDefault()"></canvas>
<script type="text/javascript">
assets = ["cat_16x16.png",
"jump_game.pyxres",
"noguchi_128x128.png",
"offscreen.pyxres",
"platformer.pyxres",
"pyxel_logo_38x16.png",
"sample.pyxres",
"tileset_24x32.png",] // TODO: Selective loading
async function main() {
const filename = (new URLSearchParams(location.search)).get("py") || "11_offscreen"
const pyodide = await loadPyodide();
await pyodide.loadPackage("micropip")
const micropip = pyodide.pyimport("micropip")
await micropip.install("pyxel-1.8.0-cp37-abi3-emscripten_3_1_14_wasm32.whl")
pyodide.FS.mkdir("assets")
for (let assetName of assets) {
const asset = await fetch(`python/assets/${assetName}`)
const assetData = new Uint8Array(await asset.arrayBuffer())
pyodide.FS.writeFile(`assets/${assetName}`, assetData, { encoding: 'binary' })
}
const response = await fetch(`python/${filename}.py`)
const startButton = document.getElementById("start")
if (response.status != 200) {
const defaultScript = await (await fetch("python/00_moving_square.py")).text()
startButton.addEventListener("click", () => pyodide.runPython(defaultScript))
}
else {
const script = await response.text()
startButton.addEventListener("click", () => pyodide.runPython(script))
}
startButton.disabled = false
startButton.innerText = "Start"
}
main()
</script>
</body>
</html>