Skip to content

Commit

Permalink
refactor(CreatureFormattedTextArea): Deprecated CFTA class, move PT r…
Browse files Browse the repository at this point in the history
…eference check into FormattedTextArea

Signed-off-by: Investigamer <freethoughtleft@gmail.com>
  • Loading branch information
Investigamer committed Jan 17, 2024
1 parent 778d6b1 commit 1179b00
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 40 deletions.
3 changes: 2 additions & 1 deletion src/data/kv/test.kv
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
id: test_app
orientation: "vertical"
BoxLayout:
size_hint: 1, .08
size_hint: 1, None
height: dp(60)
orientation: "horizontal"
spacing: dp(12)
padding: dp(12)
Expand Down
24 changes: 11 additions & 13 deletions src/templates/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
ScaledTextField,
FormattedTextArea,
FormattedTextField,
FormattedTextLayer,
CreatureFormattedTextArea)
FormattedTextLayer)
from src.enums.adobe import Dimensions
from src.enums.layers import LAYERS
from src.enums.settings import (
Expand Down Expand Up @@ -630,14 +629,18 @@ def art_reference(self) -> ReferenceLayer:
return psd.get_reference_layer(self.art_frame) or psd.get_reference_layer(LAYERS.ART_FRAME)

@auto_prop_cached
def name_reference(self) -> ArtLayer:
def name_reference(self) -> Optional[ArtLayer]:
"""ArtLayer: By default, name uses Mana Cost as a reference to check collision against."""
if self.is_basic_land:
return
return self.text_layer_mana

@auto_prop_cached
def type_reference(self) -> ArtLayer:
def type_reference(self) -> Optional[ArtLayer]:
"""ArtLayer: By default, typeline uses the expansion symbol to check collision against,
otherwise fallback to the expansion symbols reference layer."""
if self.is_basic_land:
return
return self.expansion_symbol_layer or self.expansion_reference

@auto_prop_cached
Expand All @@ -646,8 +649,10 @@ def textbox_reference(self) -> ReferenceLayer:
return psd.get_reference_layer(LAYERS.TEXTBOX_REFERENCE, self.text_group)

@auto_prop_cached
def pt_reference(self) -> ReferenceLayer:
def pt_reference(self) -> Optional[ReferenceLayer]:
"""ArtLayer: Reference used to check rules text overlap with the PT Box."""
if not self.is_creature:
return
return psd.get_reference_layer(LAYERS.PT_REFERENCE, self.text_group)

"""
Expand Down Expand Up @@ -1569,21 +1574,14 @@ def is_fullart(self) -> bool:
def rules_text_and_pt_layers(self) -> None:
"""Add rules and power/toughness text."""
self.text.extend([
CreatureFormattedTextArea(
FormattedTextArea(
layer=self.text_layer_rules,
contents=self.layout.oracle_text,
flavor=self.layout.flavor_text,
reference=self.textbox_reference,
divider=self.divider_layer,
pt_reference=self.pt_reference,
centered=self.is_centered
) if self.is_creature else FormattedTextArea(
layer=self.text_layer_rules,
contents=self.layout.oracle_text,
flavor=self.layout.flavor_text,
reference=self.textbox_reference,
divider=self.divider_layer,
centered=self.is_centered
),
TextField(
layer=self.text_layer_pt,
Expand Down
4 changes: 2 additions & 2 deletions src/templates/battle.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from src.layouts import BattleLayout
from src.templates._core import BaseTemplate
from src.templates._vector import VectorTemplate
from src.text_layers import TextField, CreatureFormattedTextArea
from src.text_layers import FormattedTextArea
from src.utils.properties import auto_prop_cached

"""
Expand Down Expand Up @@ -112,7 +112,7 @@ def rules_text_and_pt_layers(self) -> None:

# Rules Text and Power / Toughness
self.text.extend([
CreatureFormattedTextArea(
FormattedTextArea(
layer = self.text_layer_rules,
contents = self.layout.oracle_text,
flavor = self.layout.flavor_text,
Expand Down
28 changes: 4 additions & 24 deletions src/text_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,10 @@ class FormattedTextArea (FormattedTextField):
* Properties
"""

@cached_property
def pt_reference(self) -> Optional[ReferenceLayer]:
return self.kwargs.get('pt_reference', None)

@cached_property
def divider(self) -> Optional[Union[ArtLayer, LayerSet]]:
"""Divider layer, if provided and flavor text exists."""
Expand Down Expand Up @@ -811,29 +815,6 @@ def execute(self):
if self.divider:
self.insert_divider()


class CreatureFormattedTextArea (FormattedTextArea):
"""FormattedTextArea which also respects the bounds of creature card's power/toughness boxes.
* Moves the combined text upward to allow it to clear any Power/Toughness boxes indicated by the
provided P/T reference layer(s).
"""

"""
* Properties
"""

@cached_property
def pt_reference(self) -> Optional[ReferenceLayer]:
return self.kwargs.get('pt_reference', None)

"""
* Methods
"""

def execute(self):
super().execute()

# Shift vertically if the text overlaps the PT box
if self.pt_reference:

Expand All @@ -858,5 +839,4 @@ def execute(self):
FormattedTextArea,
FormattedTextField,
ScaledWidthTextField,
CreatureFormattedTextArea
]

0 comments on commit 1179b00

Please sign in to comment.