init
This commit is contained in:
0
app/assets/images/.keep
Normal file
0
app/assets/images/.keep
Normal file
BIN
app/assets/images/leaderboardbg.webp
Normal file
BIN
app/assets/images/leaderboardbg.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 349 KiB |
120
app/assets/stylesheets/application.css
Normal file
120
app/assets/stylesheets/application.css
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* This is a manifest file that'll be compiled into application.css.
|
||||
*
|
||||
* With Propshaft, assets are served efficiently without preprocessing steps. You can still include
|
||||
* application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
|
||||
* cascading order, meaning styles declared later in the document or manifest will override earlier ones,
|
||||
* depending on specificity.
|
||||
*
|
||||
* Consider organizing styles into separate files for maintainability.
|
||||
*/
|
||||
|
||||
body {
|
||||
font-family: Inconsolata, Helvetica, Arial;
|
||||
font-size: 1em;
|
||||
line-height: 20px;
|
||||
font-weight: 400;
|
||||
color: #3b3b3b;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
background: #2b2b2b;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 580px) {
|
||||
body {
|
||||
font-size: 16px;
|
||||
line-height: 22px;
|
||||
}
|
||||
}
|
||||
|
||||
.wrapper {
|
||||
margin: 0 auto;
|
||||
padding: 40px;
|
||||
max-width: 800px;
|
||||
}
|
||||
|
||||
.table {
|
||||
margin: 0 0 40px 0;
|
||||
width: 100%;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
|
||||
display: table;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 580px) {
|
||||
.table {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.row {
|
||||
display: table-row;
|
||||
background: #f6f6f6;
|
||||
}
|
||||
|
||||
.row:nth-of-type(odd) {
|
||||
background: #e9e9e9;
|
||||
}
|
||||
|
||||
.row.header {
|
||||
font-weight: 900;
|
||||
color: #ffffff;
|
||||
background: #2980b9;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 580px) {
|
||||
.row {
|
||||
padding: 14px 0 7px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.row.header {
|
||||
padding: 0;
|
||||
height: 6px;
|
||||
}
|
||||
|
||||
.row.header .cell {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.row .cell {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.row .cell:before {
|
||||
margin-bottom: 3px;
|
||||
content: attr(data-title);
|
||||
min-width: 98px;
|
||||
font-size: 10px;
|
||||
line-height: 10px;
|
||||
font-weight: bold;
|
||||
text-transform: uppercase;
|
||||
color: #969696;
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.cell {
|
||||
padding: 6px 12px;
|
||||
display: table-cell;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 580px) {
|
||||
.cell {
|
||||
padding: 2px 16px;
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #ebdbd2;
|
||||
margin: auto;
|
||||
text-align: center;
|
||||
padding-top: 10px;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #458588;
|
||||
}
|
||||
|
||||
a:visited {
|
||||
color: #b16286;
|
||||
}
|
4
app/controllers/application_controller.rb
Normal file
4
app/controllers/application_controller.rb
Normal file
@ -0,0 +1,4 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
|
||||
allow_browser versions: :modern
|
||||
end
|
0
app/controllers/concerns/.keep
Normal file
0
app/controllers/concerns/.keep
Normal file
52
app/controllers/game_controller.rb
Normal file
52
app/controllers/game_controller.rb
Normal file
@ -0,0 +1,52 @@
|
||||
class GameController < ApplicationController
|
||||
respond_to? :json
|
||||
def index
|
||||
@recent_games = Game.order(timestamp: :desc).limit(20)
|
||||
end
|
||||
|
||||
def show
|
||||
@game = Game.find(params[:id])
|
||||
end
|
||||
|
||||
def create
|
||||
game_params[:timestamp] = Time.at(params[:timestamp].to_i).utc if params[:timestamp].present?
|
||||
if Game.find_by(timestamp: game_params[:timestamp])
|
||||
return head 208 # HTTP 208: Already reported
|
||||
end
|
||||
|
||||
players = []
|
||||
params[:players].each do | name, _pos |
|
||||
player = Player.find_by(name: name)
|
||||
if player.nil?
|
||||
player = Player.new(name: name, wins: 0, losses: 0, purse: 0)
|
||||
player.save
|
||||
end
|
||||
players << player
|
||||
end
|
||||
|
||||
@game = Game.create(game_params)
|
||||
|
||||
if @game.save
|
||||
players.each do | player |
|
||||
if @game.winner == player.name
|
||||
player.purse += @game.payout
|
||||
player.wins += 1
|
||||
player.save
|
||||
elsif @game.loser == player.name
|
||||
player.purse -= @game.payout
|
||||
player.losses += 1
|
||||
player.save
|
||||
end
|
||||
end
|
||||
head :ok
|
||||
else
|
||||
head :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def game_params
|
||||
params.require(:game).permit(:timestamp, :gametype, :wager, :winner, :loser, :high_roll, :low_roll, :payout)
|
||||
end
|
||||
end
|
5
app/controllers/leaderboard_controller.rb
Normal file
5
app/controllers/leaderboard_controller.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class LeaderboardController < ApplicationController
|
||||
def index
|
||||
@players = Player.order(purse: :desc)
|
||||
end
|
||||
end
|
5
app/controllers/player_controller.rb
Normal file
5
app/controllers/player_controller.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class PlayerController < ApplicationController
|
||||
def show
|
||||
@player = Player.find(params[:id])
|
||||
end
|
||||
end
|
2
app/helpers/application_helper.rb
Normal file
2
app/helpers/application_helper.rb
Normal file
@ -0,0 +1,2 @@
|
||||
module ApplicationHelper
|
||||
end
|
2
app/helpers/game_helper.rb
Normal file
2
app/helpers/game_helper.rb
Normal file
@ -0,0 +1,2 @@
|
||||
module GameHelper
|
||||
end
|
2
app/helpers/leaderboard_helper.rb
Normal file
2
app/helpers/leaderboard_helper.rb
Normal file
@ -0,0 +1,2 @@
|
||||
module LeaderboardHelper
|
||||
end
|
2
app/helpers/player_helper.rb
Normal file
2
app/helpers/player_helper.rb
Normal file
@ -0,0 +1,2 @@
|
||||
module PlayerHelper
|
||||
end
|
7
app/jobs/application_job.rb
Normal file
7
app/jobs/application_job.rb
Normal file
@ -0,0 +1,7 @@
|
||||
class ApplicationJob < ActiveJob::Base
|
||||
# Automatically retry jobs that encountered a deadlock
|
||||
# retry_on ActiveRecord::Deadlocked
|
||||
|
||||
# Most jobs are safe to ignore if the underlying records are no longer available
|
||||
# discard_on ActiveJob::DeserializationError
|
||||
end
|
4
app/mailers/application_mailer.rb
Normal file
4
app/mailers/application_mailer.rb
Normal file
@ -0,0 +1,4 @@
|
||||
class ApplicationMailer < ActionMailer::Base
|
||||
default from: "from@example.com"
|
||||
layout "mailer"
|
||||
end
|
3
app/models/application_record.rb
Normal file
3
app/models/application_record.rb
Normal file
@ -0,0 +1,3 @@
|
||||
class ApplicationRecord < ActiveRecord::Base
|
||||
primary_abstract_class
|
||||
end
|
0
app/models/concerns/.keep
Normal file
0
app/models/concerns/.keep
Normal file
10
app/models/game.rb
Normal file
10
app/models/game.rb
Normal file
@ -0,0 +1,10 @@
|
||||
class Game < ApplicationRecord
|
||||
def gametype_str
|
||||
case self.gametype
|
||||
when 0
|
||||
"Classic"
|
||||
else
|
||||
"Unknown"
|
||||
end
|
||||
end
|
||||
end
|
2
app/models/player.rb
Normal file
2
app/models/player.rb
Normal file
@ -0,0 +1,2 @@
|
||||
class Player < ApplicationRecord
|
||||
end
|
31
app/views/game/index.html.erb
Normal file
31
app/views/game/index.html.erb
Normal file
@ -0,0 +1,31 @@
|
||||
<h1>Game History</h1>
|
||||
|
||||
<% if @recent_games.any? %>
|
||||
<div class="wrapper">
|
||||
<div class="table">
|
||||
<div class="row header">
|
||||
<div class="cell">Time</div>
|
||||
<div class="cell">Wager</div>
|
||||
<div class="cell">Winner</div>
|
||||
<div class="cell">High Roll</div>
|
||||
<div class="cell">Loser</div>
|
||||
<div class="cell">Low Roll</div>
|
||||
<div class="cell">Payout</div>
|
||||
</div>
|
||||
<% @recent_games.each do |game| %>
|
||||
<div class="row">
|
||||
<div class="cell" data-title="Time"><%= Time.at(game.timestamp).strftime("%Y-%m-%d %H:%M:%S") %></div>
|
||||
<div class="cell" data-title="Wager"><%= game.wager %></div>
|
||||
<div class="cell" data-title="Winner"><%= game.winner %></div>
|
||||
<div class="cell" data-title="High Roll"><%= game.high_roll %></div>
|
||||
<div class="cell" data-title="Loser"><%= game.loser %></div>
|
||||
<div class="cell" data-title="Low Roll"><%= game.low_roll %></div>
|
||||
<div class="cell" data-title="Payout"><%= game.payout %></div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<a href="/">Leaderboard</a>
|
||||
</div>
|
||||
<% else %>
|
||||
<p>No recent games</p>
|
||||
<% end %>
|
22
app/views/game/show.html.erb
Normal file
22
app/views/game/show.html.erb
Normal file
@ -0,0 +1,22 @@
|
||||
<h1>Game <%= @game.id %></h1>
|
||||
|
||||
<table class="tg"><tbody>
|
||||
<tr>
|
||||
<th class="tg-0lax">Game Type</th>
|
||||
<th class="tg-0lax"><%= @game.gametype_str %></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="tg-0lax">Winner</th>
|
||||
<th class="tg-0lax"><%= @game.winner %></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="tg-0lax">Loser</td>
|
||||
<td class="tg-0lax"><%= @game.loser %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="tg-0lax">Payout</td>
|
||||
<td class="tg-0lax"><%= @game.payout %></td>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
|
||||
<%= link_to "Back", game_index_path %>
|
27
app/views/layouts/application.html.erb
Normal file
27
app/views/layouts/application.html.erb
Normal file
@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title><%= content_for(:title) || "Gambosite" %></title>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<%= csrf_meta_tags %>
|
||||
<%= csp_meta_tag %>
|
||||
|
||||
<%= yield :head %>
|
||||
|
||||
<%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %>
|
||||
<%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %>
|
||||
|
||||
<link rel="icon" href="/icon.png" type="image/png">
|
||||
<link rel="icon" href="/icon.svg" type="image/svg+xml">
|
||||
<link rel="apple-touch-icon" href="/icon.png">
|
||||
|
||||
<%# Includes all stylesheet files in app/assets/stylesheets %>
|
||||
<%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<%= yield %>
|
||||
</body>
|
||||
</html>
|
13
app/views/layouts/mailer.html.erb
Normal file
13
app/views/layouts/mailer.html.erb
Normal file
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<style>
|
||||
/* Email styles need to be inline */
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<%= yield %>
|
||||
</body>
|
||||
</html>
|
1
app/views/layouts/mailer.text.erb
Normal file
1
app/views/layouts/mailer.text.erb
Normal file
@ -0,0 +1 @@
|
||||
<%= yield %>
|
25
app/views/leaderboard/index.html.erb
Normal file
25
app/views/leaderboard/index.html.erb
Normal file
@ -0,0 +1,25 @@
|
||||
<h1>Force Kin Gamba Leaderboard</h1>
|
||||
|
||||
<% if @players.any? %>
|
||||
<div class="wrapper">
|
||||
<div class="table">
|
||||
<div class="row header">
|
||||
<div class="cell">Player</div>
|
||||
<div class="cell">Purse</div>
|
||||
<div class="cell">Wins</div>
|
||||
<div class="cell">Losses</div>
|
||||
</div>
|
||||
<% @players.each do |player| %>
|
||||
<div class="row">
|
||||
<div class="cell" data-title="Player"><%= player.name %></div>
|
||||
<div class="cell" data-title="Purse"><%= player.purse %></div>
|
||||
<div class="cell" data-title="Wins"><%= player.wins %></div>
|
||||
<div class="cell" data-title="Losses"><%= player.losses %></div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<a href="/games">Game History</a>
|
||||
</div>
|
||||
<% else %>
|
||||
<p>No Players!</p>
|
||||
<% end %>
|
20
app/views/player/show.html.erb
Normal file
20
app/views/player/show.html.erb
Normal file
@ -0,0 +1,20 @@
|
||||
<h1><%= @player.name %></h1>
|
||||
|
||||
<table><thead>
|
||||
<tr>
|
||||
<th>Player</th>
|
||||
<th>Purse</th>
|
||||
<th>Wins</th>
|
||||
<th>Losses</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<% @player.each do |game| %>
|
||||
<tr>
|
||||
<td><% @player.name %></td>
|
||||
<td><% @player.purse %></td>
|
||||
<td><% @player.wins %></td>
|
||||
<td><% @player.losses %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
22
app/views/pwa/manifest.json.erb
Normal file
22
app/views/pwa/manifest.json.erb
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "Gambosite",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/icon.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
},
|
||||
{
|
||||
"src": "/icon.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512",
|
||||
"purpose": "maskable"
|
||||
}
|
||||
],
|
||||
"start_url": "/",
|
||||
"display": "standalone",
|
||||
"scope": "/",
|
||||
"description": "Gambosite.",
|
||||
"theme_color": "red",
|
||||
"background_color": "red"
|
||||
}
|
26
app/views/pwa/service-worker.js
Normal file
26
app/views/pwa/service-worker.js
Normal file
@ -0,0 +1,26 @@
|
||||
// Add a service worker for processing Web Push notifications:
|
||||
//
|
||||
// self.addEventListener("push", async (event) => {
|
||||
// const { title, options } = await event.data.json()
|
||||
// event.waitUntil(self.registration.showNotification(title, options))
|
||||
// })
|
||||
//
|
||||
// self.addEventListener("notificationclick", function(event) {
|
||||
// event.notification.close()
|
||||
// event.waitUntil(
|
||||
// clients.matchAll({ type: "window" }).then((clientList) => {
|
||||
// for (let i = 0; i < clientList.length; i++) {
|
||||
// let client = clientList[i]
|
||||
// let clientPath = (new URL(client.url)).pathname
|
||||
//
|
||||
// if (clientPath == event.notification.data.path && "focus" in client) {
|
||||
// return client.focus()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (clients.openWindow) {
|
||||
// return clients.openWindow(event.notification.data.path)
|
||||
// }
|
||||
// })
|
||||
// )
|
||||
// })
|
Reference in New Issue
Block a user