make non derived readonly fields writable from the ui
This commit is contained in:
@@ -430,18 +430,22 @@ export class VMDeviceCard extends VMDeviceMixin(BaseElement) {
|
||||
|
||||
_handleChangeField(e: CustomEvent) {
|
||||
const input = e.target as SlInput;
|
||||
const field = input.getAttribute("key")!;
|
||||
const field = input.getAttribute("key")! as LogicType;
|
||||
const val = parseNumber(input.value);
|
||||
window.VM?.setDeviceField(this.deviceID, field, val);
|
||||
if (!window.VM?.setDeviceField(this.deviceID, field, val, true)) {
|
||||
input.value = this.fields.get(field).value.toString();
|
||||
}
|
||||
this.updateDevice();
|
||||
}
|
||||
|
||||
_handleChangeSlotField(e: CustomEvent) {
|
||||
const input = e.target as SlInput;
|
||||
const slot = parseInt(input.getAttribute("slotIndex")!);
|
||||
const field = input.getAttribute("key")!;
|
||||
const field = input.getAttribute("key")! as SlotLogicType;
|
||||
const val = parseNumber(input.value);
|
||||
window.VM?.setDeviceSlotField(this.deviceID, slot, field, val);
|
||||
if (!window.VM?.setDeviceSlotField(this.deviceID, slot, field, val, true)) {
|
||||
input.value = this.device.getSlotField(slot, field).toString();
|
||||
}
|
||||
this.updateDevice();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DeviceRef, DeviceTemplate, VM, init } from "ic10emu_wasm";
|
||||
import { DeviceRef, DeviceTemplate, LogicType, SlotLogicType, VM, init } from "ic10emu_wasm";
|
||||
import { DeviceDB } from "./device_db";
|
||||
import "./base_device";
|
||||
|
||||
@@ -273,11 +273,12 @@ class VirtualMachine extends EventTarget {
|
||||
return false;
|
||||
}
|
||||
|
||||
setDeviceField(id: number, field: string, val: number): boolean {
|
||||
setDeviceField(id: number, field: LogicType, val: number, force?: boolean): boolean {
|
||||
force = force ?? false;
|
||||
const device = this._devices.get(id);
|
||||
if (device) {
|
||||
try {
|
||||
device.setField(field, val);
|
||||
device.setField(field, val, force);
|
||||
this.updateDevice(device);
|
||||
return true;
|
||||
} catch (err) {
|
||||
@@ -287,11 +288,12 @@ class VirtualMachine extends EventTarget {
|
||||
return false;
|
||||
}
|
||||
|
||||
setDeviceSlotField(id: number, slot: number, field: string, val: number): boolean {
|
||||
setDeviceSlotField(id: number, slot: number, field: SlotLogicType, val: number, force?: boolean): boolean {
|
||||
force = force ?? false;
|
||||
const device = this._devices.get(id);
|
||||
if (device) {
|
||||
try {
|
||||
device.setSlotField(slot, field, val);
|
||||
device.setSlotField(slot, field, val, false);
|
||||
this.updateDevice(device);
|
||||
return true;
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user