Skip to content

Commit 49b13c1

Browse files
committed
add progress counter
1 parent 43b656f commit 49b13c1

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ <h3 class="widget-text">A heading widget...</h3>
136136
<script type="module" src="/src/main.ts"></script>
137137
</div>
138138
<footer>
139+
<p hidden id="progress-indicator" style="text-align: left;">
140+
Working... (<span id="progress-indicator-percentage">0</span>%) &nbsp;∗&nbsp;&nbsp;
141+
</p>
139142
<p>
140143
Developed and maintained with
141144
<svg

src/datapack_changes.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,13 @@ export class DatapackModifier {
6767

6868
public async applyChanges(datapacks: ReadonlyArray<Datapack>, export_settings: ExportSettings) {
6969
console.time("[DatapackModifier] Applied changes to packs");
70+
let progress = 0; let progress_max = Object.keys(this.changeQueue).length;
7071

7172
// Apply changes to files
7273
for (const change of this.changeQueue) {
73-
await this.applyChange(change);
74+
await this.applyChange(change).then(
75+
() => {progress++; document.getElementById("progress-indicator-percentage")!.innerText = Math.round(progress / progress_max * 100).toString();}
76+
);
7477
}
7578

7679
// Cache with changes created -> write to zip
@@ -85,10 +88,13 @@ export class DatapackModifier {
8588

8689
if (export_settings.modifiedOnly == false) {
8790
const dpZip = datapacks.find((dp) => dp.id === pack_id)?.zip!;
91+
progress_max += Object.keys(dpZip.files).length;
8892

8993
for (const file_name in dpZip.files) {
9094
if (file_name in dpZip.files) {
91-
const file_content = await dpZip.files[file_name].async("base64");
95+
const file_content = await dpZip.files[file_name].async("base64").then(
96+
() => {progress++; document.getElementById("progress-indicator-percentage")!.innerText = Math.round(progress / progress_max * 100).toString();}
97+
);
9298
packs[pack_id].file(file_name, file_content, {base64: true});
9399
}
94100
}

src/main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,15 @@ exportButtonElement.addEventListener("click", exportButtonClicked, { passive: tr
115115

116116
function exportButtonClicked() {
117117
console.info("Datapack export beginning...");
118+
document.getElementById("progress-indicator")!.hidden = false;
118119

119120
const export_settings = getExportSettings();
120121

121122
datapackStore.getAll().forEach((datapack) => {
122123
datapack.instancedConfig?.apply();
123124
});
124125

125-
DatapackModifierInstance.applyChanges(datapackStore.getAll(), export_settings);
126+
DatapackModifierInstance.applyChanges(datapackStore.getAll(), export_settings).then(
127+
() => {document.getElementById("progress-indicator")!.hidden = true;}
128+
);
126129
}

style.css

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,18 @@ input[type="range"]::-moz-range-thumb {
297297
}
298298

299299
footer {
300+
display: flex;
301+
width: 100%;
302+
flex-direction: row;
303+
justify-content: space-between;
304+
align-content: center;
305+
align-items: center;
306+
justify-content: center;
307+
300308
p {
301309
margin: 0;
310+
text-align: center;
302311
}
303-
304312
svg {
305313
display: inline-block;
306314
vertical-align: middle;

0 commit comments

Comments
 (0)