Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add power and toughness to card model. #21

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions source/mtga/models/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
class Card(object):

def __init__(self, name="", pretty_name="", cost=None, color_identity=None, card_type="", sub_types="",
abilities=None, set_id="", rarity="", collectible=True, set_number=-1, mtga_id=-1):
abilities=None, set_id="", rarity="", collectible=True, set_number=-1, mtga_id=-1,
power=None, toughness=None):
self.name = name
self.set = set_id
self.pretty_name = pretty_name
Expand All @@ -28,6 +29,8 @@ def __init__(self, name="", pretty_name="", cost=None, color_identity=None, card
if abilities is None:
abilities = []
self.abilities = abilities
self.power = power
self.toughness = toughness

@property
def abilities_decoded(self):
Expand Down Expand Up @@ -104,8 +107,8 @@ def __str__(self):

class GameCard(Card):

def __init__(self, name, pretty_name, cost, color_identity, card_type, sub_types, set_id, rarity, set_number, mtga_id, owner_seat_id, game_id=-1):
super().__init__(name, pretty_name, cost, color_identity, card_type, sub_types, set_id, rarity, set_number, mtga_id)
def __init__(self, name, pretty_name, cost, color_identity, card_type, sub_types, set_id, rarity, set_number, mtga_id, owner_seat_id, game_id=-1, power=None, toughness=None):
super().__init__(name, pretty_name, cost, color_identity, card_type, sub_types, set_id, rarity, set_number, mtga_id, power, toughness)
self.game_id = game_id
self.previous_iids = []
self.owner_seat_id = owner_seat_id
Expand Down
16 changes: 10 additions & 6 deletions source/mtga/set_data/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ def _get_data_location_hardcoded():

def get_data_location():
current_os = sys.platform
if current_os not in ["darwin", "win32"]:
if current_os not in ["darwin", "win32", "linux"]:
raise

return {
"darwin": get_darwin_data_location,
"win32": get_win_data_location,
"linux": get_win_data_location,
}[current_os]()

def get_darwin_data_location():
Expand Down Expand Up @@ -146,10 +147,10 @@ def get_win_data_location():
token_count += 1
else:
try:
if card["CollectorNumber"].startswith("GR") or card["CollectorNumber"].startswith("GP"):
set_number = int(card["CollectorNumber"][2]) * 1000
if card["collectorNumber"].startswith("GR") or card["collectorNumber"].startswith("GP"):
set_number = int(card["collectorNumber"][2]) * 1000
else:
set_number = int(card["CollectorNumber"])
set_number = int(card["collectorNumber"])
except ValueError:
set_number = card["grpid"]

Expand All @@ -169,15 +170,18 @@ def get_win_data_location():
abilities.append(aid)
all_abilities[aid] = text

power = card["power"]
toughness = card["toughness"]

new_card_obj = Card(name=card_name_snake_cased, pretty_name=card_title, cost=cost,
color_identity=color_identity, card_type=card_types, sub_types=sub_types,
abilities=abilities, set_id=set_id, rarity=rarity, collectible=collectible,
set_number=set_number, mtga_id=grp_id)
set_number=set_number, mtga_id=grp_id, power=power, toughness=toughness)
set_card_objs.append(new_card_obj)

except Exception:
print("hit an error on {} / {} / {}".format(card["grpid"], loc_map[card["titleId"]],
card["CollectorNumber"]))
card["collectorNumber"]))
# raise
card_set_obj = Set(set_name_class_cased, cards=set_card_objs)
dynamic_set_tuples.append((card_set_obj, all_abilities))
Expand Down