Skip to content

Commit

Permalink
sim: layouting and controls help (#23)
Browse files Browse the repository at this point in the history
* sim: layouting and controls help

* sim: fix typescript goofs
  • Loading branch information
JerwuQu authored Apr 11, 2024
1 parent 971dc91 commit c74305c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 31 deletions.
46 changes: 27 additions & 19 deletions simulator/src/ui/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export class App extends LitElement {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
touch-action: none;
user-select: none;
Expand All @@ -31,9 +29,16 @@ export class App extends LitElement {
}
.content {
width: 100vmin;
height: 100vmin;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 100vw;
height: 100vh;
overflow: hidden;
gap: 0.5rem;
padding: 0.5rem;
box-sizing: border-box;
}
/** Nudge the game upwards a bit in portrait to make space for the virtual gamepad. */
Expand All @@ -44,20 +49,18 @@ export class App extends LitElement {
}
}
.canvas-wrapper {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
}
canvas {
width: 100%;
height: auto;
height: 100%;
object-fit: contain;
image-rendering: pixelated;
image-rendering: crisp-edges;
}
.help {
font-size: 0.9em;
color: #aaa;
}
`;

private readonly runtime: Runtime;
Expand Down Expand Up @@ -267,7 +270,9 @@ export class App extends LitElement {
window.addEventListener("dragover", e => e.preventDefault());
window.addEventListener("drop", e => {
e.preventDefault();
this.loadCartFromFile(e.dataTransfer.files[0]);
if (e.dataTransfer?.files?.[0]) {
this.loadCartFromFile(e.dataTransfer.files[0]);
}
});

const pollPhysicalGamepads = () => {
Expand Down Expand Up @@ -423,7 +428,9 @@ export class App extends LitElement {
input.multiple = false;

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

document.body.appendChild(input);
Expand Down Expand Up @@ -471,15 +478,16 @@ export class App extends LitElement {

render () {
return html`
<wasm4-light-sensor .app=${this}></wasm4-light-sensor>
<div class="content">
${this.showMenu ? html`<wasm4-menu-overlay .app=${this}></wasm4-menu-overlay>`: ""}
<wasm4-notifications></wasm4-notifications>
<div class="canvas-wrapper">
${this.runtime.canvas}
<wasm4-light-sensor .app=${this}></wasm4-light-sensor>
${this.runtime.canvas}
<wasm4-leds .app=${this}></wasm4-leds>
<div class="help">
Controls: Arrows/WASD, Z/K, X/J, Enter/Y, Backspace/T, Escape
</div>
</div>
<wasm4-leds .app=${this}></wasm4-leds>
`;
// <wasm4-virtual-gamepad .app=${this}></wasm4-virtual-gamepad>
}
Expand Down
6 changes: 0 additions & 6 deletions simulator/src/ui/leds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ import { unpack888 } from "./utils";
@customElement("wasm4-leds")
export class LEDs extends LitElement {
static styles = css`
:host {
position: absolute;
bottom: 20px;
}
.leds {
display: flex;
gap: 40px;
Expand Down
6 changes: 0 additions & 6 deletions simulator/src/ui/light-sensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ import { App } from "./app";
@customElement("wasm4-light-sensor")
export class LightSensor extends LitElement {
static styles = css`
:host {
position: absolute;
top: 30px;
}
input[type="range"] {
position: relative;
-webkit-appearance: none;
Expand Down
2 changes: 2 additions & 0 deletions simulator/src/ui/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export class Notifications extends LitElement {
display: flex;
flex-direction: column;
z-index: 99;
}
.notification {
Expand Down

0 comments on commit c74305c

Please sign in to comment.