Skip to content

Commit

Permalink
working merged version
Browse files Browse the repository at this point in the history
  • Loading branch information
qfeuilla committed Nov 11, 2020
1 parent fc3c694 commit 28db80a
Show file tree
Hide file tree
Showing 152 changed files with 623 additions and 52 deletions.
Empty file modified Dockerfile
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions Gemfile
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ gem 'jbuilder', '~> 2.7'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# for game data
gem 'redis'
gem 'redis-namespace'
gem 'redis-rails'

# for auth
gem 'devise'
gem 'omniauth-marvin', '~> 1.0.2'
Expand Down
22 changes: 22 additions & 0 deletions Gemfile.lock
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,25 @@ GEM
rb-fsevent (0.10.4)
rb-inotify (0.10.1)
ffi (~> 1.0)
redis (4.2.2)
redis-actionpack (5.2.0)
actionpack (>= 5, < 7)
redis-rack (>= 2.1.0, < 3)
redis-store (>= 1.1.0, < 2)
redis-activesupport (5.2.0)
activesupport (>= 3, < 7)
redis-store (>= 1.3, < 2)
redis-namespace (1.8.0)
redis (>= 3.0.4)
redis-rack (2.1.3)
rack (>= 2.0.8, < 3)
redis-store (>= 1.2, < 2)
redis-rails (5.0.2)
redis-actionpack (>= 5.0, < 6)
redis-activesupport (>= 5.0, < 6)
redis-store (>= 1.2, < 2)
redis-store (1.9.0)
redis (>= 4, < 5)
regexp_parser (1.8.2)
responders (3.0.1)
actionpack (>= 5.0)
Expand Down Expand Up @@ -259,6 +278,9 @@ DEPENDENCIES
pg (>= 0.18, < 2.0)
puma (~> 4.1)
rails (~> 6.0.3, >= 6.0.3.4)
redis
redis-namespace
redis-rails
sass-rails (>= 6)
selenium-webdriver
spring
Expand Down
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified Rakefile
100644 → 100755
Empty file.
Empty file modified app/assets/config/manifest.js
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/application.js
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/models/GuildModel.js
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/models/UserModel.js
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/routers/AbstractRouter.js
100644 → 100755
Empty file.
6 changes: 5 additions & 1 deletion app/assets/javascripts/routers/GameRouter.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ AppClasses.Routers.GameRouter = class extends AppClasses.Routers.AbstractRouter
super(options);
// routes
this.route("game", "index");
this.route("game/:room_id", "show");
this.collections.guilds = new AppClasses.Collections.Guild();
}
index() {
this.basicView("game", "Game");
this.views.game.initGame();
}
show(room_id) {
this.viewWithRenderParam("gamePlay", "GamePlay", room_id, { room_id })
console.log(room_id);
}
}
Empty file modified app/assets/javascripts/routers/GuildRouter.js
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/routers/MainRouter.js
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/routers/ProfileRouter.js
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/structure.js
100644 → 100755
Empty file.
5 changes: 1 addition & 4 deletions app/assets/javascripts/templates/game/game.hbs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<h1>Game</h1>

<canvas style="background-color: antiquewhite;" width="300" height="300" id="{{canvasID}}">
Your web browser is probably almost older than me, time to update ?
</canvas>
<div id="game_page_id"></div>

<br>
<a href="#">Home</a>
17 changes: 17 additions & 0 deletions app/assets/javascripts/templates/game/show.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<p>You are on the game page nb : {{ room_id }}</p>
<div id="in_game_id" data-id="{{ room_id }}"></div>
<style>
* {
padding: 0;
margin: 0;
}
canvas {
background: #013333;
display: block;
margin: 0 auto;
}
</style>
<canvas id="myCanvas" width="800" height="600"></canvas>

<div class="btn"></div>
Empty file modified app/assets/javascripts/templates/guilds/form.hbs
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/templates/guilds/index.hbs
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/templates/guilds/show.hbs
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/templates/home/connectionInfos.hbs
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/templates/home/index.hbs
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/templates/profile/auth.hbs
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/templates/profile/edit.hbs
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/templates/profile/index.hbs
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/utils/forms.js
100644 → 100755
Empty file.
19 changes: 19 additions & 0 deletions app/assets/javascripts/views/game/GamePlayView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
AppClasses.Views.GamePlay = class extends Backbone.View {
constructor(opts) {
super(opts);
this.tagName = "div";
this.template = App.templates["game/show"];
}
updateRender(room_id) {
this.$el.html(this.template({
room_id
}));

return (this);
}
render(room_id) {
this.updateRender(room_id); // generates HTML
// the game has to be started in the router
return (this);
}
}
13 changes: 1 addition & 12 deletions app/assets/javascripts/views/game/GameView.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,11 @@ AppClasses.Views.Game = class extends Backbone.View {
super(opts);
this.tagName = "div";
this.template = App.templates["game/game"];
this.canvasID = "gameCanvas";
this.canvas = null;
this.ctx = null;
}
updateRender() {
this.$el.html(this.template({
canvasID: this.canvasID
}));
this.$el.html(this.template({ }));
return (this);
}
initGame() {
this.canvas = $(`#${this.canvasID}`)[0];
this.ctx = this.canvas.getContext("2d");

this.ctx.fillRect(100, 100, 100, 100)
}
render() {
this.updateRender(); // generates HTML
// the game has to be started in the router
Expand Down
Empty file modified app/assets/javascripts/views/guilds/EditGuildView.js
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/views/guilds/GuildsView.js
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/views/guilds/MyGuildView.js
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/views/guilds/NewGuildView.js
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/views/guilds/ShowGuildView.js
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/views/home/ConnectionInfoView.js
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/views/home/HomeView.js
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/views/profile/AuthInfosView.js
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/views/profile/ProfileEditView.js
100644 → 100755
Empty file.
Empty file modified app/assets/javascripts/views/profile/ProfileView.js
100644 → 100755
Empty file.
15 changes: 0 additions & 15 deletions app/assets/stylesheets/application.css

This file was deleted.

2 changes: 2 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

@import "bootstrap/scss/bootstrap";
Empty file modified app/assets/stylesheets/guilds.scss
100644 → 100755
Empty file.
Empty file modified app/assets/stylesheets/home.scss
100644 → 100755
Empty file.
Empty file modified app/assets/stylesheets/scaffolds.scss
100644 → 100755
Empty file.
Empty file modified app/channels/application_cable/channel.rb
100644 → 100755
Empty file.
15 changes: 15 additions & 0 deletions app/channels/application_cable/connection.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user

def connect
self.current_user = find_verified_user.email
end

protected

def find_verified_user
if verified_user = env['warden'].user
verified_user
else
reject_unauthorized_connection
end
end
end
end
13 changes: 13 additions & 0 deletions app/channels/game_channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class GameChannel < ApplicationCable::Channel
def subscribed
stream_from "player_#{ current_user }"
Matchmaking.create(current_user)
end

def unsubscribed
if Redis.current.get('matches') == current_user
Redis.current.set('matches', nil)
end
# Any cleanup needed when channel is unsubscribed
end
end
24 changes: 24 additions & 0 deletions app/channels/play_channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class PlayChannel < ApplicationCable::Channel
def subscribed
stream_from "play_channel_#{params[:game_room_id]}"
end

def unsubscribed
# Any cleanup needed when channel is unsubscribed
end

def take_turn(data)
last = Redis.current.get("play_channel_#{data['room_id']}_#{data['player']}");
return unless last.blank? || last == 'w' || data['input'] == 'quit'
return if !last.blank? && last == 'quit'

Redis.current.set("play_channel_#{data['room_id']}_#{data['player']}", data['input'])
end

def start_game(data)
return unless Redis.current.get("#{data['room_id']}_has_start").blank?

Redis.current.set("#{data['room_id']}_has_start", 'ok')
Game.start_game("play_channel_#{data['room_id']}")
end
end
Empty file modified app/controllers/application_controller.rb
100644 → 100755
Empty file.
Empty file modified app/controllers/guilds_controller.rb
100644 → 100755
Empty file.
Empty file modified app/controllers/home_controller.rb
100644 → 100755
Empty file.
Empty file modified app/controllers/profile_controller.rb
100644 → 100755
Empty file.
Empty file modified app/controllers/users/omniauth_callbacks_controller.rb
100644 → 100755
Empty file.
Empty file modified app/helpers/application_helper.rb
100644 → 100755
Empty file.
Empty file modified app/helpers/guilds_helper.rb
100644 → 100755
Empty file.
Empty file modified app/helpers/home_helper.rb
100644 → 100755
Empty file.
Empty file modified app/javascript/channels/consumer.js
100644 → 100755
Empty file.
Loading

0 comments on commit 28db80a

Please sign in to comment.