Skip to content

Commit

Permalink
add collectible, update generation script
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencatro committed Feb 3, 2019
1 parent efc1a2f commit 9d0c861
Show file tree
Hide file tree
Showing 10 changed files with 1,873 additions and 1,839 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,13 @@ or
from mtga.set_data import all_mtga_cards
print(all_mtga_cards.find_one("63773"))
# <Card: 'Torrential Gearhulk' ['Blue'] KLD 63773>
```

## Deploying

Because I always forget:

```bash
python setup.py sdist bdist_wheel
twine upload dist/MTGA-<version>*
```
17 changes: 14 additions & 3 deletions script/generate_set_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def generate_set_map(loc, cards, enums, set_name):
set_cards = [card for card in cards if card["set"].upper() == set_name.upper()]
assert set_cards, "No cards found in set {}. Double check your nomenclature, and ensure the input files contain your set!"

token_count = 1

print("translating {} cards from set {}".format(len(set_cards), set_name))
output_lines = []
for card in set_cards:
Expand All @@ -70,6 +72,7 @@ def generate_set_map(loc, cards, enums, set_name):
# cc's look like: o2o(U/B)o(U/B)o3oUoB, want to turn it into ["2", "(U/B)"] etc
cost = [cost_part for cost_part in cc_raw.split("o")[1:] if cost_part != "0"]
color_identity = [COLOR_ID_MAP[color_id] for color_id in card["colorIdentity"]]
collectible = card["isCollectible"]

card_type_ids = [enum_map["CardType"][card_type] for card_type in card["types"]]
card_types = " ".join([loc_map[loc_id] for loc_id in card_type_ids])
Expand All @@ -81,7 +84,14 @@ def generate_set_map(loc, cards, enums, set_name):

rarity = RARITY_ID_MAP[card["rarity"]]

set_number = int(card["CollectorNumber"])
if card["isToken"]:
set_number = token_count + 10000
token_count += 1
else:
if card["CollectorNumber"].startswith("GR"):
set_number = int(card["CollectorNumber"][2]) * 1000
else:
set_number = int(card["CollectorNumber"])

grp_id = card["grpid"]
abilities = []
Expand All @@ -99,7 +109,7 @@ def generate_set_map(loc, cards, enums, set_name):
# name, pretty_name, cost, color_identity, card_type, sub_types, set_id, rarity, set_number, mtga_id
new_card_str = '{} = Card(name="{}", pretty_name="{}", cost={},\n' \
'{{}}color_identity={}, card_type="{}", sub_types="{}",\n' \
'{{}}abilities={}, set_id="{}", rarity="{}", set_number={},\n' \
'{{}}abilities={}, set_id="{}", rarity="{}", collectible={}, set_number={},\n' \
'{{}}mtga_id={})'.format(
card_name_class_cased_suffixed,
card_name_snake_cased,
Expand All @@ -111,6 +121,7 @@ def generate_set_map(loc, cards, enums, set_name):
abilities,
set_id,
rarity,
collectible,
set_number,
grp_id
).format(" "*indentation_length, " "*indentation_length, " "*indentation_length)
Expand Down Expand Up @@ -156,6 +167,6 @@ def generate_set_map(loc, cards, enums, set_name):
generate_set_map(loc, cards, enums, args.set)
else:
print("generating all sets!")
known_sets = ["ana", "dar", "grn", "m19", "rix", "xln"]
known_sets = ["ana", "dar", "grn", "m19", "rix", "xln", "rna"]
for card_set in known_sets:
generate_set_map(loc, cards, enums, card_set)
3 changes: 2 additions & 1 deletion source/mtga/models/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class Card(object):

def __init__(self, name="", pretty_name="", cost=None, color_identity=None, card_type="", sub_types="",
abilities=None, set_id="", rarity="", set_number=-1, mtga_id=-1):
abilities=None, set_id="", rarity="", collectible=True, set_number=-1, mtga_id=-1):
self.name = name
self.set = set_id
self.pretty_name = pretty_name
Expand All @@ -24,6 +24,7 @@ def __init__(self, name="", pretty_name="", cost=None, color_identity=None, card
self.set_number = set_number
self.mtga_id = mtga_id
self.rarity = rarity
self.collectible = collectible
if abilities is None:
abilities = []
self.abilities = abilities
Expand Down
118 changes: 63 additions & 55 deletions source/mtga/set_data/ana.py

Large diffs are not rendered by default.

600 changes: 302 additions & 298 deletions source/mtga/set_data/dom.py

Large diffs are not rendered by default.

625 changes: 313 additions & 312 deletions source/mtga/set_data/grn.py

Large diffs are not rendered by default.

661 changes: 330 additions & 331 deletions source/mtga/set_data/m19.py

Large diffs are not rendered by default.

438 changes: 219 additions & 219 deletions source/mtga/set_data/rix.py

Large diffs are not rendered by default.

610 changes: 305 additions & 305 deletions source/mtga/set_data/rna.py

Large diffs are not rendered by default.

631 changes: 316 additions & 315 deletions source/mtga/set_data/xln.py

Large diffs are not rendered by default.

0 comments on commit 9d0c861

Please sign in to comment.