Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (!localStorage["Test.typing.chars"]) {
- localStorage["Test.typing.chars"] = 0;
- localStorage["Test.typing.chars.bonus"] = 0;
- }
- YourWorld.Color = 0x008000;
- var coords = [0,0];
- var prevCoords = [0,0];
- var prevText = [];
- var previousLine = cursorCoords;
- var canSkip = 0;
- var typingStreak = 0;
- var typed = document.createElement("div");
- var progressFill = document.createElement("div");
- var progress = document.createElement("meter");
- typed.innerHTML = `${parseFloat(localStorage["Test.typing.chars"]).toLocaleString("en-US")} typed <span style="font-size: 30%;">(+${parseFloat(localStorage["Test.typing.chars.bonus"]).toLocaleString("en-US")})</span>`;
- typed.style = "position: absolute; top: 0; left: 0; width: 100%; height: 64px; text-align: center; background: #00000080; color: white; font-size: 48px; font-family: arial;";
- progressFill.style = "position: absolute; top: calc(100% - 32px); left: 0; width: 100%; height: 32px; background: #00000080";
- progress.style = "position: absolute; width: 95%; left: 2.5%; top: calc(100% - 24px)";
- progress.value = 0;
- main_view.appendChild(typed);
- main_view.appendChild(progress);
- main_view.appendChild(progressFill);
- state.userModel.username = (parseFloat(localStorage["Test.typing.chars"]) + parseFloat(localStorage["Test.typing.chars.bonus"])).toLocaleString("en-US");
- updateText = () => {
- prevText = [
- getCharInfoXY(coords[0],coords[1]),
- getCharInfoXY(coords[0],coords[1]+1),
- [],
- ];
- for (let i = 0; i < state.userModel.username.length; i++) {
- prevText[2].push(getCharInfoXY(coords[0]+i,coords[1]+2));
- }
- }
- updateCoords = () => {
- if (!cursorCoords) {
- return false;
- }
- coords = [cursorCoords[0]*16 + cursorCoords[2], cursorCoords[1]*8 + cursorCoords[3]];
- }
- update = (e,f,g) => {
- if (prevText[0].char == f && prevText[0].color != 0x008000) {
- moveCursor("right");
- prevText[0].color = 0x008000;
- if (g) {
- localStorage["Test.typing.chars.bonus"]++;
- } else {
- localStorage["Test.typing.chars"]++;
- canSkip = canSkip == 1000 ? 1000 : canSkip + 1;
- typingStreak++;
- progress.value = canSkip/1000;
- progress.style.filter = `hue-rotate(${~~(canSkip/100)*36}deg) brightness(${1+~~(canSkip/100)/10})`;
- YourWorld.Color = canSkip >= 100 ? 0x60C000 + ~~(canSkip/4) : 0x008000;
- }
- typed.innerHTML = `${parseFloat(localStorage["Test.typing.chars"]).toLocaleString("en-US")} typed <span style="font-size: 30%;">(+${parseFloat(localStorage["Test.typing.chars.bonus"]).toLocaleString("en-US")})</span>`;
- state.userModel.username = (parseFloat(localStorage["Test.typing.chars"]) + parseFloat(localStorage["Test.typing.chars.bonus"])).toLocaleString("en-US");
- }
- updateCoords();
- if (coords == prevCoords) {
- return false;
- }
- if (coords[0] != prevCoords[0]+1 || e) {
- writeCharToXY(prevText[0].char,prevText[0].color,prevCoords[0],prevCoords[1]);
- }
- writeCharToXY(prevText[1].char,prevText[1].color,prevCoords[0],prevCoords[1]+1);
- for (let i = 0; i < prevText[2].length; i++) {
- writeCharToXY(prevText[2][i].char,prevText[2][i].color,prevCoords[0]+i,prevCoords[1]+2);
- }
- updateText();
- writeCharToXY("█",YourWorld.Color,coords[0],coords[1]);
- writeCharToXY("|",0,coords[0],coords[1]+1);
- for (let i = 0; i < state.userModel.username.length; i++) {
- writeCharToXY(state.userModel.username[i],0,coords[0]+i,coords[1]+2);
- }
- prevCoords = coords;
- }
- skip = () => {
- let interval = setInterval(() => {
- update(1,prevText[0].char,1);
- if (prevText[0].char == " " || prevText[0].color == 0x008000) {
- clearInterval(interval);
- YourWorld.Color = canSkip >= 100 ? 0x60C000 + ~~(canSkip/4) : 0x008000;
- }
- });
- }
- onkeydown = e => {
- if (e.key.length == 1) {
- update(1,e.key);
- } else if (e.key == "Tab" && canSkip >= 100) {
- skip();
- canSkip -= 100;
- progress.value = canSkip/1000;
- progress.style.filter = `hue-rotate(${~~(canSkip/100)*36}deg) brightness(${1+~~(canSkip/100)/10})`;
- YourWorld.Color = 0xFFBF00;
- } else if (e.key == "Enter") {
- cursorCoords = previousLine;
- moveCursor("down");
- previousLine = cursorCoords;
- } else if (e.key != "Shift" && e.key != "CapsLock") {
- previousLine = cursorCoords;
- }
- }
- onclick = () => {
- update(1);
- previousLine = cursorCoords;
- typingStreak = 0;
- }
- setInterval(() => {update(1)},100);
- w.setFlushInterval(1);
- updateText();
- writeChar = () => {}
- setInterval(() => {
- if (typingStreak > 50) {
- positionX+=(-(cursorCoords[0]+cursorCoords[2]/tileC)*tileW-positionX)/2;
- positionY+=(-(cursorCoords[1]+cursorCoords[3]/tileR)*tileH-positionY)/2;
- w.render();
- }
- },30);
Add Comment
Please, Sign In to add comment