Skip to content

Commit dfd0d04

Browse files
authored
Added Python Hivemind to bot creation (#79)
* Added Python Hivemind to bot creation * Bumped version
1 parent f531cbb commit dfd0d04

5 files changed

Lines changed: 54 additions & 9 deletions

File tree

rlbot_gui/bot_management/bot_creation.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,37 @@ def bootstrap_scratch_bot(bot_name, directory):
105105
replace_all(config_file, r'port = .*$', 'port = ' + str(random.randint(20000, 65000)))
106106

107107
return config_file
108+
109+
110+
def bootstrap_python_hivemind(hive_name, directory):
111+
sanitized_name = convert_to_filename(hive_name)
112+
bot_directory = Path(directory or '.')
113+
top_dir = bot_directory / sanitized_name
114+
if os.path.exists(top_dir):
115+
raise FileExistsError(f'There is already a bot named {sanitized_name}, please choose a different name!')
116+
117+
with tempfile.TemporaryDirectory() as tmpdirname:
118+
tmpdir = Path(tmpdirname)
119+
print('created temporary directory', tmpdir)
120+
121+
download_and_extract_zip(
122+
download_url='https://github.com/ViliamVadocz/RLBotPythonHivemindExample/archive/master.zip',
123+
local_folder_path=tmpdir)
124+
125+
safe_move(tmpdir / 'RLBotPythonHivemindExample-master', top_dir)
126+
127+
128+
config_file = top_dir / 'config.cfg'
129+
drone_file = top_dir / 'src' / 'drone.py'
130+
hive_file = top_dir / 'src' / 'hive.py'
131+
132+
replace_all(config_file, r'name = .*$', f'name = {hive_name}')
133+
replace_all(drone_file, r'hive_name = .*$', f'hive_name = "{hive_name} Hivemind"')
134+
replace_all(drone_file, r'hive_key = .*$', f'hive_key = "{random.randint(100000, 999999) + hash(hive_name)}"')
135+
replace_all(hive_file, r'class .*\(PythonHivemind\)', f'class {hive_name}Hivemind(PythonHivemind)')
136+
137+
# This is intended to open the example python file in the default system editor for .py files.
138+
# Hopefully this will be VS Code or notepad++ or something. If it gets executed as a python script, no harm done.
139+
os.startfile(hive_file)
140+
141+
return config_file

rlbot_gui/gui.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
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, convert_to_filename
20+
from rlbot_gui.bot_management.bot_creation import bootstrap_python_bot, bootstrap_scratch_bot, bootstrap_python_hivemind, convert_to_filename
2121
from rlbot_gui.bot_management.downloader import BotpackDownloader, get_json_from_url
2222
from rlbot_gui.match_runner.match_runner import hot_reload_bots, shut_down, start_match_helper, \
2323
do_infinite_loop_content, spawn_car_in_showroom, set_game_state, fetch_game_tick_packet
@@ -419,6 +419,17 @@ def begin_scratch_bot(bot_name):
419419
return {'error': str(e)}
420420

421421

422+
@eel.expose
423+
def begin_python_hivemind(hive_name):
424+
bot_directory = ensure_bot_directory()
425+
426+
try:
427+
config_file = bootstrap_python_hivemind(hive_name, bot_directory)
428+
return {'bots': load_bundle(config_file)}
429+
except FileExistsError as e:
430+
return {'error': str(e)}
431+
432+
422433
@eel.expose
423434
def set_state(state):
424435
set_game_state(state)

rlbot_gui/gui/main.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@
337337
<div>
338338
<md-radio v-model="newBotLanguageChoice" value="python">Python</md-radio>
339339
<md-radio v-model="newBotLanguageChoice" value="scratch">Scratch</md-radio>
340+
<md-radio v-model="newBotLanguageChoice" value="python_hive">Python Hivemind</md-radio>
340341
</div>
341342
</md-dialog-content>
342343

@@ -587,16 +588,15 @@
587588
if (!bot_name) {
588589
this.snackbarContent = "Please choose a proper name!";
589590
this.showSnackbar = true;
590-
}
591-
592-
if (language === 'python') {
591+
} else if (language === 'python') {
593592
this.showProgressSpinner = true;
594593
eel.begin_python_bot(bot_name)(this.botLoadHandler);
595-
}
596-
597-
if (language === 'scratch') {
594+
} else if (language === 'scratch') {
598595
this.showProgressSpinner = true;
599596
eel.begin_scratch_bot(bot_name)(this.botLoadHandler);
597+
} else if (language === 'python_hive') {
598+
this.showProgressSpinner = true;
599+
eel.begin_python_hivemind(bot_name)(this.botLoadHandler);
600600
}
601601
},
602602
openFolderSettingsDialog: function() {

rlbot_gui/upgrade/upgrade_replacer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import shutil
22
from pathlib import Path
33

4-
from env.Lib import os
4+
import os
55

66

77
def replace_upgrade_file():

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import setuptools
22

3-
__version__ = '0.0.55'
3+
__version__ = '0.0.56'
44

55
with open("README.md", "r") as readme_file:
66
long_description = readme_file.read()

0 commit comments

Comments
 (0)