comparison pyntnclick/main.py @ 792:bdaffaa8b6bf pyntnclick

Loading and saving! (Plus a bunch of other stuff to make it possible.)
author Jeremy Thurgood <firxen@gmail.com>
date Sun, 27 Jan 2013 12:43:28 +0200
parents fb8c146017a9
children 42cfafa20437
comparison
equal deleted inserted replaced
791:56ec01e51f3d 792:bdaffaa8b6bf
68 68
69 locale.setlocale(locale.LC_ALL, "") 69 locale.setlocale(locale.LC_ALL, "")
70 lang = locale.getdefaultlocale(['LANGUAGE', 'LC_ALL', 'LC_CTYPE', 70 lang = locale.getdefaultlocale(['LANGUAGE', 'LC_ALL', 'LC_CTYPE',
71 'LANG'])[0] 71 'LANG'])[0]
72 self.resource = Resources(self._resource_module, lang) 72 self.resource = Resources(self._resource_module, lang)
73 gettext.bindtextdomain(self.constants.i18n_name, 73 gettext.bindtextdomain(self.constants.short_name,
74 self.resource.get_resource_path('locale')) 74 self.resource.get_resource_path('locale'))
75 gettext.textdomain(self.constants.i18n_name) 75 gettext.textdomain(self.constants.short_name)
76 76
77 self._check_translations() 77 self._check_translations()
78 78
79 self.sound = Sound(self.resource) 79 self.sound = Sound(self.resource)
80 self.debug_options = [] 80 self.debug_options = []
86 mopath = self.resource.get_resource_path('locale') 86 mopath = self.resource.get_resource_path('locale')
87 for candidate in os.listdir(popath): 87 for candidate in os.listdir(popath):
88 if candidate.endswith('.po'): 88 if candidate.endswith('.po'):
89 polang = candidate.split('.', 1)[0] 89 polang = candidate.split('.', 1)[0]
90 pofile = os.path.join(popath, candidate) 90 pofile = os.path.join(popath, candidate)
91 mofile = gettext.find(self.constants.i18n_name, mopath, 91 mofile = gettext.find(self.constants.short_name, mopath,
92 (polang,)) 92 (polang,))
93 if mofile is None: 93 if mofile is None:
94 print 'Missing mo file for %s' % pofile 94 print 'Missing mo file for %s' % pofile
95 continue 95 continue
96 if os.stat(pofile).st_mtime > os.stat(mofile).st_mtime: 96 if os.stat(pofile).st_mtime > os.stat(mofile).st_mtime:
97 print 'po file %s is newer than mo file %s' % (pofile, 97 print 'po file %s is newer than mo file %s' % (pofile,
98 mofile) 98 mofile)
99 99
100 def initial_state(self): 100 def initial_state(self, game_state=None):
101 """Create a copy of the initial game state.""" 101 """Create a copy of the initial game state."""
102 initial_state = state.Game(self) 102 initial_state = state.Game(self, self.game_state_class()(game_state))
103 initial_state.set_debug_rects(self._debug_rects) 103 initial_state.set_debug_rects(self._debug_rects)
104 for scene in self._scene_list: 104 for scene in self._scene_list:
105 initial_state.load_scenes(scene) 105 initial_state.load_scenes(scene)
106 initial_state.change_scene(self._initial_scene) 106 if initial_state.data['current_scene'] is None:
107 initial_state.data.set_current_scene(self._initial_scene)
108 initial_state.change_scene(initial_state.data['current_scene'])
107 return initial_state 109 return initial_state
108 110
109 def game_state(self): 111 def game_state_class(self):
110 return state.GameState() 112 return state.GameState
111 113
112 def game_constants(self): 114 def game_constants(self):
113 return GameConstants() 115 return GameConstants()
114 116
115 def option_parser(self): 117 def option_parser(self):
191 self.engine.set_screen(self.START_SCREEN) 193 self.engine.set_screen(self.START_SCREEN)
192 try: 194 try:
193 self.engine.run() 195 self.engine.run()
194 except KeyboardInterrupt: 196 except KeyboardInterrupt:
195 pass 197 pass
198
199 def get_default_save_location(self):
200 """Return a default save game location."""
201 app = self.constants.short_name
202 if sys.platform.startswith("win"):
203 if "APPDATA" in os.environ:
204 return os.path.join(os.environ["APPDATA"], app)
205 return os.path.join(os.path.expanduser("~"), "." + app)
206 elif 'XDG_DATA_HOME' in os.environ:
207 return os.path.join(os.environ["XDG_DATA_HOME"], app)
208 return os.path.join(os.path.expanduser("~"), ".local", "share", app)