Skip to content

PlaneswalkerLayout

src.layouts.PlaneswalkerLayout

Bases: NormalLayout

Planeswalker card layout introduced in Lorwyn block.

Source code in src\layouts.py
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
class PlaneswalkerLayout(NormalLayout):
    """Planeswalker card layout introduced in Lorwyn block."""
    card_class: str = LayoutType.Planeswalker

    """
    * Text Info
    """

    @auto_prop_cached
    def oracle_text(self) -> str:
        """Fix Scryfall's minus character."""
        if self.is_alt_lang:
            return self.card.get('printed_text', self.card.get('oracle_text', '')).replace("\u2212", "-")
        return self.oracle_text_raw

    @auto_prop_cached
    def oracle_text_raw(self) -> str:
        """Fix Scryfall's minus character."""
        return super().oracle_text_raw.replace("\u2212", "-")

    """
    * Planeswalker Properties
    """

    @auto_prop_cached
    def loyalty(self) -> str:
        """Planeswalker starting loyalty."""
        return self.card.get('loyalty', '')

    @auto_prop_cached
    def pw_size(self) -> int:
        """Returns the size of this Planeswalker layout, usually based on number of abilities."""
        if self.name in planeswalkers_tall:
            # Special cases, long ability box
            return 4
        # Short ability box for 3 or less, otherwise tall box
        return 3 if len(self.pw_abilities) <= 3 else 4

    @auto_prop_cached
    def pw_abilities(self) -> list[dict]:
        """Processes Planeswalker text into listed abilities."""
        lines = Reg.PLANESWALKER.findall(self.oracle_text_raw)
        en_lines = lines.copy()

        # Process alternate language lines if needed
        if self.is_alt_lang and 'printed_text' in self.card:

            # Separate alternate language lines
            alt_lines = self.oracle_text.split('\n')
            new_lines: list[str] = []
            for line in lines:

                # Ensure number of breaks matches alternate text
                breaks = line.count('\n') + 1
                if not alt_lines or not (len(alt_lines) >= breaks):
                    new_lines = lines
                    break

                # Slice and add lines
                new_lines.append('\n'.join(alt_lines[:breaks]))
                alt_lines = alt_lines[breaks:]

            # Replace with alternate language lines
            lines = new_lines

        # Create list of ability dictionaries
        abilities: list[dict] = []
        for i, line in enumerate(lines):
            index = en_lines[i].find(": ")
            abilities.append({
                                 # Activated ability
                                 'text': line[index + 1:].lstrip(),
                                 'icon': en_lines[i][0],
                                 'cost': en_lines[i][0:index]
                             } if 5 > index > 0 else {
                # Static ability
                'text': line,
                'icon': None,
                'cost': None
            })
        return abilities

Attributes

card_class: str = LayoutType.Planeswalker

  • Text Info

Functions

loyalty() -> str

Planeswalker starting loyalty.

Source code in src\layouts.py
861
862
863
864
@auto_prop_cached
def loyalty(self) -> str:
    """Planeswalker starting loyalty."""
    return self.card.get('loyalty', '')

oracle_text() -> str

Fix Scryfall's minus character.

Source code in src\layouts.py
845
846
847
848
849
850
@auto_prop_cached
def oracle_text(self) -> str:
    """Fix Scryfall's minus character."""
    if self.is_alt_lang:
        return self.card.get('printed_text', self.card.get('oracle_text', '')).replace("\u2212", "-")
    return self.oracle_text_raw

oracle_text_raw() -> str

Fix Scryfall's minus character.

Source code in src\layouts.py
852
853
854
855
@auto_prop_cached
def oracle_text_raw(self) -> str:
    """Fix Scryfall's minus character."""
    return super().oracle_text_raw.replace("\u2212", "-")

pw_abilities() -> list[dict]

Processes Planeswalker text into listed abilities.

Source code in src\layouts.py
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
@auto_prop_cached
def pw_abilities(self) -> list[dict]:
    """Processes Planeswalker text into listed abilities."""
    lines = Reg.PLANESWALKER.findall(self.oracle_text_raw)
    en_lines = lines.copy()

    # Process alternate language lines if needed
    if self.is_alt_lang and 'printed_text' in self.card:

        # Separate alternate language lines
        alt_lines = self.oracle_text.split('\n')
        new_lines: list[str] = []
        for line in lines:

            # Ensure number of breaks matches alternate text
            breaks = line.count('\n') + 1
            if not alt_lines or not (len(alt_lines) >= breaks):
                new_lines = lines
                break

            # Slice and add lines
            new_lines.append('\n'.join(alt_lines[:breaks]))
            alt_lines = alt_lines[breaks:]

        # Replace with alternate language lines
        lines = new_lines

    # Create list of ability dictionaries
    abilities: list[dict] = []
    for i, line in enumerate(lines):
        index = en_lines[i].find(": ")
        abilities.append({
                             # Activated ability
                             'text': line[index + 1:].lstrip(),
                             'icon': en_lines[i][0],
                             'cost': en_lines[i][0:index]
                         } if 5 > index > 0 else {
            # Static ability
            'text': line,
            'icon': None,
            'cost': None
        })
    return abilities

pw_size() -> int

Returns the size of this Planeswalker layout, usually based on number of abilities.

Source code in src\layouts.py
866
867
868
869
870
871
872
873
@auto_prop_cached
def pw_size(self) -> int:
    """Returns the size of this Planeswalker layout, usually based on number of abilities."""
    if self.name in planeswalkers_tall:
        # Special cases, long ability box
        return 4
    # Short ability box for 3 or less, otherwise tall box
    return 3 if len(self.pw_abilities) <= 3 else 4