Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebHost: unify references to options #2037

Merged
merged 14 commits into from
Oct 24, 2023
Merged
2 changes: 1 addition & 1 deletion Generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def main(args=None, callback=ERmain):
for player in range(1, args.multi + 1):
player_path_cache[player] = player_files.get(player, args.weights_file_path)
name_counter = Counter()
erargs.player_settings = {}
erargs.player_options = {}

player = 1
while player <= args.multi:
Expand Down
16 changes: 8 additions & 8 deletions WebHostLib/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ def start_playing():
return render_template(f"startPlaying.html")


@app.route('/weighted-settings')
def weighted_settings():
return render_template(f"weighted-settings.html")
@app.route('/weighted-options')
def weighted_options():
return render_template(f"weighted-options.html")


# Player settings pages
@app.route('/games/<string:game>/player-settings')
def player_settings(game):
return render_template(f"player-settings.html", game=game, theme=get_world_theme(game))
# Player options pages
@app.route('/games/<string:game>/player-options')
def player_options(game):
return render_template(f"player-options.html", game=game, theme=get_world_theme(game))
alwaysintreble marked this conversation as resolved.
Show resolved Hide resolved


# Game Info Pages
Expand Down Expand Up @@ -171,6 +171,6 @@ def get_sitemap():
available_games: List[Dict[str, Union[str, bool]]] = []
for game, world in AutoWorldRegister.world_types.items():
if not world.hidden:
has_settings: bool = isinstance(world.web.settings_page, bool) and world.web.settings_page
has_settings: bool = isinstance(world.web.options_page, bool) and world.web.options_page
available_games.append({ 'title': game, 'has_settings': has_settings })
return render_template("siteMap.html", games=available_games)
34 changes: 17 additions & 17 deletions WebHostLib/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_html_doc(option_type: type(Options.Option)) -> str:
return "Please document me!"
return "\n".join(line.strip() for line in option_type.__doc__.split("\n")).strip()

weighted_settings = {
weighted_options = {
"baseOptions": {
"description": "Generated by https://archipelago.gg/",
"name": "Player",
Expand All @@ -41,8 +41,8 @@ def get_html_doc(option_type: type(Options.Option)) -> str:
**world.option_definitions
}

# Generate JSON files for player-settings pages
player_settings = {
# Generate JSON files for player-options pages
player_options = {
"baseOptions": {
"description": f"Generated by https://archipelago.gg/ for {game_name}",
"game": game_name,
Expand Down Expand Up @@ -120,29 +120,29 @@ def get_html_doc(option_type: type(Options.Option)) -> str:
}

else:
logging.debug(f"{option} not exported to Web Settings.")
logging.debug(f"{option} not exported to Web options.")

player_settings["gameOptions"] = game_options
player_options["gameOptions"] = game_options

os.makedirs(os.path.join(target_folder, 'player-settings'), exist_ok=True)
os.makedirs(os.path.join(target_folder, 'player-options'), exist_ok=True)

with open(os.path.join(target_folder, 'player-settings', game_name + ".json"), "w") as f:
json.dump(player_settings, f, indent=2, separators=(',', ': '))
with open(os.path.join(target_folder, 'player-options', game_name + ".json"), "w") as f:
json.dump(player_options, f, indent=2, separators=(',', ': '))

if not world.hidden and world.web.settings_page is True:
# Add the random option to Choice, TextChoice, and Toggle settings
if not world.hidden and world.web.options_page is True:
# Add the random option to Choice, TextChoice, and Toggle options
for option in game_options.values():
if option["type"] == "select":
option["options"].append({"name": "Random", "value": "random"})

if not option["defaultValue"]:
option["defaultValue"] = "random"

weighted_settings["baseOptions"]["game"][game_name] = 0
weighted_settings["games"][game_name] = {}
weighted_settings["games"][game_name]["gameSettings"] = game_options
weighted_settings["games"][game_name]["gameItems"] = tuple(world.item_names)
weighted_settings["games"][game_name]["gameLocations"] = tuple(world.location_names)
weighted_options["baseOptions"]["game"][game_name] = 0
weighted_options["games"][game_name] = {}
weighted_options["games"][game_name]["gameSettings"] = game_options
weighted_options["games"][game_name]["gameItems"] = tuple(world.item_names)
weighted_options["games"][game_name]["gameLocations"] = tuple(world.location_names)

with open(os.path.join(target_folder, 'weighted-settings.json'), "w") as f:
json.dump(weighted_settings, f, indent=2, separators=(',', ': '))
with open(os.path.join(target_folder, 'weighted-options.json'), "w") as f:
json.dump(weighted_options, f, indent=2, separators=(',', ': '))
Loading