Skip to content

ClassLayout

src.layouts.ClassLayout

Bases: NormalLayout

Class card layout, introduced in Adventures in the Forgotten Realms.

Source code in src\layouts.py
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
class ClassLayout(NormalLayout):
    """Class card layout, introduced in Adventures in the Forgotten Realms."""
    card_class: str = LayoutType.Class

    """
    * Class Properties
    """

    @auto_prop_cached
    def class_text(self) -> str:
        """Text comprised of class ability lines."""
        return strip_lines(self.oracle_text, 1)

    @auto_prop_cached
    def class_description(self) -> str:
        """Description at the top of the Class card."""
        return get_line(self.oracle_text, 0)

    @auto_prop_cached
    def class_lines(self) -> list[dict]:
        """Unpack class text into list of dictionaries containing ability levels, cost, and text."""

        # Initial class ability
        initial, *lines = self.class_text.split('\n')
        abilities: list[dict] = [{'text': initial, 'cost': None, 'level': 1}]

        # Add level-up abilities
        for line in ["\n".join(lines[i:i + 2]) for i in range(0, len(lines), 2)]:
            # Try to match this line to a class ability
            details = Reg.CLASS.match(line)
            if details and len(details.groups()) >= 3:
                abilities.append({
                    'cost': details[1],
                    'level': details[2],
                    'text': details[3]
                })
                continue
            # Otherwise add line to the previous ability
            abilities[-1]['text'] += f'\n{line}'
        return abilities

Attributes

card_class: str = LayoutType.Class

  • Class Properties

Functions

class_description() -> str

Description at the top of the Class card.

Source code in src\layouts.py
1167
1168
1169
1170
@auto_prop_cached
def class_description(self) -> str:
    """Description at the top of the Class card."""
    return get_line(self.oracle_text, 0)

class_lines() -> list[dict]

Unpack class text into list of dictionaries containing ability levels, cost, and text.

Source code in src\layouts.py
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
@auto_prop_cached
def class_lines(self) -> list[dict]:
    """Unpack class text into list of dictionaries containing ability levels, cost, and text."""

    # Initial class ability
    initial, *lines = self.class_text.split('\n')
    abilities: list[dict] = [{'text': initial, 'cost': None, 'level': 1}]

    # Add level-up abilities
    for line in ["\n".join(lines[i:i + 2]) for i in range(0, len(lines), 2)]:
        # Try to match this line to a class ability
        details = Reg.CLASS.match(line)
        if details and len(details.groups()) >= 3:
            abilities.append({
                'cost': details[1],
                'level': details[2],
                'text': details[3]
            })
            continue
        # Otherwise add line to the previous ability
        abilities[-1]['text'] += f'\n{line}'
    return abilities

class_text() -> str

Text comprised of class ability lines.

Source code in src\layouts.py
1162
1163
1164
1165
@auto_prop_cached
def class_text(self) -> str:
    """Text comprised of class ability lines."""
    return strip_lines(self.oracle_text, 1)