Mercurial > rinkhals
comparison gamelib/gameboard.py @ 463:e3408c803b12
Save and restore tilevid when loading / saving games.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Mon, 23 Nov 2009 22:43:55 +0000 |
parents | aba7f1439571 |
children | d5e4959cfe7a |
comparison
equal
deleted
inserted
replaced
462:aba7f1439571 | 463:e3408c803b12 |
---|---|
74 FENCE = tiles.REVERSE_TILE_MAP['fence'] | 74 FENCE = tiles.REVERSE_TILE_MAP['fence'] |
75 WOODLAND = tiles.REVERSE_TILE_MAP['woodland'] | 75 WOODLAND = tiles.REVERSE_TILE_MAP['woodland'] |
76 BROKEN_FENCE = tiles.REVERSE_TILE_MAP['broken fence'] | 76 BROKEN_FENCE = tiles.REVERSE_TILE_MAP['broken fence'] |
77 | 77 |
78 SIMPLIFY = [ | 78 SIMPLIFY = [ |
79 'tv', | |
79 'chickens', | 80 'chickens', |
80 'buildings', | 81 'buildings', |
81 'foxes', | 82 'foxes', |
82 'cash', | 83 'cash', |
83 'wood', | 84 'wood', |
847 sell_price = float(10*width*height)/treesleft | 848 sell_price = float(10*width*height)/treesleft |
848 buy_price = sell_price*(1.1) | 849 buy_price = sell_price*(1.1) |
849 self.wood_sell_price, self.wood_buy_price = int(sell_price), int(buy_price) | 850 self.wood_sell_price, self.wood_buy_price = int(sell_price), int(buy_price) |
850 | 851 |
851 def save_game(self): | 852 def save_game(self): |
853 # clear selected animals and tool states before saving | |
854 self.reset_states() | |
852 return serializer.simplify(self) | 855 return serializer.simplify(self) |
853 | 856 |
854 def restore_game(self, data): | 857 def restore_game(self, data): |
855 if 'refid' not in data or 'class' not in data or data['class'] != self.__class__.__name__: | 858 if 'refid' not in data or 'class' not in data or data['class'] != self.__class__.__name__: |
856 import pprint | |
857 pprint.pprint(data) | |
858 print self.__class__.__name__ | |
859 raise ValueError("Invalid save game.") | 859 raise ValueError("Invalid save game.") |
860 newself = serializer.unsimplify(data) | 860 |
861 # clear old state | |
861 self.clear_chickens() | 862 self.clear_chickens() |
862 self.clear_buildings() | 863 self.clear_buildings() |
863 for chicken in newself.chickens: | 864 |
864 self.add_chicken(chicken) | 865 # set new state |
865 for building in newself.buildings: | 866 newself = serializer.unsimplify(data) |
866 self.add_building(building) | 867 |
868 #import pdb | |
869 #pdb.set_trace() | |
870 | |
867 for attr in self.SIMPLIFY: | 871 for attr in self.SIMPLIFY: |
868 if attr in ('chickens', 'buildings'): | 872 if attr in ('chickens', 'buildings'): |
869 continue | 873 continue |
870 setattr(self, attr, getattr(newself, attr)) | 874 setattr(self, attr, getattr(newself, attr)) |
875 | |
876 self.tv.png_folder_load_tiles('tiles') | |
877 self.tvw.vid = self.tv | |
878 self.tvw.vid.bounds = pygame.Rect((0, 0), self.tv.tile_to_view(self.tv.size)) | |
879 | |
880 for chicken in newself.chickens: | |
881 self.add_chicken(chicken) | |
882 | |
883 for building in newself.buildings: | |
884 self.add_building(building) | |
885 | |
886 self.reset_states() | |
871 self.redraw_counters() | 887 self.redraw_counters() |
888 self.update() | |
872 | 889 |
873 | 890 |
874 class TextDialog(gui.Dialog): | 891 class TextDialog(gui.Dialog): |
875 def __init__(self, title, text, **params): | 892 def __init__(self, title, text, **params): |
876 title_label = gui.Label(title) | 893 title_label = gui.Label(title) |