def _delete_savegame(self, map_files): """Deletes the selected savegame if the user confirms self._gui has to contain the widget "savegamelist" @param map_files: list of files that corresponds to the entries of 'savegamelist' @return: True if something was deleted, else False """ selected_item = self._gui.collectData("savegamelist") if selected_item == -1 or selected_item >= len(map_files): self._windows.open_popup( T("No file selected"), T("You need to select a savegame to delete.")) return False selected_file = map_files[selected_item] message = T( "Do you really want to delete the savegame '{name}'?").format( name=SavegameManager.get_savegamename_from_filename( selected_file)) if self._windows.open_popup(T("Confirm deletion"), message, show_cancel_button=True): try: os.unlink(selected_file) return True except: self._windows.open_popup(T("Error!"), T("Failed to delete savefile!")) return False else: # player cancelled deletion return False
def _delete_savegame(self, map_files): """Deletes the selected savegame if the user confirms self.current has to contain the widget "savegamelist" @param map_files: list of files that corresponds to the entries of 'savegamelist' @return: True if something was deleted, else False """ selected_item = self.current.collectData("savegamelist") if selected_item == -1: self.show_popup(_("No file selected"), _("You need to select a savegame to delete")) return False selected_file = map_files[selected_item] if self.show_popup(_("Confirm deletion"), _('Do you really want to delete the savegame "%s"?') % \ SavegameManager.get_savegamename_from_filename(selected_file), \ show_cancel_button = True): os.unlink(selected_file) return True else: return False
def _delete_savegame(self, map_files): """Deletes the selected savegame if the user confirms self._gui has to contain the widget "savegamelist" @param map_files: list of files that corresponds to the entries of 'savegamelist' @return: True if something was deleted, else False """ selected_item = self._gui.collectData("savegamelist") if selected_item == -1 or selected_item >= len(map_files): self._windows.open_popup(_("No file selected"), _("You need to select a savegame to delete.")) return False selected_file = map_files[selected_item] message = _("Do you really want to delete the savegame '{name}'?").format( name=SavegameManager.get_savegamename_from_filename(selected_file)) if self._windows.open_popup(_("Confirm deletion"), message, show_cancel_button=True): try: os.unlink(selected_file) return True except: self._windows.open_popup(_("Error!"), _("Failed to delete savefile!")) return False else: # player cancelled deletion return False
def __init__(self, game_identifier, is_map, options=None): is_random_map = False if is_map: self.upgrader = None handle, self._temp_path = tempfile.mkstemp() os.close(handle) super(SavegameAccessor, self).__init__(dbfile=self._temp_path) with open('content/savegame_template.sql') as savegame_template: self.execute_script(savegame_template.read()) if isinstance(game_identifier, list): is_random_map = True random_island_sequence = game_identifier else: self._map_path = game_identifier else: self.upgrader = SavegameUpgrader(game_identifier) self._temp_path = None game_identifier = self.upgrader.get_path() super(SavegameAccessor, self).__init__(dbfile=game_identifier) map_name_data = self('SELECT value FROM metadata WHERE name = ?', 'map_name') if not map_name_data: is_random_map = True random_island_sequence = self('SELECT value FROM metadata WHERE name = ?', 'random_island_sequence')[0][0].split(' ') else: map_name = map_name_data[0][0] if map_name.startswith('USER_MAPS_DIR:'): self._map_path = PATHS.USER_MAPS_DIR + map_name[len('USER_MAPS_DIR:'):] elif os.path.isabs(map_name): self._map_path = map_name else: self._map_path = SavegameManager.get_filename_from_map_name(map_name) if is_random_map: handle, self._temp_path2 = tempfile.mkstemp() os.close(handle) random_map_db = DbReader(self._temp_path2) with open('content/map-template.sql') as map_template: random_map_db.execute_script(map_template.read()) for island_id, island_string in enumerate(random_island_sequence): create_random_island(random_map_db, island_id, island_string) random_map_db.close() self._map_path = self._temp_path2 self('INSERT INTO metadata VALUES(?, ?)', 'random_island_sequence', ' '.join(random_island_sequence)) if options is not None: if options.map_padding is not None: self("INSERT INTO map_properties VALUES(?, ?)", 'padding', options.map_padding) self('ATTACH ? AS map_file', self._map_path) if is_random_map: self.map_name = random_island_sequence elif os.path.isabs(self._map_path): self.map_name = self._map_path else: self.map_name = SavegameManager.get_savegamename_from_filename(self._map_path) map_padding = self("SELECT value FROM map_properties WHERE name = 'padding'") self.map_padding = int(map_padding[0][0]) if map_padding else MAP.PADDING self._load_building() self._load_settlement() self._load_concrete_object() self._load_production() self._load_storage() self._load_wildanimal() self._load_unit() self._load_building_collector() self._load_production_line() self._load_unit_path() self._load_storage_global_limit() self._load_health() self._load_fish_data() self._hash = None
def __init__(self, game_identifier, is_map, options=None): is_random_map = False if is_map: self.upgrader = None handle, self._temp_path = tempfile.mkstemp() os.close(handle) super().__init__(dbfile=self._temp_path) with open('content/savegame_template.sql') as savegame_template: self.execute_script(savegame_template.read()) if isinstance(game_identifier, list): is_random_map = True random_island_sequence = game_identifier else: self._map_path = game_identifier else: self.upgrader = SavegameUpgrader(game_identifier) self._temp_path = None game_identifier = self.upgrader.get_path() super().__init__(dbfile=game_identifier) map_name_data = self('SELECT value FROM metadata WHERE name = ?', 'map_name') if not map_name_data: is_random_map = True random_island_sequence = self( 'SELECT value FROM metadata WHERE name = ?', 'random_island_sequence')[0][0].split(' ') else: map_name = map_name_data[0][0] if map_name.startswith('USER_MAPS_DIR:'): self._map_path = PATHS.USER_MAPS_DIR + map_name[ len('USER_MAPS_DIR:'):] elif os.path.isabs(map_name): self._map_path = map_name else: self._map_path = SavegameManager.get_filename_from_map_name( map_name) if is_random_map: handle, self._temp_path2 = tempfile.mkstemp() os.close(handle) random_map_db = DbReader(self._temp_path2) with open('content/map-template.sql') as map_template: random_map_db.execute_script(map_template.read()) for island_id, island_string in enumerate(random_island_sequence): create_random_island(random_map_db, island_id, island_string) random_map_db.close() self._map_path = self._temp_path2 self('INSERT INTO metadata VALUES(?, ?)', 'random_island_sequence', ' '.join(random_island_sequence)) if options is not None: if options.map_padding is not None: self("INSERT INTO map_properties VALUES(?, ?)", 'padding', options.map_padding) if not os.path.exists(self._map_path): raise MapFileNotFound("Map file " + str(self._map_path) + " not found!") self('ATTACH ? AS map_file', self._map_path) if is_random_map: self.map_name = random_island_sequence elif os.path.isabs(self._map_path): self.map_name = self._map_path else: self.map_name = SavegameManager.get_savegamename_from_filename( self._map_path) map_padding = self( "SELECT value FROM map_properties WHERE name = 'padding'") self.map_padding = int( map_padding[0][0]) if map_padding else MAP.PADDING self._load_building() self._load_settlement() self._load_concrete_object() self._load_production() self._load_storage() self._load_wildanimal() self._load_unit() self._load_building_collector() self._load_production_line() self._load_unit_path() self._load_storage_global_limit() self._load_health() self._load_fish_data() self._hash = None
def __init__(self, game_identifier, is_map): is_random_map = False if is_map: self.upgrader = None handle, self._temp_path = tempfile.mkstemp() os.close(handle) super(SavegameAccessor, self).__init__(dbfile=self._temp_path) with open("content/savegame_template.sql") as savegame_template: self.execute_script(savegame_template.read()) if isinstance(game_identifier, list): is_random_map = True random_island_sequence = game_identifier else: self._map_path = game_identifier else: self.upgrader = SavegameUpgrader(game_identifier) self._temp_path = None game_identifier = self.upgrader.get_path() super(SavegameAccessor, self).__init__(dbfile=game_identifier) map_name_data = self("SELECT value FROM metadata WHERE name = ?", "map_name") if not map_name_data: is_random_map = True random_island_sequence = self("SELECT value FROM metadata WHERE name = ?", "random_island_sequence")[0][ 0 ].split(" ") else: map_name = map_name_data[0][0] if os.path.isabs(map_name): self._map_path = map_name else: self._map_path = SavegameManager.get_filename_from_map_name(map_name) if is_random_map: handle, self._temp_path2 = tempfile.mkstemp() os.close(handle) random_map_db = DbReader(self._temp_path2) with open("content/map-template.sql") as map_template: random_map_db.execute_script(map_template.read()) for island_id, island_string in enumerate(random_island_sequence): create_random_island(random_map_db, island_id, island_string) random_map_db.close() self._map_path = self._temp_path2 self("INSERT INTO metadata VALUES(?, ?)", "random_island_sequence", " ".join(random_island_sequence)) self("ATTACH ? AS map_file", self._map_path) if is_random_map: self.map_name = random_island_sequence elif os.path.isabs(self._map_path): self.map_name = self._map_path else: self.map_name = SavegameManager.get_savegamename_from_filename(self._map_path) self._load_building() self._load_settlement() self._load_concrete_object() self._load_production() self._load_storage() self._load_wildanimal() self._load_unit() self._load_building_collector() self._load_production_line() self._load_unit_path() self._load_storage_global_limit() self._load_health() self._load_fish_data() self._hash = None
def __init__(self, game_identifier, is_map): is_random_map = False if is_map: self.upgrader = None handle, self._temp_path = tempfile.mkstemp() os.close(handle) super(SavegameAccessor, self).__init__(dbfile=self._temp_path) with open('content/savegame_template.sql') as savegame_template: self.execute_script(savegame_template.read()) if isinstance(game_identifier, list): is_random_map = True random_island_sequence = game_identifier else: self._map_path = game_identifier else: self.upgrader = SavegameUpgrader(game_identifier) self._temp_path = None game_identifier = self.upgrader.get_path() super(SavegameAccessor, self).__init__(dbfile=game_identifier) map_name_data = self('SELECT value FROM metadata WHERE name = ?', 'map_name') if not map_name_data: is_random_map = True random_island_sequence = self( 'SELECT value FROM metadata WHERE name = ?', 'random_island_sequence')[0][0].split(' ') else: map_name = map_name_data[0][0] if os.path.isabs(map_name): self._map_path = map_name else: self._map_path = SavegameManager.get_filename_from_map_name( map_name) if is_random_map: handle, self._temp_path2 = tempfile.mkstemp() os.close(handle) random_map_db = DbReader(self._temp_path2) with open('content/map-template.sql') as map_template: random_map_db.execute_script(map_template.read()) for island_id, island_string in enumerate(random_island_sequence): create_random_island(random_map_db, island_id, island_string) random_map_db.close() self._map_path = self._temp_path2 self('INSERT INTO metadata VALUES(?, ?)', 'random_island_sequence', ' '.join(random_island_sequence)) self('ATTACH ? AS map_file', self._map_path) if is_random_map: self.map_name = random_island_sequence elif os.path.isabs(self._map_path): self.map_name = self._map_path else: self.map_name = SavegameManager.get_savegamename_from_filename( self._map_path) self._load_building() self._load_settlement() self._load_concrete_object() self._load_production() self._load_storage() self._load_wildanimal() self._load_unit() self._load_building_collector() self._load_production_line() self._load_unit_path() self._load_storage_global_limit() self._load_health() self._load_fish_data() self._hash = None