From 8206cac29ec2ce86e0b0a68360ec714b573e13f6 Mon Sep 17 00:00:00 2001 From: David Gay Date: Fri, 4 Jun 2021 10:21:20 -0400 Subject: Timer progress bar --- app/models/character.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'app/models') diff --git a/app/models/character.rb b/app/models/character.rb index 1169672..8a72ccd 100644 --- a/app/models/character.rb +++ b/app/models/character.rb @@ -187,12 +187,12 @@ class Character < ApplicationRecord end def activity_time_remaining - time = duration_of_activity - (Time.now - self.activity_started_at) + time = activity_duration - (Time.now - self.activity_started_at) time -= rested_duration_to_spend_on_activity if self.rested_duration > 0 time end - def duration_of_activity + def activity_duration return nil unless self.activity duration_data = self.activity.whatnot[:duration] duration = duration_data[:base] @@ -209,9 +209,13 @@ class Character < ApplicationRecord [duration, duration_data[:minimum] || 10].max end + def percentage_of_activity_completed + (1 - (activity_time_remaining / activity_duration)) * 100 + end + def rested_duration_to_spend_on_activity return nil unless self.activity - [(duration_of_activity / 2).floor, self.rested_duration].min + [(activity_duration / 2).floor, self.rested_duration].min end def can_do_activity?(activity, ignore_cost: false, ignore_requirements: false) -- cgit v1.2.3