From 11245462f06e91670641ac7e47830036da2a0664 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 17 Sep 2021 18:41:26 -0400 Subject: [PATCH] Added gameInfo page using markdown, removed old game sub-pages and directories --- WebHostLib/__init__.py | 16 ++---- WebHostLib/static/assets/gameInfo.js | 54 +++++++++++++++++++ .../assets/gameInfo/en_A Link to the Past.md | 1 + .../static/assets/gameInfo/en_Factorio.md | 1 + .../static/assets/gameInfo/en_Subnautica.md | 1 + WebHostLib/templates/gameInfo.html | 14 +++++ .../A Link to the Past.html | 15 ------ .../templates/games/Factorio/Factorio.html | 15 ------ .../templates/games/Minecraft/Minecraft.html | 15 ------ .../games/Subnautica/Subnautica.html | 15 ------ .../{games/games.html => supportedGames.html} | 0 11 files changed, 76 insertions(+), 71 deletions(-) create mode 100644 WebHostLib/static/assets/gameInfo.js create mode 100644 WebHostLib/static/assets/gameInfo/en_A Link to the Past.md create mode 100644 WebHostLib/static/assets/gameInfo/en_Factorio.md create mode 100644 WebHostLib/static/assets/gameInfo/en_Subnautica.md create mode 100644 WebHostLib/templates/gameInfo.html delete mode 100644 WebHostLib/templates/games/A Link to the Past/A Link to the Past.html delete mode 100644 WebHostLib/templates/games/Factorio/Factorio.html delete mode 100644 WebHostLib/templates/games/Minecraft/Minecraft.html delete mode 100644 WebHostLib/templates/games/Subnautica/Subnautica.html rename WebHostLib/templates/{games/games.html => supportedGames.html} (100%) diff --git a/WebHostLib/__init__.py b/WebHostLib/__init__.py index fb3eee55..10006a29 100644 --- a/WebHostLib/__init__.py +++ b/WebHostLib/__init__.py @@ -88,16 +88,10 @@ def player_settings(game): return render_template(f"player-settings.html", game=game) -# Game sub-pages -@app.route('/games//') -def game_pages(game, page): - return render_template(f"/games/{game}/{page}.html") - - -# Game landing pages -@app.route('/games/') -def game_page(game): - return render_template(f"/games/{game}/{game}.html") +# Game Info Pages +@app.route('/games//info/') +def game_page(game, lang): + return render_template('gameInfo.html', game=game, lang=lang) # List of supported games @@ -107,7 +101,7 @@ def games(): for game, world in AutoWorldRegister.world_types.items(): if not world.hidden: worlds[game] = world.__doc__ if world.__doc__ else "No description provided." - return render_template("games/games.html", worlds=worlds) + return render_template("supportedGames.html", worlds=worlds) @app.route('/tutorial///') diff --git a/WebHostLib/static/assets/gameInfo.js b/WebHostLib/static/assets/gameInfo.js new file mode 100644 index 00000000..e6dcfa48 --- /dev/null +++ b/WebHostLib/static/assets/gameInfo.js @@ -0,0 +1,54 @@ +window.addEventListener('load', () => { + const gameInfo = document.getElementById('game-info'); + new Promise((resolve, reject) => { + const ajax = new XMLHttpRequest(); + ajax.onreadystatechange = () => { + if (ajax.readyState !== 4) { return; } + if (ajax.status === 404) { + reject("Sorry, this game's info page is not available in that language yet."); + return; + } + if (ajax.status !== 200) { + reject("Something went wrong while loading the info page."); + return; + } + resolve(ajax.responseText); + }; + ajax.open('GET', `${window.location.origin}/static/assets/gameInfo/` + + `${gameInfo.getAttribute('data-lang')}_${gameInfo.getAttribute('data-game')}.md`, true); + ajax.send(); + }).then((results) => { + // Populate page with HTML generated from markdown + showdown.setOption('tables', true); + showdown.setOption('strikethrough', true); + showdown.setOption('simpleLineBreaks', true); + showdown.setOption('literalMidWordUnderscores', true); + gameInfo.innerHTML += (new showdown.Converter()).makeHtml(results); + adjustHeaderWidth(); + + // Reset the id of all header divs to something nicer + const headers = Array.from(document.querySelectorAll('h1, h2, h3, h4, h5, h6')); + const scrollTargetIndex = window.location.href.search(/#[A-z0-9-_]*$/); + for (let i=0; i < headers.length; i++){ + const headerId = headers[i].innerText.replace(/[ ]/g,'-').toLowerCase() + headers[i].setAttribute('id', headerId); + headers[i].addEventListener('click', () => + window.location.href = window.location.href.substring(0, scrollTargetIndex) + `#${headerId}`); + } + + // Manually scroll the user to the appropriate header if anchor navigation is used + if (scrollTargetIndex > -1) { + try{ + const scrollTarget = window.location.href.substring(scrollTargetIndex + 1); + document.getElementById(scrollTarget).scrollIntoView({ behavior: "smooth" }); + } catch(error) { + console.error(error); + } + } + }).catch((error) => { + console.error(error); + gameInfo.innerHTML = + `

This page is out of logic!

+

Click here to return to safety.

`; + }); +}); diff --git a/WebHostLib/static/assets/gameInfo/en_A Link to the Past.md b/WebHostLib/static/assets/gameInfo/en_A Link to the Past.md new file mode 100644 index 00000000..dd3f67a5 --- /dev/null +++ b/WebHostLib/static/assets/gameInfo/en_A Link to the Past.md @@ -0,0 +1 @@ +# Link to the Past Game Info diff --git a/WebHostLib/static/assets/gameInfo/en_Factorio.md b/WebHostLib/static/assets/gameInfo/en_Factorio.md new file mode 100644 index 00000000..53531182 --- /dev/null +++ b/WebHostLib/static/assets/gameInfo/en_Factorio.md @@ -0,0 +1 @@ +# Factorio Game Info diff --git a/WebHostLib/static/assets/gameInfo/en_Subnautica.md b/WebHostLib/static/assets/gameInfo/en_Subnautica.md new file mode 100644 index 00000000..b0412287 --- /dev/null +++ b/WebHostLib/static/assets/gameInfo/en_Subnautica.md @@ -0,0 +1 @@ +# Subnautica Game Info diff --git a/WebHostLib/templates/gameInfo.html b/WebHostLib/templates/gameInfo.html new file mode 100644 index 00000000..ea69d742 --- /dev/null +++ b/WebHostLib/templates/gameInfo.html @@ -0,0 +1,14 @@ +{% extends 'pageWrapper.html' %} + +{% block head %} + {{ game }} Info + + +{% endblock %} + +{% block body %} + {% include 'header/grassHeader.html' %} +
+ +
+{% endblock %} diff --git a/WebHostLib/templates/games/A Link to the Past/A Link to the Past.html b/WebHostLib/templates/games/A Link to the Past/A Link to the Past.html deleted file mode 100644 index 49d4c702..00000000 --- a/WebHostLib/templates/games/A Link to the Past/A Link to the Past.html +++ /dev/null @@ -1,15 +0,0 @@ -{% extends 'pageWrapper.html' %} - -{% block head %} - A Link to the Past - - - -{% endblock %} - -{% block body %} - {% include 'header/grassHeader.html' %} -
- Coming Soon™ -
-{% endblock %} diff --git a/WebHostLib/templates/games/Factorio/Factorio.html b/WebHostLib/templates/games/Factorio/Factorio.html deleted file mode 100644 index 6dc6a530..00000000 --- a/WebHostLib/templates/games/Factorio/Factorio.html +++ /dev/null @@ -1,15 +0,0 @@ -{% extends 'pageWrapper.html' %} - -{% block head %} - Factorio - - - -{% endblock %} - -{% block body %} - {% include 'header/grassHeader.html' %} -
- Coming Soon™ -
-{% endblock %} diff --git a/WebHostLib/templates/games/Minecraft/Minecraft.html b/WebHostLib/templates/games/Minecraft/Minecraft.html deleted file mode 100644 index 1e758411..00000000 --- a/WebHostLib/templates/games/Minecraft/Minecraft.html +++ /dev/null @@ -1,15 +0,0 @@ -{% extends 'pageWrapper.html' %} - -{% block head %} - Minecraft - - - -{% endblock %} - -{% block body %} - {% include 'header/grassHeader.html' %} -
- Coming Soon™ -
-{% endblock %} diff --git a/WebHostLib/templates/games/Subnautica/Subnautica.html b/WebHostLib/templates/games/Subnautica/Subnautica.html deleted file mode 100644 index d456c607..00000000 --- a/WebHostLib/templates/games/Subnautica/Subnautica.html +++ /dev/null @@ -1,15 +0,0 @@ -{% extends 'pageWrapper.html' %} - -{% block head %} - Subnautica - - - -{% endblock %} - -{% block body %} - {% include 'header/grassHeader.html' %} -
- Coming Soon™ -
-{% endblock %} diff --git a/WebHostLib/templates/games/games.html b/WebHostLib/templates/supportedGames.html similarity index 100% rename from WebHostLib/templates/games/games.html rename to WebHostLib/templates/supportedGames.html