def load_level_file(self, path): """Load the specified level file. Reports errors to the user. Raises Cancel if an error occurs.""" try: self.game.load_level(path) except EnvironmentError, e: alert("Unable to load '%s': %s" % (os.path.basename(path), e)) raise Cancel
def load_game_file(self, path): """Load a saved game from the specified path. Reports errors to the user. Raises Cancel if cancelled or an error occurs.""" try: self.game.load_game(path) except EnvironmentError, e: alert("Unable to load '%s': %s" % (os.path.basename(path), e)) raise Cancel
def load_game_file(self, path): """Load a saved game from the specified path. Reports errors to the user. Raises Cancel if cancelled or an error occurs.""" try: self.game.load_game(path) except EnvironmentError, e: alert("Unable to load '%s': %s" % ( os.path.basename(path), e)) raise Cancel
def update(self): client = self.client dir = client.directory suffixes = client.suffixes def filter(name): path = os.path.join(dir, name) return os.path.isdir(path) or self.client.filter(path) try: names = [name for name in os.listdir(dir) if not name.startswith(".") and filter(name)] except EnvironmentError, e: alert("%s: %s" % (dir, e)) names = []
def create_level_set_cmd(self): """Implementation of the 'Create Level Set' command.""" path = request_new_filename(prompt = "Create level set named:", suffix = self.game.level_set_suffix, directory = self.game.get_custom_level_set_dir(), filename = "CustomLevels") if path: name = os.path.basename(path) try: os.mkdir(path) except EnvironmentError, e: alert("Unable to create '%s': %s:" % (name, e)) return self.game.set_playing_level_dir(path) alert("Level set '%s' created." % name)
def update(self): client = self.client dir = client.directory suffixes = client.suffixes def filter(name): path = os.path.join(dir, name) return os.path.isdir(path) or self.client.filter(path) try: names = [ name for name in os.listdir(dir) if not name.startswith(".") and filter(name) ] except EnvironmentError, e: alert("%s: %s" % (dir, e)) names = []
def save_game(self, prompt): """Save the game. If prompt is true or no save pathname is set, ask for a pathname. Reports errors to the user. Raises Cancel if cancelled or an error occurs.""" game = self.game old_path = game.get_save_path() if prompt or not game.save_name: new_path = request_new_filename(prompt = "Save game as:", suffix = game.save_file_suffix, pathname = old_path) else: new_path = old_path if not new_path: raise Cancel try: game.save_game(new_path) except EnvironmentError, e: alert("Unable to save '%s': %s" % ( os.path.basename(new_path), e)) raise Cancel
def save_game(self, prompt): """Save the game. If prompt is true or no save pathname is set, ask for a pathname. Reports errors to the user. Raises Cancel if cancelled or an error occurs.""" game = self.game old_path = game.get_save_path() if prompt or not game.save_name: new_path = request_new_filename(prompt="Save game as:", suffix=game.save_file_suffix, pathname=old_path) else: new_path = old_path if not new_path: raise Cancel try: game.save_game(new_path) except EnvironmentError, e: alert("Unable to save '%s': %s" % (os.path.basename(new_path), e)) raise Cancel
def write_level(self, ask_path): """Writes the current level to a file. If ask_path is true, or the level has not been saved before, asks the user for a pathname, otherwise writes it to the previously-used pathname. Reports errors to the user. Returns true unless cancelled or an error occurs.""" game = self.game dir = game.editing_level_dir name = game.level_name or "" if dir and name and not ask_path: path = os.path.join(dir, name) else: if not dir: dir = game.get_level_save_dir() path = request_new_filename(prompt = "Save level as:", suffix = game.level_file_suffix, directory = dir, filename = name) if path: try: game.write_level(path) game.level_needs_saving = False return True except EnvironmentError, e: alert("Unable to save '%s': %s" % ( os.path.basename(path), mess))
def load_file(self, path): """Load a saved game. Reports errors to the user.""" if path.endswith(self.game.save_file_suffix): self.restore_game(path) else: alert("Unrecognized file: %s" % path)
def save_game_cmd(self): """Implementation of the 'Save Game' command.""" self.save_game(prompt = False) alert("Game saved.")
def save_game_cmd(self): """Implementation of the 'Save Game' command.""" self.save_game(prompt=False) alert("Game saved.")
def no_levels_found(self): """Called when a level set is found to contain no levels.""" alert("No levels found.")