Merge branch 'master' of leafbla.de:dominic/waschmarken

This commit is contained in:
Dominic Zimmer 2020-07-17 23:30:38 +02:00
commit f0b30fdd7d
2 changed files with 37 additions and 8 deletions

View File

@ -21,9 +21,8 @@
} }
#scoreboard .bar { #scoreboard .bar {
background-color: chartreuse; height: 1.2em;
width: 80%; border-radius: 0.6em;
height: 0.8em;
} }
</style> </style>

View File

@ -1,5 +1,33 @@
"use strict" "use strict"
const COLORS = [
'#7FD9E2',
// '#8ED4F8',
'#ADCCFF',
// '#D1C2FC',
'#EDBAE9',
// '#FEB5CE',
'#FFB7B2',
// '#F3BE9C',
'#DCC892',
// '#BFD197',
'#A0D7AA',
// '#87DAC6',
];
// https://stackoverflow.com/a/7616484
Object.defineProperty(String.prototype, 'hashCode', {
value: function () {
var hash = 0, i, chr;
for (i = 0; i < this.length; i++) {
chr = this.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
}
});
function render_scoreboard(data) { function render_scoreboard(data) {
const users = Object.values(data.users); const users = Object.values(data.users);
@ -24,6 +52,8 @@ function render_scoreboard(data) {
const score_percent = Math.floor(10 + (user.score - min_score) / (max_score - min_score) * 90) + "%"; const score_percent = Math.floor(10 + (user.score - min_score) / (max_score - min_score) * 90) + "%";
bar.style.width = score_percent; bar.style.width = score_percent;
const color_index = ((user.uuid.hashCode() % COLORS.length) + COLORS.length) % COLORS.length;
bar.style.backgroundColor = COLORS[color_index];
name.innerText = user.name; name.innerText = user.name;
score.innerText = user.score; score.innerText = user.score;
@ -49,4 +79,4 @@ async function update_scoreboard() {
} }
update_scoreboard(); update_scoreboard();
setInterval(update_scoreboard, 1000); // setInterval(update_scoreboard, 1000);