Factor common code out of xboard and gnushogi engines.
[kaya/ydirson.git] / lib / board / element_manager.rb
blob7b34e409191b75c280ce2ee01e72e955108396f0
1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 require 'board/board'
9 require 'board/pool'
11 module ElementManager
12   def create_elements
13     Hash.new.tap do |elements|
14       elements[:board] = Board.new(scene, theme, game)
15       elements[:pools] = if game.respond_to? :pool
16         game.players.inject({}) do |res, player|
17           res[player] = Pool.new(scene, theme, game)
18           res
19         end
20       else
21         {}
22       end
23       clock_class = loader.get_matching(:clock)
24       elements[:clocks] = game.players.inject({}) do |res, player|
25         res[player] = clock_class.new(scene)
26         res
27       end
28     end
29   end
30 end