Compare commits

..

7 Commits

Author SHA1 Message Date
RolimirKal 02cdfc98dd Bug Fix
Changes:
- If an out of range update is received, set the current progress to zero or max to avoid getting stuck on the default value when the page is loaded after exceeding the goal.
2026-08-20 20:16:00 -04:00
RolimirKal bf578cf830 Art Update
Changes:
- New art
2026-07-31 03:11:10 -04:00
RolimirKal a3dd9c6b19 Bug Fix
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
2026-07-30 10:30:26 -04:00
RolimirKal c89d341651 BugFix
Changes:
- Now pulls goal progress from correct object
- Fixed incorrect acceptable animation range
2026-07-30 08:39:48 -04:00
RolimirKal 72fe8d1abb Merge branch 'main' of https://git.thewisewolf.dev/CarmiCoven/BookBar 2026-07-30 08:25:13 -04:00
RolimirKal cc16e2d9e6 Deconflict
Changes:
- Websocket URL and channel name
2026-07-30 08:15:19 -04:00
RolimirKal b77252b0b1 Animate!
Changes:
- re-enabled reconnecting websocket
- restructured goal progress update logic
- separated test sim and animation logic
- set animation to loop from zero to current progress
- set default goal progress to 25 for clearer troubleshooting
2026-07-30 08:10:29 -04:00
94 changed files with 130 additions and 25 deletions
+2 -2
View File
@@ -81,7 +81,7 @@ p {
background-size: contain;
background-repeat: no-repeat;
background-size: contain;
background-image: url("src/Books/BookBar_v8_f0000.png");
background-image: url("src/Books/BookBar_f0000.png");
}
.barFlashHelper {
position: absolute;
@@ -91,7 +91,7 @@ p {
height: 100%;
background-repeat: no-repeat;
background-size: contain;
background-image: url("src/Books/BookBar_v8_f0000.png");
background-image: url("src/Books/BookBar_f0000.png");
}
#barBack {
}
+125 -20
View File
@@ -1,16 +1,21 @@
window.addEventListener("DOMContentLoaded", () => {
//Create progress bar
const book_bar = new ProgressBar();
//Pat Lilac
const websocket = new ReconnectingWebSocket("wss://lilac.thewisewolf.dev/tracker/timer/ws");
communicate(websocket, book_bar);
});
class ProgressBar {
constructor() {
this.current_progress = 0;
this.current_progress = 25;
this.max_progress = 45;
this.anim_progress = 0;
this.animating = false;
this.simming = false;
this.target_element = document.getElementById("progressBar");
this.bar_back = document.getElementById("barBack");
this.bar_front = document.getElementById("barFront");
@@ -22,42 +27,135 @@ class ProgressBar {
if (index_string.length < 2) {
index_string = "0" + index_string;
}
img_fetcher.src = "src/Books/BookBar_v8_f00" + index_string + ".png";
img_fetcher.src = "src/Books/BookBar_f00" + index_string + ".png";
image_cache.push(img_fetcher);
};
}
//SET NUMBER OF COLORED BOOKS
//Set current campaign progress
setProgress(val) {
if (Number.isInteger(val) && (this.target_element != null) && (this.bar_back != null) && (this.bar_front != null)) {
if (Number.isInteger(val)
&& (val >= 0)
&& (val <= this.max_progress)
&& (val != this.current_progress)) {
this.current_progress = val;
this.anim_progress = 0;
} else {
if (Number.isInteger(val)
&& (val >= this.max_progress)
&& (val != this.current_progress)) {
this.current_progress = this.max_progress;
this.anim_progress = 0;
console.warn("Progress update: Goal Exceeded.")
}
if (Number.isInteger(val)
&& (val <= 0)
&& (val != this.current_progress)) {
this.current_progress = 0;
this.anim_progress = 0;
console.warn("Progress update: Goal Subceeded.")
}
console.warn("Progress update failed.")
}
}
//Render current animation state to the screen
renderProgress(val) {
if (Number.isInteger(val)
&& (this.target_element != null)
&& (this.bar_back != null)
&& (this.bar_front != null)
&& (val >= 0)
&& (val <= this.current_progress)
&& (val <= this.max_progress)) {
let val_string = val.toString();
if (val_string.length < 2) {
val_string = "0" + val_string;
}
this.bar_back.style.backgroundImage = "url(src/Books/BookBar_v8_f00" + val_string + ".png)";
this.bar_back.style.backgroundImage = "url(src/Books/BookBar_f00" + val_string + ".png)";
setTimeout(this.antiFlash.bind(this), 150, val_string, val);
} else {
console.warn("Progress render failed.")
}
}
//Prevent image flicker by pre-loading a version of the image then rendering the top image with a delay
antiFlash(val_string, new_val) {
this.bar_front.style.backgroundImage = "url(src/Books/BookBar_v8_f00" + val_string + ".png)";
if ((new_val >= 0) && (new_val <= this.max_progress)) {
this.current_progress = new_val;
this.bar_front.style.backgroundImage = "url(src/Books/BookBar_f00" + val_string + ".png)";
//Increment the animation ticker (plus an extra round of safety checks)
if ((new_val >= 0)
&& (new_val <= this.current_progress)
&& (this.anim_progress <= this.max_progress)
&& (new_val <= this.max_progress)) {
this.anim_progress = new_val;
}
else {
console.warn("Progress update is out of range.");
console.warn("Anim antiFlash render is out of range.");
}
}
//TEST ANIMATION
//Progress Animation
animProgress() {
//animate
if (this.animating == true) {
if ((this.anim_progress >= 0)
&& (this.anim_progress < this.current_progress)
&& (this.anim_progress < this.max_progress)) {
this.renderProgress(this.anim_progress + 1);
setTimeout(this.animProgress.bind(this), 500);
}
//loop
if (this.anim_progress == this.current_progress) {
setTimeout(this.renderProgress.bind(this, 0), 5000);
setTimeout(this.animProgress.bind(this), 5500);
}
}
}
//Toggle animation on
animStart() {
if (this.animating != true){
this.animating = true;
this.animProgress();
} else {
console.warn("Animation already running");
}
}
//Toggle animation off
animEnd() {
this.animating = false;
}
//TEST SIMULATION
simProgress() {
//sim
if (this.simming == true) {
if (this.current_progress < this.max_progress) {
this.setProgress(this.current_progress + 1);
setTimeout(this.simProgress.bind(this), 500);
setTimeout(this.simProgress.bind(this), 38500);
}
//loop
if (this.current_progress == this.max_progress) {
setTimeout(() => this.setProgress(0), 5000);
setTimeout(this.simProgress.bind(this), 5500);
setTimeout(() => this.setProgress(0), 10000);
setTimeout(this.simProgress.bind(this), 95500);
}
}
}
simStart() {
console.log("starting");
this.simming = true;
this.simProgress();
console.log("started");
}
simEnd() {
console.log("ending");
this.simming = false;
}
}
@@ -97,9 +195,8 @@ class ReconnectingWebSocket {
if (this.closing) {
console.log('Closing Websocket.')
} {
console.warn('WebSocket closed. Reconnecting... (disabled for now)');
//this.reconnect();
//TODO turn that back on ^
console.warn('WebSocket closed. Reconnecting...');
this.reconnect();
}
};
@@ -151,7 +248,8 @@ function communicate(websocket, book_bar) {
console.log("Communicating");
const params = new URLSearchParams(window.location.search);
// INITIALIZE CLASS HERE
book_bar.simProgress();
//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.send(
@@ -176,16 +274,23 @@ function communicate(websocket, book_bar) {
switch (event.method) {
case "setTimer":
//do something with the new data
console.log("set timer: " + event);
book_bar.setProgress(event.reward_progress);
console.log("set timer: " + args.reward_progress);
book_bar.setProgress(args.reward_progress);
//animEnd();
//setTimeout(book_bar.setProgress(args.reward_progress), 7500);
//setTimeout(book_bar.animStart, 7800);
break;
case "noTimer":
//do something default
console.log("no timer: " + event);
console.log("no timer: " + args);
break;
case "endTimer":
//do something for the final time
console.log("end timer: " + event);
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
default:
throw new Error(`Unsupported method requested: ${event.method}.`)
Binary file not shown.

After

Width:  |  Height:  |  Size: 206 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 247 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 268 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 273 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 284 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 295 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 307 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 309 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 319 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 322 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 346 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 350 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 356 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 371 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 380 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 232 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 250 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 255 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 259 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 265 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 270 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 274 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 279 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 282 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 287 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 291 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 296 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 300 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 303 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 307 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 311 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 316 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 320 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 323 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 327 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 329 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 333 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 335 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 338 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 342 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 343 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 347 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 352 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 354 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 358 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 363 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 366 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 368 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 374 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 378 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 380 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 385 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 386 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 389 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 392 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 397 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 400 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 402 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 408 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 408 KiB