Computer/src/ui/components/resetButtons.ts

32 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-03-13 06:01:33 +00:00
import { el } from "../../etc";
2024-03-26 03:03:20 +00:00
import { UiEventHandler, UiCpuSignalHandler, UiCpuSignal } from "../../events";
2024-03-13 06:01:33 +00:00
import UiComponent from "../uiComponent";
export default class ResetButtons implements UiComponent {
container: HTMLElement;
events: UiEventHandler;
cpu_signals: UiCpuSignalHandler;
constructor(element: HTMLElement, events: UiEventHandler, cpu_signals: UiCpuSignalHandler) {
this.container = element;
this.events = events;
this.cpu_signals = cpu_signals;
2024-03-26 03:03:20 +00:00
const reset_button = el("button").cl("nostyle").ti("Reset State").tx("⟳").fin();
const trash_button = el("button").cl("nostyle").ti("Delete Code").tx("🗑").fin();
2024-03-13 06:01:33 +00:00
reset_button.addEventListener("click", () => this.resetClicked());
trash_button.addEventListener("click", () => this.trashClicked());
2024-03-13 06:01:33 +00:00
this.container.append(reset_button, trash_button);
}
2024-03-26 03:03:20 +00:00
resetClicked(): void {
this.cpu_signals.dispatch(UiCpuSignal.RequestCpuSoftReset);
}
2024-03-13 06:01:33 +00:00
trashClicked(): void {
2024-03-26 03:03:20 +00:00
const a = confirm("Clear all code? Irreversible");
if (a) {
this.cpu_signals.dispatch(UiCpuSignal.RequestCpuReset);
}
2024-03-13 06:01:33 +00:00
}
}