Skip to content

Commit 9eb267a

Browse files
NSPC911NSPBot911
andauthored
[webUI] add 'Mine then Craft' toggle (#41)
Co-authored-by: NSPBot911 <176916861+NSPBot911@users.noreply.github.com>
1 parent a8f905d commit 9eb267a

File tree

6 files changed

+426
-261
lines changed

6 files changed

+426
-261
lines changed

webUI/app.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,14 @@ function updateSelectedConflictsActiveColor() {
271271

272272
function updateDownloadButton(st) {
273273
const downloadButton = document.querySelector(".download-selected-button");
274-
if (st["raw"].length == 0) {
274+
if (
275+
st["raw"].length == 0 ||
276+
(document.querySelector(
277+
".devtools-toggle-mine-then-craft input[type='checkbox']",
278+
).checked &&
279+
Number(numberElement.textContent) <
280+
getSelectedTweaks()["raw"].length * 20)
281+
) {
275282
downloadButton.disabled = true;
276283
} else {
277284
downloadButton.disabled = false;
@@ -454,7 +461,8 @@ function toggleCategory(label) {
454461

455462
// i wonder what this is for
456463
function downloadSelectedTweaks() {
457-
// set min_engine_version
464+
// get selected tweaks
465+
const jsonData = getSelectedTweaks();
458466
document.querySelector(".loading-screen").style =
459467
"opacity: 1; pointer-events: all;";
460468
var mcVersion = document.getElementById("mev").value;
@@ -474,8 +482,6 @@ function downloadSelectedTweaks() {
474482
}
475483
packName = packName.replaceAll("/", "-");
476484
consoler("download", "cyan", `Pack Name is set to ${packName}`, "white");
477-
// get selected tweaks
478-
jsonData = getSelectedTweaks();
479485
// fetch
480486
fetchPack("https", jsonData, packName, mcVersion);
481487
}
@@ -545,6 +551,22 @@ function fetchPack(protocol, jsonData, packName, mcVersion) {
545551
OreUI.becomeEnabled(downloadbutton);
546552
statusElement.innerText = "";
547553
document.querySelector(".loading-screen").removeAttribute("style");
554+
// do the minethencraft stuff
555+
if (
556+
document.querySelector(
557+
".devtools-toggle-mine-then-craft input[type='checkbox']",
558+
).checked
559+
) {
560+
const numberElement = document.querySelector(
561+
"#mineThenCraftPoints > .number",
562+
);
563+
// if it fails, skill issue
564+
numberElement.innerText =
565+
Number(numberElement.textContent) - jsonData["raw"].length * 20;
566+
if (Number(numberElement.textContent) > jsonData["raw"].length * 20) {
567+
document.querySelector(".download-selected-button");
568+
}
569+
}
548570
})
549571
.catch(async (error) => {
550572
consoler("error", "red", `Error Dump: ${error}`, "white");
@@ -791,3 +813,6 @@ document.querySelectorAll("input[type=checkbox]").forEach((checkbox) => {
791813
});
792814

793815
loadedParamsChecker();
816+
document
817+
.querySelector(".devtools-toggle-mine-then-craft input[type='checkbox']")
818+
.click();

webUI/extra.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/* other vars necessary */
22
const serverip = "localhost";
33
const textures = [
4-
{ src: "images/blocks/stone.png", probability: 0.618 },
5-
{ src: "images/blocks/copper_ore.png", probability: 0.128 },
6-
{ src: "images/blocks/coal_ore.png", probability: 0.128 },
7-
{ src: "images/blocks/iron_ore.png", probability: 0.064 },
8-
{ src: "images/blocks/lapis_ore.png", probability: 0.032 },
9-
{ src: "images/blocks/redstone_ore.png", probability: 0.016 },
10-
{ src: "images/blocks/gold_ore.png", probability: 0.008 },
11-
{ src: "images/blocks/emerald_ore.png", probability: 0.004 },
12-
{ src: "images/blocks/diamond_ore.png", probability: 0.002 },
4+
{ src: "stone.png", probability: 0.59 },
5+
{ src: "copper_ore.png", probability: 0.128 },
6+
{ src: "coal_ore.png", probability: 0.128 },
7+
{ src: "iron_ore.png", probability: 0.064 },
8+
{ src: "lapis_ore.png", probability: 0.032 },
9+
{ src: "redstone_ore.png", probability: 0.032 },
10+
{ src: "gold_ore.png", probability: 0.016 },
11+
{ src: "emerald_ore.png", probability: 0.008 },
12+
{ src: "diamond_ore.png", probability: 0.002 },
1313
];
1414

1515
/* consoler object */
@@ -50,8 +50,9 @@ function selectTexture() {
5050
return texture.src;
5151
}
5252
}
53+
// on the off chance that it breaks
54+
return "stone.png";
5355
}
54-
5556
function createTiles() {
5657
const container = document.getElementById("background-container");
5758
const numColumns = Math.ceil(window.innerWidth / 100) + 2;
@@ -63,7 +64,9 @@ function createTiles() {
6364
for (let j = 0; j < numRows; j++) {
6465
const tile = document.createElement("div");
6566
tile.className = "tile";
66-
tile.style.backgroundImage = `url("${selectTexture()}")`;
67+
const tile_image = `${selectTexture()}`;
68+
tile.style.backgroundImage = `url("images/blocks/${tile_image}")`;
69+
tile.dataset.type = tile_image;
6770
rowDiv.appendChild(tile);
6871
}
6972
container.appendChild(rowDiv);
@@ -92,6 +95,13 @@ createTiles();
9295

9396
window.addEventListener("resize", createTiles);
9497

98+
// utility for miner.js
99+
function updateTile(element) {
100+
const tile_image = `${selectTexture()}`;
101+
element.style.backgroundImage = `url("images/blocks/${tile_image}")`;
102+
element.dataset.type = tile_image;
103+
}
104+
95105
// Handle Loading Screen
96106
const loading_screen_element = document.querySelector(".loading-screen");
97107
if (Math.random() <= 0.9) {

webUI/index.html

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ <h3>
134134
</div>
135135
<div class="devtools-toggle-mine-then-craft">
136136
<label class="switch">
137-
<input disabled="" type="checkbox"/>
137+
<input checked="" type="checkbox"/>
138138
<span class="slider">
139139
</span>
140140
</label>
@@ -174,10 +174,18 @@ <h3>
174174
Unselect?
175175
</div>
176176
</div>
177+
<div id="mineThenCraftPoints" oreui-color="purple" oreui-type="general">
178+
<span class="number">
179+
0
180+
</span>
181+
points
182+
</div>
177183
<div class="capture-exit" onclick="closePanel();">
178184
</div>
179185
<script src="extra.js">
180186
</script>
187+
<script src="miner.js">
188+
</script>
181189
<div class="image-container" onclick="showDevToolsPanel();">
182190
<img alt="Resource Packs" id="title" src="images/title.png"/>
183191
</div>
@@ -186,6 +194,9 @@ <h3>
186194
<input id="searchBar" oninput="filterPacks()" oreui-color="dark" oreui-type="input" placeholder="Search for a pack..." type="text"/>
187195
<div class="search-results" id="searchResults" oreui-color="dark" oreui-type="general">
188196
</div>
197+
<div id="startMining" onclick="toggleViewAll(this)" oreui-active-color="green" oreui-color="dark" oreui-type="button" style="--bezel-size: 0px">
198+
Start Mining
199+
</div>
189200
</div>
190201
<div class="category">
191202
<div class="category-label" onclick="toggleCategory(this);" oreui-color="dark" oreui-type="button">
@@ -7963,46 +7974,44 @@ <h3>
79637974
</div>
79647975
</div>
79657976
<div class="download-container">
7966-
<input id="fileNameInput" oreui-color="dark" oreui-type="input" placeholder="Enter Pack name" type="text">
7967-
<select id="mev" name="mev" oreui-color="dark" oreui-type="general">
7968-
<option value="1.21.70">
7969-
1.21.70
7970-
</option>
7971-
<option value="1.21.0">
7972-
1.21
7973-
</option>
7974-
<option value="1.20.0">
7975-
1.20
7976-
</option>
7977-
<option value="1.19.0">
7978-
1.19
7979-
</option>
7980-
<option value="1.18.0">
7981-
1.18
7982-
</option>
7983-
<option value="1.17.0">
7984-
1.17
7985-
</option>
7986-
<option value="1.16.0">
7987-
1.16
7988-
</option>
7989-
</select>
7990-
<div class="zipinputcontainer" oreui-color="purple" oreui-type="button">
7991-
<input id="zipInput" type="file">
7992-
<span class="selectedFile">
7993-
Upload Pack
7994-
</span>
7995-
</input>
7996-
</div>
7997-
<button class="download-selected-button" disabled="" onclick="downloadSelectedTweaks()" oreui-color="dark" oreui-type="button">
7998-
Download
7999-
</button>
8000-
<div id="selected-tweaks" oreui-color="dark" oreui-type="general">
8001-
<div class="tweak-list-pack" no-pack="">
8002-
Select some packs and see them appear here!
8003-
</div>
7977+
<input id="fileNameInput" oreui-color="dark" oreui-type="input" placeholder="Enter Pack name" type="text"/>
7978+
<select id="mev" name="mev" oreui-color="dark" oreui-type="general">
7979+
<option value="1.21.70">
7980+
1.21.70
7981+
</option>
7982+
<option value="1.21.0">
7983+
1.21
7984+
</option>
7985+
<option value="1.20.0">
7986+
1.20
7987+
</option>
7988+
<option value="1.19.0">
7989+
1.19
7990+
</option>
7991+
<option value="1.18.0">
7992+
1.18
7993+
</option>
7994+
<option value="1.17.0">
7995+
1.17
7996+
</option>
7997+
<option value="1.16.0">
7998+
1.16
7999+
</option>
8000+
</select>
8001+
<div class="zipinputcontainer" oreui-color="purple" oreui-type="button">
8002+
<input id="zipInput" type="file"/>
8003+
<span class="selectedFile">
8004+
Upload Pack
8005+
</span>
8006+
</div>
8007+
<button class="download-selected-button" disabled="" onclick="downloadSelectedTweaks()" oreui-color="dark" oreui-type="button">
8008+
Download
8009+
</button>
8010+
<div id="selected-tweaks" oreui-color="dark" oreui-type="general">
8011+
<div class="tweak-list-pack" no-pack="">
8012+
Select some packs and see them appear here!
80048013
</div>
8005-
</input>
8014+
</div>
80068015
</div>
80078016
<script src="app.js">
80088017
</script>

0 commit comments

Comments
 (0)