🐛 Fixed Score-thing
This commit is contained in:
@@ -29,15 +29,17 @@
|
|||||||
// let data_by_username = {};
|
// let data_by_username = {};
|
||||||
let score_by_username = {};
|
let score_by_username = {};
|
||||||
|
|
||||||
|
const do_sth = () => {
|
||||||
for (const i of new_data) {
|
for (const i of new_data) {
|
||||||
/* data_by_username[i.username] = {
|
|
||||||
answer: i.answer,
|
|
||||||
right: i.right,
|
|
||||||
time_taken: i.time_taken,
|
|
||||||
score: i.score
|
|
||||||
};*/
|
|
||||||
score_by_username[i.username] = i.score;
|
score_by_username[i.username] = i.score;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$: {
|
||||||
|
new_data;
|
||||||
|
score_by_username;
|
||||||
|
do_sth();
|
||||||
|
}
|
||||||
|
|
||||||
let player_names;
|
let player_names;
|
||||||
|
|
||||||
@@ -56,7 +58,16 @@
|
|||||||
// for (let i = 0; i++; i < player_names.length) {
|
// for (let i = 0; i++; i < player_names.length) {
|
||||||
// console.log(data)
|
// console.log(data)
|
||||||
for (const i of player_names) {
|
for (const i of player_names) {
|
||||||
data[i] = score_by_username[i] + data[i];
|
if (isNaN(data[i])) {
|
||||||
|
data[i] = 0;
|
||||||
|
}
|
||||||
|
console.log(score_by_username[i], '1');
|
||||||
|
data[i] = (score_by_username[i] ?? 0) + data[i];
|
||||||
|
}
|
||||||
|
for (const i of new_data) {
|
||||||
|
if (!data[i.username]) {
|
||||||
|
data[i.username] = score_by_username[i.username];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
show_new_score_clicked = true;
|
show_new_score_clicked = true;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -74,7 +85,6 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
<button on:click={show_new_score}>Show new Score</button>
|
|
||||||
<div class="flex justify-center">
|
<div class="flex justify-center">
|
||||||
<div>
|
<div>
|
||||||
<table class="table-auto text-xl">
|
<table class="table-auto text-xl">
|
||||||
@@ -83,8 +93,8 @@
|
|||||||
<th class="p-2 border-b-2 border-b-black">Points</th>
|
<th class="p-2 border-b-2 border-b-black">Points</th>
|
||||||
{#if show_new_score_clicked}
|
{#if show_new_score_clicked}
|
||||||
<th in:fly={{ x: 300 }} class="p-2 border-b-2 border-b-black"
|
<th in:fly={{ x: 300 }} class="p-2 border-b-2 border-b-black"
|
||||||
>Points added</th
|
>Points added
|
||||||
>
|
</th>
|
||||||
{/if}
|
{/if}
|
||||||
</tr>
|
</tr>
|
||||||
{#each player_names as player, i (player)}
|
{#each player_names as player, i (player)}
|
||||||
@@ -96,9 +106,10 @@
|
|||||||
in:fly={{ x: 300 }}
|
in:fly={{ x: 300 }}
|
||||||
class:hidden={i > 3}
|
class:hidden={i > 3}
|
||||||
class="p-2"
|
class="p-2"
|
||||||
class:text-red-600={score_by_username[player] === 0}
|
class:text-red-600={score_by_username[player] === 0 ||
|
||||||
|
score_by_username[player] === undefined}
|
||||||
>
|
>
|
||||||
+{score_by_username[player]}
|
+{score_by_username[player] ?? '0'}
|
||||||
</td>
|
</td>
|
||||||
{/if}
|
{/if}
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -31,24 +31,30 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$: console.log(score_by_username, scores, 'dieter');
|
||||||
for (const i of question_results) {
|
for (const i of question_results) {
|
||||||
score_by_username[i.username] = i.score;
|
score_by_username[i.username] = i.score;
|
||||||
}
|
}
|
||||||
|
|
||||||
$: scores = sortObjectbyValue(scores);
|
$: scores = sortObjectbyValue(scores);
|
||||||
|
|
||||||
for (const i of Object.keys(scores)) {
|
const do_sth = () => {
|
||||||
scores[i] = score_by_username[i] + scores[i];
|
for (const i of Object.keys(score_by_username)) {
|
||||||
|
scores[i] = (score_by_username[i] ?? 0) + (scores[i] ?? 0);
|
||||||
}
|
}
|
||||||
|
scores = scores;
|
||||||
|
};
|
||||||
|
|
||||||
|
do_sth();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div class="flex justify-center h-screen">
|
<div class="flex justify-center h-screen">
|
||||||
<div class="m-auto flex flex-col">
|
<div class="m-auto flex flex-col">
|
||||||
<p class="p-4 bg-black bg-opacity-40 rounded-lg text-2xl">
|
<p class="p-4 bg-black bg-opacity-40 rounded-lg text-2xl">
|
||||||
+{score_by_username[username]}
|
+{score_by_username[username] ?? '0'}
|
||||||
</p>
|
</p>
|
||||||
<p>Total score: {scores[username]}</p>
|
<p>Total score: {scores[username] ?? '0'}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user