This commit is contained in:
Ross
2025-12-06 22:54:55 +00:00
parent 2dc1631fd2
commit e541e4cc31
3 changed files with 67 additions and 36 deletions
+42 -36
View File
@@ -48,50 +48,56 @@
</div>
<div style="padding:8px 10px; border-top:1px solid rgba(0,0,0,0.04); background:#fafafa;">
<div style="display:flex; flex-direction:column; gap:6px;">
<div style="display:flex; justify-content:space-between; align-items:center;">
<div style="font-size:0.9rem; font-weight:700">Speed</div>
<div style="display:flex; align-items:center; gap:8px;">
<div style="font-weight:800">{{ card.speed_display }}</div>
<div aria-hidden="true" style="display:flex; gap:2px;">
{% for t in card.speed_star_types %}
<span style="font-size:0.95rem; line-height:1; color: {% if t == 'full' %}#1abc9c{% elif t == 'half' %}#1abc9c; opacity:0.55{% else %}#ddd{% endif %};">{% if t == 'empty' %}☆{% else %}★{% endif %}</span>
{% endfor %}
{% with s=card.speed_percent w=card.weight_percent it=card.intelligence_percent h=card.height_percent %}
<div style="display:flex; justify-content:space-between; align-items:center; {% if card.is_top_trump and 'speed' in card.best_stats %}box-shadow:inset 6px 0 0 #1abc9c; border-radius:4px;{% endif %}">
<div style="font-size:0.9rem; font-weight:700">Speed</div>
<div style="display:flex; align-items:center; gap:8px;">
<div style="font-weight:800">{{ card.speed_display }}</div>
<div aria-hidden="true" style="display:flex; gap:2px;">
{% for t in card.speed_star_types %}
<span style="font-size:0.95rem; line-height:1; color: {% if t == 'full' %}#1abc9c{% elif t == 'half' %}#1abc9c; opacity:0.55{% else %}#ddd{% endif %};">{% if t == 'empty' %}☆{% else %}★{% endif %}</span>
{% endfor %}
</div>
</div>
</div>
</div>
<div style="display:flex; justify-content:space-between; align-items:center;">
<div style="font-size:0.9rem; font-weight:700">Weight</div>
<div style="display:flex; align-items:center; gap:8px;">
<div style="font-weight:800">{{ card.weight_display }}</div>
<div aria-hidden="true" style="display:flex; gap:2px;">
{% for t in card.weight_star_types %}
<span style="font-size:0.95rem; line-height:1; color: {% if t == 'full' %}#d35400{% elif t == 'half' %}#d35400; opacity:0.55{% else %}#ddd{% endif %};">{% if t == 'empty' %}☆{% else %}★{% endif %}</span>
{% endfor %}
<div style="display:flex; justify-content:space-between; align-items:center; {% if card.is_top_trump and 'weight' in card.best_stats %}box-shadow:inset 6px 0 0 #d35400; border-radius:4px;{% endif %}">
<div style="font-size:0.9rem; font-weight:700">Weight</div>
<div style="display:flex; align-items:center; gap:8px;">
<div style="font-weight:800">{{ card.weight_display }}</div>
<div aria-hidden="true" style="display:flex; gap:2px;">
{% for t in card.weight_star_types %}
<span style="font-size:0.95rem; line-height:1; color: {% if t == 'full' %}#d35400{% elif t == 'half' %}#d35400; opacity:0.55{% else %}#ddd{% endif %};">{% if t == 'empty' %}☆{% else %}★{% endif %}</span>
{% endfor %}
</div>
</div>
</div>
</div>
<div style="display:flex; justify-content:space-between; align-items:center;">
<div style="font-size:0.9rem; font-weight:700">Intelligence</div>
<div style="display:flex; align-items:center; gap:8px;">
<div style="font-weight:800">{{ card.intelligence_display }}</div>
<div aria-hidden="true" style="display:flex; gap:2px;">
{% for t in card.intelligence_star_types %}
<span style="font-size:0.95rem; line-height:1; color: {% if t == 'full' %}#8e44ad{% elif t == 'half' %}#8e44ad; opacity:0.55{% else %}#ddd{% endif %};">{% if t == 'empty' %}☆{% else %}★{% endif %}</span>
{% endfor %}
<div style="display:flex; justify-content:space-between; align-items:center; {% if card.is_top_trump and 'intelligence' in card.best_stats %}box-shadow:inset 6px 0 0 #8e44ad; border-radius:4px;{% endif %}">
<div style="font-size:0.9rem; font-weight:700">Intelligence</div>
<div style="display:flex; align-items:center; gap:8px;">
<div style="font-weight:800">{{ card.intelligence_display }}</div>
<div aria-hidden="true" style="display:flex; gap:2px;">
{% for t in card.intelligence_star_types %}
<span style="font-size:0.95rem; line-height:1; color: {% if t == 'full' %}#8e44ad{% elif t == 'half' %}#8e44ad; opacity:0.55{% else %}#ddd{% endif %};">{% if t == 'empty' %}☆{% else %}★{% endif %}</span>
{% endfor %}
</div>
</div>
</div>
</div>
<div style="display:flex; justify-content:space-between; align-items:center;">
<div style="font-size:0.9rem; font-weight:700">Height</div>
<div style="display:flex; align-items:center; gap:8px;">
<div style="font-weight:800">{{ card.height_display }}</div>
<div aria-hidden="true" style="display:flex; gap:2px;">
{% for t in card.height_star_types %}
<span style="font-size:0.95rem; line-height:1; color: {% if t == 'full' %}#27ae60{% elif t == 'half' %}#27ae60; opacity:0.55{% else %}#ddd{% endif %};">{% if t == 'empty' %}☆{% else %}★{% endif %}</span>
{% endfor %}
<div style="display:flex; justify-content:space-between; align-items:center; {% if card.is_top_trump and 'height' in card.best_stats %}box-shadow:inset 6px 0 0 #27ae60; border-radius:4px;{% endif %}">
<div style="font-size:0.9rem; font-weight:700">Height</div>
<div style="display:flex; align-items:center; gap:8px;">
<div style="font-weight:800">{{ card.height_display }}</div>
<div aria-hidden="true" style="display:flex; gap:2px;">
{% for t in card.height_star_types %}
<span style="font-size:0.95rem; line-height:1; color: {% if t == 'full' %}#27ae60{% elif t == 'half' %}#27ae60; opacity:0.55{% else %}#ddd{% endif %};">{% if t == 'empty' %}☆{% else %}★{% endif %}</span>
{% endfor %}
</div>
</div>
</div>
</div>
{% endwith %}
{% if card.facts_list %}
<div style="margin-top:6px; border-top:1px solid rgba(0,0,0,0.03); padding-top:6px; font-size:0.85rem; color:#333;">
<strong style="display:block; margin-bottom:4px;">Fun facts</strong>
+25
View File
@@ -456,6 +456,31 @@ def print_preview(request):
for i in range(0, len(ordered), per_page):
pages.append(ordered[i:i+per_page])
# -- Top-trump calculation across the full selection -----------------
# For each card compute its best stat percent (0-100) and the stat(s)
# that achieve that percent. Then find the global maximum best-value and
# mark any card whose best-value equals that maximum as a top-trump.
all_best_values = []
for c in ordered:
# compute percents using model helpers
s = c.speed_percent()
w = c.weight_percent()
it = c.intelligence_percent()
h = c.height_percent()
# map names to values
stats = {'speed': s, 'weight': w, 'intelligence': it, 'height': h}
max_val = max(stats.values())
best_stats = [name for name, val in stats.items() if val == max_val]
# attach computed attributes so templates can read them
setattr(c, 'best_value', max_val)
setattr(c, 'best_stats', best_stats)
all_best_values.append(max_val)
# determine global maximum and mark cards as top-trump if they match
global_max = max(all_best_values) if all_best_values else 0
for c in ordered:
setattr(c, 'is_top_trump', getattr(c, 'best_value', 0) == global_max)
# ---------------------------------------------------------------------
# Determine grid columns for layout: use 1 column for 1-up, 2 columns for 2/4-up
columns = 1 if per_page == 1 else 2
BIN
View File
Binary file not shown.