Skip to content

Commit

Permalink
pop_racer
Browse files Browse the repository at this point in the history
  • Loading branch information
nalbam committed Aug 30, 2019
1 parent ffeb7bc commit df8545d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 21 deletions.
18 changes: 16 additions & 2 deletions static/league.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ div {

.lb-items .lb-header>div:nth-child(2),
.lb-items .lb-row>div:nth-child(2) {
/* font-weight: bold; */
margin-right: auto;
text-align: left;
width: 35%;
Expand Down Expand Up @@ -128,10 +129,10 @@ div {

.pop-layer .pop-bg {
background: #000;
filter: alpha(opacity=50);
filter: alpha(opacity=70);
height: 100%;
left: 0;
opacity: .6;
opacity: .7;
position: absolute;
top: 0;
width: 100%;
Expand All @@ -153,9 +154,22 @@ div {
.pop-layer .pop-container .pop-racer {
padding: 1%;
font-size: 10vw;
font-weight: bold;
}

.pop-layer .pop-container .pop-time {
padding: 1%;
font-size: 5vw;
}

.pop-rank1 {
color: #fbdf47;
}

.pop-rank2 {
color: #cacacd;
}

.pop-rank3 {
color: #fac07b;
}
42 changes: 23 additions & 19 deletions static/league.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,39 @@ function reload() {
}

function reloaded(res) {
let isNewRacer = false;
let isNew = false;
if (items.length > 0 && items.length !== res.items.length) {
isNewRacer = true;
isNew = true;
}

let newRecordPos;
let newRecordName;
let newRecordTime;
let rank;
let racerName;
let lapTime;

res.items.sort(compare);

for (let i = 0; i < items.length; i++) {
if (items[i].lapTime !== res.items[i].lapTime) {
newRecordPos = i + 1;
newRecordName = res.items[i].racerName;
newRecordTime = res.items[i].lapTime;
rank = i + 1;
racerName = res.items[i].racerName;
lapTime = res.items[i].lapTime;
break;
}
}

if (isNewRacer && !newRecordName) {
if (isNew && !racerName) {
let j = res.items.length - 1;
newRecordPos = res.items.length;
newRecordName = res.items[j].racerName;
newRecordTime = res.items[j].lapTime;
rank = res.items.length;
racerName = res.items[j].racerName;
lapTime = res.items[j].lapTime;
}

if (isNewRacer || newRecordName) {
console.log(`new ${isNewRacer} ${newRecordPos} ${newRecordName} ${newRecordTime}`);
if (isNewRacer) {
popup('New Challenger!', newRecordName, newRecordTime);
if (isNew || racerName) {
console.log(`new ${isNew} ${rank} ${racerName} ${lapTime}`);
if (isNew) {
popup('New Challenger!', rank, racerName, lapTime);
} else {
popup('New Record!', newRecordName, newRecordTime);
popup('New Record!', rank, racerName, lapTime);
}
}

Expand Down Expand Up @@ -124,14 +124,18 @@ $(function () {
}, 10000);
});

function popup(title, racer, time) {
function popup(title, rank, racer, time) {
document.querySelector('.pop-title').innerText = title;
document.querySelector('.pop-racer').innerText = racer;
document.querySelector('.pop-time').innerText = time;

let pop_racer = document.querySelector('.pop-racer');
pop_racer.classList.add(`pop-racer${rank}`);
pop_racer.innerText = racer;

$('.pop-layer').fadeIn();

setTimeout(function () {
$('.pop-layer').fadeOut();
pop_racer.classList.remove(`pop-racer${rank}`);
}, 9000);
}

0 comments on commit df8545d

Please sign in to comment.