From ff2e57705e9743ac565a844be7a61c4b45818d38 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Tue, 31 Aug 2021 19:54:55 +0200 Subject: [PATCH] WebHost: sample yamls now render Range defaults correctly --- WebHostLib/options.py | 12 +++++++++++- WebHostLib/templates/options.yaml | 19 +++++++++++-------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/WebHostLib/options.py b/WebHostLib/options.py index 56d01737..9edbbe6c 100644 --- a/WebHostLib/options.py +++ b/WebHostLib/options.py @@ -11,8 +11,18 @@ target_folder = os.path.join("WebHostLib", "static", "generated") def create(): for game_name, world in AutoWorldRegister.world_types.items(): + def dictify_range(option): + data = {option.range_start: 0, option.range_end: 0, "random": 0, "random-low": 0, "random-high": 0, + option.default: 50} + notes = { + option.range_start: "minimum value", + option.range_end: "maximum value" + } + return data, notes + res = Template(open(os.path.join("WebHostLib", "templates", "options.yaml")).read()).render( - options=world.options, __version__=__version__, game=game_name, yaml_dump=yaml.dump + options=world.options, __version__=__version__, game=game_name, yaml_dump=yaml.dump, + dictify_range=dictify_range ) with open(os.path.join(target_folder, game_name + ".yaml"), "w") as f: diff --git a/WebHostLib/templates/options.yaml b/WebHostLib/templates/options.yaml index 746ff8be..c84ee3f8 100644 --- a/WebHostLib/templates/options.yaml +++ b/WebHostLib/templates/options.yaml @@ -18,7 +18,8 @@ # http://www.yamllint.com/ description: Default {{ game }} Template # Used to describe your yaml. Useful if you have multiple files -name: YourName{number} # Your name in-game. Spaces will be replaced with underscores and there is a 16 character limit +# Your name in-game. Spaces will be replaced with underscores and there is a 16 character limit +name: YourName{number} #{player} will be replaced with the player's slot number. #{PLAYER} will be replaced with the player's slot number if that slot number is greater than 1. #{number} will be replaced with the counter value of the name. @@ -51,16 +52,18 @@ progression_balancing: # - "Progressive Weapons" # exclude_locations: # Force certain locations to never contain progression items, and always be filled with junk. # - "Master Sword Pedestal" +{%- macro range_option(option) %} + # you can add additional values between minimum and maximum + {%- set data, notes = dictify_range(option) %} + {%- for entry, default in data.items() %} + {{ entry }}: {{ default }}{% if notes[entry] %} # {{ notes[entry] }}{% endif %} + {%- endfor -%} +{%- endmacro -%} {{ game }}: {%- for option_key, option in options.items() %} {{ option_key }}:{% if option.__doc__ %} # {{ option.__doc__ | replace('\n', '\n#') | indent(4, first=False) }}{% endif %} {%- if option.range_start is defined %} - # you can add additional values between minimum and maximum - {{ option.range_start }}: 0 # minimum value - {{ option.range_end }}: 0 # maximum value - random: 50 - random-low: 0 - random-high: 0 + {{- range_option(option) -}} {%- elif option.options -%} {%- for suboption_option_id, sub_option_name in option.name_lookup.items() %} {{ sub_option_name }}: {% if suboption_option_id == option.default %}50{% else %}0{% endif %} @@ -69,4 +72,4 @@ progression_balancing: {{ yaml_dump(option.default) | indent(4, first=False) }} {%- endif -%} {%- endfor -%} - {% if not options %}{}{% endif %} \ No newline at end of file + {% if not options %}{}{% endif %}