Changes:
- Only update if the target progress is different from the current progress
- fix anim loop binding logic
- Comment and warning clarifications
- delay animation start to let websocket connect
This commit is contained in:
2026-07-30 10:30:26 -04:00
parent c89d341651
commit a3dd9c6b19
+16 -6
View File
@@ -38,8 +38,10 @@ class ProgressBar {
setProgress(val) { setProgress(val) {
if (Number.isInteger(val) if (Number.isInteger(val)
&& (val >= 0) && (val >= 0)
&& (val <= this.max_progress)) { && (val <= this.max_progress)
&& (val != this.current_progress)) {
this.current_progress = val; this.current_progress = val;
this.anim_progress = 0;
} else { } else {
console.warn("Progress update failed.") console.warn("Progress update failed.")
} }
@@ -76,7 +78,7 @@ class ProgressBar {
this.anim_progress = new_val; this.anim_progress = new_val;
} }
else { else {
console.warn("Anim update is out of range."); console.warn("Anim antiFlash render is out of range.");
} }
} }
@@ -92,7 +94,7 @@ class ProgressBar {
} }
//loop //loop
if (this.anim_progress == this.current_progress) { if (this.anim_progress == this.current_progress) {
setTimeout(() => this.renderProgress(0), 5000); setTimeout(this.renderProgress.bind(this, 0), 5000);
setTimeout(this.animProgress.bind(this), 5500); setTimeout(this.animProgress.bind(this), 5500);
} }
} }
@@ -113,7 +115,7 @@ class ProgressBar {
this.animating = false; this.animating = false;
} }
//TEST ANIMATION //TEST SIMULATION
simProgress() { simProgress() {
//sim //sim
if (this.simming == true) { if (this.simming == true) {
@@ -179,7 +181,7 @@ class ReconnectingWebSocket {
if (this.closing) { if (this.closing) {
console.log('Closing Websocket.') console.log('Closing Websocket.')
} { } {
console.warn('WebSocket closed. Reconnecting... (disabled for now)'); console.warn('WebSocket closed. Reconnecting...');
this.reconnect(); this.reconnect();
} }
}; };
@@ -232,7 +234,8 @@ function communicate(websocket, book_bar) {
console.log("Communicating"); console.log("Communicating");
const params = new URLSearchParams(window.location.search); const params = new URLSearchParams(window.location.search);
// INITIALIZE CLASS HERE // INITIALIZE CLASS HERE
book_bar.animStart(); //queue animation start after a few seconds to allow for initial status from server
setTimeout(book_bar.animStart.bind(book_bar),5000);
websocket.onopen = () => { websocket.onopen = () => {
websocket.send( websocket.send(
@@ -259,6 +262,9 @@ function communicate(websocket, book_bar) {
//do something with the new data //do something with the new data
console.log("set timer: " + args.reward_progress); console.log("set timer: " + args.reward_progress);
book_bar.setProgress(args.reward_progress); book_bar.setProgress(args.reward_progress);
//animEnd();
//setTimeout(book_bar.setProgress(args.reward_progress), 7500);
//setTimeout(book_bar.animStart, 7800);
break; break;
case "noTimer": case "noTimer":
//do something default //do something default
@@ -267,6 +273,10 @@ function communicate(websocket, book_bar) {
case "endTimer": case "endTimer":
//do something for the final time //do something for the final time
console.log("end timer: " + args); console.log("end timer: " + args);
//book_bar.renderProgress(args.reward_progress);
//book_bar.animEnd();
//setTimeout(book_bar.renderProgress(args.reward_progress), 7500);
//setTimeout(book_bar.animStart, 7800);
break break
default: default:
throw new Error(`Unsupported method requested: ${event.method}.`) throw new Error(`Unsupported method requested: ${event.method}.`)