88from rlbot .parsing .agent_config_parser import create_looks_configurations , BOT_CONFIG_LOADOUT_HEADER , \
99 BOT_CONFIG_LOADOUT_ORANGE_HEADER , BOT_CONFIG_LOADOUT_PAINT_BLUE_HEADER , BOT_CONFIG_LOADOUT_PAINT_ORANGE_HEADER , \
1010 load_bot_appearance
11- from rlbot .parsing .bot_config_bundle import get_bot_config_bundle , BotConfigBundle
12- from rlbot .parsing .directory_scanner import scan_directory_for_bot_configs
11+ from rlbot .parsing .bot_config_bundle import get_bot_config_bundle , get_script_config_bundle , RunnableConfigBundle
12+ from rlbot .parsing .directory_scanner import scan_directory_for_bot_configs , scan_directory_for_script_configs
1313from rlbot .parsing .match_settings_config_parser import map_types , game_mode_types , \
1414 boost_amount_mutator_types , match_length_types , max_score_types , overtime_mutator_types , \
1515 series_length_mutator_types , game_speed_mutator_types , ball_max_speed_mutator_types , ball_type_mutator_types , \
1616 ball_weight_mutator_types , ball_size_mutator_types , ball_bounciness_mutator_types , rumble_mutator_types , \
1717 boost_strength_mutator_types , gravity_mutator_types , demolish_mutator_types , respawn_time_mutator_types , \
1818 existing_match_behavior_types
1919
20- from rlbot_gui .bot_management .bot_creation import bootstrap_python_bot , bootstrap_scratch_bot , bootstrap_python_hivemind , convert_to_filename
20+ from rlbot_gui .bot_management .bot_creation import bootstrap_python_bot , bootstrap_scratch_bot , \
21+ bootstrap_python_hivemind , convert_to_filename
2122from rlbot_gui .bot_management .downloader import BotpackDownloader , get_json_from_url
2223from rlbot_gui .match_runner .match_runner import hot_reload_bots , shut_down , start_match_helper , \
2324 do_infinite_loop_content , spawn_car_in_showroom , set_game_state , fetch_game_tick_packet
@@ -80,7 +81,18 @@ def serialize_bundle(bundle):
8081 }
8182
8283
83- def load_bundle (filename ):
84+ def serialize_script_bundle (bundle ):
85+ return {
86+ 'name' : bundle .name ,
87+ 'type' : 'script' ,
88+ 'image' : 'imgs/rlbot.png' ,
89+ 'path' : bundle .config_path ,
90+ 'info' : read_info (bundle ),
91+ 'logo' : try_copy_logo (bundle )
92+ }
93+
94+
95+ def load_bot_bundle (filename ):
8496 try :
8597 bundle = get_bot_config_bundle (filename )
8698 return [serialize_bundle (bundle )]
@@ -90,10 +102,20 @@ def load_bundle(filename):
90102 return []
91103
92104
105+ def load_script_bundle (filename ):
106+ try :
107+ bundle = get_script_config_bundle (filename )
108+ return [serialize_script_bundle (bundle )]
109+ except Exception as e :
110+ print (e )
111+
112+ return []
113+
114+
93115@eel .expose
94116def pick_bot_config ():
95117 filename = pick_location (False )
96- bundle = load_bundle (filename )
118+ bundle = load_script_bundle ( filename ) or load_bot_bundle (filename )
97119
98120 if bundle :
99121 bot_folder_settings ["files" ][filename ] = {"visible" : True }
@@ -124,7 +146,7 @@ def validate_bots(bots):
124146
125147 for bot in bots :
126148 if bot ["type" ] in ('rlbot' , 'party_member_bot' ):
127- valid_bots += load_bundle (bot ["path" ])
149+ valid_bots += load_bot_bundle (bot ["path" ])
128150 else :
129151 valid_bots .append (bot )
130152
@@ -186,7 +208,7 @@ def pick_location(is_folder):
186208 return filename
187209
188210
189- def read_info (bundle : BotConfigBundle ):
211+ def read_info (bundle : RunnableConfigBundle ):
190212 details_header = 'Details'
191213 if bundle .base_agent_config .has_section (details_header ):
192214 return {
@@ -263,14 +285,33 @@ def scan_for_bots():
263285
264286 for file , props in bot_folder_settings ['files' ].items ():
265287 if props ['visible' ]:
266- bots = load_bundle (file ) # Returns a list of size 1
288+ bots = load_bot_bundle (file ) # Returns a list of size 1
267289 for bot in bots :
268290 bot_hash [bot ['path' ]] = bot
269291
270292 return list (bot_hash .values ())
271293
272294
273- def try_copy_logo (bundle : BotConfigBundle ):
295+ @eel .expose
296+ def scan_for_scripts ():
297+ script_hash = {}
298+
299+ for folder , props in bot_folder_settings ['folders' ].items ():
300+ if props ['visible' ]:
301+ bots = get_scripts_from_directory (folder )
302+ for bot in bots :
303+ script_hash [bot ['path' ]] = bot
304+
305+ for file , props in bot_folder_settings ['files' ].items ():
306+ if props ['visible' ]:
307+ bots = load_script_bundle (file ) # Returns a list of size 1
308+ for bot in bots :
309+ script_hash [bot ['path' ]] = bot
310+
311+ return list (script_hash .values ())
312+
313+
314+ def try_copy_logo (bundle : RunnableConfigBundle ):
274315 logo_path = bundle .get_logo_file ()
275316 if logo_path is not None and os .path .exists (logo_path ):
276317 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):
285326 return [serialize_bundle (bundle ) for bundle in scan_directory_for_bot_configs (bot_directory )]
286327
287328
329+ def get_scripts_from_directory (bot_directory ):
330+ return [serialize_script_bundle (bundle ) for bundle in scan_directory_for_script_configs (bot_directory )]
331+
332+
288333@eel .expose
289334def get_language_support ():
290335 java_return_code = os .system ("java -version" )
@@ -402,7 +447,7 @@ def begin_python_bot(bot_name):
402447
403448 try :
404449 config_file = bootstrap_python_bot (bot_name , bot_directory )
405- return {'bots' : load_bundle (config_file )}
450+ return {'bots' : load_bot_bundle (config_file )}
406451 except FileExistsError as e :
407452 return {'error' : str (e )}
408453
@@ -414,7 +459,7 @@ def begin_scratch_bot(bot_name):
414459 try :
415460 config_file = bootstrap_scratch_bot (bot_name , bot_directory )
416461 install_package ('webdriver_manager' ) # Scratch bots need this, and the GUI's python doesn't have it by default.
417- return {'bots' : load_bundle (config_file )}
462+ return {'bots' : load_bot_bundle (config_file )}
418463 except FileExistsError as e :
419464 return {'error' : str (e )}
420465
@@ -425,7 +470,7 @@ def begin_python_hivemind(hive_name):
425470
426471 try :
427472 config_file = bootstrap_python_hivemind (hive_name , bot_directory )
428- return {'bots' : load_bundle (config_file )}
473+ return {'bots' : load_bot_bundle (config_file )}
429474 except FileExistsError as e :
430475 return {'error' : str (e )}
431476
0 commit comments