Skip to content

Commit

Permalink
add new functionality (display downloaded maps)
Browse files Browse the repository at this point in the history
  • Loading branch information
redd-rl committed Jun 17, 2023
1 parent a91df46 commit 816f44f
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 10 deletions.
5 changes: 4 additions & 1 deletion loader.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ def startPage():
def close_window():
close_application()
if __name__ == "__main__":
FlaskUI(app=app, browser_path="C:\Program Files\Google\Chrome\Application\chrome.exe", server="flask", port=3000).run()
try:
FlaskUI(app=app, browser_path="C:\Program Files\Google\Chrome\Application\chrome.exe", server="flask", port=3000).run()
except FileNotFoundError:
FlaskUI(app=app, server="flask", port=3000).run()
81 changes: 81 additions & 0 deletions static/js/search.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,96 @@
function myFunction() {
var checkbox = document.getElementById('downloaded');
if (checkbox.checked != false)
{
let maps
let mapsPromise = fetch('http://127.0.0.1:5757/maplist')
.then(response => response.json())
.catch(error => {
// Handle any errors
console.error(error);
});
mapsPromise.then(data => {
// Handle the response data
const maps = data;
console.log(maps);

// Continue with your code that depends on the fetched data
// ...
// maps.includes(nodes[i].id) && nodes[i].innerText.toLowerCase().includes(filter)
var input = document.getElementById("Search");
var filter = input.value.toLowerCase();
var nodes = document.getElementsByClassName('grid-container');
for (i = 0; i < nodes.length; i++) {
if (maps.includes(nodes[i].id) && nodes[i].innerText.toLowerCase().includes(filter)) {
nodes[i].style.display = "block";
} else {
nodes[i].style.display = "none";
}
}
window.scrollTo(0,0);
});
} else
{
var input = document.getElementById("Search");
var filter = input.value.toLowerCase();
var nodes = document.getElementsByClassName('grid-container');
for (i = 0; i < nodes.length; i++) {
if (nodes[i].innerText.toLowerCase().includes(filter)) {
nodes[i].style.display = "block";
} else {
nodes[i].style.display = "none";
}
}
}
}
function displayDownloaded() {
var checkbox = document.getElementById('downloaded');
if (checkbox.checked != false)
{
let maps
let mapsPromise = fetch('http://127.0.0.1:5757/maplist')
.then(response => response.json())
.catch(error => {
// Handle any errors
console.error(error);
});
mapsPromise.then(data => {
// Handle the response data
const maps = data;
console.log(maps);

// Continue with your code that depends on the fetched data
// ...
var nodes = document.getElementsByClassName('grid-container');
for (i = 0; i < nodes.length; i++) {
if (maps.includes(nodes[i].id)) {
nodes[i].style.display = "block";
} else {
nodes[i].style.display = "none";
}
}
window.scrollTo(0,0);
});
} else {
var nodes = document.getElementsByClassName('grid-container');
var input = document.getElementById("Search");
console.log(input);
var filter = input.value.toLowerCase();
console.log(filter == '');
for (i = 0; i < nodes.length; i++) {
if (filter != "") {
if (maps.includes(nodes[i].id) && nodes[i].innerText.toLowerCase().includes(filter)) {
nodes[i].style.display = "block";
} else {
nodes[i].style.display = "none";
}

} else {
nodes[i].style.display = "block";
}
}
}

}
function key_down(e)
{
Expand Down
13 changes: 13 additions & 0 deletions static/styles/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ h2 {
button {
font-family: 'Lexend';
}

p {
color: white;
font-family: 'Lexend';
Expand All @@ -141,6 +142,7 @@ p {
img {
border-radius: 5px;
max-width: 100%;
width: 100%;
margin-left: auto;
margin-right: auto;
height: auto;
Expand Down Expand Up @@ -211,6 +213,17 @@ img {
font-size: 16px;
position: absolute;
}
.downloadtext {
float: right;
margin-right: 30px;
}
.downloadbox {
display: inline-block;
padding: 15px 32px;
float: right;
margin-top: 20px;

}
.download-button {
border: 8px;
border-radius: 5px;
Expand Down
24 changes: 15 additions & 9 deletions webServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def cleanHTML(html):
pass
return cleantext
def format_map(customMap: dict):
return f"""<div class="grid-container">
return f"""<div id="{customMap.get('path')}" class="grid-container">
<article class="grid-item">
<a class="grid-item-image">
<img src="{customMap.get('img')}">
Expand Down Expand Up @@ -158,6 +158,10 @@ def getBasePage():
<button class="restore-button" name="restore" type="submit" value="restore"> Restore Underpass
</button>
</form>
<p class="downloadtext">Display downloaded maps</p>
<form target="post-receiver">
<input type="checkbox" onclick="displayDownloaded()" id="downloaded" class="downloadbox">
</form>
<h1 class="active">Redd's scuffed map loader</h1>
<tr>
<div class="search-container">
Expand Down Expand Up @@ -265,14 +269,8 @@ def scrapePage(depth_limit=None):
if gameVersion in ("steam".casefold(), "epic games".casefold(), "epicgames".casefold()):
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()):
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"
Expand All @@ -298,7 +296,7 @@ def scrapePage(depth_limit=None):
#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"
mapPath = customPath + r"TAGame\CookedPCConsole\Labs_Underpass_P.upk"
#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 @@ -399,6 +397,7 @@ def getFeedback(type):
</div>
`
parent.document.body.appendChild(div)</script>"""

@app.route("/", methods=['GET'])
def startPage():
try:
Expand All @@ -411,6 +410,10 @@ def startPage():
fullPage = half1 + ''.join(formattedMaps) + half2
return fullPage

@app.route("/maplist", methods=['GET'])
def maplist():
return os.listdir(Path.cwd().__str__() + '\\maps')

@app.route("/receiver", methods=['POST'])
def getFormResponse():
if request.method == "POST":
Expand Down Expand Up @@ -446,5 +449,8 @@ def getFormResponse():
return getFeedback("restore")
return "true"
if __name__ == "__main__":
FlaskUI(app=app, browser_path="C:\Program Files\Google\Chrome\Application\chrome.exe", server="flask", port=5757).run()
try:
FlaskUI(app=app, browser_path="C:\Program Files\Google\Chrome\Application\chrome.exe", server="flask", port=5757).run()
except FileNotFoundError:
FlaskUI(app=app, server="flask", port=5757).run()

0 comments on commit 816f44f

Please sign in to comment.