def load_python_file(self): file_path = QtWidgets.QFileDialog.getOpenFileName( self, 'Load Agent Class', '', 'Python Files (*.py)')[0] if not file_path or not os.path.exists(file_path): return preset = self.get_current_preset() if not preset.load_agent_class(file_path): self.popup_message( "This file does not extend BaseAgent, using BaseAgent", "Invalid Python File", QtWidgets.QMessageBox.Information) if preset.config_path is None or not os.path.isfile( preset.config_path): start = get_python_root() else: start = os.path.dirname(preset.config_path) try: rel_path = os.path.relpath(file_path, start) except ValueError: rel_path = file_path preset.config.set_value("Locations", "python_file", rel_path) self.preset_python_file_lineedit.setText(rel_path) bot_parameters = preset.config["Bot Parameters"] self.add_parameters_to_gui(bot_parameters)
def load_agent(self, overall_index: int=None): """ Loads all data for overall_index from the overall config and also loads both presets :param overall_index: the index of the targeted agent :return agent: an Agent (gui_agent) class with all loaded values """ if not self.index_manager.has_free_slots(): return None if overall_index is None: overall_index = self.index_manager.get_new_index() else: self.index_manager.use_index(overall_index) agent = self.add_agent(overall_index=overall_index) agent_preset = self.add_agent_preset(agent.get_agent_config_path()) agent.set_agent_preset(agent_preset) loadout_file = self.overall_config.get(PARTICIPANT_CONFIGURATION_HEADER, PARTICIPANT_LOADOUT_CONFIG_KEY, overall_index) if loadout_file is None or loadout_file == "None": directory = os.path.dirname(os.path.realpath(agent.get_agent_config_path())) file_path = agent_preset.config.get(BOT_CONFIG_MODULE_HEADER, LOOKS_CONFIG_KEY) loadout_file = os.path.realpath(os.path.join(directory, file_path)) else: directory = get_python_root() file_path = loadout_file loadout_file = os.path.realpath(os.path.join(directory, file_path)) loadout_preset = self.add_loadout_preset(loadout_file) agent.set_loadout_preset(loadout_preset) agent.set_name(agent_preset.config.get(BOT_CONFIG_MODULE_HEADER, BOT_NAME_KEY)) return agent
def load_agent(self, overall_index: int = None): """ Loads all data for overall_index from the overall config and also loads both presets :param overall_index: the index of the targeted agent :return agent: an Agent (gui_agent) class with all loaded values """ if not self.index_manager.has_free_slots(): return None if overall_index is None: overall_index = self.index_manager.get_new_index() else: self.index_manager.use_index(overall_index) agent = self.add_agent(overall_index=overall_index) path_in_overall_config = agent.get_agent_config_path() if path_in_overall_config is None: # Fall back to the path of the first agent if there's nothing configured. path_in_overall_config = self.overall_config.getpath( PARTICIPANT_CONFIGURATION_HEADER, PARTICIPANT_CONFIG_KEY, 0) agent_preset = self.add_agent_preset(path_in_overall_config) agent.set_agent_preset(agent_preset) agent.set_name( agent_preset.config.get(BOT_CONFIG_MODULE_HEADER, BOT_NAME_KEY)) # Add the preset's loadout as a loadout own_loadout = self.add_loadout_preset(agent_preset.looks_path) # Agent has a loadout defined in overall config, load that if it is not None loadout_file_in_overall_config = self.overall_config.get( PARTICIPANT_CONFIGURATION_HEADER, PARTICIPANT_LOADOUT_CONFIG_KEY, overall_index) if loadout_file_in_overall_config is None or loadout_file_in_overall_config == "None": agent.set_loadout_preset(own_loadout) else: directory = get_python_root() file_path = loadout_file_in_overall_config loadout_file_in_overall_config = os.path.realpath( os.path.join(directory, file_path)) loadout_preset = self.add_loadout_preset( loadout_file_in_overall_config) agent.set_loadout_preset(loadout_preset) return agent
def get_dll_directory(): return os.path.join(get_python_root(), 'rlbot', 'dll')