Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions rlbot_gui/bot_management/bot_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,37 @@ def bootstrap_scratch_bot(bot_name, directory):
replace_all(config_file, r'port = .*$', 'port = ' + str(random.randint(20000, 65000)))

return config_file


def bootstrap_python_hivemind(hive_name, directory):
sanitized_name = convert_to_filename(hive_name)
bot_directory = Path(directory or '.')
top_dir = bot_directory / sanitized_name
if os.path.exists(top_dir):
raise FileExistsError(f'There is already a bot named {sanitized_name}, please choose a different name!')

with tempfile.TemporaryDirectory() as tmpdirname:
tmpdir = Path(tmpdirname)
print('created temporary directory', tmpdir)

download_and_extract_zip(
download_url='https://github.com/ViliamVadocz/RLBotPythonHivemindExample/archive/master.zip',
local_folder_path=tmpdir)

safe_move(tmpdir / 'RLBotPythonHivemindExample-master', top_dir)


config_file = top_dir / 'config.cfg'
drone_file = top_dir / 'src' / 'drone.py'
hive_file = top_dir / 'src' / 'hive.py'

replace_all(config_file, r'name = .*$', f'name = {hive_name}')
replace_all(drone_file, r'hive_name = .*$', f'hive_name = "{hive_name} Hivemind"')
replace_all(drone_file, r'hive_key = .*$', f'hive_key = "{random.randint(100000, 999999) + hash(hive_name)}"')
replace_all(hive_file, r'class .*\(PythonHivemind\)', f'class {hive_name}Hivemind(PythonHivemind)')

# This is intended to open the example python file in the default system editor for .py files.
# Hopefully this will be VS Code or notepad++ or something. If it gets executed as a python script, no harm done.
os.startfile(hive_file)

return config_file
13 changes: 12 additions & 1 deletion rlbot_gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
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, 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
Expand Down Expand Up @@ -419,6 +419,17 @@ def begin_scratch_bot(bot_name):
return {'error': str(e)}


@eel.expose
def begin_python_hivemind(hive_name):
bot_directory = ensure_bot_directory()

try:
config_file = bootstrap_python_hivemind(hive_name, bot_directory)
return {'bots': load_bundle(config_file)}
except FileExistsError as e:
return {'error': str(e)}


@eel.expose
def set_state(state):
set_game_state(state)
Expand Down
12 changes: 6 additions & 6 deletions rlbot_gui/gui/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@
<div>
<md-radio v-model="newBotLanguageChoice" value="python">Python</md-radio>
<md-radio v-model="newBotLanguageChoice" value="scratch">Scratch</md-radio>
<md-radio v-model="newBotLanguageChoice" value="python_hive">Python Hivemind</md-radio>
</div>
</md-dialog-content>

Expand Down Expand Up @@ -587,16 +588,15 @@
if (!bot_name) {
this.snackbarContent = "Please choose a proper name!";
this.showSnackbar = true;
}

if (language === 'python') {
} else if (language === 'python') {
this.showProgressSpinner = true;
eel.begin_python_bot(bot_name)(this.botLoadHandler);
}

if (language === 'scratch') {
} else if (language === 'scratch') {
this.showProgressSpinner = true;
eel.begin_scratch_bot(bot_name)(this.botLoadHandler);
} else if (language === 'python_hive') {
this.showProgressSpinner = true;
eel.begin_python_hivemind(bot_name)(this.botLoadHandler);
}
},
openFolderSettingsDialog: function() {
Expand Down
2 changes: 1 addition & 1 deletion rlbot_gui/upgrade/upgrade_replacer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import shutil
from pathlib import Path

from env.Lib import os
import os


def replace_upgrade_file():
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import setuptools

__version__ = '0.0.55'
__version__ = '0.0.56'

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