Skip to content

Commit 9f3b6d5

Browse files
committed
add custom rng (WIP)
1 parent 39948bd commit 9f3b6d5

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

index.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ <h2>Manage</h2>
1717
</div>
1818
<div class="buttons">
1919
<div>
20-
<h2>Stackable (Up)</h2>
20+
<h2><input type="checkbox" id="uprng" checked>&nbsp;Stackable (Up)</h2>
2121
</div>
2222
<div>
23-
<h2>Stackable (Down)</h2>
23+
<h2><input type="checkbox" id="downrng" checked>&nbsp;Stackable (Down)</h2>
2424
</div>
2525
<div>
26-
<h2>Overlap</h2>
26+
<h2><input type="checkbox" id="overlaprng" checked>&nbsp;Overlap</h2>
2727
</div>
2828
<div>
29-
<h2>Joiners & Misc.</h2>
29+
<h2><input type="checkbox" id="joinrng">&nbsp;Joiners & Misc.</h2>
3030
</div>
3131
</div>
3232
<script src="./button.js" defer></script>

index.js

+39-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ waitForElm('.buttons > div:last-child > button:last-child').then((elm) => {
2424
addRand.addEventListener('click', function() {
2525
while (i != 0) {
2626
if (!multiMode) {
27-
textArea.value += characters[Math.floor(Math.random() * 163)].innerText;
27+
textArea.value += characters[getRandomChar()].innerText;
2828
} else {
29-
multiArea.value += characters[Math.floor(Math.random() * 163)].innerText;
29+
multiArea.value += characters[getRandomChar()].innerText;
3030
}
3131
i--
3232
};
@@ -50,7 +50,7 @@ waitForElm('.buttons > div:last-child > button:last-child').then((elm) => {
5050
})
5151

5252

53-
function waitForElm(selector) {
53+
function waitForElm(selector) { // https://stackoverflow.com/a/61511955
5454
return new Promise(resolve => {
5555
if (document.querySelector(selector)) {
5656
return resolve(document.querySelector(selector));
@@ -69,4 +69,40 @@ function waitForElm(selector) {
6969
subtree: true
7070
});
7171
});
72+
}
73+
74+
function getRandomChar() { // TODO: Impove this
75+
let uprng = document.getElementById('uprng').checked
76+
let downrng = document.getElementById('downrng').checked
77+
let overlaprng = document.getElementById('overlaprng').checked
78+
let joinrng = document.getElementById('joinrng').checked
79+
let upchars = 52//lineCount('./chars/up.txt')
80+
let downchars = 40//lineCount('./chars/down.txt')
81+
let overlapchars = 67//lineCount('./chars/overlap.txt')
82+
let joinchars = 4//lineCount('./chars/join.txt')
83+
let char = Math.floor(Math.random() * (upchars + downchars + overlapchars + joinchars + 1))
84+
console.log(char + ' ' + upchars)
85+
if (char <= upchars && uprng) { // TODO: I hate this must fix
86+
return char
87+
} else if (char <= upchars + downchars && char >= upchars && downrng) {
88+
return char
89+
} else if (char <= upchars + downchars + overlapchars
90+
&& char >= upchars + downchars && overlaprng) {
91+
return char
92+
} else if (char <= upchars + downchars + overlapchars + joinchars
93+
&& char >= upchars + downchars + overlapchars && joinrng) { // Fails if only join selected, too much recursion
94+
return char
95+
} else {
96+
return getRandomChar()
97+
}
98+
}
99+
100+
function lineCount(file) {
101+
return fetch(file)
102+
.then(response => response.text())
103+
.then(fileContent => {
104+
const lines = fileContent.split('\n');
105+
console.log(lines.length)
106+
return lines.length;
107+
})
72108
}

0 commit comments

Comments
 (0)