From 517e72f44217e7e1c06608bb42719d39d5d381b0 Mon Sep 17 00:00:00 2001
From: CaitSith2
Date: Wed, 4 May 2022 20:03:19 -0700
Subject: [PATCH] Add options to generate page (#450)
* Add Item cheat permission to generate page.
* Indicate that both remaining_mode and item cheat are disabled in race mode.
* Add server_password
* refine tooltips and help for server_password and !admin command.
* Add Plando options to generation page.
* Remove debugging code
* Style adjustments and HTML formatting and tag fixes with the goal of making the page nicer looking and not as vertical.
Co-authored-by: Chris Wilson
---
MultiServer.py | 5 +-
WebHostLib/api/generate.py | 2 +-
WebHostLib/check.py | 6 +-
WebHostLib/generate.py | 17 +-
WebHostLib/static/styles/generate.css | 19 ++-
WebHostLib/templates/generate.html | 225 +++++++++++++++++---------
6 files changed, 187 insertions(+), 87 deletions(-)
diff --git a/MultiServer.py b/MultiServer.py
index a454284f..f61701d2 100644
--- a/MultiServer.py
+++ b/MultiServer.py
@@ -1060,7 +1060,10 @@ class ClientMessageProcessor(CommonCommandProcessor):
@mark_raw
def _cmd_admin(self, command: str = ""):
- """Allow remote administration of the multiworld server"""
+ """Allow remote administration of the multiworld server
+ Usage: "!admin login " in order to log in to the remote interface.
+ Once logged in, you can then use "!admin " to issue commands.
+ If you need further help once logged in. use "!admin /help" """
output = f"!admin {command}"
if output.lower().startswith(
diff --git a/WebHostLib/api/generate.py b/WebHostLib/api/generate.py
index 90280eba..faad50e1 100644
--- a/WebHostLib/api/generate.py
+++ b/WebHostLib/api/generate.py
@@ -45,7 +45,7 @@ def generate_api():
"detail": app.config["MAX_ROLL"]}, 409
meta = get_meta(meta_options_source)
meta["race"] = race
- results, gen_options = roll_options(options)
+ results, gen_options = roll_options(options, meta["plando_options"])
if any(type(result) == str for result in results.values()):
return {"text": str(results),
"detail": results}, 400
diff --git a/WebHostLib/check.py b/WebHostLib/check.py
index 991af59b..46de51b8 100644
--- a/WebHostLib/check.py
+++ b/WebHostLib/check.py
@@ -62,7 +62,7 @@ def get_yaml_data(file) -> Union[Dict[str, str], str]:
return options
-def roll_options(options: Dict[str, Union[dict, str]]) -> Tuple[Dict[str, Union[str, bool]], Dict[str, dict]]:
+def roll_options(options: Dict[str, Union[dict, str]], plando_options: set = {"bosses", "items", "connections", "texts"}) -> Tuple[Dict[str, Union[str, bool]], Dict[str, dict]]:
results = {}
rolled_results = {}
for filename, text in options.items():
@@ -77,11 +77,11 @@ def roll_options(options: Dict[str, Union[dict, str]]) -> Tuple[Dict[str, Union[
try:
if len(yaml_datas) == 1:
rolled_results[filename] = roll_settings(yaml_datas[0],
- plando_options={"bosses", "items", "connections", "texts"})
+ plando_options=plando_options)
else:
for i, yaml_data in enumerate(yaml_datas):
rolled_results[f"{filename}/{i + 1}"] = roll_settings(yaml_data,
- plando_options={"bosses", "items", "connections", "texts"})
+ plando_options=plando_options)
except Exception as e:
results[filename] = f"Failed to generate mystery in {filename}: {e}"
else:
diff --git a/WebHostLib/generate.py b/WebHostLib/generate.py
index da821cf5..00904762 100644
--- a/WebHostLib/generate.py
+++ b/WebHostLib/generate.py
@@ -22,11 +22,22 @@ from .upload import upload_zip_to_db
def get_meta(options_source: dict) -> dict:
+ plando_options = {
+ options_source.get("plando_bosses", ""),
+ options_source.get("plando_items", ""),
+ options_source.get("plando_connections", ""),
+ options_source.get("plando_texts", "")
+ }
+ plando_options -= {""}
+
meta = {
"hint_cost": int(options_source.get("hint_cost", 10)),
"forfeit_mode": options_source.get("forfeit_mode", "goal"),
"remaining_mode": options_source.get("remaining_mode", "disabled"),
"collect_mode": options_source.get("collect_mode", "disabled"),
+ "item_cheat": bool(int(options_source.get("item_cheat", 1))),
+ "server_password": options_source.get("server_password", None),
+ "plando_options": plando_options
}
return meta
@@ -44,10 +55,9 @@ def generate(race=False):
if type(options) == str:
flash(options)
else:
- results, gen_options = roll_options(options)
- # get form data -> server settings
meta = get_meta(request.form)
meta["race"] = race
+ results, gen_options = roll_options(options, meta["plando_options"])
if race:
meta["item_cheat"] = False
@@ -89,6 +99,8 @@ def gen_game(gen_options, meta: TypeOptional[Dict[str, object]] = None, owner=No
meta.setdefault("hint_cost", 10)
race = meta.get("race", False)
del (meta["race"])
+ plando_options = meta.get("plando", {"bosses", "items", "connections", "texts"})
+ del (meta["plando_options"])
try:
target = tempfile.TemporaryDirectory()
playercount = len(gen_options)
@@ -108,6 +120,7 @@ def gen_game(gen_options, meta: TypeOptional[Dict[str, object]] = None, owner=No
erargs.outputname = seedname
erargs.outputpath = target.name
erargs.teams = 1
+ erargs.plando_options = ", ".join(plando_options)
name_counter = Counter()
for player, (playerfile, settings) in enumerate(gen_options.items(), 1):
diff --git a/WebHostLib/static/styles/generate.css b/WebHostLib/static/styles/generate.css
index 8b77d981..066fb8a7 100644
--- a/WebHostLib/static/styles/generate.css
+++ b/WebHostLib/static/styles/generate.css
@@ -6,7 +6,7 @@
}
#generate-game{
- width: 700px;
+ width: 990px;
min-height: 360px;
text-align: center;
}
@@ -25,9 +25,26 @@
margin-bottom: 1rem;
}
+#generate-game-tables-container{
+ display: flex;
+ flex-direction: row;
+ flex-wrap: wrap;
+ justify-content: space-around;
+}
+
+.table-wrapper select {
+ width: 200px;
+}
+
+.table-wrapper input:not([type]){
+ width: 200px;
+}
+
#generate-game-form-wrapper table td{
text-align: left;
padding-right: 0.5rem;
+ vertical-align: top;
+ width: 230px;
}
#generate-form-button-row{
diff --git a/WebHostLib/templates/generate.html b/WebHostLib/templates/generate.html
index 8b07940f..4a562083 100644
--- a/WebHostLib/templates/generate.html
+++ b/WebHostLib/templates/generate.html
@@ -35,86 +35,153 @@
+
+