Skip to content

Commit

Permalink
more tiny simulator improvements (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
JerwuQu authored Apr 11, 2024
1 parent 4fbf6b9 commit 971dc91
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
32 changes: 20 additions & 12 deletions simulator/src/ui/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ export class App extends LitElement {
fetch("http://localhost:2468/cart.wasm").then(async res => {
await this.resetCart(new Uint8Array(await (res).arrayBuffer()), false);
}).catch(() => {
runtime.blueScreen("Watcher not found.\n\nStart and reload.");
if (!this.runtime.wasmBuffer) {
runtime.blueScreen("Watcher not found.\n\nStart and reload.");
}
});

const ws = new WebSocket(`ws://localhost:2468/ws`);
Expand Down Expand Up @@ -261,6 +263,13 @@ export class App extends LitElement {
}
}

// Drag and drop handlers for loading carts
window.addEventListener("dragover", e => e.preventDefault());
window.addEventListener("drop", e => {
e.preventDefault();
this.loadCartFromFile(e.dataTransfer.files[0]);
});

const pollPhysicalGamepads = () => {
// TODO
// if (!navigator.getGamepads) {
Expand Down Expand Up @@ -397,25 +406,24 @@ export class App extends LitElement {
}
}

loadCartFromFile (file: File) {
let reader = new FileReader();
reader.addEventListener("load", () => {
this.resetCart(new Uint8Array(reader.result as ArrayBuffer), false);
});
reader.readAsArrayBuffer(file);
}

importCart () {
const app = this;
const input = document.createElement("input");

input.style.display = "none";
input.type = "file";
input.accept = ".wasm";
input.multiple = false;

input.addEventListener("change", () => {
const files = input.files as FileList;
let reader = new FileReader();

reader.addEventListener("load", () => {
this.resetCart(new Uint8Array(reader.result as ArrayBuffer), false);
app.closeMenu();
});

reader.readAsArrayBuffer(files[0]);
input.addEventListener("change", async () => {
this.loadCartFromFile(input.files[0]);
});

document.body.appendChild(input);
Expand Down
2 changes: 1 addition & 1 deletion simulator/src/ui/menu-overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class MenuOverlay extends LitElement {
const pressedThisFrame = controls & (controls ^ this.lastGamepad);
this.lastGamepad = controls;

if (pressedThisFrame & (constants.CONTROLS_SELECT)) {
if (pressedThisFrame & (constants.CONTROLS_START | constants.CONTROLS_A)) {
if(this.optionContext === optionContext.DEFAULT) {
switch (this.selectedIdx) {
case this.optionIndex.CONTINUE:
Expand Down

0 comments on commit 971dc91

Please sign in to comment.