Beispiel #1
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)
Beispiel #2
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
Beispiel #3
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
Beispiel #4
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))