Skip to content

Commit

Permalink
add a progress bar, remove cli-progress dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
nquenoui committed Dec 29, 2020
1 parent a508312 commit d56aa4b
Show file tree
Hide file tree
Showing 47 changed files with 75 additions and 2,646 deletions.
70 changes: 29 additions & 41 deletions button_action.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ button = document.getElementById("button");
username_input = document.getElementById("username");
apikey_input = document.getElementById("apikey");
matchid_input = document.getElementById("matchid");
eta_div = document.getElementById("etatdiv")
eta_text = document.getElementById("etatext");
subProgressBar = document.getElementById("myProgress");
progressBar = document.getElementById("myBar");
matchid_input.value = "5003935577";
apikey_input.value = "RGAPI-aff8fe37-d6cd-46af-9312-e36bc6065baf";
console.log(button);
console.log(eta_text);

button.addEventListener("click", function(){
eta_text.classList.remove("hidden");
eta_text.innerHTML = "Reset data";
eta_div.classList.remove("hidden");
changeETA("Reset du programme");
resetData();
eta_text.innerHTML = "Ajust settings";
changeETA("Ajout des valeurs")
settings.accountName = username_input.value;
settings.APIKey = apikey_input.value;
settings.matchId = matchid_input.value;
Expand All @@ -28,7 +33,7 @@ button.addEventListener("click", function(){
(async () => {
game = null;
timeline = null;
eta_text.innerHTML = "Recherche de la game";
changeETA("Recherche de la game...")
//************Retrieve summoner and game*****************
if(settings.accountName != ""){
const playerAPI = await fetch("https://"+settings.server+".api.riotgames.com/lol/summoner/v4/summoners/by-name/"+settings.accountName+"?api_key="+settings.APIKey);
Expand Down Expand Up @@ -56,7 +61,7 @@ button.addEventListener("click", function(){
await initPlayersTeam();

//console.log(game);
eta_text.innerHTML = "Player ING ?";
changeETA("Vérification de l'existance de la partie")
//Check if player is now in game (Expect in coop vs IA). If yes, push the number of blue player
if(game.gameId == undefined){
console.log("This player is not in game / This game don't exist !")
Expand All @@ -69,7 +74,7 @@ button.addEventListener("click", function(){
});
//console.log(nbplayer_blueside);
}
eta_text.innerHTML = "Version ?";
changeETA("Verification de la version...")
//*************Retrieve actual version or old version (depends if the match is now or played)*****************
version = null;
if (settings.accountName != ""){
Expand All @@ -95,57 +100,40 @@ button.addEventListener("click", function(){
createChampJSON(jsonChamp);
createSpellJSON(jsonSpell);
console.log("Starting download of Perks...");
const b1 = new cliProgress.SingleBar({
format: 'Progress |' + '{bar}' + '| {percentage}% || {value}/{total} pictures',
barCompleteChar: '\u2588',
barIncompleteChar: '\u2591',
hideCursor: true
});
b1.start(tab_runes.length, 0, {
speed: "N/A"
});
changeETA("Téléchargement de la version de la partie : Téléchargement des runes")
subProgressBar.classList.remove("hidden");

for(let a=0; a < tab_runes.length; a++){
await downloadPerk(tab_runes[a]);
await b1.increment();
progressBar.style.width = ((a/tab_runes.length)*100) + "%";
progressBar.innerHTML = ((a/tab_runes.length)*100).toFixed(2) + "%";
}
b1.stop();
resetProgressBar();
// b1.stop();
console.log("Downloaded Perks !");

console.log("Starting download of champions...");
const b2 = new cliProgress.SingleBar({
format: 'Progress |' + '{bar}' + '| {percentage}% || {value}/{total} pictures',
barCompleteChar: '\u2588',
barIncompleteChar: '\u2591',
hideCursor: true
});
b2.start(tab_champ.length, 0, {
speed: "N/A"
});
changeETA("Téléchargement de la version de la partie : Téléchargement des champions")
subProgressBar.classList.remove("hidden");

for(let b=0; b < tab_champ.length; b++){
await downloadChamp(tab_champ[b]);
await b2.increment();
progressBar.style.width = ((b/tab_champ.length)*100) + "%";
progressBar.innerHTML = ((b/tab_champ.length)*100).toFixed(2) + "%";
}
b2.stop();
resetProgressBar();
console.log("Downloaded champions !");

console.log("Starting download of Spell...");
const b3 = new cliProgress.SingleBar({
format: 'Progress |' + '{bar}' + '| {percentage}% || {value}/{total} pictures',
barCompleteChar: '\u2588',
barIncompleteChar: '\u2591',
hideCursor: true
});
b3.start(tab_spell.length, 0, {
speed: "N/A"
});
changeETA("Téléchargement de la version de la partie : Téléchargement des sorts")
subProgressBar.classList.remove("hidden");
for(let c=0; c < tab_spell.length; c++){
await downloadSpell(tab_spell[c]);
b3.increment();
progressBar.style.width = ((c/tab_spell.length)*100) + "%";
progressBar.innerHTML = ((c/tab_spell.length)*100).toFixed(2) + "%";
}
b3.stop();
resetProgressBar();
console.log("Downloaded Spell !");
changeETA("Version de la partie téléchargé...")

} else {
//Else, just load perks
Expand Down Expand Up @@ -187,6 +175,6 @@ button.addEventListener("click", function(){
generateImagePerks();
console.log("Picture generate !");
console.log("Picture generate !");
eta_text.classList.add("hidden");
eta_div.classList.add("hidden");
})();
}, false);
Binary file added default/loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,16 @@ async function createArrayPlayer(){
});
}

function resetProgressBar(){
subProgressBar.classList.add("hidden");
progressBar.innerHTML = "0%"
progressBar.style.width = "0%"
}

function changeETA(str){
eta_text.innerHTML = str;
}

function resetData(){
game = null;
timeline = null;
Expand Down
19 changes: 11 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<title>Hello World!</title>
<title>Image Generator for League Stream</title>
</head>
<body>
<h1>Hello World!</h1>
<button id="button">Test</button>
We are using Node.js <span id="node-version"></span>,
Chromium <span id="chrome-version"></span>,
and Electron <span id="electron-version"></span>.
<h1>Image Generator for League Stream</h1>
<div>
<span>Username :</span>
<input type="text" id="username" name="username" required>
Expand All @@ -24,8 +20,15 @@ <h1>Hello World!</h1>
<span>API Key :</span>
<input type="text" id="apikey" name="apikey" required>
</div>
<div>
<p id="etatext" class="hidden">blablabla</p>
<button id="button">Generate</button>
<div id="etatdiv" class="hidden">
<div>
<img src="default/loading.gif" width="40px" height="40px"/>
<span id="etatext">blablabla</span>
</div>
<div id="myProgress" class="hidden">
<div id="myBar">0%</div>
</div>
</div>

<!-- You can also require other files to run in this process -->
Expand Down
163 changes: 0 additions & 163 deletions node_modules/cli-progress/CHANGES.md

This file was deleted.

24 changes: 0 additions & 24 deletions node_modules/cli-progress/LICENSE.md

This file was deleted.

Loading

0 comments on commit d56aa4b

Please sign in to comment.