From 36d72e9b737315adb191bea67760de4c6e8f3806 Mon Sep 17 00:00:00 2001 From: Rachel Powers <508861+Ryex@users.noreply.github.com> Date: Tue, 9 Apr 2024 21:41:46 -0700 Subject: [PATCH] bind stack and register cell edits Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com> --- www/src/ts/virtual_machine/device.ts | 68 +++++++++++++++---------- www/src/ts/virtual_machine/registers.ts | 7 ++- www/src/ts/virtual_machine/stack.ts | 7 ++- 3 files changed, 52 insertions(+), 30 deletions(-) diff --git a/www/src/ts/virtual_machine/device.ts b/www/src/ts/virtual_machine/device.ts index bb8231c..c420bc3 100644 --- a/www/src/ts/virtual_machine/device.ts +++ b/www/src/ts/virtual_machine/device.ts @@ -93,17 +93,19 @@ export class VMDeviceCard extends VMBaseDevice { if (this.deviceID == activeIc?.id) { badges.push(html`db`); } - activeIc?.pins?.forEach((id, index) => { + activeIc?.pins?.forEach((id, _index) => { if (this.deviceID == id) { badges.push(html``); } }, this); return html` - + + +
{ - return html` ${name} + ${field.field_type} `; - })} + })} `; } renderSlot(slot: Slot, slotIndex: number): HTMLTemplateResult { const fields = Array.from(slot.fields); + const inputIdBase = `vmDeviceCard${this.deviceID}Slot${slotIndex}Field`; return html`
${fields.map( - ([name, field], _index, _fields) => html` + ([name, field], _index, _fields) => html` ${name} + ${field.field_type} `, - )} + )}
`; @@ -194,9 +210,9 @@ export class VMDeviceCard extends VMBaseDevice { return html`
${this.connections.map((connection, index, _conns) => { - const conn = - typeof connection === "object" ? connection.CableNetwork : null; - return html` + const conn = + typeof connection === "object" ? connection.CableNetwork : null; + return html` Connection:${index} ${vmNetworks.map( - (net) => - html`Network ${net}`, - )} + (net) => + html`Network ${net}`, + )} `; - })} + })}
`; } @@ -223,8 +239,8 @@ export class VMDeviceCard extends VMBaseDevice { return html`
${pins?.map( - (pin, index) => - html` + html` d${index} ${visibleDevices.map( - (device, _index) => - html` + (device, _index) => + html` Device ${device.id} : ${device.name ?? device.prefabName} `, - )} + )} `, - )} + )}
`; } @@ -350,9 +366,9 @@ export class VMDeviceList extends BaseElement { return html`
${this.devices.map( - (id, _index, _ids) => - html``, - )} + (id, _index, _ids) => + html``, + )}
`; } diff --git a/www/src/ts/virtual_machine/registers.ts b/www/src/ts/virtual_machine/registers.ts index 3752cbf..a6d1a95 100644 --- a/www/src/ts/virtual_machine/registers.ts +++ b/www/src/ts/virtual_machine/registers.ts @@ -9,6 +9,7 @@ import "@shoelace-style/shoelace/dist/components/tooltip/tooltip.js"; import "@shoelace-style/shoelace/dist/components/input/input.js"; import { RegisterSpec } from "ic10emu_wasm"; import SlInput from "@shoelace-style/shoelace/dist/components/input/input.js"; +import { parseNumber } from "../utils"; @customElement("vm-ic-registers") export class VMICRegisters extends VMActiveIC { @@ -103,7 +104,9 @@ export class VMICRegisters extends VMActiveIC { } _handleCellChange(e: Event) { - const target = e.target as SlInput; - console.log(target.getAttribute("key"), target.value); + const input = e.target as SlInput; + const index = parseInt(input.getAttribute("key")!); + const val = parseNumber(input.value) + window.VM!.setRegister(index, val); } } diff --git a/www/src/ts/virtual_machine/stack.ts b/www/src/ts/virtual_machine/stack.ts index 8188dcc..bff6900 100644 --- a/www/src/ts/virtual_machine/stack.ts +++ b/www/src/ts/virtual_machine/stack.ts @@ -8,6 +8,7 @@ import "@shoelace-style/shoelace/dist/components/icon/icon.js"; import "@shoelace-style/shoelace/dist/components/tooltip/tooltip.js"; import "@shoelace-style/shoelace/dist/components/input/input.js"; import SlInput from "@shoelace-style/shoelace/dist/components/input/input.js"; +import { parseNumber } from "../utils"; @customElement("vm-ic-stack") export class VMICStack extends VMActiveIC { @@ -88,7 +89,9 @@ export class VMICStack extends VMActiveIC { } _handleCellChange(e: Event) { - const target = e.target as SlInput; - console.log(target.getAttribute("key"), target.value); + const input = e.target as SlInput; + const index = parseInt(input.getAttribute("key")!); + const val = parseNumber(input.value) + window.VM!.setStack(index, val); } }