Archipelago/worlds/factorio/data/mod_template/macros.lua

29 lines
832 B
Lua
Raw Normal View History

{% macro dict_to_lua(dict) -%}
{
{%- for key, value in dict.items() -%}
2021-07-01 23:29:49 +00:00
["{{ key }}"] = {{ variable_to_lua(value) }}{% if not loop.last %},{% endif %}
{% endfor -%}
}
{%- endmacro %}
2021-07-04 20:21:53 +00:00
{% macro list_to_lua(list) -%}
{
{%- for key in list -%}
{{ variable_to_lua(key) }}{% if not loop.last %},{% endif %}
{% endfor -%}
}
{%- endmacro %}
2021-07-01 23:29:49 +00:00
{%- macro variable_to_lua(value) %}
{%- if value is mapping -%}{{ dict_to_lua(value) }}
{%- elif value is boolean -%}{{ value | string | lower }}
2021-07-04 20:21:53 +00:00
{%- elif value is string -%}"{{ value | safe }}"
{%- elif value is iterable -%}{{ list_to_lua(value) }}
2021-07-01 23:29:49 +00:00
{%- else -%} {{ value | safe }}
{%- endif -%}
{%- endmacro -%}
{% macro dict_to_recipe(dict) -%}
{
{%- for key, value in dict.items() -%}
{"{{ key }}", {{ value | safe }}}{% if not loop.last %},{% endif %}
{% endfor -%}
}
{%- endmacro %}