Implement notification.
[kaya/ydirson.git] / lib / ics / driver.rb
blob26933831559e762042a411b6e63f494e68275844
1 $:.unshift(File.join(File.dirname(__FILE__), '..'))
2 require 'qtutils'
3 require 'board/table'
4 require 'themes/loader'
5 require 'games/chess/chess'
6 require 'controller'
7 require 'history'
8 require 'ics/connection'
9 require 'ics/protocol'
10 require 'console'
11 require 'board/user'
12 require 'board/notify'
13 require 'ics/match_handler'
15 protocol = ICS::Protocol.new(:debug)
16 c = ICS::Connection.new('freechess.org', 23)
17 c.debug = true
18 protocol.add_observer ICS::AuthModule.new(c, 'ujjajja', '')
19 protocol.add_observer ICS::StartupModule.new(c)
20 protocol.link_to c
22 description = "KDE Board Game Suite"
23 version = "1.5"
24 about = KDE::AboutData.new("kaya", "Kaya", KDE.ki18n("Kaya"),
25     version, KDE.ki18n(description),KDE::AboutData::License_GPL,KDE.ki18n("(C) 2009 Paolo Capriotti"))
27 KDE::CmdLineArgs.init(ARGV, about)
29 app = KDE::Application.new
31 class Scene < Qt::GraphicsScene
32   def initialize
33     super
34   end
35 end
37 theme_loader = ThemeLoader.new
38 theme = Struct.new(:pieces, :background).new
39 theme.pieces = theme_loader.get('Celtic')
40 theme.background = theme_loader.get('Default', Point.new(8, 8))
42 chess = Game.get(:chess)
44 scene = Qt::GraphicsScene.new
46 state = chess.state.new
47 state.setup
49 board = Board.new(scene, theme, chess, state)
52 table = Table.new(scene, board)
53 table.size = Qt::Size.new(500, 500)
55 history = History.new(state)
56 controller = Controller.new(board, history)
58 table.show
60 console = Console.new(nil)
61 console.show
63 protocol.observe :text do |text|
64   console.append(text)
65 end
67 console.observe :input do |text|
68   c.send_text text
69 end
71 # board.observe :new_move do |data|
72 #   move = data[:move]
73 #   m = ('a'[0] + move.src.x).chr +
74 #     (8 - move.src.y).to_s +
75 #     ('a'[0] + move.dst.x).chr +
76 #     (8 - move.dst.y).to_s
77 #   puts m
78 #   c.send_text m
79 # end
81 notify = Notify.new(table)
82 user = User.new(:white, board, notify)
83 handler = ICS::MatchHandler.new(user, protocol)
85 protocol.observe :creating_game do |data|
86   puts "CREATING GAME: #{data.inspect}"
87 end
89 c.start
91 app.exec