Permalink
Browse files

Possibly working ? But mostly complete implementation of UI for accep…

…ting/declining draws
  • Loading branch information...
1 parent b2ab245 commit c498212b04e284b4f4d57206c9b77e4f13b5ea47 Dean Radcliffe committed Nov 12, 2010
@@ -13,7 +13,7 @@ def players
render :json => Player.find(:all, :conditions => "name like '#{ params[:term] }%'" ).map(&:name)
end
- # give up the ghost
+ # TODO can consolidate these match actions into one method for nice LOC savings - delegate actions to model
def resign
match.resign( request.player )
match.save!
@@ -24,6 +24,10 @@ def offer_draw
match.draw_offerer = request.player
match.save!
end
+
+ def decline_draw
+ match.update_attribute(:draw_offerer, nil)
+ end
def accept_draw
return unless match.side_of( request.player ) && match.draw_offerer != request.player
@@ -41,7 +45,6 @@ def create( switch_em = params[:opponent_side] =='white' )
end
# TODO make match a thread-local global variable
- def match; request.match; end
- private :match
+ def match; request.match; end; private :match
end
@@ -7,6 +7,11 @@
<span id="match_actions">
<%= link_to "Resign", url_for(:action => 'resign'), :confirm => I18n.t('actions.resign.confirmation') %>
+
+ <% unless match.draw_offerer %>
+ <%= link_to "Offer Draw", url_for(:action => 'offer_draw'), :confirm => I18n.t('actions.draw.offer') %>
+ <% end %>
+
<%= link_to "PGN", match_url(request.match, :format=>'pgn') %>
</span>
@@ -26,6 +31,7 @@
</div>
<div id="my_next_matches_div" data-bind="visible:my_next_matches().length > 0">Your turn in matches: <span id="my_next_matches"></span></div>
<div id="server_msg" data-bind="visible:has_message(), text:server_messages()"></div>
+ <div id="opponents_draw_offer" data-bind="visible:opponents_draw_offer().length >=1"></div>
</span>
<div id="board_parent" style="float:left; clear:left">
@@ -13,6 +13,11 @@ view.allowed_moves = <%= board.allowed_moves.to_json %>;
view.my_next_matches( <%= my_next_matches %> )
+// Let them act on any draw they've been offered
+<% if match.active && match.draw_offerer && match.draw_offerer != request.player -%>
+view.opponents_draw_offer( "Draw offered!: <a href='#' onclick='view.accept_draw();return false;'>Accept</a> <a href='#' onclick='view.decline_draw();return false;'>Decline</a>" )
+<% end -%>
+
// Update any moves/boards they haven't seen;
<% match.moves_more_recent_than( params[:last_move_id].to_i ).each do |move| -%>
view.add_move(
@@ -29,6 +29,7 @@ var view = {
display_board: new ko.observable(<%= match.moves.length %>),
chat_msg: new ko.observable(''), //the message the user is entering
+ opponents_draw_offer: new ko.observable(''), //the message shown to the recipient of a draw offer
all_moves: new ko.observableArray([
<%= match.moves.map(&:to_json).join(",\n ") %>
@@ -261,6 +262,16 @@ var view = {
return 'white'
if( piece_id.match( /_b$/ ) )
return 'black'
+ },
+ decline_draw: function(){
+ $.post( '<%= url_for(:action => 'decline_draw') %>',
+ { authenticity_token: '<%= form_authenticity_token %>' }
+ )
+ },
+ accept_draw: function(){
+ $.post( '<%= url_for(:action => 'accept_draw') %>',
+ { authenticity_token: '<%= form_authenticity_token %>'}
+ )
}
};
@@ -388,6 +399,10 @@ view.my_next_matches.subscribe( function(){
)
})
+view.opponents_draw_offer.subscribe( function(){
+ $("#opponents_draw_offer").html( view.opponents_draw_offer() )
+})
+
// Show first move
view.display_board( view.all_boards().length - 1 );
View
@@ -30,6 +30,8 @@ en:
actions:
resign:
confirmation: Are you truly ready to accept disgrace and sulk back to the rock from under which you came ?
+ draw:
+ offer: This draw offer will be available until either accepted or your opponent moves. Ok ?
chat_actions:
script: '/script:'
View
@@ -20,10 +20,11 @@
end
create_table "gameplays", :force => true do |t|
- t.integer "player_id", :null => false
- t.integer "match_id", :null => false
- t.boolean "black", :default => false
- t.string "move_queue", :limit => 20
+ t.integer "player_id", :null => false
+ t.integer "match_id", :null => false
+ t.boolean "black", :default => false
+ t.string "move_queue", :limit => 20
+ t.boolean "email_notify", :default => true
t.datetime "created_at"
t.datetime "updated_at"
end
@@ -33,6 +34,7 @@
t.string "start_pos", :limit => 100
t.string "result", :limit => 10
t.integer "winning_player"
+ t.integer "draw_offerer"
t.string "name", :limit => 100
t.datetime "created_at"
t.datetime "updated_at"
@@ -18,6 +18,8 @@ h1 { font-size: 18pt; font-weight: bold; margin-bottom:3px; }
/*#playback_controls{ float:left;}*/
#server_msg { float:left; width:376px; height:20px; padding:2px; font-size: 10pt;
border: 1px black solid; background-color:#ddd;}
+#opponents_draw_offer { float:left; width:376px; height:20px; padding:2px; font-size: 10pt;
+ border: 1px black solid; background-color:#ddd;}
#match_status{ float:left; margin-right:20px; }
#original_board {margin-bottom: 5px;}

0 comments on commit c498212

Please sign in to comment.