feat: attempt at refactoring code, new placeholder json for tests
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<svg baseProfile="tiny" height="417px" version="1.2" width="298px" xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><linearGradient id="grad1" x1="0" x2="1" y1="0" y2="0"><stop offset="0" stop-color="yellow" stop-opacity="1" /><stop offset="1" stop-color="yellow" stop-opacity="0" /></linearGradient><linearGradient id="grad2" x1="0" x2="0" y1="1" y2="0"><stop offset="0" stop-color="#ff9935" stop-opacity="1" /><stop offset="1" stop-color="#ffe744" stop-opacity="1" /></linearGradient></defs><rect fill="black" height="417px" rx="15" ry="18" width="298px" x="0" y="0" /><rect fill="rgb(206, 182, 167)" height="388px" rx="0" ry="0" width="274px" x="12" y="12" /><text fill="black" font-family="Helvetica" font-size="19px" font-weight="bold" text-anchor="middle" x="149.0" y="36">Rallier les Troupes</text><text fill="black" font-family="Helvetica" font-size="13px" text-anchor="middle" x="149.0" y="53">Action, Charme</text><circle cx="36" cy="37" fill="black" r="20" /><circle cx="35" cy="36" fill="url(#grad2)" r="20" /><circle cx="262" cy="38" fill="rgb(202, 129, 25)" r="21" /><circle cx="260" cy="36" fill="yellow" r="20" /><text fill="black" font-family="Helvetica" font-size="24px" font-weight="bold" text-anchor="middle" x="260" y="43">4</text><rect fill="black" height="200px" width="298px" x="0" y="65" /><image height="200" width="298" x="0" xlink:href="lancersiz3.png" y="65" /><rect fill="url(#grad1)" height="135px" width="30px" x="12" y="265" /><circle cx="129.0" cy="302" fill="red" r="22" /><text fill="white" font-family="Helvetica" font-size="24px" font-weight="bold" text-anchor="middle" x="129.0" y="311">5</text><circle cx="189.0" cy="302" fill="green" r="22" /><text fill="white" font-family="Helvetica" font-size="24px" font-weight="bold" text-anchor="middle" x="189.0" y="311">5</text><line stroke="black" stroke-width="1" x1="20" x2="278" y1="345" y2="345" /><circle cx="48" cy="371" fill="black" r="15" /><circle cx="47" cy="370" fill="url(#grad2)" r="15" /><text fill="black" font-family="Helvetica" font-size="14px" text-anchor="middle" x="149.0" y="375">Mobilisez un Champion.</text></svg>
|
||||
<svg baseProfile="tiny" height="417px" version="1.2" width="298px" xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><linearGradient id="grad1" x1="0" x2="1" y1="0" y2="0"><stop offset="0" stop-color="yellow" stop-opacity="1" /><stop offset="1" stop-color="yellow" stop-opacity="0" /></linearGradient><linearGradient id="grad2" x1="0" x2="0" y1="1" y2="0"><stop offset="0" stop-color="#ff9935" stop-opacity="1" /><stop offset="1" stop-color="#ffe744" stop-opacity="1" /></linearGradient></defs><rect fill="black" height="417px" rx="15" ry="18" width="298px" x="0" y="0" /><rect fill="rgb(206, 182, 167)" height="388px" rx="0" ry="0" width="274px" x="12" y="12" /><text fill="black" font-family="Helvetica" font-size="19px" font-weight="bold" text-anchor="middle" x="149.0" y="36">Rallier les Troupes</text><text fill="black" font-family="Helvetica" font-size="13px" text-anchor="middle" x="149.0" y="53">Action, Charme</text><circle cx="36" cy="37" fill="black" r="20" /><circle cx="35" cy="36" fill="url(#grad2)" r="20" /><circle cx="262" cy="38" fill="rgb(202, 129, 25)" r="21" /><circle cx="260" cy="36" fill="yellow" r="20" /><text fill="black" font-family="Helvetica" font-size="24px" font-weight="bold" text-anchor="middle" x="260" y="43">4</text><rect fill="black" height="200px" width="298px" x="0" y="65" /><image height="200" width="298" x="0" xlink:href="lancersiz3.png" y="65" /><rect fill="url(#grad1)" height="135px" width="30px" x="12" y="265" /><circle cx="129.0" cy="302" fill="green" r="22" /><text fill="white" font-family="Helvetica" font-size="24px" font-weight="bold" text-anchor="middle" x="129.0" y="311">5</text><circle cx="189.0" cy="302" fill="red" r="22" /><text fill="white" font-family="Helvetica" font-size="24px" font-weight="bold" text-anchor="middle" x="189.0" y="311">5</text><line stroke="black" stroke-width="1" x1="20" x2="278" y1="345" y2="345" /><circle cx="48" cy="371" fill="black" r="15" /><circle cx="47" cy="370" fill="url(#grad2)" r="15" /><text fill="black" font-family="Helvetica" font-size="14px" text-anchor="middle" x="149.0" y="375">Mobilisez un champion.</text></svg>
|
||||
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<svg baseProfile="tiny" height="417px" version="1.2" width="298px" xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><linearGradient id="grad1" x1="0" x2="1" y1="0" y2="0"><stop offset="0" stop-color="yellow" stop-opacity="1" /><stop offset="1" stop-color="yellow" stop-opacity="0" /></linearGradient><linearGradient id="grad2" x1="0" x2="0" y1="1" y2="0"><stop offset="0" stop-color="#ff9935" stop-opacity="1" /><stop offset="1" stop-color="#ffe744" stop-opacity="1" /></linearGradient></defs><rect fill="black" height="417px" rx="15" ry="18" width="298px" x="0" y="0" /><rect fill="rgb(206, 182, 167)" height="388px" rx="0" ry="0" width="274px" x="12" y="12" /><text fill="black" font-family="Helvetica" font-size="19px" font-weight="bold" text-anchor="middle" x="149.0" y="36">Rallier les Troupes</text><text fill="black" font-family="Helvetica" font-size="13px" text-anchor="middle" x="149.0" y="53">Action, Charme</text><circle cx="36" cy="37" fill="black" r="20" /><circle cx="35" cy="36" fill="url(#grad2)" r="20" /><circle cx="262" cy="38" fill="rgb(202, 129, 25)" r="21" /><circle cx="260" cy="36" fill="yellow" r="20" /><text fill="black" font-family="Helvetica" font-size="24px" font-weight="bold" text-anchor="middle" x="260" y="43">4</text><rect fill="black" height="200px" width="298px" x="0" y="65" /><image height="200" width="298" x="0" xlink:href="lancersiz3.png" y="65" /><rect fill="url(#grad1)" height="135px" width="30px" x="12" y="265" /><circle cx="129.0" cy="302" fill="red" r="22" /><text fill="white" font-family="Helvetica" font-size="24px" font-weight="bold" text-anchor="middle" x="129.0" y="311">5</text><circle cx="189.0" cy="302" fill="green" r="22" /><text fill="white" font-family="Helvetica" font-size="24px" font-weight="bold" text-anchor="middle" x="189.0" y="311">5</text><line stroke="black" stroke-width="1" x1="20" x2="278" y1="345" y2="345" /><circle cx="48" cy="371" fill="black" r="15" /><circle cx="47" cy="370" fill="url(#grad2)" r="15" /><text fill="black" font-family="Helvetica" font-size="14px" text-anchor="middle" x="149.0" y="375">Mobilisez un Champion.</text></svg>
|
||||
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"id": 13,
|
||||
"role": "market",
|
||||
"card_type": "action",
|
||||
"faction": "yellow",
|
||||
"name": "Taxation",
|
||||
"cost": 1,
|
||||
"init_amount": 3,
|
||||
"effects": [
|
||||
{
|
||||
"effect": "gold",
|
||||
"amount": 2
|
||||
},
|
||||
{
|
||||
"effect": "heal",
|
||||
"amount": 6,
|
||||
"effect_type": "faction_combo"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -3,6 +3,11 @@
|
||||
"title": "Rallier les Troupes",
|
||||
"type": "Action, Charme",
|
||||
"image_path": "lancersiz3.png"
|
||||
},
|
||||
"13": {
|
||||
"title": "Caprisun",
|
||||
"type": "Action, 20cl",
|
||||
"image_path": "lancersiz3.png"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
from typing import List
|
||||
|
||||
stats_radius = 22
|
||||
|
||||
|
||||
def draw_effects_resources_for_row(dwg, effects: List, y: int, x_width: int):
|
||||
row_1_nb_effects = len(effects)
|
||||
|
||||
row_1_x_offset = -20
|
||||
row_1_x_step = 60
|
||||
if row_1_nb_effects == 1:
|
||||
row_1_x_offset = 0
|
||||
elif row_1_nb_effects == 2:
|
||||
row_1_x_offset = -20
|
||||
elif row_1_nb_effects == 3:
|
||||
row_1_x_offset = -40
|
||||
row_1_nb_effects_applied = 0
|
||||
|
||||
for effect in effects:
|
||||
if effect.get('effect') == 'damage':
|
||||
x_effect_pos = x_width/2 + row_1_x_offset + row_1_x_step*row_1_nb_effects_applied
|
||||
dwg.add(dwg.circle(center=(x_effect_pos, y + stats_radius), r=stats_radius, fill='red'))
|
||||
dwg.add(dwg.text(str(effect.get('amount')), insert=(x_effect_pos, y + stats_radius + 9), text_anchor='middle', fill='white', font_size='24px', font_weight="bold", font_family='Helvetica'))
|
||||
row_1_nb_effects_applied += 1
|
||||
|
||||
if effect.get('effect') == 'gold':
|
||||
x_effect_pos = x_width/2 + row_1_x_offset + row_1_x_step*row_1_nb_effects_applied
|
||||
dwg.add(dwg.circle(center=(x_effect_pos, y + stats_radius), r=stats_radius, fill='yellow'))
|
||||
dwg.add(dwg.text(str(effect.get('amount')), insert=(x_effect_pos, y + stats_radius + 9), text_anchor='middle', fill='black', font_size='24px', font_weight="bold", font_family='Helvetica'))
|
||||
row_1_nb_effects_applied += 1
|
||||
|
||||
if effect.get('effect') == 'heal':
|
||||
x_effect_pos = x_width/2 + row_1_x_offset + row_1_x_step*row_1_nb_effects_applied
|
||||
dwg.add(dwg.circle(center=(x_effect_pos, y + stats_radius), r=stats_radius, fill='green'))
|
||||
dwg.add(dwg.text(str(effect.get('amount')), insert=(x_effect_pos, y + stats_radius + 9), text_anchor='middle', fill='white', font_size='24px', font_weight="bold", font_family='Helvetica'))
|
||||
row_1_nb_effects_applied += 1
|
||||
+38
-38
@@ -64,7 +64,9 @@
|
||||
|
||||
import svgwrite
|
||||
import json
|
||||
from typing import Array
|
||||
from typing import List
|
||||
|
||||
from draw import draw_effects_resources_for_row
|
||||
|
||||
|
||||
with open('src/card_data.json') as f:
|
||||
@@ -80,7 +82,6 @@ title_y_offset = 24
|
||||
title_font_size = 19
|
||||
subtitle_font_size = 13
|
||||
cost_right_offset = 38
|
||||
stats_radius = 22
|
||||
effect_text_size = 14
|
||||
row_1_base_y = 280
|
||||
row_2_base_y = 375
|
||||
@@ -110,7 +111,7 @@ icon_colors = {
|
||||
with open('src/actual_card_data.json') as f:
|
||||
card_data = json.load(f)
|
||||
|
||||
card_skin_data = all_skin_data['id']
|
||||
card_skin_data = all_skin_data[str(card_data['id'])]
|
||||
|
||||
|
||||
# Create a new SVG drawing
|
||||
@@ -164,58 +165,57 @@ dwg.add(dwg.image(card_skin_data['image_path'], insert=(0, 65), size=(x_width, 2
|
||||
dwg.add(dwg.rect(insert=(border_width_x, 265), size=(str(30) + 'px', str(y_height - 265 - border_width_y) + 'px'), fill='url(#grad1)'))
|
||||
|
||||
# TODO: figure out nb of effects and adjust row_1_x_offset accordingly
|
||||
def is_base_effect(array: Array):
|
||||
return array['effect_type'] == 'champion_action' or not array['effect_type']
|
||||
def is_base_effect(array: List):
|
||||
return not 'effect_type' in array.keys() or array['effect_type'] == 'champion_action'
|
||||
|
||||
card_effects: Array = card_data['effects']
|
||||
card_effects: List = card_data['effects']
|
||||
base_effects = list(filter(is_base_effect, card_effects))
|
||||
other_effects = list(filter(lambda x: not is_base_effect(x), card_effects))
|
||||
# card_effects = card_data['row_1']
|
||||
# row_1_nb_effects = len(card_data['row_1'].keys())
|
||||
row_1_nb_effects = len(base_effects)
|
||||
|
||||
row_1_x_offset = -20
|
||||
row_1_x_step = 60
|
||||
if row_1_nb_effects == 1:
|
||||
row_1_x_offset = 0
|
||||
elif row_1_nb_effects == 2:
|
||||
row_1_x_offset = -20
|
||||
elif row_1_nb_effects == 3:
|
||||
row_1_x_offset = -40
|
||||
row_1_nb_effects_applied = 0
|
||||
|
||||
# Draw row 1 stats
|
||||
for effect in base_effects:
|
||||
if effect.get('effect') == 'damage':
|
||||
# if card_effects.get('damage'):
|
||||
x_effect_pos = x_width/2 + row_1_x_offset + row_1_x_step*row_1_nb_effects_applied
|
||||
dwg.add(dwg.circle(center=(x_effect_pos, row_1_base_y + stats_radius), r=stats_radius, fill='red'))
|
||||
dwg.add(dwg.text(str(effect.get('amount')), insert=(x_effect_pos, row_1_base_y + stats_radius + 9), text_anchor='middle', fill='white', font_size='24px', font_weight="bold", font_family='Helvetica'))
|
||||
row_1_nb_effects_applied += 1
|
||||
# for effect in base_effects:
|
||||
# if effect.get('effect') == 'damage':
|
||||
# # if card_effects.get('damage'):
|
||||
# x_effect_pos = x_width/2 + row_1_x_offset + row_1_x_step*row_1_nb_effects_applied
|
||||
# dwg.add(dwg.circle(center=(x_effect_pos, row_1_base_y + stats_radius), r=stats_radius, fill='red'))
|
||||
# dwg.add(dwg.text(str(effect.get('amount')), insert=(x_effect_pos, row_1_base_y + stats_radius + 9), text_anchor='middle', fill='white', font_size='24px', font_weight="bold", font_family='Helvetica'))
|
||||
# row_1_nb_effects_applied += 1
|
||||
|
||||
if effect.get('effect') == 'gold':
|
||||
x_effect_pos = x_width/2 + row_1_x_offset + row_1_x_step*row_1_nb_effects_applied
|
||||
dwg.add(dwg.circle(center=(x_effect_pos, row_1_base_y + stats_radius), r=stats_radius, fill='yellow'))
|
||||
dwg.add(dwg.text(str(card_data['row_1']['gold']), insert=(x_effect_pos, row_1_base_y + stats_radius + 9), text_anchor='middle', fill='black', font_size='24px', font_weight="bold", font_family='Helvetica'))
|
||||
row_1_nb_effects_applied += 1
|
||||
# if effect.get('effect') == 'gold':
|
||||
# x_effect_pos = x_width/2 + row_1_x_offset + row_1_x_step*row_1_nb_effects_applied
|
||||
# dwg.add(dwg.circle(center=(x_effect_pos, row_1_base_y + stats_radius), r=stats_radius, fill='yellow'))
|
||||
# dwg.add(dwg.text(str(effect.get('amount')), insert=(x_effect_pos, row_1_base_y + stats_radius + 9), text_anchor='middle', fill='black', font_size='24px', font_weight="bold", font_family='Helvetica'))
|
||||
# row_1_nb_effects_applied += 1
|
||||
|
||||
if card_effects.get('heal'):
|
||||
x_effect_pos = x_width/2 + row_1_x_offset + row_1_x_step*row_1_nb_effects_applied
|
||||
dwg.add(dwg.circle(center=(x_effect_pos, row_1_base_y + stats_radius), r=stats_radius, fill='green'))
|
||||
dwg.add(dwg.text(str(card_data['row_1']['heal']), insert=(x_effect_pos, row_1_base_y + stats_radius + 9), text_anchor='middle', fill='white', font_size='24px', font_weight="bold", font_family='Helvetica'))
|
||||
row_1_nb_effects_applied += 1
|
||||
# if effect.get('effect') == 'heal':
|
||||
# x_effect_pos = x_width/2 + row_1_x_offset + row_1_x_step*row_1_nb_effects_applied
|
||||
# dwg.add(dwg.circle(center=(x_effect_pos, row_1_base_y + stats_radius), r=stats_radius, fill='green'))
|
||||
# dwg.add(dwg.text(str(effect.get('amount')), insert=(x_effect_pos, row_1_base_y + stats_radius + 9), text_anchor='middle', fill='white', font_size='24px', font_weight="bold", font_family='Helvetica'))
|
||||
# row_1_nb_effects_applied += 1
|
||||
draw_effects_resources_for_row(dwg, base_effects, row_1_base_y, x_width)
|
||||
|
||||
if card_data['row_2']:
|
||||
if other_effects:
|
||||
# Draw row 1 to row 2 separator
|
||||
dwg.add(dwg.line(start=(0 + row_1_to_2_separator_shorten_by, row_1_to_2_separator_y), end=(x_width - row_1_to_2_separator_shorten_by, row_1_to_2_separator_y), stroke='black', stroke_width=1))
|
||||
# Draw row 2 effect text
|
||||
# If ally effect, draw ally icon (TODO condition)
|
||||
|
||||
for effect in other_effects:
|
||||
# TODO handle case where there is both faction combo and trash can
|
||||
|
||||
if effect.get('effect_type') == 'faction_combo':
|
||||
row_2_icon_x = border_width_x + 35
|
||||
row_2_icon_y = row_2_base_y - 5
|
||||
dwg.add(dwg.circle(center=(row_2_icon_x + 1, row_2_icon_y + 1), r=15, fill='black'))
|
||||
dwg.add(dwg.circle(center=(row_2_icon_x, row_2_icon_y), r=15, fill='url(#grad2)'))
|
||||
# dwg.add(dwg.image(card_data['faction_icon'], insert=(x_width - 30 - 15, 30 - 15), size=(30, 30)))
|
||||
dwg.add(dwg.text(card_data['row_2']['effect'], insert=(x_width/2, row_2_base_y), text_anchor='middle', fill='black', font_size=str(effect_text_size) + 'px', font_family='Helvetica'))
|
||||
# Draw row 2 stats
|
||||
|
||||
# Draw row 2 effect text
|
||||
effect_text_2 = ""
|
||||
if effect.get('effect') == 'prepare':
|
||||
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'))
|
||||
|
||||
# Save the SVG file
|
||||
dwg.save()
|
||||
|
||||
Reference in New Issue
Block a user