Skip to content

Commit

Permalink
ADD identifiers.mtgjsonV4Id for help translating. Fix mtgjson#613
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeldaZach committed Jul 8, 2020
1 parent 728fba0 commit b112aab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions mtgjson5/classes/mtgjson_identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class MtgjsonIdentifiersObject:
scryfall_illustration_id: Optional[str]
scryfall_oracle_id: Optional[str]
tcgplayer_product_id: Optional[str]
mtgjson_v4_id: Optional[str]

def __init__(self) -> None:
"""
Expand Down
28 changes: 23 additions & 5 deletions mtgjson5/set_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,34 +484,52 @@ def add_leadership_skills(mtgjson_card: MtgjsonCardObject) -> None:
def add_uuid(mtgjson_card: MtgjsonCardObject) -> None:
"""
Construct a UUIDv5 for each MTGJSON card object
This will also add UUIDv4 for legacy support
:param mtgjson_card: Card object
"""

if {"Token", "Card"}.intersection(mtgjson_card.types):
# Tokens have a special generation method
id_source = (
id_source_v5 = (
mtgjson_card.name
+ (mtgjson_card.face_name or "")
+ "".join((mtgjson_card.colors or ""))
+ (mtgjson_card.power or "")
+ (mtgjson_card.toughness or "")
+ (mtgjson_card.side or "")
+ mtgjson_card.set_code[1:]
+ mtgjson_card.set_code[1:].lower()
+ (mtgjson_card.identifiers.scryfall_id or "")
+ (mtgjson_card.identifiers.scryfall_illustration_id or "")
)

id_source_v4 = (
mtgjson_card.name
+ "".join((mtgjson_card.colors or ""))
+ (mtgjson_card.power or "")
+ (mtgjson_card.toughness or "")
+ (mtgjson_card.side or "")
+ mtgjson_card.set_code[1:].upper()
+ (mtgjson_card.identifiers.scryfall_id or "")
)
else:
# Normal cards only need a few pieces of data
id_source = (
id_source_v5 = (
ScryfallProvider().get_class_id()
+ (mtgjson_card.identifiers.scryfall_id or "")
+ (mtgjson_card.identifiers.scryfall_illustration_id or "")
+ mtgjson_card.set_code
+ mtgjson_card.set_code.lower()
+ mtgjson_card.name
+ (mtgjson_card.face_name or "")
)

mtgjson_card.uuid = str(uuid.uuid5(uuid.NAMESPACE_DNS, id_source))
id_source_v4 = (
"sf" + (mtgjson_card.identifiers.scryfall_id or "") + mtgjson_card.name
)

mtgjson_card.uuid = str(uuid.uuid5(uuid.NAMESPACE_DNS, id_source_v5))
mtgjson_card.identifiers.mtgjson_v4_id = str(
uuid.uuid5(uuid.NAMESPACE_DNS, id_source_v4)
)


def build_mtgjson_card(
Expand Down

0 comments on commit b112aab

Please sign in to comment.