+++ /dev/null
-#!/usr/bin/python
-
-import json
-import urllib
-import os
-import time
-
-import logging
-import operator
-from collections import defaultdict
-
-
-class App:
- def __init__(self):
- self.settings = self.load_settings()
-
- self.download_images()
-
- def load_settings(self, path='settings.json'):
- logging.debug('loading settings from %s', path)
-
- settings = {
- 'last_card_json_update': 0,
- 'last_card_img_update': 0}
-
- try:
- with open(path) as f:
- settings.update(json.load(f))
- except:
- logging.debug('could not load settings, using defaults')
- self.save_settings(settings)
-
- return settings
-
- def save_settings(self, settings={}, path='settings.json'):
- logging.debug('saving %s', path)
-
- try:
- with open(path, 'w') as f:
- json.dump(settings, f, sort_keys=True, indent=4, separators=(',', ': '))
- except:
- logging.exception('failed')
-
- def download_images(self):
- queue = []
- for card in CARDDB.all():
- path = 'img/cards/%s.jpg' % card['id']
- path_boosted = 'img/cards/%sb.jpg' % card['id']
-
- if not os.path.isfile(path):
- queue += [path]
-
- if card.get('type') == 'Mane' and not os.path.isfile(path_boosted):
- queue += [path_boosted]
-
- logging.debug('downloading %d card images', len(queue))
-
- for path in queue:
- try:
- urllib.urlretrieve('http://ponyhead.com/%s' % path, path)
- except KeyError:
- logging.exception('failed: %s', path)
-
- def new_game(self, teams):
- self.game = Game(teams=teams)
-
-
-class Action:
- def __init__(self, obj):
- self.obj = obj
-
- def do(self):
- raise NotImplementedError
-
- def undo(self):
- raise NotImplementedError
-
-class Pass(Action): pass
-class Move(Action): pass
-class Draw(Action): pass
-class Play(Action): pass
-
-class Card:
- uid_counter = 0
-
- def __init__(self, **kwargs):
- self.uid = Card.uid_counter
- Card.uid_counter += 1
-
- self.tags = []
- self.__dict__.update(kwargs)
- self.name = self.title + (', ' + self.subtitle if self.__dict__.get('subtitle') is not None else '')
-
- def __repr__(self):
- return "#%d %s (%s)" % (self.uid, self.name, ','.join(self.tags))
-
- def tag(self, tag):
- self.tags += [tag]
-
-
-class Player:
- def __init__(self, id, team, decklist):
- self.id = id
- self.team = team
- self.at = 0
- self.points = 0
- self.decklist = decklist
-
-class Game:
- def __init__(self, players):
- self.players = players
- self.running = True
- self.cards = []
-
- for player in self.players:
- tag_owner = 'owner=%d' % player.id
- tag_controller = 'controller=%d' % player.id
-
- for card_id in player.decklist.cards:
- card = Card(tags=[tag_owner, tag_controller], **CARDDB.by_id(card_id))
-
- self.cards += [card]
-
- print self.cards
-
-
-if __name__ == '__main__':
- logging.basicConfig(
- format='%(asctime)s %(levelname)s %(message)s',
- datefmt='%H:%M:%S',
- level=logging.DEBUG)
-
- APP = App()
-
- game = Game(players=(
- Player(id=1, team=1, decklist=DeckList(xml='deck.xml')),
- Player(id=2, team=2, decklist=DeckList(xml='deck.xml'))))