feat: champion features

This commit is contained in:
2024-05-26 19:58:10 +02:00
parent fbd7222f05
commit ba5c35368d
8 changed files with 251 additions and 8 deletions
+51 -4
View File
@@ -3,7 +3,7 @@ import json
from typing import List
import os
from draw import draw_effects_resources_for_row
from draw import create_pentagon, draw_effects_resources_for_row
with open('src/data/heron_skin.json') as f:
@@ -17,6 +17,7 @@ border_width_y = 17
border_upper_offset = 5
title_y_offset = 24
title_font_size = 19
title_font_size_small = 16
subtitle_font_size = 13
cost_right_offset = 38
effect_text_size = 14
@@ -50,7 +51,11 @@ with open('src/data/cards_data.json') as f:
for card_data in cards:
# Get card skin data
card_skin_data = all_skin_data[str(card_data['id'])]
try:
card_skin_data = all_skin_data[str(card_data['id'])]
except KeyError:
print('Missing skin data for card id:', card_data['id'], 'using default skin data')
card_skin_data = { 'title': card_data['name'], 'image_path': '../../img/missing.png'}
# Create a new SVG drawing
output_dir = 'output/' + all_skin_data['skin_name']
@@ -83,10 +88,23 @@ for card_data in cards:
# Draw title area
# dwg.add(dwg.rect(insert=(0, 0), size=(str(x_width) + 'px', '50px'), fill='white'))
dwg.add(dwg.text(card_skin_data['title'], insert=(x_width/2, title_y_offset + border_width_y - border_upper_offset), text_anchor='middle', fill='black', font_size=str(title_font_size) + 'px', font_weight="bold", font_family='Helvetica'))
card_title = card_skin_data['title']
temp_title_font_size = title_font_size
if len(card_title) > 20:
temp_title_font_size = title_font_size_small
if len(card_title) > 23:
temp_title_font_size = title_font_size_small - 2
dwg.add(dwg.text(card_skin_data['title'], insert=(x_width/2, title_y_offset + border_width_y - border_upper_offset), text_anchor='middle', fill='black', font_size=str(temp_title_font_size) + 'px', font_weight="bold", font_family='Helvetica'))
# Draw type area
dwg.add(dwg.text(card_skin_data['type'], insert=(x_width/2, title_y_offset + title_font_size + 10), text_anchor='middle', fill='black', font_size=str(subtitle_font_size) + 'px', font_family='Helvetica'))
card_type_text = ""
if card_data['card_type'] == 'champion':
card_type_text = "Champion"
elif card_data['card_type'] == 'action':
card_type_text = "Action"
if 'flavor_text_type' in card_skin_data.keys():
card_type_text += ', ' + card_skin_data['flavor_text_type']
dwg.add(dwg.text(card_type_text, insert=(x_width/2, title_y_offset + title_font_size + 10), text_anchor='middle', fill='black', font_size=str(subtitle_font_size) + 'px', font_family='Helvetica'))
# Draw faction icon
dwg.add(dwg.circle(center=(border_width_x + 23 + 1, border_width_y - border_upper_offset + 20 + 4 + 1), r=20, fill='black'))
@@ -104,6 +122,12 @@ for card_data in cards:
dwg.add(dwg.rect(insert=(border_width_x, 265), size=(str(30) + 'px', str(y_height - 265 - border_width_y) + 'px'), fill='url(#grad1)'))
# If champion, draw champion action icon
if card_data['card_type'] == 'champion':
row_1_icon_x = border_width_x + 35
dwg.add(dwg.circle(center=(row_1_icon_x + 1, row_1_base_y + 20 + 1), r=15, fill='#111'))
dwg.add(dwg.circle(center=(row_1_icon_x, row_1_base_y + 20), r=15, fill='#555'))
# TODO: figure out nb of effects and adjust row_1_x_offset accordingly
def is_base_effect(array: List):
return not 'effect_type' in array.keys() or array['effect_type'] == 'champion_action'
@@ -117,6 +141,9 @@ for card_data in cards:
# Draw row 1 stats
draw_effects_resources_for_row(dwg, base_effects, row_1_base_y, x_width)
# Draw row 1 text
effect_text_1 = ""
if other_effects:
# Draw row 1 to row 2 separator
@@ -139,5 +166,25 @@ for card_data in cards:
effect_text_2 = "Mobilisez un champion."
dwg.add(dwg.text(effect_text_2, insert=(x_width/2, row_2_base_y), text_anchor='middle', fill='black', font_size=str(effect_text_size) + 'px', font_family='Helvetica'))
# If champion, draw champion shield with defense
if card_data['card_type'] == 'champion':
if not card_data['guard']:
pentagon_points = create_pentagon(center=(x_width - border_width_x - 15, y_height - 30), radius=28)
dwg.add(dwg.polygon(points=pentagon_points, fill='darkgrey', stroke='#eee', stroke_width=1))
# dwg.add(dwg.circle(center=(x_width - border_width_x - 15, y_height - 30), r=27, fill='darkgrey'))
# dwg.add(dwg.circle(center=(x_width - border_width_x - 15, y_height - 30), r=25, fill='lightgrey'))
dwg.add(dwg.text(str(card_data['defense']), insert=(x_width - border_width_x - 15, y_height - 20), text_anchor='middle', fill='black', font_size='28px', font_weight="bold", font_family='Helvetica'))
else:
pentagon_points = create_pentagon(center=(x_width - border_width_x - 15, y_height - 30), radius=28)
dwg.add(dwg.polygon(points=pentagon_points, fill='black', stroke='lightgrey', stroke_width=1))
# dwg.add(dwg.circle(center=(x_width - border_width_x - 15, y_height - 30), r=27, fill='lightgrey'))
# dwg.add(dwg.circle(center=(x_width - border_width_x - 15, y_height - 30), r=25, fill='#111'))
# Draw guard rectangle with text inside, above the shield
dwg.add(dwg.rect(insert=(x_width - border_width_x - 40, y_height - 72), size=(49, 17), fill='lightgrey'))
dwg.add(dwg.rect(insert=(x_width - border_width_x - 39, y_height - 71), size=(47, 15), fill='#111'))
dwg.add(dwg.text('Garde', insert=(x_width - border_width_x - 15, y_height - 59), text_anchor='middle', fill='white', font_size='12px', font_weight="bold", font_family='Helvetica'))
dwg.add(dwg.text(str(card_data['defense']), insert=(x_width - border_width_x - 15, y_height - 20), text_anchor='middle', fill='white', font_size='28px', font_weight="bold", font_family='Helvetica'))
# Save the SVG file
dwg.save()