2 # -*- coding: utf-8 -*-
11 from collections
import defaultdict
13 from mlpccg
.DeckList
import DeckList
14 from mlpccg
.CardDb
import CARDDB
18 self
.settings
= self
.load_settings()
20 # self.download_images()
22 def load_settings(self
, path
='settings.json'):
23 logging
.debug('loading settings from %s', path
)
26 'last_card_json_update': 0,
27 'last_card_img_update': 0}
31 settings
.update(json
.load(f
))
33 logging
.debug('could not load settings, using defaults')
34 self
.save_settings(settings
)
38 def save_settings(self
, settings
={}, path
='settings.json'):
39 logging
.debug('saving %s', path
)
42 with
open(path
, 'w') as f
:
43 json
.dump(settings
, f
, sort_keys
=True, indent
=4, separators
=(',', ': '))
45 logging
.exception('failed')
47 def download_images(self
):
49 for card
in CARDDB
.all():
50 path
= 'img/cards/%s.jpg' % card
['id']
51 path_boosted
= 'img/cards/%sb.jpg' % card
['id']
53 if not os
.path
.isfile(path
):
56 if card
.get('type') == 'Mane' and not os
.path
.isfile(path_boosted
):
57 queue
+= [path_boosted
]
59 logging
.debug('downloading %d card images', len(queue
))
63 urllib
.urlretrieve('http://ponyhead.com/%s' % path
, path
)
65 logging
.exception('failed: %s', path
)
67 def new_game(self
, teams
):
68 self
.game
= Game(teams
=teams
)
72 def __init__(self
, obj
):
76 raise NotImplementedError
79 raise NotImplementedError
81 class Pass(Action
): pass
82 class Move(Action
): pass
83 class Draw(Action
): pass
84 class Play(Action
): pass
89 def __init__(self
, **kwargs
):
90 self
.uid
= Card
.uid_counter
93 self
.__dict
__.update(kwargs
)
94 # self.name = self.title + (', ' + self.subtitle if self.__dict__.get('subtitle') is not None else '')
97 return "#%d %s" % (self
.uid
, self
.title
.encode('utf-8'))
100 def __init__(self
, id, team
, decklist
):
105 self
.decklist
= decklist
108 def __init__(self
, players
):
109 self
.players
= players
112 for player
in self
.players
:
113 for card_data
in player
.decklist
.cards
:
114 card
= Card(owner
=player
.id, controller
=player
.id, **CARDDB
.by_id(card_data
['id']))
116 self
.cards
[card
.uid
] = card
118 if __name__
== '__main__':
120 format
='%(asctime)s %(levelname)s %(message)s',
126 game
= Game(players
=(
127 Player(id=1, team
=1, decklist
=DeckList(url
='http://ponyhead.com/deckbuilder?v1code=pr206x3-cn185x2-pr79x3-pr161x1-pr108x3-cn117x2-pr165x1-pr85x3-pr82x3-pr83x3-pr163x2-cn80x3-cn86x3-pr67x1-pr194x2-cn7x1-pr130x3-pr118x3-pr179x2-pr94x3-pr11x3-cn95x3-cn98x3')),
128 Player(id=2, team
=2, decklist
=DeckList(url
='http://ponyhead.com/deckbuilder?v1code=pr127x1-cn185x2-pr79x3-cn75x3-pr167x2-pr163x2-cn21x1-pr67x3-pr198x1-cn191x1-pr206x3-pr118x3-pr171x2-pr151x3-pr176x2-cn1x1-pr152x3-pr115x3-pr117x3-pr11x3-pr10x3-pr13x3-pr14x2-pr19x3'))))