forked from HoloTech/twitch-subathon-timer
Add timer end checking
This commit is contained in:
28
timer.js
28
timer.js
@@ -8,6 +8,8 @@ class Timer {
|
|||||||
constructor(renderer, timer_data) {
|
constructor(renderer, timer_data) {
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
this.destroying = false;
|
this.destroying = false;
|
||||||
|
this.ended = false;
|
||||||
|
|
||||||
//TEMP
|
//TEMP
|
||||||
this.temptime = 15;
|
this.temptime = 15;
|
||||||
|
|
||||||
@@ -34,7 +36,18 @@ class Timer {
|
|||||||
this.leaderboard = timer_data.leaderboard;
|
this.leaderboard = timer_data.leaderboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_ended() {
|
||||||
|
if (!this.ended && this.end_at < new Date()) {
|
||||||
|
this.ended = True;
|
||||||
|
this.renderer.finale();
|
||||||
|
}
|
||||||
|
return this.ended;
|
||||||
|
}
|
||||||
|
|
||||||
render_time() {
|
render_time() {
|
||||||
|
if (this.check_ended()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.renderer.render_time(
|
this.renderer.render_time(
|
||||||
//TEMP
|
//TEMP
|
||||||
this.temptime
|
this.temptime
|
||||||
@@ -43,6 +56,9 @@ class Timer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
if (this.check_ended()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Render goal
|
// Render goal
|
||||||
|
|
||||||
if (this.next_goal != null) {
|
if (this.next_goal != null) {
|
||||||
@@ -151,7 +167,7 @@ class TimerRenderer {
|
|||||||
if (this.scrollboxes[i].id == 'ScrollWrapGoal') {
|
if (this.scrollboxes[i].id == 'ScrollWrapGoal') {
|
||||||
|
|
||||||
// Check if element text overflows
|
// Check if element text overflows
|
||||||
if (this.goal_name.getBoundingClientRect().width > (this.scrollboxes[i].getBoundingClientRect().width * .85) ) {
|
if (this.goal_name.getBoundingClientRect().width > (this.scrollboxes[i].getBoundingClientRect().width * .85)) {
|
||||||
// Toggle animation
|
// Toggle animation
|
||||||
this.goal_name.classList.add("scrollAnim");
|
this.goal_name.classList.add("scrollAnim");
|
||||||
this.goal_namedupe.classList.add("scrollAnim");
|
this.goal_namedupe.classList.add("scrollAnim");
|
||||||
@@ -170,7 +186,7 @@ class TimerRenderer {
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Check if element text overflows
|
// Check if element text overflows
|
||||||
if (this.userboxes[i].getBoundingClientRect().width > (this.scrollboxes[i].getBoundingClientRect().width * .75) ) {
|
if (this.userboxes[i].getBoundingClientRect().width > (this.scrollboxes[i].getBoundingClientRect().width * .75)) {
|
||||||
// Toggle animation
|
// Toggle animation
|
||||||
this.userboxes[i].classList.add("scrollAnim");
|
this.userboxes[i].classList.add("scrollAnim");
|
||||||
this.userdupeboxes[i].classList.add("scrollAnim");
|
this.userdupeboxes[i].classList.add("scrollAnim");
|
||||||
@@ -270,10 +286,10 @@ class TimerRenderer {
|
|||||||
// Bitwise OR done to convert floats to integers if needed
|
// Bitwise OR done to convert floats to integers if needed
|
||||||
this.goal_progress.textContent = String(current | 0) + '/' + String(required | 0)
|
this.goal_progress.textContent = String(current | 0) + '/' + String(required | 0)
|
||||||
|
|
||||||
console.log('ratio' + current/required);
|
console.log('ratio' + current / required);
|
||||||
if (current/required > .02) {
|
if (current / required > .02) {
|
||||||
console.log('%' + (current/required) * 100);
|
console.log('%' + (current / required) * 100);
|
||||||
this.goal_bar.style.maskImage = `linear-gradient(to right, #55CBFF 0%, #55CBFF ${((current/required) - .02)*100}%, transparent ${(current/required)*100}%)`;
|
this.goal_bar.style.maskImage = `linear-gradient(to right, #55CBFF 0%, #55CBFF ${((current / required) - .02) * 100}%, transparent ${(current / required) * 100}%)`;
|
||||||
} else {
|
} else {
|
||||||
this.goal_bar.style.maskImage = `linear-gradient(to right, transparent 0%)`;
|
this.goal_bar.style.maskImage = `linear-gradient(to right, transparent 0%)`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user