diff --git a/app/models/game.rb b/app/models/game.rb
index b92db62d..65caf0a4 100644
--- a/app/models/game.rb
+++ b/app/models/game.rb
@@ -1,13 +1,13 @@
# The game class
class Game < ActiveRecord::Base
- belongs_to :table
+ belongs_to :table, optional: true
has_many :seats
has_many :players, dependent: :destroy
has_many :users, through: :players
has_many :player_cards, through: :players
has_many :plays, through: :players
- belongs_to :play_to_beat
- belongs_to :controlling_player, class_name: "Player", foreign_key: "controlling_player_id"
+ belongs_to :play_to_beat, optional: true
+ belongs_to :controlling_player, class_name: "Player", foreign_key: "controlling_player_id", optional: true
accepts_nested_attributes_for :players
#validates :title, presence: true
after_create :add_table
@@ -177,7 +177,7 @@ class Game < ActiveRecord::Base
@inventory_counts.include? 0
end
-private
+# private
def add_table
self.table ||= Table.create current_game_id: self.id
diff --git a/app/models/player.rb b/app/models/player.rb
index d96ed08e..488bc370 100644
--- a/app/models/player.rb
+++ b/app/models/player.rb
@@ -1,7 +1,7 @@
# Associates users to games
class Player < ActiveRecord::Base
belongs_to :game
- belongs_to :user
+ belongs_to :user, optional: true
has_many :player_cards
has_many :plays
@@ -32,7 +32,7 @@ class Player < ActiveRecord::Base
def display_name
return user.email.split("@")[0] if self.user
- return "BotPlayer" if self.is_bot?
+ return "BotPlayer #{self.id}" if self.is_bot?
return ("Guest" + self.soft_token)[0..9] if self.soft_token
return "Empty"
end
diff --git a/app/models/player_card.rb b/app/models/player_card.rb
index 3e6942d0..6ad35945 100644
--- a/app/models/player_card.rb
+++ b/app/models/player_card.rb
@@ -1,6 +1,6 @@
class PlayerCard < ActiveRecord::Base
belongs_to :player
- belongs_to :play
+ belongs_to :play, optional: true
def to_s
# TODO: Shouldn't hard code face cards here
diff --git a/app/models/seat.rb b/app/models/seat.rb
index 847749de..98e146f5 100644
--- a/app/models/seat.rb
+++ b/app/models/seat.rb
@@ -14,12 +14,12 @@ class Seat < ActiveRecord::Base
self.reload
if self.player == nil
# TODO: Decouple seat from game
- # self.player_id = self.table.current_game.add_player_from_user(current_user).id
+ self.player_id = self.table.current_game.add_player_from_user(current_user).id
end
- # self.player.user_id = current_user.id
- # self.player.soft_token = current_user.soft_token
- # self.player.save
+ self.player.user_id = current_user.id
+ self.player.soft_token = current_user.soft_token
+ self.player.save
self.user_id = current_user.id
self.user_soft_token = current_user.soft_token
diff --git a/app/models/table.rb b/app/models/table.rb
index ba41050c..7baef55e 100644
--- a/app/models/table.rb
+++ b/app/models/table.rb
@@ -6,7 +6,7 @@ class Table < ActiveRecord::Base
has_many :users, through: :seats
has_many :games
has_many :players, through: :games
- belongs_to :token
+ # belongs_to :token
#TODO: Deprecated current_game_id from database.
# Instead calculate with self.current_game
#
@@ -14,7 +14,7 @@ class Table < ActiveRecord::Base
#TODO: Should these be part of Game initialize instead of callback?
after_create :add_seats
- # after_create :add_game
+ after_create :add_game # TODO decouple game from table
# Returns the newest joinable table or creates a new table if none are found
# scope :play_now, lambda { |user|
@@ -36,6 +36,8 @@ class Table < ActiveRecord::Base
def add_game
self.games.create
+ # game = self.games.new
+ # game.
end
# private
diff --git a/app/policies/table_policy.rb b/app/policies/table_policy.rb
index 51405109..9e61b4fc 100644
--- a/app/policies/table_policy.rb
+++ b/app/policies/table_policy.rb
@@ -15,11 +15,11 @@ class TablePolicy
end
def create?
- @current_user.admin?
+ @current_user.admin? || true
end
def new?
- @current_user.admin?
+ @current_user.admin? || true
end
def edit?
@@ -36,7 +36,8 @@ class TablePolicy
end
def play_now?
- @current_user.admin? || @current_user.email == "bort@13.24x7.hk"
+ return true
+ # @current_user.admin? || @current_user.email == "bort@13.24x7.hk"
end
def new_game?
diff --git a/app/views/layouts/_navigation_links.html.erb b/app/views/layouts/_navigation_links.html.erb
deleted file mode 100644
index f1993ebd..00000000
--- a/app/views/layouts/_navigation_links.html.erb
+++ /dev/null
@@ -1,37 +0,0 @@
-
diff --git a/app/views/layouts/_navigation_links.html.haml b/app/views/layouts/_navigation_links.html.haml
new file mode 100644
index 00000000..723fdd66
--- /dev/null
+++ b/app/views/layouts/_navigation_links.html.haml
@@ -0,0 +1,28 @@
+%nav
+ %ul
+ %li= link_to 'Home', root_path, class: "home-link", data: { turbo: false }
+ -# - if current_user.signed_in?
+ -# %li= link_to 'My Tendy Zone', root_path, class: "home-link", data: { turbo: false }
+ -# %li= link_to 'Public', '/public', data: { turbo: false }
+ -# %li= link_to 'Tokens', tokens_path
+ -# %li= link_to 'Profiles', profiles_path
+ -# %li= link_to 'Projects', projects_path
+ -# %li= link_to 'MetaPurse', metapurses_path
+ -# - if policy(:canister).index?
+ -# %li= link_to 'Canisters', canisters_path
+ -# %li= link_to 'Doodads', doodads_path, data: { turbo: false }
+ -# - if policy(:bot).index?
+ -# %li= link_to 'Bots', bots_path
+ - if policy(:table).index?
+ %li= link_to 'Tables', tables_path
+ -# - if policy(:room).index?
+ -# %li= link_to 'Chat', rooms_path
+ - if current_user.signed_in?
+ - if current_user.admin?
+ %li= link_to 'Users', users_path
+ - if current_user.signed_in?
+ %li= link_to 'My account', edit_user_registration_path
+ %li= link_to 'Sign out', destroy_user_session_path, :method=>'delete'
+ - else
+ %li= link_to 'Sign in', new_user_session_path
+ %li= link_to 'Sign up', new_user_registration_path
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index c2484793..5e1ded7e 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -26,7 +26,7 @@
<%= render "layouts/navigation_links" %>
- <%= render "layouts/navigation_wallet" %>
+ <%# <%= render "layouts/navigation_wallet" %1> %>
<%= render "layouts/flashmessages" %>
@@ -35,9 +35,9 @@
<%= yield %>
-
+ <%# %>