Skip to content

Commit

Permalink
UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ambiguousname committed Feb 25, 2024
1 parent a688cbe commit a931941
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
<body>
<div id="text">
<button id="compile">Compile & Run</button>
<button id="stop">Stop & Edit</button>
</div>
<div id="resize"></div>
<iframe id="game" src="player.html">
Expand Down
33 changes: 19 additions & 14 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as cm from "./editor.js";


function resizeFromMouse(event) {
document.getElementById("text").style.minWidth = event.clientX + "px";
document.getElementById("text").style.minWidth = (event.screenX) + "px";
}

window.onload = async function() {
Expand All @@ -11,14 +11,24 @@ window.onload = async function() {
let resize = document.getElementById("resize");
resize.addEventListener("mousedown", (e) => {
e.preventDefault();

function remove() {
document.removeEventListener("mousemove", resizeFromMouse);
game.contentWindow.removeEventListener("mousemove", resizeFromMouse);
}

document.addEventListener("mousemove", resizeFromMouse);
document.addEventListener("mouseup", () => document.removeEventListener("mousemove", resizeFromMouse))
game.contentWindow.addEventListener("mousemove", resizeFromMouse);
document.addEventListener("mouseup", remove);
game.contentWindow.addEventListener("mouseup", remove);
});

top.addEventListener("keydown", (e) => {
e.stopPropagation();
}, true);

var app = null;
function compileWAT(wabt, text) {
if (game.src === "about:blank") {
return;
}
try {
let result = wabt.parseWat("", text);
let bin = result.toBinary({
Expand All @@ -34,30 +44,25 @@ window.onload = async function() {
let wasm4Cart = game.contentDocument.getElementById("wasm4-cart-json");
let json = `{"WASM4_CART":"${encode(bin.buffer)}","WASM4_CART_SIZE":${bin.buffer.length}}`;
wasm4Cart.innerText = json;
let app = new game.contentWindow.wasm4.App();
if (app !== null) {
game.contentDocument.body.innerHTML = "";
}
app = new game.contentWindow.wasm4.App();
game.contentDocument.body.appendChild(app);
} catch (error) {
alert(error);
console.error(error);
cm.setEditable(cm.editor, true);
}
}

let wabt = await new WabtModule();
cm.setEditable(cm.editor, false);

compileWAT(wabt, cm.editor.state.doc.toString());

document.getElementById("compile").onclick = function() {
cm.setEditable(cm.editor, false);
game.src = "player.html";
game.onload = function() {
compileWAT(wabt, cm.editor.state.doc.toString());
}
}

document.getElementById("stop").onclick = function() {
game.src = "about:blank";
cm.setEditable(cm.editor, true);
}
}

0 comments on commit a931941

Please sign in to comment.