From 28ea1dc56a713fb4e3e0623f7a4c21dd30a0b484 Mon Sep 17 00:00:00 2001 From: Tyler Arehart Date: Mon, 25 May 2020 16:44:45 -0700 Subject: [PATCH 1/5] Updating the GUI to handle scripts. --- rlbot_gui/gui.py | 55 +++++++++++++++++++++++--- rlbot_gui/gui/css/style.css | 9 ++++- rlbot_gui/gui/main.vue | 32 +++++++++++++-- rlbot_gui/match_runner/match_runner.py | 6 ++- 4 files changed, 91 insertions(+), 11 deletions(-) diff --git a/rlbot_gui/gui.py b/rlbot_gui/gui.py index 669cfe0a..76b1654d 100644 --- a/rlbot_gui/gui.py +++ b/rlbot_gui/gui.py @@ -8,8 +8,8 @@ from rlbot.parsing.agent_config_parser import create_looks_configurations, BOT_CONFIG_LOADOUT_HEADER, \ BOT_CONFIG_LOADOUT_ORANGE_HEADER, BOT_CONFIG_LOADOUT_PAINT_BLUE_HEADER, BOT_CONFIG_LOADOUT_PAINT_ORANGE_HEADER, \ load_bot_appearance -from rlbot.parsing.bot_config_bundle import get_bot_config_bundle, BotConfigBundle -from rlbot.parsing.directory_scanner import scan_directory_for_bot_configs +from rlbot.parsing.bot_config_bundle import get_bot_config_bundle, get_script_config_bundle, RunnableConfigBundle +from rlbot.parsing.directory_scanner import scan_directory_for_bot_configs, scan_directory_for_script_configs from rlbot.parsing.match_settings_config_parser import map_types, game_mode_types, \ boost_amount_mutator_types, match_length_types, max_score_types, overtime_mutator_types, \ series_length_mutator_types, game_speed_mutator_types, ball_max_speed_mutator_types, ball_type_mutator_types, \ @@ -17,7 +17,8 @@ boost_strength_mutator_types, gravity_mutator_types, demolish_mutator_types, respawn_time_mutator_types, \ existing_match_behavior_types -from rlbot_gui.bot_management.bot_creation import bootstrap_python_bot, bootstrap_scratch_bot, bootstrap_python_hivemind, convert_to_filename +from rlbot_gui.bot_management.bot_creation import bootstrap_python_bot, bootstrap_scratch_bot, \ + bootstrap_python_hivemind, convert_to_filename from rlbot_gui.bot_management.downloader import BotpackDownloader, get_json_from_url from rlbot_gui.match_runner.match_runner import hot_reload_bots, shut_down, start_match_helper, \ do_infinite_loop_content, spawn_car_in_showroom, set_game_state, fetch_game_tick_packet @@ -80,6 +81,17 @@ def serialize_bundle(bundle): } +def serialize_script_bundle(bundle): + return { + 'name': bundle.name, + 'type': 'script', + 'image': 'imgs/rlbot.png', + 'path': bundle.config_path, + 'info': read_info(bundle), + 'logo': try_copy_logo(bundle) + } + + def load_bundle(filename): try: bundle = get_bot_config_bundle(filename) @@ -90,6 +102,16 @@ def load_bundle(filename): return [] +def load_script_bundle(filename): + try: + bundle = get_script_config_bundle(filename) + return [serialize_script_bundle(bundle)] + except Exception as e: + print(e) + + return [] + + @eel.expose def pick_bot_config(): filename = pick_location(False) @@ -186,7 +208,7 @@ def pick_location(is_folder): return filename -def read_info(bundle: BotConfigBundle): +def read_info(bundle: RunnableConfigBundle): details_header = 'Details' if bundle.base_agent_config.has_section(details_header): return { @@ -270,7 +292,26 @@ def scan_for_bots(): return list(bot_hash.values()) -def try_copy_logo(bundle: BotConfigBundle): +@eel.expose +def scan_for_scripts(): + script_hash = {} + + for folder, props in bot_folder_settings['folders'].items(): + if props['visible']: + bots = get_scripts_from_directory(folder) + for bot in bots: + script_hash[bot['path']] = bot + + for file, props in bot_folder_settings['files'].items(): + if props['visible']: + bots = load_script_bundle(file) # Returns a list of size 1 + for bot in bots: + script_hash[bot['path']] = bot + + return list(script_hash.values()) + + +def try_copy_logo(bundle: RunnableConfigBundle): logo_path = bundle.get_logo_file() if logo_path is not None and os.path.exists(logo_path): web_url = 'imgs/logos/' + convert_to_filename(bundle.name) + '/' + convert_to_filename(logo_path) @@ -285,6 +326,10 @@ def get_bots_from_directory(bot_directory): return [serialize_bundle(bundle) for bundle in scan_directory_for_bot_configs(bot_directory)] +def get_scripts_from_directory(bot_directory): + return [serialize_script_bundle(bundle) for bundle in scan_directory_for_script_configs(bot_directory)] + + @eel.expose def get_language_support(): java_return_code = os.system("java -version") diff --git a/rlbot_gui/gui/css/style.css b/rlbot_gui/gui/css/style.css index f6636eba..8db2f8d4 100644 --- a/rlbot_gui/gui/css/style.css +++ b/rlbot_gui/gui/css/style.css @@ -68,9 +68,16 @@ body { opacity: 0.4; } +.draggable { + cursor: move; +} + .bot-card { margin: 5px; - cursor: move; +} + +.bot-card .md-switch { + margin: 5px 5px; } .center-flex { diff --git a/rlbot_gui/gui/main.vue b/rlbot_gui/gui/main.vue index ae4ddeb7..64a8ffb4 100644 --- a/rlbot_gui/gui/main.vue +++ b/rlbot_gui/gui/main.vue @@ -98,7 +98,7 @@ - + + + {{script.name}} + + blur_on + +
@@ -130,7 +137,7 @@
Blue Team
- + {{ bot.name }} @@ -148,7 +155,7 @@
Orange Team
- + {{ bot.name }} @@ -301,7 +308,7 @@ - + palette Edit Appearance @@ -446,6 +453,7 @@ data () { return { botPool: STARTING_BOT_POOL, + scriptPool: [], blueTeam: [], orangeTeam: [], teamSelection: "blue", @@ -479,6 +487,7 @@ enable_rendering: false, enable_state_setting: false, auto_save_replay: false, + scripts: [], }, randomMapPool: [], showMutatorDialog: false, @@ -514,6 +523,7 @@ startMatch: async function (event) { if (this.matchSettings.randomizeMap) await this.setRandomMap(); + this.matchSettings.scripts = this.scriptPool.filter((val) => { return val.enabled }); eel.save_match_settings(this.matchSettings); eel.save_team_settings(this.blueTeam, this.orangeTeam); @@ -571,6 +581,7 @@ this.matchSettings.enable_rendering = false; this.matchSettings.enable_state_setting = true; this.matchSettings.auto_save_replay = false; + this.matchSettings.scripts = []; this.resetMutatorsToDefault(); this.updateBGImage(this.matchSettings.map); @@ -625,6 +636,7 @@ eel.save_folder_settings(this.folderSettings); this.botPool = STARTING_BOT_POOL; eel.scan_for_bots()(this.botsReceived); + eel.scan_for_scripts()(this.scriptsReceived); }, passesFilter: function(botName) { return botName.toLowerCase().includes(this.botNameFilter.toLowerCase()); @@ -651,6 +663,16 @@ this.showProgressSpinner = false; }, + scriptsReceived: function (scripts) { + const freshScripts = scripts.filter( (script) => + !this.scriptPool.find( (element) => element.path === script.path )); + freshScripts.forEach((script) => {script.enabled = !!this.matchSettings.scripts.find( (element) => element.path === script.path )}); + + this.scriptPool = this.scriptPool.concat(freshScripts).sort((a, b) => a.name.localeCompare(b.name)); + + this.showProgressSpinner = false; + }, + applyLanguageWarnings: function () { if (this.languageSupport) { this.botPool.forEach((bot) => { @@ -674,6 +696,7 @@ if (matchSettings) { Object.assign(this.matchSettings, matchSettings); this.updateBGImage(this.matchSettings.map); + this.scriptPool.forEach((script) => {script.enabled = !!this.matchSettings.scripts.find( (element) => element.path === script.path )}); } else { this.resetMatchSettingsToDefault(); } @@ -715,6 +738,7 @@ created: function () { eel.get_folder_settings()(this.folderSettingsReceived); eel.scan_for_bots()(this.botsReceived); + eel.scan_for_scripts()(this.scriptsReceived); eel.get_match_options()(this.matchOptionsReceived); eel.get_match_settings()(this.matchSettingsReceived); eel.get_team_settings()(this.teamSettingsReceived); diff --git a/rlbot_gui/match_runner/match_runner.py b/rlbot_gui/match_runner/match_runner.py index 5ae7bdb8..40d10c10 100644 --- a/rlbot_gui/match_runner/match_runner.py +++ b/rlbot_gui/match_runner/match_runner.py @@ -2,7 +2,7 @@ from rlbot.gateway_util import NetworkingRole from rlbot.matchconfig.loadout_config import LoadoutConfig -from rlbot.matchconfig.match_config import PlayerConfig, MatchConfig, MutatorConfig +from rlbot.matchconfig.match_config import PlayerConfig, MatchConfig, MutatorConfig, ScriptConfig from rlbot.parsing.incrementing_integer import IncrementingInteger from rlbot.setup_manager import SetupManager from rlbot.utils.structures.bot_input_struct import PlayerInput @@ -26,6 +26,9 @@ def create_player_config(bot, human_index_tracker: IncrementingInteger): player_config.config_path = bot['path'] return player_config +def create_script_config(script): + return ScriptConfig(script['path']) + def spawn_car_in_showroom(loadout_config: LoadoutConfig, team: int, showcase_type: str, map_name: str): match_config = MatchConfig() @@ -150,6 +153,7 @@ def start_match_helper(bot_list, match_settings): human_index_tracker = IncrementingInteger(0) match_config.player_configs = [create_player_config(bot, human_index_tracker) for bot in bot_list] + match_config.script_configs = [create_script_config(script) for script in match_settings['scripts']] global sm if sm is not None: From 9598f9e7d63ccfcfe5636a2f92ca6dfd7b3e2be6 Mon Sep 17 00:00:00 2001 From: Tyler Arehart Date: Mon, 25 May 2020 20:57:22 -0700 Subject: [PATCH 2/5] Tweaking spacing. --- rlbot_gui/gui/css/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rlbot_gui/gui/css/style.css b/rlbot_gui/gui/css/style.css index 8db2f8d4..fa32009e 100644 --- a/rlbot_gui/gui/css/style.css +++ b/rlbot_gui/gui/css/style.css @@ -77,7 +77,7 @@ body { } .bot-card .md-switch { - margin: 5px 5px; + margin: 5px 8px; } .center-flex { From 1121fe181df8d6bc3a72f67b78e721a8935a9de7 Mon Sep 17 00:00:00 2001 From: Tyler Arehart Date: Mon, 25 May 2020 23:46:08 -0700 Subject: [PATCH 3/5] Bumping version number. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ba2bbfc2..c73065ee 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ import setuptools -__version__ = '0.0.58' +__version__ = '0.0.59' with open("README.md", "r") as readme_file: long_description = readme_file.read() From fb25389a0751a55ddde718ef5e0aa384f41154dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Pihrt?= Date: Tue, 26 May 2020 14:12:47 +0200 Subject: [PATCH 4/5] Fix loading scripts by file --- rlbot_gui/gui.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/rlbot_gui/gui.py b/rlbot_gui/gui.py index 76b1654d..b6c72293 100644 --- a/rlbot_gui/gui.py +++ b/rlbot_gui/gui.py @@ -92,7 +92,7 @@ def serialize_script_bundle(bundle): } -def load_bundle(filename): +def load_bot_bundle(filename): try: bundle = get_bot_config_bundle(filename) return [serialize_bundle(bundle)] @@ -115,7 +115,7 @@ def load_script_bundle(filename): @eel.expose def pick_bot_config(): filename = pick_location(False) - bundle = load_bundle(filename) + bundle = load_script_bundle(filename) or load_bot_bundle(filename) if bundle: bot_folder_settings["files"][filename] = {"visible": True} @@ -146,7 +146,7 @@ def validate_bots(bots): for bot in bots: if bot["type"] in ('rlbot', 'party_member_bot'): - valid_bots += load_bundle(bot["path"]) + valid_bots += load_bot_bundle(bot["path"]) else: valid_bots.append(bot) @@ -285,7 +285,7 @@ def scan_for_bots(): for file, props in bot_folder_settings['files'].items(): if props['visible']: - bots = load_bundle(file) # Returns a list of size 1 + bots = load_bot_bundle(file) # Returns a list of size 1 for bot in bots: bot_hash[bot['path']] = bot @@ -447,7 +447,7 @@ def begin_python_bot(bot_name): try: config_file = bootstrap_python_bot(bot_name, bot_directory) - return {'bots': load_bundle(config_file)} + return {'bots': load_bot_bundle(config_file)} except FileExistsError as e: return {'error': str(e)} @@ -459,7 +459,7 @@ def begin_scratch_bot(bot_name): try: config_file = bootstrap_scratch_bot(bot_name, bot_directory) install_package('webdriver_manager') # Scratch bots need this, and the GUI's python doesn't have it by default. - return {'bots': load_bundle(config_file)} + return {'bots': load_bot_bundle(config_file)} except FileExistsError as e: return {'error': str(e)} @@ -470,7 +470,7 @@ def begin_python_hivemind(hive_name): try: config_file = bootstrap_python_hivemind(hive_name, bot_directory) - return {'bots': load_bundle(config_file)} + return {'bots': load_bot_bundle(config_file)} except FileExistsError as e: return {'error': str(e)} From 2bc3499f04d8d9bc3c0f7cd9392d80810e65746c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Pihrt?= Date: Tue, 26 May 2020 14:16:17 +0200 Subject: [PATCH 5/5] Fix bot/script pool reloading on folder settings changes --- rlbot_gui/gui/main.vue | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rlbot_gui/gui/main.vue b/rlbot_gui/gui/main.vue index 64a8ffb4..abb60b30 100644 --- a/rlbot_gui/gui/main.vue +++ b/rlbot_gui/gui/main.vue @@ -632,9 +632,10 @@ eel.get_folder_settings()(this.folderSettingsReceived); this.showFolderSettingsDialog = true; }, - applyFolderSettings: function() { - eel.save_folder_settings(this.folderSettings); + applyFolderSettings: async function() { + await eel.save_folder_settings(this.folderSettings)(); this.botPool = STARTING_BOT_POOL; + this.scriptPool = []; eel.scan_for_bots()(this.botsReceived); eel.scan_for_scripts()(this.scriptsReceived); }, @@ -710,6 +711,8 @@ folderSettingsReceived: function (folderSettings) { this.folderSettings = folderSettings; + eel.scan_for_bots()(this.botsReceived); + eel.scan_for_scripts()(this.scriptsReceived); }, botpackUpdateChecked: function (isBotpackUpToDate) { this.showBotpackUpdateSnackbar = !isBotpackUpToDate; @@ -720,7 +723,6 @@ this.showSnackbar = true; this.showDownloadProgressDialog = false; eel.get_folder_settings()(this.folderSettingsReceived); - eel.scan_for_bots()(this.botsReceived); }, onInstallationComplete: function (result) { @@ -737,8 +739,6 @@ }, created: function () { eel.get_folder_settings()(this.folderSettingsReceived); - eel.scan_for_bots()(this.botsReceived); - eel.scan_for_scripts()(this.scriptsReceived); eel.get_match_options()(this.matchOptionsReceived); eel.get_match_settings()(this.matchSettingsReceived); eel.get_team_settings()(this.teamSettingsReceived);