Feat : more text edge cases

This commit is contained in:
2024-07-01 11:51:06 +02:00
parent 7ed67521cf
commit 61424b7881
103 changed files with 661 additions and 622 deletions
+14 -12
View File
@@ -9,22 +9,24 @@
},
"effects":{
"draw":"Piochez une carte.",
"draw_n":"Piochez %a cartes.",
"draw_amount":"Piochez %a cartes.",
"stun":"Assomez le champion ciblé.",
"stack_next_card_bought":"Mettez la prochaine carte dont vous faites l'acquisition\nau dessus de votre pioche.",
"sacrifice":"Vous pouvez sacrifier une carte de votre main\nou de votre défausse.",
"stack_next_card_bought":"Mettez la prochaine carte dont\nvous faites l'acquisition ce tour-ci\nau dessus de votre pioche.",
"sacrifice":"Vous pouvez sacrifier une carte\nde votre main ou de votre défausse.",
"sacrifice_times":"Vous pouvez sacrifier jusqu'à %a\ncartes de votre main et/ou de votre défausse.",
"restack_discarded_champion":"Mettez un champion de votre défausse\nau dessus de votre pioche.",
"make_discard":"L'adversaire ciblé se défausse d'une carte.",
"draw_and_discard":"Vous pouvez piocher une carte.\nSi vous faites ainsi, défaussez vous d'une carte.",
"play_next_card_bought":"Mettez dans votre main la prochaine carte\ndont vous faites l'acquisition."
"make_discard":"L'adversaire ciblé%nse défausse d'une carte.",
"draw_and_discard":"Vous pouvez piocher une carte, puis\n vous défausser d'une carte.",
"draw_and_discard_times":"Vous pouvez piocher jusqu'à %a cartes,\ndéfaussez-vous ensuite d'autant de cartes",
"play_next_card_bought":"Mettez la prochaine carte dont\nvous faites l'acquisition ce tour-ci\n dans votre main."
},
"per":{
"champion":"pour chaque Champion que vous avez en jeu",
"cother_hampion":"pour chaque autre Champion que vous avez en jeu",
"other_guard":"pour chaque autre Garde que vous avez en jeu",
"other_card_of_same_faction":"pour chaque autre x que vous avez en jeu",
"champion_of_same_faction":"pour chaque Champion x que vous avez en jeu",
"other_knife_played":"pour chaque autre Couteau que vous avez en jeu"
"champion":"pour chaque Champion\nque vous avez en jeu",
"other_champion":"pour chaque autre Champion\nque vous avez en jeu",
"other_guard":"pour chaque autre\nGarde que vous avez en jeu",
"other_card_of_same_faction":"pour chaque autre x\nque vous avez en jeu",
"champion_of_same_faction":"pour chaque Champion x\nque vous avez en jeu",
"other_knife_played":"pour chaque autre Couteau\nque vous avez en jeu"
}
}
+49 -12
View File
@@ -24,7 +24,7 @@ def create_icon(
radius: float = stats_radius,
):
group = dw.Group()
group.append(dw.Circle(cx=0, cy=0, r=radius, fill=fill_circle, x=0, y=0))
group.append(dw.Circle(cx=0, cy=0, r=radius, fill=fill_circle, x=0, y=0, onclick="console.log()"))
group.append(
dw.Text(
str(amount),
@@ -148,7 +148,7 @@ resourceIcons = {
}
def create_effect_text(effects: list[Effect], height: int, width: int):
def create_effect_text(effects: list[Effect], height: float, width: int):
group = dw.Group()
effect_text = ""
@@ -162,29 +162,53 @@ def create_effect_text(effects: list[Effect], height: int, width: int):
elif e.get("amount", 1) > 1:
translation = (
translation_fr.get("effects")
.get(e.get("effect") + "_n", e.get("effect"))
.get(e.get("effect") + "_amount", e.get("effect"))
.replace(
"%a",
str(translation_fr.get("numbers").get(str(e.get("amount", "")))),
)
)
elif e.get("times", 1) > 1:
translation = (
translation_fr.get("effects")
.get(e.get("effect") + "_times", e.get("effect"))
.replace(
"%a",
str(translation_fr.get("numbers").get(str(e.get("times", "")))),
)
)
else:
translation = translation_fr.get("effects").get(
e.get("effect"), e.get("effect")
)
e.get("effect"), e.get("effect") )
if(len(effect_text)>20):
effect_text+="\n"
effect_text += translation
font_size = min(effect_text_size, max((effect_text_size*2)-len(effect_text)*.5,11))
if width < 250:
effect_text = effect_text.replace("%n","\n")
else:
effect_text = effect_text.replace("%n"," ")
# Attempt to estimate font width
font_width = .5
line_width = max(*[len(x) for x in effect_text.split("\n")], len(effect_text))*font_width
# Take width in account
font_size = effect_text_size
font_size = min(font_size, (font_size*3)-line_width, font_size * width / (line_width or 1))
# Take height in account
font_size = min((height)/(effect_text.count("\n") or 1), font_size)
font_size = max(font_size, 11)
group.append(
dw.Text(
effect_text,
x=width / 2,
x=0,
y=(-font_size/2)*effect_text.count("\n"),
text_anchor="middle",
fill="black",
# Attempt to estimate font width
font_size=font_size,
font_family="Helvetica",
)
@@ -195,10 +219,12 @@ def create_effect_text(effects: list[Effect], height: int, width: int):
def create_effect_row(effects: list[Effect], type: str, height: int, width: int):
group = dw.Group()
has_icon = False
if type == "faction_combo":
has_icon = True
group.append(
dw.Circle(
cx=35,
cx=30,
cy=height / 2,
r=15,
fill="url(#grad2)",
@@ -206,9 +232,10 @@ def create_effect_row(effects: list[Effect], type: str, height: int, width: int)
)
)
elif type == "suicide":
has_icon = True
group.append(
dw.Circle(
cx=35,
cx=30,
cy=height / 2,
r=15,
fill="black",
@@ -217,9 +244,10 @@ def create_effect_row(effects: list[Effect], type: str, height: int, width: int)
)
elif type == "champion_action":
has_icon = True
group.append(
dw.Circle(
cx=35,
cx=30,
cy=height / 2,
r=15,
fill="gray",
@@ -232,16 +260,25 @@ def create_effect_row(effects: list[Effect], type: str, height: int, width: int)
effect_with_text = list(filter(lambda x: x not in effect_with_icons, effects))
text_y_pos = height - effect_text_size / 1.5
if height > 100:
text_y_pos = (height/2) + effect_text_size + stats_radius
text_height= height/6
if len(effect_with_icons) == 0:
text_y_pos = (height / 2) + (effect_text_size / 4)
text_height= height
icon_y_pos = (height / 2) - effect_text_size / 2
if len(effect_with_text) == 0:
icon_y_pos = height / 2
text_width = width
if has_icon:
text_width = width - 70
group.append(
dw.Use(create_effect_text(effect_with_text, height, width), 0, text_y_pos)
dw.Use(create_effect_text(effect_with_text, text_height, text_width), width/2, text_y_pos)
)
icon_radius = min(height / 3, stats_radius)