Skip to content

Commit

Permalink
lol i made it better
Browse files Browse the repository at this point in the history
  • Loading branch information
redd-rl committed Jun 23, 2024
1 parent bfd797f commit 9de0e2c
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 48 deletions.
54 changes: 54 additions & 0 deletions askdialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import tkinter as tk
# We found two installations, choose your preferred installation for us to load custom maps to.
def select_platform_dialog():
root = tk.Tk()
root.withdraw() # Hide the main tkinter window

# Create a custom Toplevel dialog
dialog = tk.Toplevel(root)
dialog.title("Select Platform")

# Label with instructions
label = tk.Label(dialog, text="We found two installations.\nChoose your preferred installation for us to load custom maps to.")
label.pack(pady=10)

# Variable to store the selected platform
selected_platform = tk.StringVar()

# Function to handle button click and return the platform
def button_clicked(platform):
selected_platform.set(platform)
dialog.quit() # Breaks the mainloop
dialog.destroy() # Close the dialog

# Button for Steam
btn_steam = tk.Button(dialog, text="Steam", width=10,
command=lambda: button_clicked("Steam"))
btn_steam.pack(pady=5)

# Button for Epic Games
btn_epic = tk.Button(dialog, text="Epic Games", width=10,
command=lambda: button_clicked("Epic Games"))
btn_epic.pack(pady=5)

# Set minimum width of the dialog to fit the title and content
dialog.update_idletasks()
min_width = max(dialog.winfo_width(), 300) # Adjust 300 as needed
dialog.minsize(min_width, dialog.winfo_height())

# Center the dialog on the screen
width = dialog.winfo_width()
height = dialog.winfo_height()
x = (dialog.winfo_screenwidth() // 2) - (width // 2)
y = (dialog.winfo_screenheight() // 2) - (height // 2)
dialog.geometry(f'+{x}+{y}')

# Run the tkinter main loop
root.mainloop()

# Return the selected platform after the dialog is closed
return selected_platform.get()

if __name__ == "__main__":
platform = select_platform_dialog()
print(f"Selected platform: {platform}")
2 changes: 1 addition & 1 deletion load-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h1>
<div class="holder">
<div class="bar">
</div>
<iframe src="https://www.youtube.com/embed/dvjy6V4vLlI" title="Subway Surfers (2018) - Gameplay Compilation HD" frameborder="0">
<iframe src="https://subwaysurfersgame.io/subway-surfers-game.embed?d=20240609" title="Subway Surfers (2018) - Gameplay Compilation HD" frameborder="0">
</iframe>
</div>
<a href="/close" class="exit" role="button">
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"versionNumber": "0.1.5"
"versionNumber": "0.1.6"
}
27 changes: 27 additions & 0 deletions static/js/settings_handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function openSettingsDialog() {
var overlay = document.getElementById('overlay');
overlay.style.display = 'flex';
var dropdown = document.getElementById('platformSelect');
dropdown.innerHTML = '';
var option1 = document.createElement('option');
option1.value = 'steam';
option1.textContent = 'Steam';
dropdown.appendChild(option1);
var option2 = document.createElement('option');
option2.value = 'epicgames';
option2.textContent = 'Epic Games';
dropdown.appendChild(option2);
}

function closeSettingsDialog() {
var overlay = document.getElementById('overlay');
overlay.style.display = 'none'; // Hide overlay
}

function handleFileSelection(event) {
const file = event.target.files[0];
if (file) {
console.log("Selected file:", file.name);
console.log("File path (not accessible due to browser security):", event.target.value);
}
}
24 changes: 22 additions & 2 deletions static/styles/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ body {
align-items: center;
border-radius: 5px;
}

.dialog-box {
background-color: #3d3d3d;
padding: 20px;
border-radius: 30px;
}

.restore-button {

}

.form-container {
display: inline-block;
justify-content: space-around; /* Adjust spacing between forms */
margin-top: 20px;
}

/* Style for individual forms */
.form-wrapper {
text-align: left; /* Center align content within each form wrapper */
}
#overlay {
justify-content: center;
align-items: center;
Expand Down Expand Up @@ -106,8 +127,7 @@ h1 {
color: white;
font-family: 'Lexend';
float: left;
display: inline;
padding-left: 20px;
/* display: inline; */
letter-spacing: 3px;
}
.grid {
Expand Down
176 changes: 132 additions & 44 deletions webServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
from tkinter.filedialog import askdirectory
from tkinter.simpledialog import askstring
from askdialog import select_platform_dialog
os.chdir("app")
import requests
from bs4 import BeautifulSoup
Expand All @@ -19,6 +20,7 @@
import click
with open("log.txt", "w") as handle:
handle.write("")

logging.basicConfig(# filename=Path.cwd().__str__() + "log.txt",
filemode='a',
format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
Expand Down Expand Up @@ -180,14 +182,53 @@ def getBasePage():
<link rel= "stylesheet" type= "text/css" href= "static/styles/style.css">
<link rel="icon" href="static/favicon.ico">
<script type="text/javascript" src="static/js/search.js"></script>
<body>
<script type="text/javascript" src="static/js/settings_handler.js"></script>
<body onload="closeSettingsDialog();">
<div id="overlay" class="overlay">
<div class="dialog-box">
<h1 class="settingsTitle" style="
float: none;
">Settings</h1>
<!-- Settings form -->
<form action="http://127.0.0.1:5757/receive_settings" method="post" enctype="multipart/form-data" target="post-receiver" style="
font-family: 'Lexend';
color: white;">
<label for="platformSelect">Platform:</label>
<select id="platformSelect" name="platform" style="
font-family: 'Lexend';">
<option value="epicgames">Epic Games</option></select>
<option value="steam">Steam</option>
<br>
<br>
<label for="fileInput">Browse to RocketLeague.exe File:</label>
<br>
<h2 style="
font-size: 16px;
">Will ask for filepath when submit button is pressed.</h2>
<br>
<h2 style="
font-size: 16px;
">If no windows pop up, check your desktop or start minimizing windows. It will appear.</h2>
<br><br>
<!-- Submit button to post the form data -->
<button type="submit" class="download-button" style="
float: right;" onclick="closeSettingsDialog()">Submit</button>
<button class="restore-button btn" onclick="closeSettingsDialog()" style="
float: left;">Cancel</button>
</form>
<!-- Button to close the dialog -->
</div>
</div>
<div class="topnav">
<form action="http://127.0.0.1:5757/receiver" method="post" target="post-receiver">
<button class="restore-button" name="restore" type="submit" value="restore"> Restore Underpass
</button>
</form>
<p class="downloadtext">Display downloaded maps</p>
<button class="download-button btn" onclick="openSettingsDialog()" style="
margin-left: 220px;
">Open Settings</button>
<form target="post-receiver">
<p class="downloadtext">Display downloaded maps</p>
<input type="checkbox" onclick="displayDownloaded()" id="downloaded" class="downloadbox">
</form>
<h1 class="active">Redd's scuffed map loader</h1>
Expand Down Expand Up @@ -221,14 +262,15 @@ def getLethamyrMaps(depth_limit=None):
while nextPage != None:
mapsJson = json.loads(maps.text)
nextPage = mapsJson["links"]["next"]
if nextPage == None:
break
for customMap in mapsJson['data']:
customMap: dict
name = customMap.get('name', None)
identifier: str = name.lower().replace(" ", "")
author = "Lethamyr"
downloadUrl = customMap.get("download_url", None)
description = customMap.get("description", "Blank description.")
log.debug(f"downloaded {name}, download url '{downloadUrl}'")
active = {
"name": name,
"author": author,
Expand All @@ -242,8 +284,6 @@ def getLethamyrMaps(depth_limit=None):
"rlmus": False,
}
mapTotal.append(active)
if nextPage == None:
break
log.info(f"requesting {nextPage}")
maps = requests.get(nextPage)
except:
Expand All @@ -260,54 +300,68 @@ def getLethamyrMaps(depth_limit=None):
epicGames = False
steam = False
fileDirectory = Path.cwd()
#print("searching for rocket league...")
if os.path.exists(r"C:\Program Files\Epic Games\rocketleague\Binaries\Win64\RocketLeague.exe"):
#print("Found Epic Games Rocket League")
epicGames = True
if os.path.exists(r"C:\Program Files (x86)\Steam\steamapps\common\rocketleague\Binaries\Win64\RocketLeague.exe"):
#print("Found Steam Rocket League")
steam = True
if steam and epicGames:
#print("Found both Steam and Epic Games Rocket League installations, which one would you like to load maps to?\n")
while True:
gameVersion = askstring(prompt="Found both Steam and Epic Games Rocket League installations, which one would you like to load maps to? (Type steam or epic games)",title="Enter a string:")
if gameVersion in ("steam".casefold(), "epic games".casefold(), "epicgames".casefold()):
if gameVersion == "steam":
if os.path.exists(Path.cwd() / "config.json"):
with open(Path.cwd() / "config.json", "r") as handle:
configuration = json.loads(handle.read())
mapPath = configuration['mapPath']
gamePath = configuration['gamePath']
gameVersion = configuration['gameVersion']
steam = True if gameVersion == "steam" else False
epicGames = True if gameVersion == "epicgames" else False
else:
#print("searching for rocket league...")
if os.path.exists(r"C:\Program Files\Epic Games\rocketleague\Binaries\Win64\RocketLeague.exe"):
#print("Found Epic Games Rocket League")
epicGames = True
if os.path.exists(r"C:\Program Files (x86)\Steam\steamapps\common\rocketleague\Binaries\Win64\RocketLeague.exe"):
#print("Found Steam Rocket League")
steam = True
if steam and epicGames:
#print("Found both Steam and Epic Games Rocket League installations, which one would you like to load maps to?\n")
while True:
gameVersion = select_platform_dialog()
if gameVersion == "Steam":
gameVersion = "steam"
gamePath = r"C:\Program Files (x86)\Steam\steamapps\common\rocketleague\Binaries\Win64\RocketLeague.exe"
mapPath = r"C:\Program Files (x86)\Steam\steamapps\common\rocketleague\TAGame\CookedPCConsole\Labs_Underpass_P.upk"
break
elif gameVersion in ("epic games".casefold(), "epicgames".casefold()):
elif gameVersion == "Epic Games":
gameVersion = "epicgames"
gamePath = r"C:\Program Files\Epic Games\rocketleague\Binaries\Win64\RocketLeague.exe"
mapPath = r"C:\Program Files\Epic Games\rocketleague\TAGame\CookedPCConsole\Labs_Underpass_P.upk"
break
elif steam:
gameVersion = "steam"
gamePath = r"C:\Program Files (x86)\Steam\steamapps\common\rocketleague\Binaries\Win64\RocketLeague.exe"
mapPath = r"C:\Program Files (x86)\Steam\steamapps\common\rocketleague\TAGame\CookedPCConsole\Labs_Underpass_P.upk"
elif epicGames:
gameVersion = "epicgames"
gamePath = r"C:\Program Files\Epic Games\rocketleague\Binaries\Win64\RocketLeague.exe"
mapPath = r"C:\Program Files\Epic Games\rocketleague\TAGame\CookedPCConsole\Labs_Underpass_P.upk"
else:
#print("Found no installation,")
customPath = askdirectory(initialdir="C:\\", mustexist=True, title=r"Please specify the base directory to rocket league, e.g 'C:\Program Files\Epic Games\rocketleague\' or 'C:\Program Files (x86)\Steam\steamapps\common\rocketleague\'")
if os.path.exists(fr"{customPath}\Binaries\Win64\RocketLeague.exe") and os.path.exists(fr"{customPath}\TAGame\CookedPCConsole\Labs_Underpass_P.upk"):
#print("That's a valid Rocket League path, thank you!")
pass
elif steam:
gameVersion = "steam"
gamePath = r"C:\Program Files (x86)\Steam\steamapps\common\rocketleague\Binaries\Win64\RocketLeague.exe"
mapPath = r"C:\Program Files (x86)\Steam\steamapps\common\rocketleague\TAGame\CookedPCConsole\Labs_Underpass_P.upk"
elif epicGames:
gameVersion = "epicgames"
gamePath = r"C:\Program Files\Epic Games\rocketleague\Binaries\Win64\RocketLeague.exe"
mapPath = r"C:\Program Files\Epic Games\rocketleague\TAGame\CookedPCConsole\Labs_Underpass_P.upk"
else:
while True:
#print("That wasn't a valid path! Try again, make sure to follow the format listed above.")
customPath = askdirectory(initialdir="C:\\", mustexist=True, title=r"Please specify the base directory to rocket league, e.g 'C:\Program Files\Epic Games\rocketleague\' or 'C:\Program Files (x86)\Steam\steamapps\common\rocketleague\', if you opened this by mistake, type 'stop' to exit.")
if customPath.casefold() == "stop".casefold():
#print("exiting...")
exit()
if os.path.exists(fr"{customPath}\Binaries\Win64\RocketLeague.exe") and os.path.exists(fr"{customPath}\TAGame\CookedPCConsole\Labs_Underpass_P.upk"):
#print("That's a valid Rocket League path, thank you!")
break
gamePath = customPath + r"Binaries\Win64\RocketLeague.exe"
mapPath = customPath + r"TAGame\CookedPCConsole\Labs_Underpass_P.upk"
#print("Found no installation,")
customPath = askdirectory(initialdir="C:\\", mustexist=True, title=r"Please specify the base directory to rocket league, e.g 'C:\Program Files\Epic Games\rocketleague\' or 'C:\Program Files (x86)\Steam\steamapps\common\rocketleague\'")
if os.path.exists(fr"{customPath}\Binaries\Win64\RocketLeague.exe") and os.path.exists(fr"{customPath}\TAGame\CookedPCConsole\Labs_Underpass_P.upk"):
#print("That's a valid Rocket League path, thank you!")
pass
else:
while True:
#print("That wasn't a valid path! Try again, make sure to follow the format listed above.")
customPath = askdirectory(initialdir="C:\\", mustexist=True, title=r"Please specify the base directory to rocket league, e.g 'C:\Program Files\Epic Games\rocketleague\' or 'C:\Program Files (x86)\Steam\steamapps\common\rocketleague\', if you opened this by mistake, type 'stop' to exit.")
if customPath.casefold() == "stop".casefold():
#print("exiting...")
exit()
if os.path.exists(fr"{customPath}\Binaries\Win64\RocketLeague.exe") and os.path.exists(fr"{customPath}\TAGame\CookedPCConsole\Labs_Underpass_P.upk"):
#print("That's a valid Rocket League path, thank you!")
break
gamePath = customPath + r"Binaries\Win64\RocketLeague.exe"
mapPath = customPath + r"TAGame\CookedPCConsole\Labs_Underpass_P.upk"
with open(Path.cwd() / "config.json", "w") as handle:
handle.write(json.dumps(
{"gamePath": gamePath,
"mapPath": mapPath,
"gameVersion": gameVersion}
))
#print(f"Chosen game version is {'Steam' if steam else 'Epic Games'}")
#print(f"Rocket League path is: {gamePath}")
#print(mapPath)
Expand Down Expand Up @@ -408,6 +462,22 @@ def getFeedback(type):
</div>
`
parent.document.body.appendChild(div)</script>"""
elif type == "opensettings":
return """
<script>
var div = parent.document.createElement('div');
div.id = 'overlay';
div.innerHTML = `
<div id="alertbox">
<h1>
Restored Underpass
</h1>
<button type="submit" onclick="removeOverlay()">
Ok
</button>
</div>
`
parent.document.body.appendChild(div)</script>"""

@app.route("/", methods=['GET'])
def startPage():
Expand All @@ -425,6 +495,24 @@ def startPage():
def maplist():
return os.listdir(Path.cwd().__str__() + '\\maps')

@app.route("/receive_settings", methods=['POST'])
def receive_settings():
if request.method == "POST":
customPath = askdirectory(initialdir="C:\\", mustexist=True, title=r"Please specify the base directory to rocket league, e.g 'C:\Program Files\Epic Games\rocketleague\' or 'C:\Program Files (x86)\Steam\steamapps\common\rocketleague\'")
global gamePath
gamePath = customPath + r"Binaries\Win64\RocketLeague.exe"
global mapPath
mapPath = customPath + r"TAGame\CookedPCConsole\Labs_Underpass_P.upk"
if "platformSelect" in request.form.keys():
global gameVersion
gameVersion = request.form.get("platformSelect")
with open(Path.cwd() / "config.json", "w") as handle:
handle.write(json.dumps(
{"gamePath": gamePath,
"mapPath": mapPath,
"gameVersion": gameVersion}
))

@app.route("/receiver", methods=['POST'])
def getFormResponse():
if request.method == "POST":
Expand Down

0 comments on commit 9de0e2c

Please sign in to comment.