a bit of typing
This commit is contained in:
parent
5ab9166a10
commit
7bd74e3b59
2 changed files with 12 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
|||
import { f32ToRound10, isPlainObject, Song } from "./common.ts";
|
||||
import { f32ToRound10, isPlainObject, Song, SongMode } from "./common.ts";
|
||||
import { elements as elementsPromise } from "./dom.ts";
|
||||
import { fromUrlData, setUrlData } from "./url/mod.ts";
|
||||
import type { EditorView } from "@codemirror/view";
|
||||
|
||||
const searchParams = new URLSearchParams(location.search);
|
||||
|
||||
|
@ -26,7 +27,10 @@ let byteSample = 0;
|
|||
|
||||
let isPlaying = false;
|
||||
|
||||
let songData = {
|
||||
let songData: {
|
||||
sampleRate: number,
|
||||
mode: SongMode,
|
||||
} = {
|
||||
sampleRate: 8000, // float32
|
||||
mode: "Bytebeat",
|
||||
};
|
||||
|
@ -37,7 +41,7 @@ let timeUnit = null;
|
|||
|
||||
let animationFrameId = null;
|
||||
|
||||
let codeEditor = null;
|
||||
let codeEditor: HTMLTextAreaElement | EditorView | null = null;
|
||||
|
||||
let elements = null; // TODO remove
|
||||
|
||||
|
@ -236,9 +240,9 @@ function getCodeEditorText(): string {
|
|||
return codeEditor.state.doc.toString();
|
||||
}
|
||||
}
|
||||
function setCodeEditorText(value: string) {
|
||||
function setCodeEditorText(value?: string) {
|
||||
if (codeEditor instanceof Element) {
|
||||
codeEditor.value = value;
|
||||
codeEditor.value = value as string;
|
||||
} else {
|
||||
codeEditor.dispatch({
|
||||
changes: { from: 0, to: codeEditor.state.doc.length, insert: value },
|
||||
|
@ -296,7 +300,7 @@ function getSong(): Song {
|
|||
return { code: getCodeEditorText(), ...songData };
|
||||
}
|
||||
|
||||
function setSong(songData?: Song, play = true) {
|
||||
function setSong(songData?: Partial<Song>, play = true) {
|
||||
let code, sampleRate, mode;
|
||||
if (songData) {
|
||||
({ code, sampleRate, mode } = songData);
|
||||
|
|
|
@ -10,12 +10,12 @@ function stripInlineEntryToSong(entry: Readonly<EntryBase & InlineEntry>, codeTy
|
|||
const { sampleRate, mode } = entry;
|
||||
return { code: entry[codeType], sampleRate, mode };
|
||||
}
|
||||
function createByteSnippet(text: string, onclick: () => void) {
|
||||
function createByteSnippet(text: string | undefined, onclick: () => void) {
|
||||
const interactElem = document.createElement("button");
|
||||
const codeElem = document.createElement("code");
|
||||
interactElem.title = "Click to play this code";
|
||||
interactElem.className = "code-button";
|
||||
codeElem.innerText = text;
|
||||
codeElem.innerText = text as string;
|
||||
interactElem.addEventListener("click", onclick);
|
||||
interactElem.append(codeElem);
|
||||
return interactElem;
|
||||
|
|
Loading…
Reference in a new issue