Skip to content

SplitLayout

src.layouts.SplitLayout

Bases: NormalLayout

Split card layout, introduced in Invasion.

Source code in src\layouts.py
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
class SplitLayout(NormalLayout):
    """Split card layout, introduced in Invasion."""
    card_class: str = LayoutType.Split

    # Static properties
    is_nyx: bool = False
    is_land: bool = False
    is_basic_land: bool = False
    is_artifact: bool = False
    is_creature: bool = False
    is_legendary: bool = False
    is_companion: bool = False
    is_colorless: bool = False
    toughness: str = ''
    power: str = ''

    def __str__(self):
        return (f"{self.display_name}"
                f"{f' [{self.set}]' if self.set else ''}"
                f"{f' {{{self.collector_number}}}' if self.collector_number else ''}")

    """
    * Core Data
    """

    @auto_prop_cached
    def art_file(self) -> list[Path]:
        """list[Path]: Two image files, second is appended during render process."""
        return [self.file['file']]

    @auto_prop_cached
    def display_name(self) -> str:
        """Both side names."""
        return f"{self.name[0]} // {self.name[1]}"

    @auto_prop_cached
    def card(self) -> list[dict]:
        """Both side objects."""
        return [c for c in self.scryfall.get('card_faces', [])]

    """
    * Colors
    """

    @auto_prop_cached
    def color_identity(self) -> list:
        """Color identity is shared by both halves, use raw Scryfall instead of 'card' data."""
        return self.scryfall.get('color_identity', [])

    @auto_prop_cached
    def color_indicator(self) -> str:
        """Color indicator is shared by both halves, use raw Scryfall instead of 'card' data."""
        return get_ordered_colors(self.scryfall.get('color_indicator', []))

    """
    * Images
    """

    @auto_prop_cached
    def scryfall_scan(self) -> str:
        """Scryfall large image scan, if available."""
        return self.scryfall.get('image_uris', {}).get('large', '')

    """
    * Collector Info
    """

    @auto_prop_cached
    def artist(self) -> str:
        """Card artist name, use Scryfall raw data instead of 'card' data."""
        if self.file.get('artist'):
            return self.file['artist']

        # Check for duplicate last names
        artist, count = self.scryfall.get('artist', 'Unknown'), []
        if '&' in artist:
            for w in artist.split(' '):
                if w in count:
                    count.remove(w)
                count.append(w)
            return ' '.join(count)
        return artist

    """
    * Symbols
    """

    @auto_prop_cached
    def watermark(self) -> list[Optional[str]]:
        """Name of the card's watermark file that is actually used, if provided."""
        watermarks: list[Optional[str]] = []
        for wm in self.watermark_svg:
            if not wm:
                watermarks.append(None)
            elif wm.stem.upper() == 'WM':
                watermarks.append(wm.parent.stem.lower())
            else:
                watermarks.append(wm.stem.lower())
        return watermarks

    @auto_prop_cached
    def watermark_raw(self) -> list[Optional[str]]:
        """Name of the card's watermark from raw Scryfall data, if provided."""
        return [c.get('watermark', '') for c in self.card]

    @auto_prop_cached
    def watermark_svg(self) -> list[Optional[Path]]:
        """Path to the watermark SVG file, if provided."""
        def _find_watermark_svg(wm: str) -> Optional[Path]:
            """Try to find a watermark SVG asset, allowing for special cases and set code fallbacks.

            Args:
                wm: Watermark name or set code to look for.

            Returns:
                Path to a watermark SVG file if found, otherwise None.

            Notes:
                - 'set' maps to the symbol collection of the set this card was first printed in.
                - 'symbol' maps to the symbol collection of this card object's set.
            """
            if not wm:
                return
            wm = wm.lower()

            # Special case watermarks
            if wm in ['set', 'symbol']:
                return get_watermark_svg_from_set(
                    self.first_print.get('set', self.set) if wm == 'set' else self.set)

            # Look for normal watermark
            return get_watermark_svg(wm)

        # Find a watermark SVG for each face
        watermarks = []
        for w in self.watermark_raw:
            if CFG.watermark_mode == WatermarkMode.Disabled:
                # Disabled Mode
                watermarks.append(None)
                continue
            elif CFG.watermark_mode == WatermarkMode.Forced:
                # Forced Mode
                watermarks.append(
                    _find_watermark_svg(
                        CFG.watermark_default))
                continue
            else:
                # Automatic Mode
                path = _find_watermark_svg(w)
                if path or CFG.watermark_mode == WatermarkMode.Automatic:
                    watermarks.append(path)
                    continue
                # Fallback Mode
                watermarks.append(
                    _find_watermark_svg(
                        CFG.watermark_default))
        return watermarks

    """
    * Text Info
    """

    @auto_prop_cached
    def name(self) -> list[str]:
        """Both side names."""
        if self.is_alt_lang:
            return [c.get('printed_name', c.get('name', '')) for c in self.card]
        return [c.get('name', '') for c in self.card]

    @auto_prop_cached
    def name_raw(self) -> str:
        """Sanitized card name to use for rendered image file."""
        return f"{self.name[0]} _ {self.name[1]}"

    @auto_prop_cached
    def type_line(self) -> list[str]:
        """Both side type lines."""
        if self.is_alt_lang:
            return [c.get('printed_type_line', c.get('type_line', '')) for c in self.card]
        return [c.get('type_line', '') for c in self.card]

    @auto_prop_cached
    def mana_cost(self) -> list[str]:
        """Both side mana costs."""
        return [c.get('mana_cost', '') for c in self.card]

    @auto_prop_cached
    def oracle_text(self) -> list[str]:
        """Both side oracle texts."""
        text = []
        for t in [
            c.get('printed_text', c.get('oracle_text', ''))
            if self.is_alt_lang else c.get('oracle_text', '')
            for c in self.card
        ]:
            # Remove Fuse if present in oracle text data
            t = ''.join(t.split('\n')[:-1]) if 'Fuse' in self.keywords else t
            text.append(t)
        return text

    @auto_prop_cached
    def flavor_text(self) -> list[str]:
        """Both sides flavor text."""
        return [c.get('flavor_text', '') for c in self.card]

    """
    * Bool Data
    """

    @auto_prop_cached
    def is_hybrid(self) -> list[bool]:
        """Both sides hybrid check."""
        return [f['is_hybrid'] for f in self.frame]

    @auto_prop_cached
    def is_colorless(self) -> list[bool]:
        """Both sides colorless check."""
        return [f['is_colorless'] for f in self.frame]

    """
    * Frame Details
    """

    @auto_prop_cached
    def frame(self) -> list[FrameDetails]:
        """Both sides frame data."""
        return [get_frame_details(c) for c in self.card]

    @auto_prop_cached
    def pinlines(self) -> list[str]:
        """Both sides pinlines identity."""
        return [f['pinlines'] for f in self.frame]

    @auto_prop_cached
    def twins(self) -> list[str]:
        """Both sides twins identity."""
        return [f['twins'] for f in self.frame]

    @auto_prop_cached
    def background(self) -> list[str]:
        """Both sides background identity."""
        return [f['background'] for f in self.frame]

    @auto_prop_cached
    def identity(self) -> list[str]:
        """Both sides frame accurate color identity."""
        return [f['identity'] for f in self.frame]

Functions

art_file() -> list[Path]

list[Path]: Two image files, second is appended during render process.

Source code in src\layouts.py
1240
1241
1242
1243
@auto_prop_cached
def art_file(self) -> list[Path]:
    """list[Path]: Two image files, second is appended during render process."""
    return [self.file['file']]

artist() -> str

Card artist name, use Scryfall raw data instead of 'card' data.

Source code in src\layouts.py
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
@auto_prop_cached
def artist(self) -> str:
    """Card artist name, use Scryfall raw data instead of 'card' data."""
    if self.file.get('artist'):
        return self.file['artist']

    # Check for duplicate last names
    artist, count = self.scryfall.get('artist', 'Unknown'), []
    if '&' in artist:
        for w in artist.split(' '):
            if w in count:
                count.remove(w)
            count.append(w)
        return ' '.join(count)
    return artist

background() -> list[str]

Both sides background identity.

Source code in src\layouts.py
1453
1454
1455
1456
@auto_prop_cached
def background(self) -> list[str]:
    """Both sides background identity."""
    return [f['background'] for f in self.frame]

card() -> list[dict]

Both side objects.

Source code in src\layouts.py
1250
1251
1252
1253
@auto_prop_cached
def card(self) -> list[dict]:
    """Both side objects."""
    return [c for c in self.scryfall.get('card_faces', [])]

color_identity() -> list

Color identity is shared by both halves, use raw Scryfall instead of 'card' data.

Source code in src\layouts.py
1259
1260
1261
1262
@auto_prop_cached
def color_identity(self) -> list:
    """Color identity is shared by both halves, use raw Scryfall instead of 'card' data."""
    return self.scryfall.get('color_identity', [])

color_indicator() -> str

Color indicator is shared by both halves, use raw Scryfall instead of 'card' data.

Source code in src\layouts.py
1264
1265
1266
1267
@auto_prop_cached
def color_indicator(self) -> str:
    """Color indicator is shared by both halves, use raw Scryfall instead of 'card' data."""
    return get_ordered_colors(self.scryfall.get('color_indicator', []))

display_name() -> str

Both side names.

Source code in src\layouts.py
1245
1246
1247
1248
@auto_prop_cached
def display_name(self) -> str:
    """Both side names."""
    return f"{self.name[0]} // {self.name[1]}"

flavor_text() -> list[str]

Both sides flavor text.

Source code in src\layouts.py
1415
1416
1417
1418
@auto_prop_cached
def flavor_text(self) -> list[str]:
    """Both sides flavor text."""
    return [c.get('flavor_text', '') for c in self.card]

frame() -> list[FrameDetails]

Both sides frame data.

Source code in src\layouts.py
1438
1439
1440
1441
@auto_prop_cached
def frame(self) -> list[FrameDetails]:
    """Both sides frame data."""
    return [get_frame_details(c) for c in self.card]

identity() -> list[str]

Both sides frame accurate color identity.

Source code in src\layouts.py
1458
1459
1460
1461
@auto_prop_cached
def identity(self) -> list[str]:
    """Both sides frame accurate color identity."""
    return [f['identity'] for f in self.frame]

is_colorless() -> list[bool]

Both sides colorless check.

Source code in src\layouts.py
1429
1430
1431
1432
@auto_prop_cached
def is_colorless(self) -> list[bool]:
    """Both sides colorless check."""
    return [f['is_colorless'] for f in self.frame]

is_hybrid() -> list[bool]

Both sides hybrid check.

Source code in src\layouts.py
1424
1425
1426
1427
@auto_prop_cached
def is_hybrid(self) -> list[bool]:
    """Both sides hybrid check."""
    return [f['is_hybrid'] for f in self.frame]

mana_cost() -> list[str]

Both side mana costs.

Source code in src\layouts.py
1396
1397
1398
1399
@auto_prop_cached
def mana_cost(self) -> list[str]:
    """Both side mana costs."""
    return [c.get('mana_cost', '') for c in self.card]

name() -> list[str]

Both side names.

Source code in src\layouts.py
1377
1378
1379
1380
1381
1382
@auto_prop_cached
def name(self) -> list[str]:
    """Both side names."""
    if self.is_alt_lang:
        return [c.get('printed_name', c.get('name', '')) for c in self.card]
    return [c.get('name', '') for c in self.card]

name_raw() -> str

Sanitized card name to use for rendered image file.

Source code in src\layouts.py
1384
1385
1386
1387
@auto_prop_cached
def name_raw(self) -> str:
    """Sanitized card name to use for rendered image file."""
    return f"{self.name[0]} _ {self.name[1]}"

oracle_text() -> list[str]

Both side oracle texts.

Source code in src\layouts.py
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
@auto_prop_cached
def oracle_text(self) -> list[str]:
    """Both side oracle texts."""
    text = []
    for t in [
        c.get('printed_text', c.get('oracle_text', ''))
        if self.is_alt_lang else c.get('oracle_text', '')
        for c in self.card
    ]:
        # Remove Fuse if present in oracle text data
        t = ''.join(t.split('\n')[:-1]) if 'Fuse' in self.keywords else t
        text.append(t)
    return text

pinlines() -> list[str]

Both sides pinlines identity.

Source code in src\layouts.py
1443
1444
1445
1446
@auto_prop_cached
def pinlines(self) -> list[str]:
    """Both sides pinlines identity."""
    return [f['pinlines'] for f in self.frame]

scryfall_scan() -> str

Scryfall large image scan, if available.

Source code in src\layouts.py
1273
1274
1275
1276
@auto_prop_cached
def scryfall_scan(self) -> str:
    """Scryfall large image scan, if available."""
    return self.scryfall.get('image_uris', {}).get('large', '')

twins() -> list[str]

Both sides twins identity.

Source code in src\layouts.py
1448
1449
1450
1451
@auto_prop_cached
def twins(self) -> list[str]:
    """Both sides twins identity."""
    return [f['twins'] for f in self.frame]

type_line() -> list[str]

Both side type lines.

Source code in src\layouts.py
1389
1390
1391
1392
1393
1394
@auto_prop_cached
def type_line(self) -> list[str]:
    """Both side type lines."""
    if self.is_alt_lang:
        return [c.get('printed_type_line', c.get('type_line', '')) for c in self.card]
    return [c.get('type_line', '') for c in self.card]

watermark() -> list[Optional[str]]

Name of the card's watermark file that is actually used, if provided.

Source code in src\layouts.py
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
@auto_prop_cached
def watermark(self) -> list[Optional[str]]:
    """Name of the card's watermark file that is actually used, if provided."""
    watermarks: list[Optional[str]] = []
    for wm in self.watermark_svg:
        if not wm:
            watermarks.append(None)
        elif wm.stem.upper() == 'WM':
            watermarks.append(wm.parent.stem.lower())
        else:
            watermarks.append(wm.stem.lower())
    return watermarks

watermark_raw() -> list[Optional[str]]

Name of the card's watermark from raw Scryfall data, if provided.

Source code in src\layouts.py
1315
1316
1317
1318
@auto_prop_cached
def watermark_raw(self) -> list[Optional[str]]:
    """Name of the card's watermark from raw Scryfall data, if provided."""
    return [c.get('watermark', '') for c in self.card]

watermark_svg() -> list[Optional[Path]]

Path to the watermark SVG file, if provided.

Source code in src\layouts.py
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
@auto_prop_cached
def watermark_svg(self) -> list[Optional[Path]]:
    """Path to the watermark SVG file, if provided."""
    def _find_watermark_svg(wm: str) -> Optional[Path]:
        """Try to find a watermark SVG asset, allowing for special cases and set code fallbacks.

        Args:
            wm: Watermark name or set code to look for.

        Returns:
            Path to a watermark SVG file if found, otherwise None.

        Notes:
            - 'set' maps to the symbol collection of the set this card was first printed in.
            - 'symbol' maps to the symbol collection of this card object's set.
        """
        if not wm:
            return
        wm = wm.lower()

        # Special case watermarks
        if wm in ['set', 'symbol']:
            return get_watermark_svg_from_set(
                self.first_print.get('set', self.set) if wm == 'set' else self.set)

        # Look for normal watermark
        return get_watermark_svg(wm)

    # Find a watermark SVG for each face
    watermarks = []
    for w in self.watermark_raw:
        if CFG.watermark_mode == WatermarkMode.Disabled:
            # Disabled Mode
            watermarks.append(None)
            continue
        elif CFG.watermark_mode == WatermarkMode.Forced:
            # Forced Mode
            watermarks.append(
                _find_watermark_svg(
                    CFG.watermark_default))
            continue
        else:
            # Automatic Mode
            path = _find_watermark_svg(w)
            if path or CFG.watermark_mode == WatermarkMode.Automatic:
                watermarks.append(path)
                continue
            # Fallback Mode
            watermarks.append(
                _find_watermark_svg(
                    CFG.watermark_default))
    return watermarks