diff --git a/src/settings.ts b/src/settings.ts index 27f143f..c1a6b91 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -18,30 +18,52 @@ document.querySelector('#content').innerHTML = `

Gauntlet Settings

-`; + +
+Prepping + + + + + + + + + + + + + +
+
+`; -async function addKeySetter(functionName: string, displayName?: string) +/** + * Create a text field and corresponding button for setting the key of a function. + * @param keybind the keybind to set + */ +async function addKeySetter(keybind: Keybind) { - if (displayName === undefined) - displayName = pretty(functionName); + if (keybind.displayName === null) + keybind.displayName = pretty(keybind.functionName); const setKeyInput: HTMLInputElement = document.createElement('input'); setKeyInput.type = 'button'; setKeyInput.value = 'Set'; setKeyInput.classList.add('button'); setKeyInput.addEventListener('click', async (e: MouseEvent): Promise => { - console.log(`Setting ${functionName}`); - const key: string = (document.querySelector(`#${functionName}-key`) as HTMLInputElement).value + console.log(`Setting ${keybind.functionName}`); + const key: string = (document.querySelector(`#${keybind.functionName}-key`) as HTMLInputElement).value .toUpperCase(); - await setStorageValue(functionName, key); + await setStorageValue(keybind.functionName, key); }); const tr: HTMLTableRowElement = document.createElement('tr'); const td1: HTMLTableDataCellElement = document.createElement('td'); - td1.innerHTML += ``; + td1.innerHTML += ``; const td2: HTMLTableDataCellElement = document.createElement('td'); td2.innerHTML += - ``; + ``; const td3: HTMLTableDataCellElement = document.createElement('td'); td3.appendChild(setKeyInput); tr.appendChild(td1); @@ -50,23 +72,37 @@ async function addKeySetter(functionName: string, displayName?: string) document.querySelector('#keys').appendChild(tr); } +async function setJumpPoint(e: MouseEvent): Promise +{ + const jumpPoint: string = + canonicalize((document.querySelector('#jump-point') as HTMLInputElement).value); + await setStorageValue('jp', jumpPoint); +} + +async function setPassword(e: MouseEvent): Promise +{ + const password: string = (document.querySelector('#prep-password') as HTMLInputElement).value; + await setStorageValue('password', password); +} + +async function setSwitchers(e: MouseEvent): Promise +{ + let switchers: string[] = + (document.querySelector('#switchers') as HTMLTextAreaElement).value.split('\n'); + for (let i = 0; i < switchers.length; i++) + switchers[i] = canonicalize(switchers[i]); + await setStorageValue('switchers', switchers); +} + (async () => { // Set up the keybind setting form - for (let i = 0; i < keybinds.length; i++) { - if (keybinds[i].displayName) - await addKeySetter(keybinds[i].functionName, keybinds[i].displayName); - else - await addKeySetter(keybinds[i].functionName); - } + for (let i = 0; i < keybinds.length; i++) + await addKeySetter(keybinds[i]); // Other settings (document.querySelector('#jump-point') as HTMLInputElement).value = await getStorageValue('jp'); - document.querySelector('#set-jump-point') - .addEventListener('click', async (e: MouseEvent): Promise => - { - const jumpPoint: string = - canonicalize((document.querySelector('#jump-point') as HTMLInputElement).value); - await setStorageValue('jp', jumpPoint); - }); + document.querySelector('#set-jump-point').addEventListener('click', setJumpPoint); + document.querySelector('#set-prep-password').addEventListener('click', setPassword); + document.querySelector('#set-switchers').addEventListener('click', setSwitchers); })(); \ No newline at end of file