core: allow string defaults in yaml templates (#1051)
* allow string defaults in yaml templates * have default_converter handle strings * handle all default values in the yaml * allow for random range options * yaml dump dicts * strip the whities * rip out the converter * accidentally stripped the dicts * goodbye readability
This commit is contained in:
parent
3cbbf905d1
commit
4c0c93b083
|
@ -31,9 +31,12 @@ def create():
|
||||||
data.update({
|
data.update({
|
||||||
option.range_start: 0,
|
option.range_start: 0,
|
||||||
option.range_end: 0,
|
option.range_end: 0,
|
||||||
"random": 0, "random-low": 0, "random-high": 0,
|
|
||||||
option.default: 50
|
option.default: 50
|
||||||
})
|
})
|
||||||
|
for sub_option in {"random", "random-low", "random-high"}:
|
||||||
|
if sub_option != option.default:
|
||||||
|
data[sub_option] = 0
|
||||||
|
|
||||||
notes = {
|
notes = {
|
||||||
special: "minimum value without special meaning",
|
special: "minimum value without special meaning",
|
||||||
option.range_start: "minimum value",
|
option.range_start: "minimum value",
|
||||||
|
@ -49,11 +52,6 @@ def create():
|
||||||
|
|
||||||
return data, notes
|
return data, notes
|
||||||
|
|
||||||
def default_converter(default_value):
|
|
||||||
if isinstance(default_value, (set, frozenset)):
|
|
||||||
return list(default_value)
|
|
||||||
return default_value
|
|
||||||
|
|
||||||
def get_html_doc(option_type: type(Options.Option)) -> str:
|
def get_html_doc(option_type: type(Options.Option)) -> str:
|
||||||
if not option_type.__doc__:
|
if not option_type.__doc__:
|
||||||
return "Please document me!"
|
return "Please document me!"
|
||||||
|
@ -79,7 +77,7 @@ def create():
|
||||||
res = Template(file_data).render(
|
res = Template(file_data).render(
|
||||||
options=all_options,
|
options=all_options,
|
||||||
__version__=__version__, game=game_name, yaml_dump=yaml.dump,
|
__version__=__version__, game=game_name, yaml_dump=yaml.dump,
|
||||||
dictify_range=dictify_range, default_converter=default_converter,
|
dictify_range=dictify_range,
|
||||||
)
|
)
|
||||||
|
|
||||||
del file_data
|
del file_data
|
||||||
|
|
|
@ -43,14 +43,18 @@ requires:
|
||||||
{%- if option.range_start is defined and option.range_start is number %}
|
{%- if option.range_start is defined and option.range_start is number %}
|
||||||
{{- range_option(option) -}}
|
{{- range_option(option) -}}
|
||||||
{%- elif option.options -%}
|
{%- elif option.options -%}
|
||||||
{%- for suboption_option_id, sub_option_name in option.name_lookup.items() %}
|
{%- 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 %}
|
{{ sub_option_name }}: {% if suboption_option_id == option.default %}50{% else %}0{% endif %}
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
{% if option.default == "random" %}
|
{% if option.name_lookup[option.default] not in option.options %}
|
||||||
random: 50
|
{{ option.default }}: 50
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
{%- elif option.default is string %}
|
||||||
|
{{ option.default }}: 50
|
||||||
|
{%- elif option.default is iterable and option.default is not mapping %}
|
||||||
|
{{ option.default | list }}
|
||||||
{%- else %}
|
{%- else %}
|
||||||
{{ yaml_dump(default_converter(option.default)) | indent(4, first=False) }}
|
{{ yaml_dump(option.default) | indent(4, first=false) }}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
{% if not options %}{}{% endif %}
|
{% if not options %}{}{% endif %}
|
||||||
|
|
Loading…
Reference in New Issue