ProfilePageView: fix winrate
This commit is contained in:
@ -21,7 +21,7 @@ export default class extends AbstractView {
|
|||||||
await this.fillHistory(games);
|
await this.fillHistory(games);
|
||||||
await this.fillStatistics(games);
|
await this.fillStatistics(games);
|
||||||
|
|
||||||
if (this.profile.id === client.me.id)
|
if (!client.me || this.profile.id === client.me.id)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const addFriendButton = document.getElementById('addFriendButton'),
|
const addFriendButton = document.getElementById('addFriendButton'),
|
||||||
@ -78,8 +78,8 @@ export default class extends AbstractView {
|
|||||||
*/
|
*/
|
||||||
async fillStatistics(games)
|
async fillStatistics(games)
|
||||||
{
|
{
|
||||||
let winrateDiv = document.getElementById("winrate");
|
const winrateDiv = document.getElementById("winrate");
|
||||||
|
|
||||||
let win = 0;
|
let win = 0;
|
||||||
let lose = 0;
|
let lose = 0;
|
||||||
|
|
||||||
@ -87,13 +87,17 @@ export default class extends AbstractView {
|
|||||||
if (game.finished === false)
|
if (game.finished === false)
|
||||||
return
|
return
|
||||||
|
|
||||||
if (client.me.id === game.winner.id)
|
if (this.profile.id === game.winner.id)
|
||||||
win++;
|
win++;
|
||||||
else
|
else
|
||||||
lose++;
|
lose++;
|
||||||
});
|
});
|
||||||
|
|
||||||
winrateDiv.innerText = `winrate: ${win + lose === 0 ? "🤓" : win / (win + lose)}`
|
if (games.length) {
|
||||||
|
winrateDiv.innerText = `Winrate: ${win / (win + lose) * 100}%`;
|
||||||
|
} else {
|
||||||
|
winrateDiv.innerText = `Winrate: 🤓`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fillHistory(games)
|
async fillHistory(games)
|
||||||
|
Reference in New Issue
Block a user