Nice cards templates
This commit is contained in:
+77
-2
@@ -5,6 +5,7 @@ from __future__ import annotations
|
||||
from pathlib import Path
|
||||
|
||||
from genshin_tcg.data.catalog import Catalog
|
||||
from genshin_tcg.models import parse_catalog
|
||||
from genshin_tcg.rendering.context import (
|
||||
ActionView,
|
||||
CharacterView,
|
||||
@@ -62,6 +63,80 @@ def test_character_tags_include_element_and_weapon(sample_catalog: Catalog) -> N
|
||||
assert view.tags[1].label == "Épée à deux mains"
|
||||
|
||||
|
||||
def test_character_tag_order_matches_the_official_print(
|
||||
tmp_path: Path, sample_catalog: Catalog
|
||||
) -> None:
|
||||
"""The official layout stacks element, nation/faction, then weapon."""
|
||||
view = build_view(
|
||||
sample_catalog.get("test_pyro"),
|
||||
assets_dir=tmp_path / "assets",
|
||||
html_dir=tmp_path / "build" / "html",
|
||||
factions={"test_pyro": "liyue"},
|
||||
width_px=744,
|
||||
height_px=1039,
|
||||
)
|
||||
assert isinstance(view, CharacterView)
|
||||
assert [tag.kind for tag in view.tags] == ["element", "faction", "weapon"]
|
||||
|
||||
|
||||
def test_none_token_labels_do_not_collide(tmp_path: Path) -> None:
|
||||
"""``WeaponType.NONE`` ("other weapon") and ``CardType.NONE`` ("event card")
|
||||
share the ``"none"`` token but must not share a label."""
|
||||
catalog = Catalog(
|
||||
cards=tuple(
|
||||
parse_catalog(
|
||||
[
|
||||
{
|
||||
"_id": 1,
|
||||
"id": "monster",
|
||||
"type": "character",
|
||||
"name": "Monstre",
|
||||
"hp": 8,
|
||||
"energy": 0,
|
||||
"element": "hydro",
|
||||
"weapon": "none",
|
||||
"skills": [
|
||||
{
|
||||
"_id": 11,
|
||||
"type": "Attaque normale",
|
||||
"name": "Charge",
|
||||
"desc": "Inflige 2 pts de DGT physiques.",
|
||||
"cost": [{"type": "hydro", "count": 1}],
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
"_id": 2,
|
||||
"id": "event",
|
||||
"type": "none",
|
||||
"name": "Événement",
|
||||
"skills": {"cost": [], "desc": "Rien."},
|
||||
},
|
||||
]
|
||||
)
|
||||
)
|
||||
)
|
||||
monster = build_view(
|
||||
catalog.get("monster"),
|
||||
assets_dir=tmp_path / "assets",
|
||||
html_dir=tmp_path / "build" / "html",
|
||||
width_px=744,
|
||||
height_px=1039,
|
||||
)
|
||||
event = build_view(
|
||||
catalog.get("event"),
|
||||
assets_dir=tmp_path / "assets",
|
||||
html_dir=tmp_path / "build" / "html",
|
||||
width_px=744,
|
||||
height_px=1039,
|
||||
)
|
||||
assert isinstance(monster, CharacterView)
|
||||
assert isinstance(event, ActionView)
|
||||
assert monster.weapon_label == "Autre arme"
|
||||
assert [tag.label for tag in monster.tags if tag.kind == "weapon"] == ["Autre arme"]
|
||||
assert event.type_label == "Événement"
|
||||
|
||||
|
||||
def test_character_skills_and_costs(sample_catalog: Catalog) -> None:
|
||||
view = _character(sample_catalog)
|
||||
assert len(view.skills) == 3
|
||||
@@ -76,7 +151,7 @@ def test_character_skills_and_costs(sample_catalog: Catalog) -> None:
|
||||
def test_character_description_is_cleaned_and_highlighted(sample_catalog: Catalog) -> None:
|
||||
view = _character(sample_catalog)
|
||||
assert "<br/>" in view.skills[0].description_html
|
||||
assert '<span style="color: #FFFFFFFF">DGT ' in view.skills[1].description_html
|
||||
assert '<span style="color: #3a332a">DGT ' in view.skills[1].description_html
|
||||
assert "inline-die" in view.skills[1].description_html
|
||||
assert view.skills[1].sub_name == "Flamme éternelle"
|
||||
assert view.skills[1].sub_description_html is not None
|
||||
@@ -107,7 +182,7 @@ def test_action_view_fields(sample_catalog: Catalog) -> None:
|
||||
assert view.requirement == "test_pyro"
|
||||
assert [die.count for die in view.cost] == [4]
|
||||
assert "<br/>" in view.description_html
|
||||
assert '<span style="color: #FFD700">Action de combat</span>' in view.description_html
|
||||
assert '<span style="color: #988316">Action de combat</span>' in view.description_html
|
||||
|
||||
|
||||
def test_action_without_cost_gets_placeholder_die(sample_catalog: Catalog) -> None:
|
||||
|
||||
+18
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from genshin_tcg.markup import clean_markup, inline_symbols, sanitize, strip_markup
|
||||
from genshin_tcg.markup import clean_markup, inline_symbols, panel_ink, sanitize, strip_markup
|
||||
|
||||
|
||||
def test_clean_markup_converts_color_tags() -> None:
|
||||
@@ -19,6 +19,23 @@ def test_clean_markup_keeps_colour_and_underline_spans() -> None:
|
||||
assert clean_markup(raw) == expected
|
||||
|
||||
|
||||
def test_clean_markup_applies_colour_map() -> None:
|
||||
raw = '<span style="color: #FFFFFFFF">DGT</span>'
|
||||
assert clean_markup(raw, color_map=panel_ink) == '<span style="color: #3a332a">DGT</span>'
|
||||
|
||||
|
||||
def test_panel_ink_neutralises_achromatic_and_darkens_hues() -> None:
|
||||
# White would be invisible on the frosted panel, so it collapses to ink.
|
||||
# The dataset writes colours as #RRGGBBAA, so the trailing byte is alpha.
|
||||
assert panel_ink("#FFFFFFFF") == "#3a332a"
|
||||
assert panel_ink("#FFFFFF") == "#3a332a"
|
||||
# Chromatic keyword colours keep their hue but gain contrast.
|
||||
assert panel_ink("#FFD780FF") == "#986F16" # gold
|
||||
assert panel_ink("#7EC236FF") == "#588826" # Dendro green
|
||||
# Anything that is not a hex colour is passed through untouched.
|
||||
assert panel_ink("red") == "red"
|
||||
|
||||
|
||||
def test_sanitize_removes_script_and_event_handlers() -> None:
|
||||
dirty = '<script>alert(1)</script><span onclick="x()" style="color: red;">ok</span>'
|
||||
cleaned = sanitize(dirty)
|
||||
|
||||
Reference in New Issue
Block a user