From 49d01ef3715cd805574fa995b2be9fc79cfbc418 Mon Sep 17 00:00:00 2001 From: Paolo Capriotti Date: Fri, 19 Jun 2009 21:40:54 +0200 Subject: [PATCH] Fix navigation and highlighting. --- lib/board/board.rb | 9 ++------- lib/controller.rb | 3 +++ lib/games/chess/animator.rb | 16 +++++++++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/board/board.rb b/lib/board/board.rb index 7c47053..80f519a 100644 --- a/lib/board/board.rb +++ b/lib/board/board.rb @@ -103,8 +103,7 @@ class Board < Qt::GraphicsItemGroup if e.button == Qt::RightButton # go back using the right button self.selection = nil - changed - notify_observers :back => nil + fire :back else p = to_logical(e.pos) @@ -113,7 +112,7 @@ class Board < Qt::GraphicsItemGroup validate = @game.validator.new(@state) if validate[move] perform! move - notify_observers :new_move => { :move => move, :state => @state.dup } + fire :new_move => { :move => move, :state => @state.dup } end self.selection = nil @@ -137,25 +136,21 @@ class Board < Qt::GraphicsItemGroup def perform!(move) @state.perform!(move) animate :forward, move - highlight(move) end def back(state, move) @state = state.dup animate :back, move - highlight(move) end def forward(state, move) @state = state.dup animate :forward, move - highlight(move) end def warp(state) @state = state.dup animate :warp, :instant => true - highlight(nil) end def animate(direction, *args) diff --git a/lib/controller.rb b/lib/controller.rb index c2eb7de..8fc2f19 100644 --- a/lib/controller.rb +++ b/lib/controller.rb @@ -15,11 +15,13 @@ class Controller def on_new_move(data) @history.add_move(data[:state], data[:move]) + @board.highlight(data[:move]) end def on_back state, move = @history.back @board.back(state.dup, move) + @board.highlight(@history.move) rescue History::OutOfBound puts "error: first move" end @@ -27,6 +29,7 @@ class Controller def on_forward state, move = @history.forward @board.forward(state.dup, move) + @board.highlight(@history.move) rescue History::OutOfBound puts "error: last move" end diff --git a/lib/games/chess/animator.rb b/lib/games/chess/animator.rb index 719dbb1..c3e3457 100644 --- a/lib/games/chess/animator.rb +++ b/lib/games/chess/animator.rb @@ -10,7 +10,7 @@ module Chess end def specific_move!(piece, src, dst) - path = if piece.type == :knight + path = if piece and piece.type == :knight Path::LShape else Path::Linear @@ -40,12 +40,13 @@ module Chess end def forward(state, move) + piece = state.board[move.dst] capture = disappear_on! move.dst - actual_move = specific_move! state.board[move.dst], move.src, move.dst + actual_move = specific_move! piece, move.src, move.dst extra = if move.type == :king_side_castling - move! move.dst + Point.new(1, 0), move.dst - Point.new(1, 0) + specific_move! piece, move.dst + Point.new(1, 0), move.dst - Point.new(1, 0) elsif move.type == :queen_side_castling - move! move.dst - Point.new(2, 0), move.dst + Point.new(1, 0) + specific_move! piece, move.dst - Point.new(2, 0), move.dst + Point.new(1, 0) end rest = warp(state, :instant => false) @@ -55,11 +56,12 @@ module Chess end def back(state, move) - actual_move = move! move.dst, move.src + piece = state.board[move.src] + actual_move = specific_move! piece, move.dst, move.src extra = if move.type == :king_side_castling - move! move.dst - Point.new(1, 0), move.dst + Point.new(1, 0) + specific_move! piece, move.dst - Point.new(1, 0), move.dst + Point.new(1, 0) elsif move.type == :queen_side_castling - move! move.dst + Point.new(1, 0), move.dst - Point.new(2, 0) + specific_move! piece, move.dst + Point.new(1, 0), move.dst - Point.new(2, 0) end rest = warp(state, :instant => false) -- 2.11.4.GIT