Factor common code out of xboard and gnushogi engines.
[kaya/ydirson.git] / lib / board / item_bag.rb
blob3e7964a60784ee20a61f2fd36d466b807a2491ab
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 'item'
10 module ItemBag
11   def add_item(key, *args)
12     remove_item key
13     item = create_item(key, *args)
14     items[key] = item
15   end
16   
17   def remove_item(key, *args)
18     if items[key]
19       destroy_item items[key] unless args.include? :keep
20       removed = items[key]
21       items[key] = nil
22       removed
23     end
24   end
25   
26   def move_item(src, dst)
27     remove_item dst
28     items[dst] = items[src]
29     items[src] = nil
30     items[dst]
31   end
32 end