{# # ============================================================================ # MOLECULE: BADGE GROUP CARD # ============================================================================ # Une seule carte pour une série de niveaux (outil ou achievement). # La bulle montre la progression vers le prochain niveau. # Les dots indiquent les niveaux débloqués. # # PARAMETRES # | levels | array | requis | [{name, description, unlocked, earned_at, progress, target, tokens}] | # | hexColorInner | string | #0C81E4 | Couleur principale (hex) | # | hexColorOuter | string | #EFF6FF | Couleur fond clair (hex) | # | class | string | '' | Classes additionnelles | # ============================================================================ #} {% set levels = levels ?? [] %} {% set hexColorInner = hexColorInner ?? '#0C81E4' %} {% set hexColorOuter = hexColorOuter ?? '#EFF6FF' %} {% set class = class ?? '' %} {# Détermine le niveau affiché et les compteurs #} {% set currentLevel = null %} {% set maxUnlockedLevel = null %} {% set unlockedCount = 0 %} {% for lvl in levels %} {% if lvl.unlocked %} {% set maxUnlockedLevel = lvl %} {% set unlockedCount = unlockedCount + 1 %} {% elseif currentLevel is null %} {% set currentLevel = lvl %} {% endif %} {% endfor %} {% set allUnlocked = currentLevel is null %} {% set displayLevel = currentLevel ?? maxUnlockedLevel %} {% set totalLevels = levels|length %} {# Progression bulle #} {% if allUnlocked %} {% set bProg = 1 %} {% set bTarget = 1 %} {% elseif displayLevel %} {% set bProg = displayLevel.progress ?? 0 %} {% set bTarget = displayLevel.target is not null and displayLevel.target > 0 ? displayLevel.target : 1 %} {% else %} {% set bProg = 0 %} {% set bTarget = 1 %} {% endif %} {# ── Calcul tokens non réclamés ── #} {% set unclaimedTokens = 0 %} {% set unclaimedSlugs = [] %} {% for lvl in levels %} {% if lvl.unlocked and lvl.tokensClaimed is defined and not lvl.tokensClaimed %} {% set unclaimedTokens = unclaimedTokens + (lvl.tokens ?? 0) %} {% set unclaimedSlugs = unclaimedSlugs|merge([lvl.slug]) %} {% endif %} {% endfor %} {% set currentLevelTokens = displayLevel.tokens ?? 0 %}
{{ displayLevel.name|split(' — ')|first }}
{{ displayLevel.description }}
{% endif %} {# Dots de progression — un point par niveau #} {% if totalLevels > 1 %}{{ maxUnlockedLevel.earned_at|format_date('medium', locale='fr') }}
{% elseif displayLevel and displayLevel.progress is not null and displayLevel.target is not null and not allUnlocked %}{{ bProg }}/{{ bTarget }}
{% elseif maxUnlockedLevel is null %}Verrouillé
{% endif %} {# Bouton Collecter — tokens non encore réclamés #} {% set unclaimedTokens = 0 %} {% set unclaimedSlugs = [] %} {% for lvl in levels %} {% if lvl.unlocked and lvl.tokensClaimed is defined and not lvl.tokensClaimed %} {% set unclaimedTokens = unclaimedTokens + (lvl.tokens ?? 0) %} {% set unclaimedSlugs = unclaimedSlugs|merge([lvl.slug]) %} {% endif %} {% endfor %} {% if unclaimedTokens > 0 %}