This commit is contained in:
Zach Graham 2023-08-04 20:52:58 -05:00
parent d24600cbd4
commit 3cab30027a
1 changed files with 11 additions and 32 deletions

View File

@ -90,54 +90,33 @@ async function getMappingForLetter(letter) {
} }
async function setNextLetter() { async function setNextLetter() {
if (currentletterIndex > currentString.length-1) { let letterbox = $("#letterbox");
if (currentLetterIndex > currentString.length-1)
return; return;
} let prevIndex = currentLetterIndex-1;
let prevIndex = currentletterIndex-1; if (prevIndex >= -1)
if (prevIndex >= -1) { await unhighlightLetter(letterbox.children()[currentLetterIndex]);
await unhighlightLetter($("#letterbox").children()[currentletterIndex]); currentLetterIndex++;
} currentLetter = currentString.charAt(currentLetterIndex).toLowerCase();
currentletterIndex++;
currentLetter = currentString.charAt(currentletterIndex).toLowerCase();
currentMapping = mappings[(await getMappingForLetter(currentLetter)).toString()]; currentMapping = mappings[(await getMappingForLetter(currentLetter)).toString()];
await highlightLetter($("#letterbox").children()[currentletterIndex]); await highlightLetter(letterbox.children()[currentLetterIndex]);
await artseyDraw(); await artseyDraw();
} }
let currentletterIndex = -1; let currentLetterIndex = -1;
let currentLetter = ''; let currentLetter = '';
let currentString = "hello world"; let currentString = "hello world";
let currentMapping = [0, 0, 0, 0, 0, 0, 0, 0]; let currentMapping = [0, 0, 0, 0, 0, 0, 0, 0];
$(document).ready(async function () { $(document).ready(async function () {
$( "body" ).on( "click", function(event) {
// $( "#target" ).trigger( "keyup" );
console.log(event);
} );
$( "#typing-text" ).on( "keypress", function() {
//console.log( "Handler for `keypress` called." );
console.log($("#typing-text").text());
} );
$('body').on("keyup", (function(e) { $('body').on("keyup", (function(e) {
//alert('Handler for .keyup() called.');
$('#typing-text').focus();
console.log("current letter: " + currentLetter + " typed letter: " + String.fromCharCode(e.which).toLowerCase()); console.log("current letter: " + currentLetter + " typed letter: " + String.fromCharCode(e.which).toLowerCase());
if (currentLetter === String.fromCharCode(e.which).toLowerCase())
if (currentLetter === String.fromCharCode(e.which).toLowerCase()) {
setNextLetter(); setNextLetter();
}
})); }));
console.log("ready! Here's a demo.");
await sleep(1000); await sleep(1000);
await setTypingText(currentString); await setTypingText(currentString);
await sleep(500); await sleep(500);
await setNextLetter(); await setNextLetter();
// for (let i = 0; i < currentString.length; i++) {
// await setNextLetter();
// await sleep(1000);
// }
}); });