40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { getContextItem } from "./lib/context.ts";
|
|
import { InputManager } from "./lib/input.ts";
|
|
import { StateMachine } from "./state/machine.ts";
|
|
import { States } from "./state/states/index.ts";
|
|
import { TrackSystem } from "./track/system.ts";
|
|
|
|
export function bootstrapInputs() {
|
|
addEventListener("keydown", (e) => {
|
|
e.preventDefault();
|
|
});
|
|
const inputManager = getContextItem<InputManager>("inputManager");
|
|
inputManager.onKey("e", () => {
|
|
const state = getContextItem<StateMachine<States>>("state");
|
|
state.transitionTo(States.EDIT_TRACK);
|
|
});
|
|
inputManager.onKey("Delete", () => {
|
|
if (inputManager.getKeyState("Control")) {
|
|
localStorage.removeItem("track");
|
|
}
|
|
});
|
|
inputManager.onKey("c", () => {
|
|
if (inputManager.getKeyState("Control")) {
|
|
const currentTrack = localStorage.getItem("track");
|
|
navigator.clipboard.writeText(currentTrack ?? "[]");
|
|
}
|
|
});
|
|
addEventListener("paste", async (e) => {
|
|
let data = e.clipboardData?.getData("text/plain");
|
|
if (!data) return;
|
|
try {
|
|
// data = data.trim().replace(/^"|"$/g, "").replace(/\\"/g, '"');
|
|
console.log(data);
|
|
const track = TrackSystem.deserialize(JSON.parse(data));
|
|
localStorage.setItem("track", track.serialize());
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
});
|
|
}
|