10 from collections
import defaultdict
15 self
.settings
= self
.load_settings()
17 self
.download_images()
19 def load_settings(self
, path
='settings.json'):
20 logging
.debug('loading settings from %s', path
)
23 'last_card_json_update': 0,
24 'last_card_img_update': 0}
28 settings
.update(json
.load(f
))
30 logging
.debug('could not load settings, using defaults')
31 self
.save_settings(settings
)
35 def save_settings(self
, settings
={}, path
='settings.json'):
36 logging
.debug('saving %s', path
)
39 with
open(path
, 'w') as f
:
40 json
.dump(settings
, f
, sort_keys
=True, indent
=4, separators
=(',', ': '))
42 logging
.exception('failed')
44 def download_images(self
):
46 for card
in CARDDB
.all():
47 path
= 'img/cards/%s.jpg' % card
['id']
48 path_boosted
= 'img/cards/%sb.jpg' % card
['id']
50 if not os
.path
.isfile(path
):
53 if card
.get('type') == 'Mane' and not os
.path
.isfile(path_boosted
):
54 queue
+= [path_boosted
]
56 logging
.debug('downloading %d card images', len(queue
))
60 urllib
.urlretrieve('http://ponyhead.com/%s' % path
, path
)
62 logging
.exception('failed: %s', path
)
64 def new_game(self
, teams
):
65 self
.game
= Game(teams
=teams
)
69 def __init__(self
, obj
):
73 raise NotImplementedError
76 raise NotImplementedError
78 class Pass(Action
): pass
79 class Move(Action
): pass
80 class Draw(Action
): pass
81 class Play(Action
): pass
86 def __init__(self
, **kwargs
):
87 self
.uid
= Card
.uid_counter
91 self
.__dict
__.update(kwargs
)
92 self
.name
= self
.title
+ (', ' + self
.subtitle
if self
.__dict
__.get('subtitle') is not None else '')
95 return "#%d %s (%s)" % (self
.uid
, self
.name
, ','.join(self
.tags
))
102 def __init__(self
, id, team
, decklist
):
107 self
.decklist
= decklist
110 def __init__(self
, players
):
111 self
.players
= players
115 for player
in self
.players
:
116 tag_owner
= 'owner=%d' % player
.id
117 tag_controller
= 'controller=%d' % player
.id
119 for card_id
in player
.decklist
.cards
:
120 card
= Card(tags
=[tag_owner
, tag_controller
], **CARDDB
.by_id(card_id
))
127 if __name__
== '__main__':
129 format
='%(asctime)s %(levelname)s %(message)s',
135 game
= Game(players
=(
136 Player(id=1, team
=1, decklist
=DeckList(xml
='deck.xml')),
137 Player(id=2, team
=2, decklist
=DeckList(xml
='deck.xml'))))