From e3ec74cfbdf2428acb849a16b9ee6311020630a8 Mon Sep 17 00:00:00 2001 From: David Gay Date: Fri, 4 Jun 2021 09:59:32 -0400 Subject: Finishing timer improvements --- CHANGELOG.md | 8 ++++---- app/javascript/controllers/timer_controller.js | 19 ++++++++++--------- app/views/application/_timer.html.erb | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7769a4..d793a17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,8 @@ All notable changes to this project will be documented in this file. ## [0.1.6] - 2021-06-04 -Note that from this point foward, I am not explicitly listing the activities required to make the items, hearth -amenities, etc that are added unless they are special in some way. +Note that from this point foward, I am not explicitly listing the addition of activities required to make the items, +hearth amenities, etc that are being added unless they warrant explicit mention for some reason. ### Added - Current activity, timer, results, and conditions (boons & banes) are now always visible. Most are located in a new box @@ -20,7 +20,7 @@ amenities, etc that are added unless they are special in some way. ### Changed - Improved accuracy and feel of timer. It now starts counting down immediately, whereas before there was an - uncomfortable delay. + uncomfortable delay. There is also no impact on the timer when changing pages; it will continue correctly. - Bazaar no longer displays your orders under "Buy Orders" or "Sell Orders". Now your own orders are only visible in the "Your Orders" section. - Remaining duration of conditions and accumulated rested time are now expressed in "human" terms instead of seconds. @@ -37,7 +37,7 @@ amenities, etc that are added unless they are special in some way. ### Fixed - No blank line was being added to combat activity results if the activity was stopped due to being too wounded. -- Beastslay activity in the Killing Fields was called "Slay in [the the](https://en.wikipedia.org/wiki/The_The) +- Beastslay activity in the Killing Fields was named "Slay in [the the](https://en.wikipedia.org/wiki/The_The) Killing Fields". ## [0.1.5] - 2021-06-03 diff --git a/app/javascript/controllers/timer_controller.js b/app/javascript/controllers/timer_controller.js index ef741bf..e85e7ca 100644 --- a/app/javascript/controllers/timer_controller.js +++ b/app/javascript/controllers/timer_controller.js @@ -5,35 +5,36 @@ export default class extends Controller { static targets = [ "timer" ]; static values = { - start: Number, + counter: Number, postUrl: String, } - initialize() { - this.counter = this.startValue; - this.timerTarget.textContent = this.counter; + connect() { + if (!this.timerInterval) this.startUpdating(); + this.timerTarget.textContent = this.counterValue; this.postFailures = 0; - this.startUpdating(); } startUpdating() { let controller = this; - this.timerInterval = setInterval(() => { + controller.timerInterval = setInterval(() => { if (controller.postFailures >= 5) { alert("An error occurred. Please submit a bug report, explaining what you were doing when it occurred."); clearInterval(controller.timerInterval); return; } - if (controller.counter > 0) controller.counter--; + if (controller.counterValue > 0) controller.counterValue--; - if (controller.counter > 0) { - controller.timerTarget.textContent = controller.counter.toString(); + if (controller.counterValue > 0) { + controller.timerTarget.textContent = controller.counterValue.toString(); } else { Rails.ajax({ type: "POST", url: controller.postUrlValue, success: () => { + clearInterval(controller.timerInterval); + controller.timerInterval = null; controller.postFailures = 0; }, error: () => { diff --git a/app/views/application/_timer.html.erb b/app/views/application/_timer.html.erb index edbc7ea..46b1134 100644 --- a/app/views/application/_timer.html.erb +++ b/app/views/application/_timer.html.erb @@ -1,7 +1,7 @@ <% if current_char.activity %>

<%= current_char.activity.name %>

-- cgit v1.2.3