From 5277eba2a7f7d098122b1f9fbd36ed98b1ffb070 Mon Sep 17 00:00:00 2001
From: Paolo Capriotti
Date: Thu, 25 Jun 2009 13:03:17 +0200
Subject: [PATCH] Add 'save' action.
---
lib/clock.rb | 2 +-
lib/controller.rb | 2 +-
lib/games/chess/pgn.rb | 4 ++--
lib/interaction/match.rb | 5 +++++
lib/mainwindow.rb | 16 ++++++++++++++++
5 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/lib/clock.rb b/lib/clock.rb
index 11104f2..1f1b3d4 100644
--- a/lib/clock.rb
+++ b/lib/clock.rb
@@ -95,7 +95,7 @@ class Clock
end
def timer
- if @main > 0
+ if @main > 0 or (not @byoyomi)
{ :main => @main }
else
{ :byoyomi => @byoyomi.dup }
diff --git a/lib/controller.rb b/lib/controller.rb
index ce34bc3..4653cf7 100644
--- a/lib/controller.rb
+++ b/lib/controller.rb
@@ -8,7 +8,7 @@ class Controller
include Observer
include Player
- attr_reader :history
+ attr_reader :match
attr_reader :color
attr_reader :controlled
attr_reader :table
diff --git a/lib/games/chess/pgn.rb b/lib/games/chess/pgn.rb
index a5795e9..33aa61b 100644
--- a/lib/games/chess/pgn.rb
+++ b/lib/games/chess/pgn.rb
@@ -15,8 +15,8 @@ class PGN
tag(:site, info[:site]) +
tag(:date, date) +
tag(:round, info[:round]) +
- tag(:white, info[:white]) +
- tag(:black, info[:black]) +
+ tag(:white, info.fetch(:players, {})[:white]) +
+ tag(:black, info.fetch(:players, {})[:black]) +
tag(:result, result(info[:result])) +
game(history) + " " +
result(info[:result]) + "\n"
diff --git a/lib/interaction/match.rb b/lib/interaction/match.rb
index f94bbcd..a5530ca 100644
--- a/lib/interaction/match.rb
+++ b/lib/interaction/match.rb
@@ -22,6 +22,7 @@ class Match
@history = nil
@kind = opts[:kind] || :local
@editable = opts.fetch(:editable, true)
+ @info = { }
end
def register(player)
@@ -111,6 +112,10 @@ class Match
:result => result,
:message => message }
end
+
+ def info
+ @info.merge(:players => @players.keys)
+ end
private
diff --git a/lib/mainwindow.rb b/lib/mainwindow.rb
index 936b399..c431363 100644
--- a/lib/mainwindow.rb
+++ b/lib/mainwindow.rb
@@ -33,6 +33,8 @@ private
def setup_actions
std_action(:open_new) { new_game(@default_game) }
std_action :quit, :slot => :close
+ std_action(:save) { save_game }
+
regular_action :back, :icon => 'go-previous',
:text => KDE.i18n("&Back") do
@controller.back
@@ -131,6 +133,20 @@ private
@controller.reset(match)
end
+
+ def save_game
+ match = @controller.match
+ if match
+ writer = match.game.game_writer.new
+ info = match.info
+ info[:players] = info[:players].inject({}) do |res, pl|
+ res[pl.color] = pl.name
+ res
+ end
+ result = writer.write(info, match.history)
+ puts result
+ end
+ end
end
class DummyPlayer
--
2.11.4.GIT