Beispiel #1
0
def name_from_card_description(c: CardDescription) -> str:
    if c['layout'] in [
            'transform', 'flip', 'adventure'
    ]:  # 'meld' has 'all_parts' not 'card_faces' so does not need to be included here despite having very similar behavior.
        return c['card_faces'][0]['name']
    if c.get('card_faces'):
        return ' // '.join([f['name'] for f in c.get('card_faces', [])])
    return c['name']
Beispiel #2
0
def is_meld_result(p: CardDescription) -> bool:
    all_parts = p.get('all_parts')
    if all_parts is None or not p['layout'] == 'meld':
        return False
    meld_result_name = next(part['name'] for part in all_parts
                            if part['component'] == 'meld_result')
    return p['name'] == meld_result_name
Beispiel #3
0
def meld_face_values(p: CardDescription,
                     cards: Dict[str, int]) -> List[Dict[str, Any]]:
    values = []
    all_parts = p.get('all_parts')
    if all_parts is None:
        raise InvalidArgumentException(
            f'Tried to insert_meld_result_faces on a card without all_parts: {p}'
        )
    front_face_names = [
        part['name'] for part in all_parts if part['component'] == 'meld_part'
    ]
    card_ids = [cards[name] for name in front_face_names]
    for card_id in card_ids:
        values.append(single_face_value(p, card_id, 2))
    return values
Beispiel #4
0
def multiple_faces_values(p: CardDescription,
                          card_id: int) -> List[Dict[str, Any]]:
    card_faces = p.get('card_faces')
    if card_faces is None:
        raise InvalidArgumentException(
            f'Tried to insert_card_faces on a card without card_faces: {p} ({card_id})'
        )
    first_face_cmc = mana.cmc(card_faces[0]['mana_cost'])
    position = 1
    face_values = []
    for face in card_faces:
        # Scryfall doesn't provide cmc on card_faces currently. See #5939.
        face['cmc'] = mana.cmc(
            face['mana_cost']) if face['mana_cost'] else first_face_cmc
        face_values.append(single_face_value(face, card_id, position))
        position += 1
    return face_values
Beispiel #5
0
def printing_value(p: CardDescription, card_id: int, set_id: int,
                   rarity_id: int) -> Dict[str, Any]:
    # pylint: disable=too-many-locals
    if not card_id or not set_id:
        raise InvalidDataException(
            f'Cannot insert printing without card_id and set_id: {card_id}, {set_id}, {p}'
        )
    result: Dict[str, Any] = {}
    result['card_id'] = card_id
    result['set_id'] = set_id
    result['rarity_id'] = rarity_id
    result['system_id'] = p.get('id')
    result['flavor'] = p.get('flavor_text')
    result['artist'] = p.get('artist')
    result['number'] = p.get('collector_number')
    result['watermark'] = p.get('watermark')
    result['reserved'] = 1 if p.get(
        'reserved') else 0  # replace True and False with 1 and 0
    return result
Beispiel #6
0
def single_face_value(p: CardDescription,
                      card_id: int,
                      position: int = 1) -> Dict[str, Any]:
    if not card_id:
        raise InvalidDataException(
            f'Cannot insert a face without a card_id: {p}')
    result: Dict[str, Any] = {}
    result['card_id'] = card_id
    result['name'] = p['name']  # always present in scryfall
    result['mana_cost'] = p['mana_cost']  # always present in scryfall
    result['cmc'] = p['cmc']  # always present
    result['power'] = p.get('power')
    result['toughness'] = p.get('toughness')
    result['loyalty'] = p.get('loyalty')
    result['type_line'] = p.get('type_line', '')
    result['oracle_text'] = p.get('oracle_text', '')
    result['hand'] = p.get('hand_modifier')
    result['life'] = p.get('life_modifier')
    result['position'] = position
    return result