From 559187954754cef01b2010184dc40aeb941b256b Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Sun, 8 Oct 2023 11:30:34 +0200 Subject: [PATCH] WebHost/Factorio: use "better" jinja practices in web tracker (#2257) --- .../templates/multiFactorioTracker.html | 70 +++++++++---------- 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/WebHostLib/templates/multiFactorioTracker.html b/WebHostLib/templates/multiFactorioTracker.html index faca756e..389a79d4 100644 --- a/WebHostLib/templates/multiFactorioTracker.html +++ b/WebHostLib/templates/multiFactorioTracker.html @@ -1,46 +1,42 @@ {% extends "multiTracker.html" %} -{% block custom_table_headers %} +{# establish the to be tracked data. Display Name, factorio/AP internal name, display image #} +{%- set science_packs = [ + ("Logistic Science Pack", "logistic-science-pack", + "https://wiki.factorio.com/images/thumb/Logistic_science_pack.png/32px-Logistic_science_pack.png"), + ("Military Science Pack", "military-science-pack", + "https://wiki.factorio.com/images/thumb/Military_science_pack.png/32px-Military_science_pack.png"), + ("Chemical Science Pack", "chemical-science-pack", + "https://wiki.factorio.com/images/thumb/Chemical_science_pack.png/32px-Chemical_science_pack.png"), + ("Production Science Pack", "production-science-pack", + "https://wiki.factorio.com/images/thumb/Production_science_pack.png/32px-Production_science_pack.png"), + ("Utility Science Pack", "utility-science-pack", + "https://wiki.factorio.com/images/thumb/Utility_science_pack.png/32px-Utility_science_pack.png"), + ("Space Science Pack", "space-science-pack", + "https://wiki.factorio.com/images/thumb/Space_science_pack.png/32px-Space_science_pack.png"), +] -%} +{%- block custom_table_headers %} +{#- macro that creates a table header with display name and image -#} +{%- macro make_header(name, img_src) %} - Logistic Science Pack - - - Military Science Pack - - - Chemical Science Pack - - - Production Science Pack - - - Utility Science Pack - - - Space Science Pack + {{ name }} +{% endmacro -%} +{#- call the macro to build the table header -#} +{%- for name, internal_name, img_src in science_packs %} + {{ make_header(name, img_src) }} +{% endfor -%} {% endblock %} {% block custom_table_row scoped %} {% if games[player] == "Factorio" %} -{% set player_inventory = named_inventory[team][player] %} -{% set prog_science = player_inventory["progressive-science-pack"] %} -{% if player_inventory["logistic-science-pack"] or prog_science %}✔{% endif %} -{% if player_inventory["military-science-pack"] or prog_science > 1%}✔{% endif %} -{% if player_inventory["chemical-science-pack"] or prog_science > 2%}✔{% endif %} -{% if player_inventory["production-science-pack"] or prog_science > 3%}✔{% endif %} -{% if player_inventory["utility-science-pack"] or prog_science > 4%}✔{% endif %} -{% if player_inventory["space-science-pack"] or prog_science > 5%}✔{% endif %} + {%- set player_inventory = named_inventory[team][player] -%} + {%- set prog_science = player_inventory["progressive-science-pack"] -%} + {%- for name, internal_name, img_src in science_packs %} + {% if player_inventory[internal_name] or prog_science > loop.index0 %}✔{% endif %} + {% endfor -%} {% else %} -❌ -❌ -❌ -❌ -❌ -❌ + {%- for _ in science_packs %} + ❌ + {% endfor -%} {% endif %} {% endblock%}