diff options
author | David Gay <david@davidgay.org> | 2021-06-04 10:21:20 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-06-04 10:21:20 -0400 |
commit | 8206cac29ec2ce86e0b0a68360ec714b573e13f6 (patch) | |
tree | 92812683a373d55d0e170c3474f4143390e67ed1 /app/models | |
parent | e3ec74cfbdf2428acb849a16b9ee6311020630a8 (diff) |
Timer progress bar
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/character.rb | 10 |
1 files changed, 7 insertions, 3 deletions
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) |