support for double faced cards... sort of

This commit is contained in:
Holly McFarland 2021-03-09 11:12:59 -05:00
parent 5cb52b90c5
commit 8d34e3c7d4
2 changed files with 40 additions and 2 deletions

25
face.py Normal file
View File

@ -0,0 +1,25 @@
# Double face cards have to be treated ENTIRELY DIFFERENTLY
# Instead of card objects we just get a list of two dictionaries.
# I've decided to try to reuse at much code as possible by jerryrigging
# my own Face object that can be passed into my card parsing logic
class Face:
def __init__(self, d):
self.d = d
def name(self):
return self.d['name']
def mana_cost(self):
return self.d['mana_cost']
def type_line(self):
return self.d['type_line']
def oracle_text(self):
return self.d['oracle_text']
def power(self):
return self.d['power']
def toughness(self):
return self.d['toughness']

View File

@ -15,6 +15,8 @@ import scrython
import nest_asyncio import nest_asyncio
nest_asyncio.apply() nest_asyncio.apply()
import face
from debug import * from debug import *
async def startup(): async def startup():
@ -48,6 +50,17 @@ async def get_cards(card_names):
return image return image
def get_text_representation(c): def get_text_representation(c):
try:
# Double face cards have to be treated ENTIRELY DIFFERENTLY
# Instead of card objects we just get a list of two dictionaries.
# I've decided to try to reuse at much code as possible by jerryrigging
# my own Face object that can be passed into my card parsing logic
return '\n\n//\n\n'.join((
get_text_representation(face.Face(card_face)) for card_face in c.card_faces()
))
except:
pass
# I genuinely think this is the best way to check whether a card has # I genuinely think this is the best way to check whether a card has
# power/toughness, considering how Scrython is implemented. # power/toughness, considering how Scrython is implemented.
# Can't even check for Creature type because of stuff like Vehicles. # Can't even check for Creature type because of stuff like Vehicles.