Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rlbot hub alpha #43

Open
wants to merge 63 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
b2c0a57
Add files via upload
LapzwansProducties Jul 13, 2019
99982e6
Add files via upload
LapzwansProducties Jul 13, 2019
e44c30a
first alpha hub and update to mainstream
LapzwansProducties Jul 23, 2019
c0bd06b
replacing browserfs by fetch api
LapzwansProducties Jul 24, 2019
b084963
Update botmanager.html
LapzwansProducties Jul 24, 2019
c06e22a
download / delete button improvement
LapzwansProducties Jul 24, 2019
0ec4f15
Update botmanager.html
LapzwansProducties Jul 24, 2019
1afcb68
Update botmanager.html
LapzwansProducties Jul 24, 2019
478bfb6
function to pass bot packaging to js
LapzwansProducties Jul 24, 2019
526d650
update functionallity
LapzwansProducties Jul 24, 2019
7717a4a
Update gui.py
LapzwansProducties Jul 24, 2019
066659e
change to botpackage.json
LapzwansProducties Jul 25, 2019
f195343
Update botmanager.html
LapzwansProducties Jul 27, 2019
35f06cc
Update main.html
LapzwansProducties Jul 27, 2019
51a6319
Update botmanager.html
LapzwansProducties Jul 27, 2019
8512f3f
changes to shorten json in repofile (change in repo repo)
LapzwansProducties Jul 27, 2019
78a8948
botmanager js to seperate file
LapzwansProducties Jul 28, 2019
4816f8f
Update botmanager.html
LapzwansProducties Jul 28, 2019
d72cfc1
some canges to make the diff tool happy
LapzwansProducties Jul 28, 2019
6fbdc09
Merge branch 'master' into master
LapzwansProducties Jul 29, 2019
4fb7d6f
Update gui.py
LapzwansProducties Jul 29, 2019
5a29b42
Update gui.py
LapzwansProducties Jul 29, 2019
728b928
Update bot_creation.py
LapzwansProducties Jul 29, 2019
d660a22
Update gui.py
LapzwansProducties Jul 29, 2019
e27fe26
Update gui.py
LapzwansProducties Jul 29, 2019
6bf26ea
Update botmanager.js
LapzwansProducties Jul 29, 2019
86baed1
Update botmanager.js
LapzwansProducties Jul 29, 2019
cb3fd72
Create hubTodo.md
LapzwansProducties Jul 29, 2019
5b7be30
small style changes
LapzwansProducties Jul 30, 2019
d99a1ce
inaccurate closing times
LapzwansProducties Jul 30, 2019
97be127
Update hubTodo.md
LapzwansProducties Jul 30, 2019
7346ce0
copy download bot folder stabillity improvement
LapzwansProducties Jul 30, 2019
1b41e6c
Merge branch 'master' of https://github.com/ard1998/RLBotGUI
LapzwansProducties Jul 30, 2019
19e3cb7
Update botmanager.js
LapzwansProducties Jul 30, 2019
90bc89a
Bracket consistency
LapzwansProducties Jul 30, 2019
f0651a4
Update style.css
LapzwansProducties Jul 31, 2019
829086a
Update botmanager.css
LapzwansProducties Jul 31, 2019
6699b9d
Update botmanager.js
LapzwansProducties Jul 31, 2019
65e9a58
Update botmanager.js
LapzwansProducties Jul 31, 2019
937082b
Update botmanager.js
LapzwansProducties Jul 31, 2019
2034b74
Update botmanager.js
LapzwansProducties Jul 31, 2019
2ca152c
shoren the refresh time
LapzwansProducties Jul 31, 2019
ddd041f
Update botmanager.js
LapzwansProducties Jul 31, 2019
afedc4f
Converting the rlbot hub to vue, mostly.
tarehart Aug 2, 2019
def288a
multi repo functions for vue
LapzwansProducties Aug 26, 2019
709b020
small changes to indicate download safety
LapzwansProducties Aug 26, 2019
3dc55f9
deleting botpack functions and giving repo downloads own folder
LapzwansProducties Aug 26, 2019
a95e82c
Add files via upload
LapzwansProducties Aug 27, 2019
a2f4a82
Add files via upload
LapzwansProducties Aug 27, 2019
639973d
vue code fixes and some changes
LapzwansProducties Aug 29, 2019
ec63692
add sideloading via url
LapzwansProducties Aug 30, 2019
cfc2052
Update botmanager.html
LapzwansProducties Aug 30, 2019
284cfff
add news support and some small layout stuff
LapzwansProducties Aug 30, 2019
b54a6eb
small changes
LapzwansProducties Aug 30, 2019
ef75592
Delete hubTodo.md
LapzwansProducties Aug 31, 2019
22ffd71
few bugfixes
LapzwansProducties Aug 31, 2019
3572ce7
embed hub in main
LapzwansProducties Sep 26, 2019
59eea5d
Update gui.py
LapzwansProducties Sep 26, 2019
0bfd8c7
Update style.css
LapzwansProducties Sep 26, 2019
a59b284
Update gui.py
LapzwansProducties Sep 27, 2019
2681fec
Update botmanager.html
LapzwansProducties Sep 27, 2019
e93bb10
hub download section to 3 column
LapzwansProducties Sep 27, 2019
532e01c
undo last commit
LapzwansProducties Sep 28, 2019
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
73 changes: 26 additions & 47 deletions rlbot_gui/bot_management/bot_creation.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from pathlib import Path
from shutil import move
import configparser
import fileinput
import os
import re
import string
import sys
import tempfile

from rlbot.agents.base_agent import BaseAgent, BOT_CONFIG_MODULE_HEADER, BOT_NAME_KEY, PYTHON_FILE_KEY
from pathlib import Path
from shutil import move

from rlbot_gui.bot_management.downloader import download_and_extract_zip

Expand All @@ -28,10 +28,17 @@ def safe_move(src, dst):
move(str(src), str(dst))


def replace_all(file, regex, replacement):
for line in fileinput.input(file, inplace=1):
updated = re.sub(regex, replacement, line)
sys.stdout.write(updated)


def bootstrap_python_bot(bot_name, directory):
sanitized_name = convert_to_filename(bot_name)
bot_directory = Path(directory or '.')
if os.path.exists(bot_directory / sanitized_name):
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:
Expand All @@ -42,56 +49,28 @@ def bootstrap_python_bot(bot_name, directory):
download_url='https://github.com/RLBot/RLBotPythonExample/archive/master.zip',
local_folder_path=tmpdir)

safe_move(tmpdir / 'RLBotPythonExample-master', bot_directory / sanitized_name)
safe_move(tmpdir / 'RLBotPythonExample-master', top_dir)

# Choose appropriate file names based on the bot name
code_dir = bot_directory / sanitized_name / sanitized_name
python_file = code_dir / f'{sanitized_name}.py'
config_file = code_dir / f'{sanitized_name}.cfg'
code_dir = top_dir / sanitized_name
python_filename = f'{sanitized_name}.py'
python_file = code_dir / python_filename
config_filename = f'{sanitized_name}.cfg'
config_file = code_dir / config_filename

replace_all(top_dir / 'rlbot.cfg', r'(participant_config_\d = ).*$',
r'\1' + os.path.join(sanitized_name, config_filename).replace('\\', '\\\\'))

# We're making some big assumptions here that the file structure / names in RLBotPythonExample will not change.
safe_move(bot_directory / sanitized_name / 'python_example', code_dir)
safe_move(top_dir / 'python_example', code_dir)
safe_move(code_dir / 'python_example.py', python_file)
safe_move(code_dir / 'python_example.cfg', config_file)

# Update the config file to point to the renamed files, and show the correct bot name.

# This is not an ideal way of modifying the config file, because:
# - It uses our custom ConfigObject class, which is limited / buggy, and we should be moving away from it
# - The ConfigObject class is not capable of 'round-tripping', i.e. if you parse a config file and then
# write it again, the comment lines will not be preserved.
# - It can still write comments, but only if they have a 'description' that has been added programmatically
# (see base_create_agent_configurations).
#
# One route is to add 'description' items for all the stuff we care about, including the stuff here
# https://github.com/RLBot/RLBotPythonExample/blob/master/python_example/python_example.cfg#L11-L27
# so that the resulting file is sortof the same (might have slightly different formatting). That's annoying
# and hard to maintain though, and again we'd be investing more in this custom config class that I would
# prefer to get rid of.
#
# Alternatives:
#
# Use the configobj library https://configobj.readthedocs.io/en/latest/configobj.html
# - I tried this in https://github.com/IamEld3st/RLBotGUI/commit/a30308940dd5a0e4a45db6ccc088e6e75a9f69f0
# which worked well for me, but people reported issues during installation. If we can get the installation
# ironed out, it will be a nice solution for modifying cfg files in general.
#
# Do a simple find-and-replace in the file
# - Very crude, but it can be reliable if we use specific commit hashes like I did in
# https://github.com/IamEld3st/RLBotGUI/commit/a30308940dd5a0e4a45db6ccc088e6e75a9f69f0
# - It would get us up and running with the new features until we can figure out a proper config modification
# solution.
raw_bot_config = configparser.RawConfigParser()
raw_bot_config.read(config_file, encoding='utf8')
agent_config = BaseAgent.base_create_agent_configurations()
agent_config.parse_file(raw_bot_config)
agent_config.set_value(BOT_CONFIG_MODULE_HEADER, BOT_NAME_KEY, bot_name)
agent_config.set_value(BOT_CONFIG_MODULE_HEADER, PYTHON_FILE_KEY, f'{sanitized_name}.py')
with open(config_file, 'w', encoding='utf8') as f:
f.write(str(agent_config))
replace_all(config_file, r'name = .*$', 'name = ' + bot_name)
skyborgff marked this conversation as resolved.
Show resolved Hide resolved
replace_all(config_file, r'python_file = .*$', 'python_file = ' + python_filename)

# 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(python_file)

return config_file
return config_file
19 changes: 19 additions & 0 deletions rlbot_gui/bot_management/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from pathlib import Path
from shutil import rmtree

from distutils.dir_util import copy_tree



def download_and_extract_zip(download_url: str, local_folder_path: Path, clobber: bool = False):
"""
Expand Down Expand Up @@ -43,3 +46,19 @@ def download_gitlfs(repo_url: str, checkout_folder: Path, branch_name: str):
file.close()

print('Done downloading git repo.')

def download_botfs(repo_url: str, checkout_folder: Path, branch_name: str, bot_path: str):
This conversation was marked as resolved.
Show resolved Hide resolved
print('Starting download of a git repo... this might take a while.')
dtracers marked this conversation as resolved.
Show resolved Hide resolved

rmtree(checkout_folder, ignore_errors=True)

# Download the most of the files eg. https://github.com/RLBot/RLBotPack/archive/master.zip
download_and_extract_zip(
download_url=repo_url + '/archive/' + branch_name + '.zip',
local_folder_path=checkout_folder, clobber=True)

repo_extraction_name = '/' + repo_url.split('/')[-1] + '-' + branch_name + '/'

copy_tree(checkout_folder + repo_extraction_name, bot_path+'/')

print('Done downloading git repo.')
74 changes: 60 additions & 14 deletions rlbot_gui/gui.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import shutil

import eel
from PyQt5.QtCore import QSettings
Expand All @@ -15,6 +16,7 @@

from rlbot_gui.bot_management.bot_creation import bootstrap_python_bot
from rlbot_gui.bot_management.downloader import download_gitlfs
from rlbot_gui.bot_management.downloader import download_botfs
from rlbot_gui.match_runner.match_runner import hot_reload_bots, shut_down, start_match_helper, do_infinite_loop_content

DEFAULT_BOT_FOLDER = 'default_bot_folder'
Expand Down Expand Up @@ -225,14 +227,53 @@ def download_bot_pack():
settings.setValue(BOT_FOLDER_SETTINGS_KEY, bot_folder_settings)
settings.sync()

@eel.expose
def download_bot(repo):

branch = ""
if "tree" in repo:
branch = repo.split('/')[-1]
repo = repo.split('/tree')[0]
else:
branch = "master"

download_botfs(
repo_url=repo,
checkout_folder='download',
branch_name=branch,
bot_path=os.path.abspath(BOTPACK_FOLDER))
return 0;

@eel.expose
def delete_bot(name):
shutil.rmtree(os.path.abspath(BOTPACK_FOLDER + "/" + name))
return 0;

@eel.expose
def isBotInstalled(bot_name):
This conversation was marked as resolved.
Show resolved Hide resolved
bot_directory = BOTPACK_FOLDER
if os.path.exists(bot_directory+'/'+bot_name):
return True
else:
return False

@eel.expose
def getBotPackaging(bot_name):
This conversation was marked as resolved.
Show resolved Hide resolved
bot_directory = BOTPACK_FOLDER
if os.path.exists(bot_directory+'/'+bot_name):
file = open(bot_directory+'/'+bot_name+'/botpackage.json',"r")
filestr = file.read()
file.close()
return filestr
else:
return False

@eel.expose
def show_bot_in_explorer(bot_cfg_path):
import subprocess
directory = os.path.dirname(bot_cfg_path)
subprocess.Popen(f'explorer "{directory}"')


@eel.expose
def hot_reload_python_bots():
hot_reload_bots()
Expand Down Expand Up @@ -279,26 +320,31 @@ def is_chrome_installed():
return chm.find_path() is not None


def start():
gui_folder = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'gui')
eel.init(gui_folder)

# Ultra rare port, unlikely to conflict with other programs.
def launch_eel(browser_mode):
skyborgff marked this conversation as resolved.
Show resolved Hide resolved
port = 51993
mode = 'chrome'

options = {'port': port}
if not is_chrome_installed():
mode = 'system-default' # Use the system default browser if the user doesn't have chrome.
options['mode'] = mode
options = {'port': port, 'mode': browser_mode}

# This disable_cache thing only works if you have tare's fork of eel https://github.com/ChrisKnott/Eel/pull/102
# installed to pip locally using this technique https://stackoverflow.com/a/49684835
# The suppress_error=True avoids the error "'options' argument deprecated in v1.0.0", we need to keep the
# options argument since a lot of our user base has an older version of eel.
eel.start('main.html', size=(1000, 800), block=False, callback=on_websocket_close, options=options,
disable_cache=True, mode=mode, port=port, suppress_error=True)
disable_cache=True, mode=browser_mode, port=port, suppress_error=True)



def start():
gui_folder = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'gui')
eel.init(gui_folder)

try:
if not is_chrome_installed():
raise Exception("Chrome does not appear to be installed.")
launch_eel('chrome')
except Exception as e:
print(f'Falling back to system default browser because: {str(e)}')
launch_eel('system-default')

while not should_quit:
do_infinite_loop_content()
eel.sleep(1.0)
eel.sleep(1.0)
129 changes: 129 additions & 0 deletions rlbot_gui/gui/botmanager.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<!DOCTYPE html>
<html>
<head>

<meta charset="utf-8">
<meta content="width=device-width,initial-scale=1,minimal-ui" name="viewport">

<link rel="icon" type="image/png" sizes="192x192" href="imgs/rlbot_logo.png">

<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"/>
<link rel="stylesheet" href="css/vue-material.min.css"/>
<link rel="stylesheet" href="css/vue-fonts.css"/>
<link rel="stylesheet" href="css/black-green-light.css"/>
<link rel="stylesheet" href="css/style.css"/>
<link rel="stylesheet" href="css/botmanager.css"/>

<title>Hub</title>

</head>
<body id="rlbotgui" onload="downloadRepos()">
<div id="app" :style="bodyStyle">

<md-toolbar class="md-primary">
<div class="md-toolbar-row">
<img class="logo" src="imgs/rlbot_logo.png">
<a href="main.html"><h3 class="md-title" style="flex: 1">RLBot</h3></a> &nbsp; &nbsp;
<a href="botmanager.html"><h3 class="md-title" style="flex: 1">Hub (alpha)</h3></a>
<div class="md-toolbar-section-end">
<md-progress-spinner v-if="showProgressSpinner" class="md-accent" :md-diameter="30" md-mode="indeterminate"></md-progress-spinner>
<md-menu md-direction="bottom-start">
<md-button md-menu-trigger class="md-icon-button">
<md-icon>more_vert</md-icon>
</md-button>

<md-menu-content>
<md-menu-item @click="showPackageInstaller = true;">
Install missing python package
</md-menu-item>
</md-menu-content>
</md-menu>
</div>
</div>
</md-toolbar>

<md-dialog :md-active.sync="showPackageInstaller">
<md-dialog-title>Install Package</md-dialog-title>

<md-dialog-content>

<md-field>
<label>Package Name</label>
<md-input v-model="packageString"></md-input>
</md-field>
</md-dialog-content>

<md-dialog-actions>
<md-button @click="installPackage()" class="md-raised md-primary">Install Package</md-button>
<md-button @click="showPackageInstaller = false">Close</md-button>
</md-dialog-actions>
</md-dialog>

<aside>
<md-card v-if="matchOptions" class="settings-card">
<md-card-header>
<div class="md-title">Filters</div>
</md-card-header>

<md-card-content>

<label for="searchBotName">search</label>
<input id="searchBotName" onkeyup="displayRepoData()" type="text" name="" class="" placeholder="search on bot name"><br>

<hr>

<div class="center-flex">

<div class="md-layout md-gutter">
<div class="md-layout-item">
<label for="gamemodes">Gamemode</label>
<div id="gamemodes" class="list">
<p><input onclick="displayRepoData()" id="1v1" type="checkbox" name="gamemode" value="1v1">1v1</p>
<p><input onclick="displayRepoData()" id="2v2" type="checkbox" name="gamemode" value="2v2">2v2</p>
<p><input onclick="displayRepoData()" id="3v3" type="checkbox" name="gamemode" value="3v3">3v3</p>
<p><input onclick="displayRepoData()" id="4v4" type="checkbox" name="gamemode" value="4v4">4v4</p>
<p><input onclick="displayRepoData()" id="hoops" type="checkbox" name="gamemode" value="Hoops">Hoops</p>
<p><input onclick="displayRepoData()" id="dropshot" type="checkbox" name="gamemode" value="Dropshot">Dropshot</p>
<p><input onclick="displayRepoData()" id="snowday" type="checkbox" name="gamemode" value="Snowday">Snowday</p>
</div>
</div>
</div>
</div>

</md-card-content>
</md-card>

<md-card v-if="matchOptions" class="settings-card">
<md-card-header>
<div class="md-title">News</div>
<p>Coming soon</p>
<br>
<p>The hub is an ALPHA preview with working functionallity. Features will be added an bugs can occur more often then expexted.</p>
</md-card-header>

<md-card-content>

<div class="center-flex">

<div class="md-layout md-gutter">

</div>
</div>

</md-card-content>
</md-card>
</aside>

<div id="main">
</div>
</div>

<script type="text/javascript" src="/eel.js"></script>
<script type="text/javascript" src="js/vue.js"></script>
<script type="text/javascript" src="js/vue-material.min.js"></script>
<script type="text/javascript" src="js/Sortable.min.js"></script>
<script type="text/javascript" src="js/vuedraggable.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<script type="text/javascript" src="js/botmanager.js"></script>
</body>
</html>
Loading