-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from cardeons/develop
Release
- Loading branch information
Showing
46 changed files
with
1,011 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
// If not specified searches for 'rubocop' executable available on PATH (default and recommended) | ||
"ruby.rubocop.executePath": "", | ||
// You can use specific path | ||
// "ruby.rubocop.executePath": "/Users/you/.rbenv/shims/" | ||
// "ruby.rubocop.executePath": "/Users/you/.rvm/gems/ruby-2.3.2/bin/" | ||
// "ruby.rubocop.executePath": "D:/bin/Ruby22-x64/bin/" | ||
// If not specified, it assumes a null value by default. | ||
"ruby.rubocop.configFilePath": ".rubocop.yml", | ||
// default true | ||
"ruby.rubocop.onSave": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the GameSocket controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: https://sass-lang.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# frozen_string_literal: true | ||
|
||
class GameChannel < ApplicationCable::Channel | ||
rescue_from Exception, with: :deliver_error_message | ||
BOARD_UPDATE = "BOARD_UPDATE" | ||
DEBUG = "DEBUG" | ||
ERROR = "ERROR" | ||
|
||
|
||
def subscribed | ||
@gameboard = current_user.player.gameboard | ||
stream_for @gameboard | ||
|
||
broadcast_to(@gameboard, {type: DEBUG ,params: { message:"you are now subscribed to the game_channel #{@gameboard.id}"}}) | ||
|
||
broadcast_to(@gameboard, {type: BOARD_UPDATE, params: Gameboard.broadcast_gameBoard(@gameboard)}) | ||
end | ||
end | ||
|
||
def play_card(params) | ||
#add actions! | ||
|
||
paramsObject = JSON.parse params | ||
puts paramsObject | ||
|
||
broadcast_to(@gameboard, {type: DEBUG ,params: { message:"You just used play_card with ", params: {paramsObject}}}) | ||
|
||
|
||
case paramsObject.to | ||
when "Inventory" | ||
broadcast_to(@gameboard, {type: DEBUG ,params: { message:"Player #{current_user.email} just played to inventory"}) | ||
current_card = Ingamedeck.find_by('id=?', paramsObject.unique_id) | ||
current_card.update_attribute(:cardable_type, "Inventory") | ||
when "Monsterone" | ||
broadcast_to(@gameboard, {type: DEBUG ,params: { message:"Player #{current_user.email} just played to monsterone"}) | ||
current_card = Ingamedeck.find_by('id=?', paramsObject.unique_id) | ||
current_card.update_attribute(:cardable_type, "Monsterone") | ||
when "Monstertwo" | ||
broadcast_to(@gameboard, {type: DEBUG ,params: { message:"Player #{current_user.email} just played to monstertwo"}) | ||
current_card = Ingamedeck.find_by('id=?', paramsObject.unique_id) | ||
current_card.update_attribute(:cardable_type, "Monstertwo") | ||
when "Monsterthree" | ||
broadcast_to(@gameboard, {type: DEBUG ,params: { message:"Player #{current_user.email} just played to monsterthree"}) | ||
current_card = Ingamedeck.find_by('id=?', paramsObject.unique_id) | ||
current_card.update_attribute(:cardable_type, "Monsterthree") | ||
when "center" | ||
broadcast_to(@gameboard, {type: DEBUG ,params: { message:"Player #{current_user.email} just played to center"}) | ||
#TODO currently not implemented | ||
else | ||
broadcast_to(@gameboard, {type: ERROR ,params: { message:"Player #{current_user.email} just played to something i dont know"}) | ||
end | ||
|
||
broadcast_to(@gameboard, {type: BOARD_UPDATE, params: Gameboard.broadcast_gameBoard(@gameboard)}) | ||
end | ||
|
||
def unsubscribed | ||
# Any cleanup needed when channel is unsubscribed | ||
end | ||
|
||
private | ||
|
||
def deliver_error_message(e) | ||
broadcast_to(@gameboard) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# frozen_string_literal: true | ||
|
||
class GamesocketChannel < ApplicationCable::Channel | ||
rescue_from Exception, with: :deliver_error_message | ||
|
||
def subscribed | ||
awaiting_players = 'awaiting_players' | ||
|
||
# access current user with current_user | ||
puts current_user | ||
|
||
# #search for gameboard with open lobby | ||
unless gameboard = Gameboard.find_by(current_state: awaiting_players) | ||
gameboard = Gameboard.create(current_state: awaiting_players) | ||
end | ||
|
||
player = Player.new(gameboard_id: gameboard.id) | ||
|
||
|
||
player.user = current_user | ||
player.save! | ||
|
||
# #add user to player | ||
|
||
# puts gameboard | ||
# puts gameboard.players | ||
|
||
lobbyisfull = false | ||
|
||
if gameboard.players.count > 3 | ||
gameboard.current_state = 'started' | ||
### add who is allowed to play | ||
# gameboard.current_user = gameboard.players.first | ||
gameboard.save | ||
lobbyisfull = true | ||
end | ||
|
||
@gameboard = Gameboard.find(gameboard.id) | ||
stream_for @gameboard | ||
|
||
broadcast_to(@gameboard, "new Player#{current_user.email} conected to the gameboard id: #{@gameboard.id}") | ||
broadcast_to(@gameboard, "players in lobby: #{@gameboard.players.count}") | ||
|
||
|
||
@gameboard.players.each do |player| | ||
PlayerChannel.broadcast_to( player.user , "only you should get this you are #{player.user.email}" ) | ||
end | ||
|
||
|
||
# if lobby is full tell other players | ||
if lobbyisfull | ||
|
||
players = @gameboard.players | ||
# much to do | ||
players.each do |player| | ||
handcard = Handcard.create(player_id: player.id) | ||
Ingamedeck.new(gameboard_id: @gameboard.id, card_id: 1, cardable_id: handcard.id, cardable_type: 'Handcard').save! | ||
Ingamedeck.new(gameboard_id: @gameboard.id, card_id: 2, cardable_id: handcard.id, cardable_type: 'Handcard').save! | ||
|
||
# player.handcard.cards << (Card.find(1)) | ||
# player.handcard.cards << (Card.find(2)) | ||
puts "--------------------" | ||
puts player.handcard.cards | ||
|
||
# broadcast_to(@gameboard, "player.handcard.cards") | ||
|
||
# broadcast_to(@gameboard, player.handcard.cards) | ||
|
||
PlayerChannel.broadcast_to(player.user, player.handcard.cards ) | ||
end | ||
|
||
broadcast_to(@gameboard, 'Lobby is full start with game') | ||
broadcast_to(@gameboard, { action: 'startGame', gameboard: @gameboard.players }) | ||
end | ||
end | ||
|
||
def play_card(data) | ||
# ##add actions! | ||
|
||
dataObject = JSON.parse data | ||
puts data | ||
|
||
|
||
|
||
|
||
broadcast_to(@gameboard, { action: 'player played', data: data }) | ||
end | ||
|
||
def unsubscribed | ||
# Any cleanup needed when channel is unsubscribed | ||
end | ||
|
||
private | ||
|
||
def deliver_error_message(e) | ||
broadcast_to(...) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
class LobbyChannel < ApplicationCable::Channel | ||
rescue_from Exception, with: :deliver_error_message | ||
|
||
def subscribed | ||
awaiting_players = 'awaiting_players' | ||
|
||
# access current user with current_user | ||
puts current_user | ||
|
||
|
||
|
||
#check if there is not a player with this user | ||
## read find or create by for simpler solution | ||
if player = Player.find(user_id:current_user.id) | ||
transmit {type: "error", params:{message: "user is already playing in #{player.gameboard_id}"}} | ||
reject | ||
end | ||
|
||
#search for gameboard with open lobby | ||
unless gameboard = Gameboard.find_by(current_state: awaiting_players) | ||
gameboard = Gameboard.create(current_state: awaiting_players) | ||
end | ||
|
||
if player.inventory | ||
|
||
#create new player | ||
player = Player.new(gameboard_id: gameboard.id) | ||
player.user = current_user | ||
player.save! | ||
|
||
|
||
|
||
handcard = Handcard.create(player_id: player.id) unless player.monsterone | ||
Ingamedeck.create(card_id: params[:monsterone], gameboard: gameboard, cardable: handcard) | ||
|
||
lobbyisfull = false | ||
|
||
|
||
if gameboard.players.count > 3 | ||
gameboard.current_state = 'started' | ||
### add add the starting user | ||
gameboard.current_player= gameboard.players.first | ||
gameboard.save | ||
lobbyisfull = true | ||
end | ||
|
||
|
||
# hopefully it is the same after saving? | ||
@gameboard = gameboard | ||
|
||
stream_for @gameboard | ||
|
||
|
||
broadcast_to(@gameboard, {type: "DEBUG" ,params: { message:"new Player#{current_user.email} conected to the gameboard id: #{@gameboard.id} players in lobby #{@gameboard.players.count}"}}) | ||
|
||
if lobbyisfull | ||
# Lobby is full tell players to start the game | ||
broadcast_to(@gameboard, {type: "DEBUG" , params: {message: 'Lobby is full start with game subscribe to Player and GameChannel'}}) | ||
|
||
Gameboard.initialize_gameBoard(@gameboard) | ||
broadcast_to(@gameboard, { type: 'START_GAME', params:{ game_id: @gameboard.id }}) | ||
end | ||
|
||
end | ||
|
||
def unsubscribed | ||
# Any cleanup needed when channel is unsubscribed | ||
end | ||
|
||
private | ||
|
||
def deliver_error_message(e) | ||
broadcast_to(@gameboard, {type: "error", params:{message: e}}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class PlayerChannel < ApplicationCable::Channel | ||
def subscribed | ||
stream_for current_user | ||
broadcast_to(current_user, { type: DEBUG, params: { message: "you are now subscribed to the player Channel #{current_user.email}" } }) | ||
broadcast_to(current_user, { type: HANDCARD_UPDATE, params: { handcards: Player.find(current_user.id).handcard.cards }) | ||
|
||
end | ||
|
||
def unsubscribed | ||
# Any cleanup needed when channel is unsubscribed | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
class GameSocketController < ApplicationController | ||
end |
Oops, something went wrong.