feat: iterate on array of cards, gen output in folder (broken img links)

This commit is contained in:
2024-05-26 01:03:04 +02:00
parent a8045728b3
commit fbd7222f05
9 changed files with 135 additions and 204 deletions
+1 -1
View File
@@ -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="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>
<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">Caprisun</text><text fill="black" font-family="Helvetica" font-size="13px" text-anchor="middle" x="149.0" y="53">Action, 20cl</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">1</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="149.0" cy="302" fill="yellow" r="22" /><text fill="black" font-family="Helvetica" font-size="24px" font-weight="bold" text-anchor="middle" x="149.0" y="311">2</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" /><circle cx="149.0" cy="372" fill="green" r="22" /><text fill="white" font-family="Helvetica" font-size="24px" font-weight="bold" text-anchor="middle" x="149.0" y="381">6</text><text fill="black" font-family="Helvetica" font-size="14px" text-anchor="middle" x="149.0" y="375" /></svg>

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB

+2
View File
@@ -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="img/skins/heron/010.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>

After

Width:  |  Height:  |  Size: 2.2 KiB

+2
View File
@@ -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">Caprisun</text><text fill="black" font-family="Helvetica" font-size="13px" text-anchor="middle" x="149.0" y="53">Action, 20cl</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">1</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="149.0" cy="302" fill="yellow" r="22" /><text fill="black" font-family="Helvetica" font-size="24px" font-weight="bold" text-anchor="middle" x="149.0" y="311">2</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" /><circle cx="149.0" cy="372" fill="green" r="22" /><text fill="white" font-family="Helvetica" font-size="24px" font-weight="bold" text-anchor="middle" x="149.0" y="381">6</text><text fill="black" font-family="Helvetica" font-size="14px" text-anchor="middle" x="149.0" y="375" /></svg>

After

Width:  |  Height:  |  Size: 2.2 KiB

-24
View File
@@ -1,24 +0,0 @@
{
"id": 10,
"role": "market",
"card_type": "action",
"faction": "yellow",
"name": "Rally the Troops",
"cost": 4,
"init_amount": 1,
"effects": [
{
"effect": "heal",
"amount": 5
},
{
"effect": "damage",
"amount": 5
},
{
"effect": "prepare",
"amount": 1,
"effect_type": "faction_combo"
}
]
}
-20
View File
@@ -1,20 +0,0 @@
{
"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"
}
]
}
+48
View File
@@ -0,0 +1,48 @@
{
"cards": [
{
"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"
}
]
},
{
"id": 10,
"role": "market",
"card_type": "action",
"faction": "yellow",
"name": "Rally the Troops",
"cost": 4,
"init_amount": 1,
"effects": [
{
"effect": "heal",
"amount": 5
},
{
"effect": "damage",
"amount": 5
},
{
"effect": "prepare",
"amount": 1,
"effect_type": "faction_combo"
}
]
}
]
}
@@ -1,8 +1,9 @@
{
"skin_name": "heron",
"10": {
"title": "Rallier les Troupes",
"type": "Action, Charme",
"image_path": "lancersiz3.png"
"image_path": "img/skins/heron/010.png"
},
"13": {
"title": "Caprisun",
+11 -89
View File
@@ -1,75 +1,12 @@
# import svgwrite
# from svgwrite import cm, mm, px
# # Configuration des chemins vers les icônes
# icons = {
# 'degats': 'path/to/damage_icon.svg',
# 'or': 'path/to/gold_icon.svg',
# 'soin': 'path/to/heal_icon.svg'
# }
# # Configuration des couleurs de fond
# background_colors = {
# 'bleue': 'lightblue',
# 'rouge': 'lightcoral',
# 'jaune': 'lightyellow',
# 'verte': 'lightgreen',
# 'sans': 'white'
# }
# def generate_card_svg(name, description, color, effects, output_path):
# # Créer un dessin SVG
# dwg = svgwrite.Drawing(output_path, profile='tiny', size=(8*cm, 12*cm))
# # Ajouter un rectangle de fond
# dwg.add(dwg.rect(insert=(0, 0), size=('100%', '100%'), fill=background_colors[color]))
# # Ajouter le titre de la carte
# dwg.add(dwg.text(name, insert=(0.5*cm, 1*cm), font_size="20px", fill='black'))
# # Ajouter la description
# dwg.add(dwg.text(description, insert=(0.5*cm, 2*cm), font_size="12px", fill='black'))
# # Ajouter les effets
# y_offset = 3*cm
# for effect in effects:
# if effect['type'] in icons:
# # Ajouter l'icône
# dwg.add(dwg.image(href=icons[effect['type']], insert=(0.5*cm, y_offset), size=(1*cm, 1*cm)))
# # Ajouter le texte de l'effet
# dwg.add(dwg.text(effect['text'], insert=(2*cm, y_offset + 0.75*cm), font_size="15px", fill='black'))
# else:
# # Ajouter le texte de l'effet sans icône
# dwg.add(dwg.text(effect['text'], insert=(0.5*cm, y_offset + 0.75*cm), font_size="15px", fill='black'))
# y_offset += 2*cm
# # Sauvegarder le fichier SVG
# dwg.save()
# # Exemple d'utilisation
# card_info = {
# 'name': 'Niko Incendiaire',
# 'description': 'Action, ghdj;spftgljh.-',
# 'color': 'bleue',
# 'effects': [
# {'type': 'degats', 'text': '8 Dégâts'},
# {'type': 'or', 'text': '5 Or'}
# ]
# }
# output_path = 'niko_incendiaire.svg'
# generate_card_svg(**card_info, output_path=output_path)
# print('Carte SVG générée avec succès!')
import svgwrite
import json
from typing import List
import os
from draw import draw_effects_resources_for_row
with open('src/card_data.json') as f:
with open('src/data/heron_skin.json') as f:
all_skin_data = json.load(f)
# Params
@@ -107,15 +44,18 @@ icon_colors = {
'yellow': ['#ff9935', '#ffe744']
}
# Load card data from JSON file
with open('src/actual_card_data.json') as f:
card_data = json.load(f)
with open('src/data/cards_data.json') as f:
cards: List = json.load(f)['cards']
for card_data in cards:
# Get card skin data
card_skin_data = all_skin_data[str(card_data['id'])]
# Create a new SVG drawing
dwg = svgwrite.Drawing('card.svg', profile='tiny', size=(str(x_width) + 'px', str(y_height) + 'px'))
output_dir = 'output/' + all_skin_data['skin_name']
os.makedirs(output_dir, exist_ok=True)
dwg = svgwrite.Drawing('output/' + all_skin_data['skin_name'] + '/' + str(card_data['id']).zfill(3) + '.svg', profile='tiny', size=(str(x_width) + 'px', str(y_height) + 'px'))
# Define linear colored gradient
gradient = dwg.linearGradient(start=(0, 0), end=(1, 0), id="grad1")
@@ -176,25 +116,6 @@ other_effects = list(filter(lambda x: not is_base_effect(x), card_effects))
# 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
# 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 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 other_effects:
@@ -210,6 +131,7 @@ for effect in other_effects:
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)'))
# Draw row 2 stats
draw_effects_resources_for_row(dwg, [effect], row_2_base_y - 25, x_width)
# Draw row 2 effect text
effect_text_2 = ""