Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more tiny simulator improvements #21

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading