Skip to content

Commit

Permalink
Add an autosplitter badge (#674)
Browse files Browse the repository at this point in the history
* Add an autosplitter badge

Adds a badge to runs that were performed using an autosplitter.

* CR comments
  • Loading branch information
glacials committed Feb 10, 2020
1 parent 67a8bdd commit f3cd4b0
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/helpers/likes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module LikesHelper

def tooltip(run)
count = run.likes.count
return nil if count.zero?
return 'Like this run' if count.zero?

likes = run.likes.joins(:user).limit(MAX_NAMES).pluck(:name)

Expand Down
3 changes: 3 additions & 0 deletions app/models/concerns/unparsed_run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def parse_into_db
attempts: run_data[:attempts],
srdc_id: srdc_id || run_data[:metadata][:srdc_id],
uses_emulator: run_data[:metadata][:uses_emulator],
uses_autosplitter: run_data[:autosplitter_settings].present?,

realtime_duration_ms: zero_to_nil(run_data[:realtime_duration_ms]),
realtime_sum_of_best_ms: zero_to_nil(run_data[:realtime_sum_of_best_ms]),
Expand Down Expand Up @@ -96,6 +97,8 @@ def process_run_metadata(run, run_data)
run_data[:category] = run.category_name
run_data[:name] = run.extended_name(false)

run_data[:autosplitter_settings] = run.auto_splitter_settings

run_data[:metadata] = {}
run_data[:metadata][:srdc_id] = run.metadata.run_id.presence
run_data[:metadata][:platform_name] = run.metadata.platform_name.presence
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.slim
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ html lang='en'
footer#footer
= yield(:footer)
.row
.col-md-6
.col-md-6.d-none.d-xl-block
- patrons = User.includes(:patreon, :twitch).joins(:patreon).where('patreon_users.pledge_cents >= 200')
- unless patrons.blank?
a> href=patreon_url
Expand Down
16 changes: 10 additions & 6 deletions app/views/runs/_timing_badge.slim
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
- if run.completed?(Run::REAL) && run.completed?(Run::GAME)
- if timing == Run::REAL
a.badge.badge-dark.tip(
title='Recorded in realtime & gametime — click to switch'
a.badge.badge-dark(
href=run_path(run, params.permit(:compare).merge(timing: 'game'))
v-tippy=true
title='Recorded in realtime & gametime—click to switch'
)
span.text-success => icon('fas', 'globe-americas')
= icon('fas', 'gamepad')
- if timing == Run::GAME
a.badge.badge-dark.tip(
title='Recorded in realtime & gametime — click to switch'
a.badge.badge-dark(
href=run_path(run, params.permit(:compare).merge(timing: 'real'))
v-tippy=true
title='Recorded in realtime & gametime—click to switch'
)
=> icon('fas', 'globe-americas')
span.text-success = icon('fas', 'gamepad')
- else
- if run.completed?(Run::REAL)
.badge.tip title='Recorded in realtime' = icon('fas', 'globe-americas')
.badge v-tippy=true title='"Recorded in realtime"'
= icon('fas', 'globe-americas')
- if run.completed?(Run::GAME)
.badge.tip title='Recorded in gametime' = icon('fas', 'gamepad')
.badge v-tippy=true title='Recorded in gametime'
= icon('fas', 'gamepad')
31 changes: 19 additions & 12 deletions app/views/runs/_title.slim
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@ h5
- old_runs.each do |old_run|
a.dropdown-item href=run_path(old_run) = old_run.duration.format
- if run.srdc_id.present?
a.badge.badge-dark.tip.mr-2 title='See on Speedrun.com' href=run.srdc_url
= image_tag(asset_path('srdc.png'), style: 'height: 0.8em', alt: 'Speedrun.com first place trophy')
a.badge.badge-dark.mr-2 href=run.srdc_url v-tippy=true title='See on Speedrun.com'
= image_tag(asset_path('srdc.png'), style: 'height: 0.8em', alt: 'Speedrun.com logo')
- if run.entry.present? && !run.entry.ghost?
a.badge.badge-dark.tip.mr-2 title='Recorded as part of a race' href=race_path(run.entry.race)
a.badge.badge-dark.mr-2 v-tippy=true href=race_path(run.entry.race) title='Recorded as part of a race'
= icon('fas', 'flag-checkered')
- if run.video&.supports_embedding?
- if run.video.youtube?
a.badge.badge-dark.tip.mr-2 href=run.video.url title='Watch on YouTube' => icon('fab', 'youtube')
a.badge.badge-dark.mr-2 href=run.video.url v-tippy=true title='Watch on YouTube'
=> icon('fab', 'youtube')
- elsif !run.video.twitch?
a.badge.badge-dark.tip.mr-2 href=run.video.url title='Watch video' => icon('fas', 'video')
a.badge.badge-dark.mr-2 href=run.video.url v-tippy=true title='Watch video'
=> icon('fas', 'video')
- if run.in_progress?(timing)
a.badge.tip.p-0.mr-2 title='In progress'
a.badge.p-0.mr-2 v-tippy=true title='In progress'
.text-danger = icon('fas', 'satellite-dish')
- if run.uses_autosplitter?
.badge.mr-2 v-tippy=true title='Used an autosplitter' = icon('fas', 'magic')

.btn-toolbar.mb-2 role='toolbar' aria={label: 'Run navigation'}
.btn-group.m-2 role='group' aria={label: 'Run navigation'}
Expand All @@ -49,29 +53,32 @@ h5
- if current_user.present?
a#claim-nav-link.btn.btn-outline-success href='#' data-confirm="Claim this run as #{current_user}?"
=> icon('fas', 'user-check')
span Claim
' Claim
- else
button.btn.btn-outline-secondary.tip.disabled title='Sign in to claim' style='cursor: default' Claim
button.btn.btn-outline-secondary.disabled v-tippy=true style='cursor: default' title='Sign in to claim'
' Claim
- if can?(:create, RunLike)
.btn-group.m-2: button#like-button.btn.tip(
.btn-group.m-2: button#like-button.btn(
data={liked: current_user.likes?(run) ? '1' : '0'}
class=(current_user.likes?(run) ? 'btn-dark' : 'btn-outline-light')
v-tippy=true
title=tooltip(run)
)
' 🎉
span#likes-count data={value: run.likes.count} = run.likes.count
- else
.btn-group.m-2: .btn.btn-outline-secondary.tip.disabled title=tooltip(run)
.btn-group.m-2: .btn.btn-outline-secondary.disabled v-tippy=true title=tooltip(run)
' 🎉
= run.likes.count
- if run.belongs_to?(current_user)
.btn-group.m-2 role='group' aria={label: 'Calls to action'}
= render 'highlight_button', run: run
- if run.category&.srdc && run.srdc_id.blank?
a.btn.btn-srdc.tip-top(
a.btn.btn-srdc(
href='#'
data={toggle: :modal, target: current_user.srdc ? '#srdc-submit' : '#srdc-link'}
title="Automatically submit to Speedrun.com. You'll get a chance to review the details first."
v-tippy=true
title='Automatically submit to Speedrun.com. You will get a chance to review the details first.'
)
=> image_tag(asset_path('srdc.png'), style: 'height: 0.8em', alt: 'Speedrun.com first place trophy')
span Auto-submit
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20200207203633_add_uses_autosplitter_to_runs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddUsesAutosplitterToRuns < ActiveRecord::Migration[6.0]
def change
add_column :runs, :uses_autosplitter, :bool, null: true
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_01_14_184419) do
ActiveRecord::Schema.define(version: 2020_02_07_203633) do

# These are extensions that must be enabled in order to support this database
enable_extension "citext"
Expand Down Expand Up @@ -290,6 +290,7 @@
t.boolean "uses_emulator", default: false
t.uuid "speedrun_dot_com_platform_id"
t.uuid "speedrun_dot_com_region_id"
t.boolean "uses_autosplitter"
t.index ["category_id"], name: "index_runs_on_category_id"
t.index ["s3_filename"], name: "index_runs_on_s3_filename"
t.index ["user_id"], name: "index_runs_on_user_id"
Expand Down

0 comments on commit f3cd4b0

Please sign in to comment.