progress is at like 25%; parsing is hard

This commit is contained in:
TheShinyMelon 2022-12-06 12:42:16 +01:00
parent f4eb982e72
commit d08c4691ac
2 changed files with 103 additions and 26 deletions

100
5/script.js Normal file
View File

@ -0,0 +1,100 @@
let output = document.getElementById("output");
let input;
let linesArr;
let parsedArr = [];
let cmdArr = [];
function readFile(input) {
let file = input.files[0];
let fileReader = new FileReader();
fileReader.readAsText(file);
fileReader.onload = function() {
input = fileReader.result;
linesArr = input.split("\n");
};
fileReader.onerror = function() {
alert(fileReader.error);
};
}
let start = document.getElementById("start");
start.addEventListener("mouseover", () => {
start.innerHTML = "pwease pwess mee hawwd mastaaa! ~^o^~"
});
start.addEventListener("mouseout", () => {
start.innerHTML = "sowwy mastaa! Ow0;"
});
start.addEventListener("click", () => {
parseArr(); //continue with parsedArr
parseCmd();
});
function parseArr() { //parsing is hard
let stackArr = [];
let cleanArr = [];
for(let l=0; l<9; l++) {
let tmpLine = [];
for(let i=0; i<linesArr[l].length; i++) {
if(linesArr[l].charAt(i)=='[') tmpLine[i+1] = linesArr[l].charAt(i+1);
if(l==8) {
if(typeof(parseInt(linesArr[l].charAt(i)))=="number") tmpLine[i] = linesArr[l].charAt(i);
if(tmpLine[i] == ' ') tmpLine[i]=undefined;
}
}
stackArr[l] = tmpLine;
}
console.log("stackArr", stackArr);
for(let i=0; i<stackArr.length-1; i++) {
let tmpLine = [];
let c=0;
for(let j=0; j<stackArr[i].length; j++) {
if(stackArr[8][j]!=undefined) {
tmpLine[c] = stackArr[i][j]
c++;
}
}
cleanArr[i] = tmpLine;
}
console.log("cleanArr", cleanArr);
for(let i=0; i<cleanArr.length; i++) {
tmpLine = [];
let c=7;
for(let j=0; j<8; j++) {
if(cleanArr[j][i] != undefined) {
tmpLine[c] = cleanArr[j][i];
}
c--;
}
parsedArr[i] = tmpLine;
}
}
function move(a, s, d) {
for(let i=0; i<a; i++) {
parsedArr[s-1][getTopPos()] = parsedArr[d-1][getTopPos()];
}
}
function getTopPos(s) {
let o=0;
for(let i=0; i<parsedArr[s].length; i++) {
if(parsedArr[s][i]==undefined) {
o=i-1;
break;
}
}
return o;
}
function parseCmd() {
for(let i=10; i<linesArr.length; i++) {
for(let j=0; j<linesArr[i].length; j++) {
if(linesArr[i].charAt(j)=='m') cmdArr[i-10] = linesArr[i].substr(j+2,1);
if(linesArr[i].charAt(j)=='f') cmdArr[i-10] = linesArr[i].substr(j+2,1);
if(linesArr[i].charAt(j)=='t') cmdArr[i-10] = linesArr[i].substr(j+2,1);
}
}
}

View File

@ -1,34 +1,11 @@
<!DOCTYPE html>
<body>
<h3>Input-File: </h3><input onchange="readFile(this)" type="file">
<h3>Input-File: </h3><input onchange='readFile(this)' type='file'>
<button id="start">pwess mee! UwU~</button>
<hr>
<h3>Output:</h3>
<p id=output>OwO Mastaaw, I dow't like bewwing in a webbwosaaww!! I feew dizzy.. -o- Anyway hewe's youww numbaaw UmU~ :</p>
<p id=output>OwO Mastaaw, I dow't like bewwing in a webbwosaaww!! I feew dizzy.. OwO° Anyway hewe's youww numbaaw UmU~ :</p>
</body>
<script>
let output = document.getElementById("output");
let input;
function readFile(input) {
let file = input.files[0];
let fileReader = new FileReader();
fileReader.readAsText(file);
fileReader.onload = function() {
input = fileReader.result;
};
fileReader.onerror = function() {
alert(fileReader.error);
};
}
let start = document.getElementById("start");
start.addEventListener("mouseover", () => {
start.innerHTML = "pwease pwess mee hawwd mastaaa! UwU~"
});
start.addEventListener("click", () => {
alert(input);
});
</script>
<script src='script.js'></script>