WebHost: add remaining and collect to options page
This commit is contained in:
parent
a5ca4f1611
commit
cd1c38515b
|
@ -9,6 +9,7 @@ from pony.orm import commit
|
||||||
|
|
||||||
from WebHostLib import app, Generation, STATE_QUEUED, Seed, STATE_ERROR
|
from WebHostLib import app, Generation, STATE_QUEUED, Seed, STATE_ERROR
|
||||||
from WebHostLib.check import get_yaml_data, roll_options
|
from WebHostLib.check import get_yaml_data, roll_options
|
||||||
|
from WebHostLib.generate import get_meta
|
||||||
|
|
||||||
|
|
||||||
@api_endpoints.route('/generate', methods=['POST'])
|
@api_endpoints.route('/generate', methods=['POST'])
|
||||||
|
@ -35,9 +36,6 @@ def generate_api():
|
||||||
if "race" in json_data:
|
if "race" in json_data:
|
||||||
race = bool(0 if json_data["race"] in {"false"} else int(json_data["race"]))
|
race = bool(0 if json_data["race"] in {"false"} else int(json_data["race"]))
|
||||||
|
|
||||||
hint_cost = int(meta_options_source.get("hint_cost", 10))
|
|
||||||
forfeit_mode = meta_options_source.get("forfeit_mode", "goal")
|
|
||||||
|
|
||||||
if not options:
|
if not options:
|
||||||
return {"text": "No options found. Expected file attachment or json weights."
|
return {"text": "No options found. Expected file attachment or json weights."
|
||||||
}, 400
|
}, 400
|
||||||
|
@ -45,7 +43,8 @@ def generate_api():
|
||||||
if len(options) > app.config["MAX_ROLL"]:
|
if len(options) > app.config["MAX_ROLL"]:
|
||||||
return {"text": "Max size of multiworld exceeded",
|
return {"text": "Max size of multiworld exceeded",
|
||||||
"detail": app.config["MAX_ROLL"]}, 409
|
"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)
|
||||||
if any(type(result) == str for result in results.values()):
|
if any(type(result) == str for result in results.values()):
|
||||||
return {"text": str(results),
|
return {"text": str(results),
|
||||||
|
@ -54,7 +53,7 @@ def generate_api():
|
||||||
gen = Generation(
|
gen = Generation(
|
||||||
options=pickle.dumps({name: vars(options) for name, options in gen_options.items()}),
|
options=pickle.dumps({name: vars(options) for name, options in gen_options.items()}),
|
||||||
# convert to json compatible
|
# convert to json compatible
|
||||||
meta=json.dumps({"race": race, "hint_cost": hint_cost, "forfeit_mode": forfeit_mode}), state=STATE_QUEUED,
|
meta=json.dumps(meta), state=STATE_QUEUED,
|
||||||
owner=session["_id"])
|
owner=session["_id"])
|
||||||
commit()
|
commit()
|
||||||
return {"text": f"Generation of seed {gen.id} started successfully.",
|
return {"text": f"Generation of seed {gen.id} started successfully.",
|
||||||
|
|
|
@ -20,6 +20,16 @@ from .check import get_yaml_data, roll_options
|
||||||
from .upload import upload_zip_to_db
|
from .upload import upload_zip_to_db
|
||||||
|
|
||||||
|
|
||||||
|
def get_meta(options_source: dict) -> dict:
|
||||||
|
meta = {
|
||||||
|
"hint_cost": int(options_source.get("hint_cost", 10)),
|
||||||
|
"forfeit_mode": options_source.get("forfeit_mode", "goal"),
|
||||||
|
"remaining_mode": options_source.get("forfeit_mode", "disabled"),
|
||||||
|
"collect_mode": options_source.get("collect_mode", "disabled"),
|
||||||
|
}
|
||||||
|
return meta
|
||||||
|
|
||||||
|
|
||||||
@app.route('/generate', methods=['GET', 'POST'])
|
@app.route('/generate', methods=['GET', 'POST'])
|
||||||
@app.route('/generate/<race>', methods=['GET', 'POST'])
|
@app.route('/generate/<race>', methods=['GET', 'POST'])
|
||||||
def generate(race=False):
|
def generate(race=False):
|
||||||
|
@ -35,9 +45,9 @@ def generate(race=False):
|
||||||
else:
|
else:
|
||||||
results, gen_options = roll_options(options)
|
results, gen_options = roll_options(options)
|
||||||
# get form data -> server settings
|
# get form data -> server settings
|
||||||
hint_cost = int(request.form.get("hint_cost", 10))
|
meta = get_meta(request.form)
|
||||||
forfeit_mode = request.form.get("forfeit_mode", "goal")
|
meta["race"] = race
|
||||||
meta = {"race": race, "hint_cost": hint_cost, "forfeit_mode": forfeit_mode}
|
|
||||||
if race:
|
if race:
|
||||||
meta["item_cheat"] = False
|
meta["item_cheat"] = False
|
||||||
meta["remaining"] = False
|
meta["remaining"] = False
|
||||||
|
|
|
@ -34,7 +34,14 @@
|
||||||
<table>
|
<table>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td><label for="forfeit_mode">Forfeit Permission:</label></td>
|
<td>
|
||||||
|
<label for="forfeit_mode">Forfeit Permission:</label>
|
||||||
|
<span
|
||||||
|
class="interactive"
|
||||||
|
data-tooltip="A forfeit releases all remaining items from the locations
|
||||||
|
in your world.">(?)
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<select name="forfeit_mode" id="forfeit_mode">
|
<select name="forfeit_mode" id="forfeit_mode">
|
||||||
<option value="auto">Automatic on goal completion</option>
|
<option value="auto">Automatic on goal completion</option>
|
||||||
|
@ -46,12 +53,49 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="collect_mode">Collect Permission:</label>
|
||||||
|
<span
|
||||||
|
class="interactive"
|
||||||
|
data-tooltip="A collect releases all of your remaining items to you
|
||||||
|
from across the multiworld.">(?)
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<select name="collect_mode" id="collect_mode">
|
||||||
|
<option value="goal">Allow !collect after goal completion</option>
|
||||||
|
<option value="auto">Automatic on goal completion</option>
|
||||||
|
<option value="auto-enabled">Automatic on goal completion and manual !collect</option>
|
||||||
|
<option value="enabled">Manual !collect</option>
|
||||||
|
<option value="disabled">Disabled</option>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="remaining_mode">Remaining Permission:</label>
|
||||||
|
<span
|
||||||
|
class="interactive"
|
||||||
|
data-tooltip="Remaining lists all items still in your world by name only.">(?)
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<select name="remaining_mode" id="remaining_mode">
|
||||||
|
<option value="disabled">Disabled</option>
|
||||||
|
<option value="goal">Allow !remaining after goal completion</option>
|
||||||
|
<option value="enabled">Manual !remaining</option>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<label for="hint_cost"> Hint Cost:</label>
|
<label for="hint_cost"> Hint Cost:</label>
|
||||||
<span
|
<span
|
||||||
class="interactive"
|
class="interactive"
|
||||||
data-tooltip="After gathering this many checks, players can !hint <itemname>
|
data-tooltip="After gathering this many checks, players can !hint <itemname>
|
||||||
to get the location of that hint item.">(?)
|
to get the location of that hint item.">(?)
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
|
|
Loading…
Reference in New Issue