Пример #1
0
    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
Пример #2
0
    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
Пример #3
0
	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
Пример #4
0
	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
Пример #5
0
	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 = []
Пример #6
0
	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)
Пример #7
0
    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 = []
Пример #8
0
	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
Пример #9
0
    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
Пример #10
0
	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))
Пример #11
0
	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)
Пример #12
0
	def save_game_cmd(self):
		"""Implementation of the 'Save Game' command."""
		self.save_game(prompt = False)
		alert("Game saved.")
Пример #13
0
 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)
Пример #14
0
 def save_game_cmd(self):
     """Implementation of the 'Save Game' command."""
     self.save_game(prompt=False)
     alert("Game saved.")
Пример #15
0
 def no_levels_found(self):
     """Called when a level set is found to contain no levels."""
     alert("No levels found.")
Пример #16
0
	def no_levels_found(self):
		"""Called when a level set is found to contain no levels."""
		alert("No levels found.")