Skip to content
This repository was archived by the owner on Apr 6, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/runs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def set_run
default_timing: @run.default_timing,
}

@compare_runs = Run.where(id: (params[:compare] || '').split(',').map { |r| r.to_i(36) })
gon.compare_runs = @compare_runs.map { |run| {id: run.id36} }
@compare_runs = Run.where(id: (params[:compare] || '').split(',').map { |r| r.to_i(36) }) + SumOfBestRun.where(id: (params[:sum_of_best] || '').split(',').map { |r| r.to_i(36) })
gon.compare_runs = @compare_runs.reject { |run| run.is_a?(SumOfBestRun) }.map { |run| {id: run.id36} }

gon.run['user'] = if @run.user.nil?
nil
Expand Down
60 changes: 60 additions & 0 deletions app/models/sum_of_best_run.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
class SumOfBestRun
include CompletedRun

attr_accessor :id, :id36, :run

delegate_missing_to :@run

def initialize(original_run)
self.id = original_run.id
self.id36 = "#{original_run.id36}-sum-of-best"
self.run = original_run
self.run.segments.each do |segment|
segment.gametime_duration_ms = segment.gametime_shortest_duration_ms
segment.realtime_duration_ms = segment.realtime_shortest_duration_ms
end
self.run.gametime_duration_ms = gametime_duration_ms
self.run.realtime_duration_ms = realtime_duration_ms
end

def gametime_duration_ms
@gametime_duration_ms ||= segments.reject { |segment| segment.gametime_duration_ms.nil? }.sum(&:gametime_duration_ms)
end

def realtime_duration_ms
@realtime_duration_ms ||= segments.reject { |segment| segment.realtime_duration_ms.nil? }.sum(&:realtime_duration_ms)
end

def segments_with_groups
return @segments_with_groups if @segments_with_groups
segment_game_end_time = 0
segment_real_end_time = 0
@segments_with_groups = run.segments_with_groups
@segments_with_groups.map! do |segment_or_group|
if segment_or_group.is_a?(Segment)
segment_or_group.gametime_duration_ms = segment_or_group.gametime_shortest_duration_ms
segment_or_group.realtime_duration_ms = segment_or_group.realtime_shortest_duration_ms
segment_or_group
elsif segment_or_group.is_a?(SegmentGroup)
segment_or_group.segments.map! do |segment|
segment.gametime_duration_ms = segment.gametime_shortest_duration_ms
segment.realtime_duration_ms = segment.realtime_shortest_duration_ms
segment_game_end_time += segment.gametime_duration_ms
segment_real_end_time += segment.realtime_duration_ms
segment.gametime_end_ms = segment_game_end_time
segment.realtime_end_ms = segment_real_end_time
segment
end
segment_or_group
end
end
end

def video
nil
end

def self.where(params)
Run.where(params).map { |run| SumOfBestRun.new(run) }
end
end
14 changes: 9 additions & 5 deletions app/views/runs/_compare_button.slim
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
.dropdown-menu aria={labelledby: 'compare'} style='height: auto; max-height: 400px; overflow-x: hidden'
.dropdown-header Mine
- comparable_runs = current_user.present? ? current_user.comparable_runs(timing, run).where.not(id: run.id) : []
- sum_of_best_run = SumOfBestRun.where(id: run.id).first
a.dropdown-item href=run_path(run, params.permit(:timing).merge(sum_of_best: run.id))
= "#{sum_of_best_run.duration(timing).format} - Your Sum of Best"
- if comparable_runs.none?
.dropdown-item.disabled: i No comparable runs by me
- comparable_runs.each do |comparable_run|
Expand All @@ -41,11 +44,12 @@
span content='Twitch highlight attached' v-tippy=true =< icon('fab', 'twitch')
- if compare_runs.any?
.btn-group.ml-1
a.btn.px-1(
content='Swap comparison'
href=run_path(compare_runs.first, params.permit(:timing).merge(compare: run))
v-tippy=true
) = icon('fas', 'exchange-alt')
- if compare_runs.all? { |run| !run.is_a?(SumOfBestRun) }
a.btn.px-1(
content='Swap comparison'
href=run_path(compare_runs.first, params.permit(:timing).merge(compare: run))
v-tippy=true
) = icon('fas', 'exchange-alt')
a.btn.px-1(
content='Remove comparison'
href=run_path(run, params.permit(:timing).delete(:compare))
Expand Down
2 changes: 1 addition & 1 deletion app/views/runs/_gold_timeline.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- if run.completed?(timing)
- if run.completed?(timing) && !run.is_a?(SumOfBestRun)
.gold.timeline.timeline-animation style="width: #{run.duration(timing) / scale_to * 100.0}%"
- run.collapsed_segments(timing).each_with_index do |segment, index|
div style="width: #{segment.proportion(timing) * 100.0}%"
Expand Down