Skip to content

Commit

Permalink
Adds initial challenges, updates lb style
Browse files Browse the repository at this point in the history
  • Loading branch information
jac241 committed Jan 3, 2022
1 parent 1cb7444 commit 63efdfa
Show file tree
Hide file tree
Showing 25 changed files with 258 additions and 61 deletions.
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'factory_bot_rails'
gem 'pry-byebug'
gem 'pry-rails'
gem 'rspec-rails', '~> 5.0.2'
end

Expand Down Expand Up @@ -112,4 +111,6 @@ gem 'net-smtp', '~> 0.3.1'

gem 'jsbundling-rails', '~> 1.0'

gem "store_model", "~> 0.12.0"
gem 'store_model', '~> 0.12.0'

gem "local_time", "~> 2.1"
5 changes: 2 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ GEM
listen (3.7.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
local_time (2.1.0)
loofah (2.13.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
Expand Down Expand Up @@ -294,8 +295,6 @@ GEM
pry-byebug (3.9.0)
byebug (~> 11.0)
pry (~> 0.13.0)
pry-rails (0.3.9)
pry (>= 0.10.4)
public_suffix (4.0.6)
puma (5.5.2)
nio4r (~> 2.0)
Expand Down Expand Up @@ -492,14 +491,14 @@ DEPENDENCIES
jsonapi-serializer
kaminari (>= 1.2.1)
listen (~> 3.7.0)
local_time (~> 2.1)
mini_magick
name_of_person (~> 1.1)
net-smtp (~> 0.3.1)
oj (~> 3.13.10)
permessage_deflate (~> 0.1.4)
pg (>= 1.2.3, < 2.0)
pry-byebug
pry-rails
puma (>= 5.5.2)
pundit
rack-attack (~> 6.5)
Expand Down
3 changes: 2 additions & 1 deletion app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//= link_tree ../images
//= link_directory ../stylesheets .css
//= link application.css
//= link application.js
//= link administrate/application.css
//= link administrate/application.js
//= link_tree ../builds
11 changes: 9 additions & 2 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
@import "font-awesome-sprockets";
@import "font-awesome";

//@import url("https://fonts.googleapis.com/css2?family=Open+Sans&display=swap");
//@import url("https://fonts.googleapis.com/css2?family=Raleway&display=swap");
//@import url("https://fonts.googleapis.com/css2?family=Exo&display=swap");
//@import url("https://fonts.googleapis.com/css2?family=Source+Sans+Pro&display=swap");
//$font-family-sans-serif: "Source Sans Pro", -apple-system, BlinkMacSystemFont,
//"Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif,
//"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji" !default;
$spacer: 0.7rem;
@import "bootstrap";

// Add SASS theme customizations here..
Expand All @@ -24,7 +32,7 @@
}

h1.form-header {
margin-bottom: 0.35em
margin-bottom: 0.35em;
}

.main {
Expand All @@ -35,4 +43,3 @@ h1.form-header {
@import "leaderboards";
@import "medals";
@import "groups";

18 changes: 17 additions & 1 deletion app/assets/stylesheets/leaderboards.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import "bootstrap/scss/variables";

.leaderboard-navigation {
margin-top: 20px;
margin-bottom: 30px;
Expand All @@ -19,10 +21,24 @@
.top-medals {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
justify-content: center;
}

.top-medal {
flex: 1 1 0;
min-width: 100px;
}

.virtual-table-row:nth-child(even) {
background-color: $gray-200;
}

.leaderboard-username {
font-size: $font-size-lg;
}

@include media-breakpoint-up(md) {
.leaderboard-username {
font-size: $font-size-base;
}
}
6 changes: 6 additions & 0 deletions app/controllers/battle_passes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class BattlePassesController < ApplicationController
before_action :authenticate_user!
def show
@battle_pass = current_user.battle_passes.last
end
end
4 changes: 2 additions & 2 deletions app/javascript/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ require("@rails/activestorage").start()
require("./channels")
require("local-time").start()

window.Rails = Rails
window.Turbolinks = Turbolinks
//window.Rails = Rails
//window.Turbolinks = Turbolinks

import "./shared/jquery"

Expand Down
8 changes: 8 additions & 0 deletions app/lib/challenges/templates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ module Templates
client_medal_id: 'Perfection',
goal: 1
}
),
ChallengeTypes::MedalTracker.new(
title: 'Earn 5 Tactical Nukes in Call of Duty: Modern Warfare 2',
xp: 500,
dataset: {
client_medal_id: 'mw2_tactical_nuke',
goal: 5
}
)
]

Expand Down
27 changes: 27 additions & 0 deletions app/models/battle_pass.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
class BattlePass < ApplicationRecord
belongs_to :user
has_many :challenges

def level
calculate_level(xp)
end

def on_challenge_completed!(challenge)
with_lock do
self.xp += challenge.xp
save!
end
end

private

def calculate_level(input_xp)
base_xp = 500
exponent = 1.5

level_acc = 0
xp_acc = 0
while xp_acc < input_xp
xp_acc = base_xp * (level_acc**exponent)
level_acc += 1
end

[level_acc - 1, 1].max
end
end
2 changes: 1 addition & 1 deletion app/models/challenge.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Challenge < ApplicationRecord
belongs_to :battle_pass
belongs_to :battle_pass, touch: true
scope :active, -> { where(active: true) }
end
18 changes: 17 additions & 1 deletion app/models/challenge_types/medal_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ class MedalCounter
attribute :client_medal_id, :string
attribute :goal, :integer
attribute :count, :integer, default: 0

def at_goal?
count >= goal
end
end

attribute :dataset, MedalCounter.to_type
Expand All @@ -16,11 +20,23 @@ def update_if_applicable!(params)
with_lock do
dataset.count += 1

self.accomplished = true
mark_accomplished_if_completed!

save!
end
end
end

def mark_accomplished_if_completed!
if dataset.at_goal?
self.accomplished = true
self.active = false
battle_pass.on_challenge_completed!(self)
end
end

def progress_percent
((dataset.count.to_f / dataset.goal) * 100).round
end
end
end
22 changes: 22 additions & 0 deletions app/views/battle_passes/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.container
.row
.col-6
%h3 Battle Pass
%p
Level
= @battle_pass.level
%p
XP
= @battle_pass.xp
.col-6
%h3 Active Challenges

#active_challenges
- @battle_pass.challenges.active.each do |challenge|
.card
.card-body
%h5.card-title= challenge.title
.card-text
.progress
.progress-bar{role: "progressbar", style: "width: #{challenge.progress_percent}%"}
= challenge.dataset.count
6 changes: 4 additions & 2 deletions app/views/groups/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
= link_to "Create new group", new_group_path, class: "btn btn-primary"
- if @my_groups.exists?
.row
%h2 My Groups
.col-12
%h2 My Groups
.row.d-flex.flex-row.justify-content-between.mb-3
= render @my_groups
.row
%h2 All Groups
.col-12
%h2 All Groups
.row.d-flex.flex-row.justify-content-between
= render @groups

Expand Down
1 change: 0 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html>
<head>
<%= render 'shared/head' %>
<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
</head>

<body>
Expand Down
11 changes: 5 additions & 6 deletions app/views/leaderboards/_leaderboard.html.haml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
- cache leaderboard, force: local_assigns.fetch(:bust_cache, false) do
#leaderboard
.leaderboard-header.row
.row
.col-8
%h3= leaderboard.title
%h4= leaderboard.title
.col.text-right
%span#leaderboard_connection_status.badge.badge-secondary{ data: { target: "live-leaderboards.status" } }
Connecting...
%p#leaderboard_last_updated_time
#leaderboard_last_updated_time
%small
Last updated at
= Time.now.strftime("%k:%M:%S")
UTC
Last updated
= local_time_ago(Time.now)
= render partial: "leaderboards/table", locals: { leaderboard: leaderboard }
2 changes: 1 addition & 1 deletion app/views/leaderboards/_short_leaderboard.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#leaderboard
.leaderboard-header.row
.row
.col-12
%h3= leaderboard.count_limited_title(@leaderboard_entries_count)
= render partial: "leaderboards/table", locals: { leaderboard: leaderboard }
Loading

0 comments on commit 63efdfa

Please sign in to comment.