Feat : prevent isolation by removing <use> elements

This commit is contained in:
2024-07-07 00:29:10 +02:00
parent ac7e34de47
commit 3055b7f658
105 changed files with 3456 additions and 3563 deletions
+91 -88
View File
@@ -86,7 +86,7 @@ def create_gold_icon(
)
def create_pentagon(cx: int, cy: int, radius: int):
def create_pentagon_lines(cx: int, cy: int, radius: int):
points: list[float] = []
for i in range(5):
x = cx + radius * cos(2 * pi * i / 5 + (pi / 2))
@@ -96,41 +96,52 @@ def create_pentagon(cx: int, cy: int, radius: int):
return points
def create_pentagon(
lines: list[str],
fill: str,
stroke: str,
close: bool = True,
stroke_width: int = 2,
):
return dw.Lines(
*lines,
fill=fill,
close=close,
stroke=stroke,
stroke_width=stroke_width,
)
def draw_champion_shield(card_data: Card, border_width_x: int):
group = dw.Group(id="champion_shield")
pentagon = dw.Lines(
*create_pentagon(cx=border_width_x - 15, cy=-30, radius=28),
close=True,
stroke_width=2,
)
defense_text = dw.Text(
str(card_data["defense"]),
font_size="28px",
font_weight="bold",
font_family="Helvetica",
text_anchor="middle",
x=border_width_x - 15,
y=-20,
)
group = []
def gen_defense_text(fill: str = "black"):
return dw.Text(
str(card_data["defense"]),
font_size="28px",
font_weight="bold",
font_family="Helvetica",
text_anchor="middle",
x=border_width_x - 15,
y=-20,
fill=fill,
)
if not card_data["guard"]:
group.append(
dw.Use(
pentagon,
0,
0,
create_pentagon(
create_pentagon_lines(cx=border_width_x - 15, cy=-30, radius=28),
fill="darkgrey",
stroke="#eee",
)
)
group.append(dw.Use(defense_text, 0, 0, fill="black"))
group.append(gen_defense_text(fill="black"))
else:
group.append(
dw.Use(
pentagon,
0,
0,
create_pentagon(
create_pentagon_lines(cx=border_width_x - 15, cy=-30, radius=28),
fill="black",
stroke="lightgrey",
)
@@ -159,7 +170,7 @@ def draw_champion_shield(card_data: Card, border_width_x: int):
)
)
group.append(dw.Use(defense_text, 0, 0, fill="white"))
group.append(gen_defense_text(fill="white"))
return group
@@ -183,7 +194,7 @@ resourceIcons = {
def create_effect_text(effects: list[Effect], height: float, width: int):
group = dw.Group()
group = []
effect_text = ""
@@ -316,10 +327,9 @@ def create_effect_row(effects: list[Effect], type: str, height: int, width: int)
if has_icon:
text_width = width - 70
group.append(
dw.Use(
dw.Group(
create_effect_text(effect_with_text, text_height, text_width),
width / 2,
text_y_pos,
transform=f"translate({width / 2},{text_y_pos})",
)
)
@@ -328,16 +338,18 @@ def create_effect_row(effects: list[Effect], type: str, height: int, width: int)
f = resourceIcons.get(e.get("effect"))
if f is not None:
group.append(
dw.Use(
f(
int(e.get("amount", 1)),
effect_id=e.get("index"),
radius=icon_radius,
),
(width / 2)
- ((len(effect_with_icons) - 1) * icon_radius * 1.5)
+ (i * icon_radius * 3),
icon_y_pos,
dw.Group(
[
f(
int(e.get("amount", 1)),
effect_id=e.get("index"),
radius=icon_radius,
)
],
transform=f"translate({(width / 2) - ((len(effect_with_icons) - 1) * icon_radius * 1.5) + (i * icon_radius * 3)},{icon_y_pos})",
**{
"v-bind:class": f"{{used:used_effects_indexes.includes({e.get('index')})}}"
},
)
)
@@ -372,7 +384,7 @@ def create_effects(effects: list[Effect], height: int, width: int):
e["index"] = str(i)
generate_subeffect_index(e)
group = dw.Group(id="effects")
group = []
grouped_effects = {
k: list(g)
for k, g in groupby(
@@ -384,38 +396,31 @@ def create_effects(effects: list[Effect], height: int, width: int):
if len(grouped_effects) == 1:
group.append(
dw.Use(
create_effect_row(
grouped_effects[effect_types[0]], effect_types[0], height, width
),
0,
0,
)
create_effect_row(
grouped_effects[effect_types[0]], effect_types[0], height, width
),
)
if len(grouped_effects) == 2:
group.append(
dw.Line(sx=10, sy=80, ex=width - 10, ey=80, stroke="black", stroke_width=1)
)
group.append(
dw.Use(
create_effect_row(
grouped_effects[effect_types[0]], effect_types[0], 80, width
),
0,
0,
)
create_effect_row(
grouped_effects[effect_types[0]], effect_types[0], 80, width
),
)
group.append(
dw.Use(
create_effect_row(
grouped_effects[effect_types[1]],
effect_types[1],
height - 80,
width,
),
0,
80,
dw.Group(
[
create_effect_row(
grouped_effects[effect_types[1]],
effect_types[1],
height - 80,
width,
)
],
transform=f"translate({0},{80})",
)
)
@@ -427,38 +432,36 @@ def create_effects(effects: list[Effect], height: int, width: int):
dw.Line(sx=10, sy=90, ex=width - 10, ey=90, stroke="black", stroke_width=1)
)
group.append(
dw.Use(
create_effect_row(
grouped_effects[effect_types[0]], effect_types[0], 45, width
),
0,
0,
create_effect_row(
grouped_effects[effect_types[0]], effect_types[0], 45, width
)
)
group.append(
dw.Use(
create_effect_row(
grouped_effects[effect_types[1]],
effect_types[1],
45,
width,
),
0,
45,
dw.Group(
[
create_effect_row(
grouped_effects[effect_types[1]],
effect_types[1],
45,
width,
)
],
transform=f"translate({0},{45})",
)
)
group.append(
dw.Use(
create_effect_row(
grouped_effects[effect_types[2]],
effect_types[2],
45,
width,
),
0,
90,
dw.Group(
[
create_effect_row(
grouped_effects[effect_types[2]],
effect_types[2],
45,
width,
)
],
transform=f"translate({0},{90})",
)
)
+7
View File
@@ -0,0 +1,7 @@
def finish_card(path: str):
pass
# with open(path,"r+", encoding="utf-8") as f:
# data = f.read().replace('width="298"', '').replace('height="417"','')
# f.truncate(0)
# f.seek(0)
# f.write(data)
+14 -13
View File
@@ -9,6 +9,8 @@ from card_types import Card, SkinData, SkinFile, Translation
from drawsvg.drawing import Drawing
from edit_card import finish_card
with open("src/data/translation_fr.json", encoding="utf-8") as f:
translation_fr: Translation = json.load(f)
@@ -83,7 +85,7 @@ for card_data in cards:
# Create a new SVG drawing
output_dir = "output/" + all_skin_data["skin_name"]
os.makedirs(output_dir, exist_ok=True)
d = Drawing(x_width, y_height, id="card"+str(card_data["id"]))
d = Drawing(x_width, y_height, id="card"+str(card_data["id"]), id_prefix=str(card_data.get('id')) + "_", **{'class':'card', 'xmlns:v-bind':"https://heron.legonzaur.fr"})
d.append(shadowFilter)
# Define linear colored gradient
@@ -162,20 +164,12 @@ for card_data in cards:
# Draw faction icon
d.append(
dw.Use(
faction_icon,
border_width_x + 23 + 1,
border_width_y - border_upper_offset + 20 + 4 + 1,
)
dw.Group(children=[faction_icon],transform=f"translate({border_width_x + 23 + 1},{border_width_y - border_upper_offset + 20 + 4 + 1})")
)
# Draw card cost
if card_data.get("cost") is not None:
d.append(
dw.Use(
create_gold_icon(cast(int,card_data.get("cost"))),
x_width - cost_right_offset,
19 + border_width_y,
)
dw.Group(children=[create_gold_icon(cast(int,card_data.get("cost")))],transform=f"translate({x_width - cost_right_offset},{19 + border_width_y})")
)
d.append(dw.Rectangle(x=0, y=65, width=x_width, height=200))
@@ -190,12 +184,19 @@ for card_data in cards:
height=135,
width=x_internal_width
)
d.append(dw.Use(effects, border_width_x,265))
d.append(dw.Group(
effects,
transform=f"translate({border_width_x},{265})",
))
# If champion, draw champion shield with defense
if card_data["card_type"] == "champion":
shield = draw_champion_shield(card_data, border_width_x)
d.append(dw.Use(shield,x_width-30, y_height))
d.append(dw.Group(
shield,
transform=f"translate({x_width-30},{y_height})",
))
# Save the SVG file
d.save_svg(f"output/{all_skin_data['skin_name']}/{str(card_data["id"]).zfill(3)}.svg")
finish_card(f"output/{all_skin_data['skin_name']}/{str(card_data["id"]).zfill(3)}.svg")