def OnListActivate(self, event): cdid = self.cardMap[self.lstCards.GetItemData(event.GetIndex())] card = database.get()[cdid] isStronghold = False if card.type == "stronghold": isStronghold = True self.AddCard(cdid, inPlay = isStronghold)
def oldload(cls, fp): """Read a deck from a list of strings (or a file-like object) and parse it. Returns a deck object. """ foundInPlay = True cardErrors=[] cardDB = database.get() deck = Deck() for c in fp: if '# Dynasty' in c: foundInPlay = False if not c.startswith('#') and c.strip() != '': (count, cardname) = c.strip().split(' ', 1) cardname = cardname.strip() if foundInPlay: print '%s starts in play.' % (cardname) try: deck.cards.append((int(count), cardDB.FindCardByName(cardname).id, foundInPlay)) except (ValueError, KeyError): cardErrors.append(cardname) if len(cardErrors) >0: raise LoadCardsNotFoundError(cardErrors, deck) return deck
def OnListActivate(self, event): cdid = self.cardMap[self.lstCards.GetItemData(event.GetIndex())] card = database.get()[cdid] isStronghold = False if card.type == "stronghold": isStronghold = True self.AddCard(cdid, inPlay=isStronghold)
def UpdateCards(self): filter = self.panelFilters.GetFilter() self.cardMap = [] self.lstCards.DeleteAllItems() for card in database.get(): if not filter(card): continue idx = self.lstCards.InsertStringItem(self.CARDLIST_COL_NAME, card.name) #self.lstCards.SetStringItem(idx, self.CARDLIST_COL_ID, card.id) self.lstCards.SetStringItem(idx, self.CARDLIST_COL_TYPE, card.type.capitalize()) # Type self.lstCards.SetStringItem(idx, self.CARDLIST_COL_CLANS, ', '.join(clan.capitalize() for clan in card.clans)) # Clans self.lstCards.SetStringItem(idx, self.CARDLIST_COL_COST, card.cost) # Cost if card.type in ['personality', 'item', 'follower', 'ancestor']: self.lstCards.SetStringItem(idx, self.CARDLIST_COL_FORCECHI, '%sF/%sC' % (card.force, card.chi)) self.lstCards.SetStringItem(idx, self.CARDLIST_COL_PH, card.personal_honor) self.lstCards.SetStringItem(idx, self.CARDLIST_COL_HR, card.honor_req) #ctext = re.sub('< */? *\w+ */?\ *>', '', card.text.replace('<br>', '\n')) #self.lstCards.SetStringItem(idx, self.CARDLIST_COL_TEXT, ctext) # Text -- simple regex to strip simple HTML self.lstCards.SetStringItem(idx, self.CARDLIST_COL_FOCUS, card.focus) self.lstCards.SetItemData(idx, len(self.cardMap)) self.cardMap.append(card.id) self.lstCards.SortItems(CardNameSorter(self.cardMap))
def Add(self, cdid, num=1, inPlay=False): card = database.get()[cdid] if card.type == 'stronghold': inPlay = True elif card.isSensei(): inPlay = True elif card.isWind(): inPlay = True if inPlay==True: widget = self.lstInPlay else: if card.isDynasty(): widget = self.lstDynasty else: # Note that strongholds end up here despite being neither. widget = self.lstFate # Make sure the cdid exists in the card map. try: mapidx = self.cardMap.index(cdid) except ValueError: mapidx = len(self.cardMap) self.cardMap.append(cdid) # See if we already have an entry. idx = widget.FindItemData(-1, mapidx) if idx != -1: widget.SetStringItem(idx, 0, str(int(widget.GetItemText(idx)) + num)) else: self.ListAddCard(widget, card, mapidx, num)
def Add(self, cdid, num=1, inPlay=False): card = database.get()[cdid] if card.type == 'stronghold': inPlay = True elif card.isSensei(): inPlay = True elif card.isWind(): inPlay = True if inPlay == True: widget = self.lstInPlay else: if card.isDynasty(): widget = self.lstDynasty else: # Note that strongholds end up here despite being neither. widget = self.lstFate # Make sure the cdid exists in the card map. try: mapidx = self.cardMap.index(cdid) except ValueError: mapidx = len(self.cardMap) self.cardMap.append(cdid) # See if we already have an entry. idx = widget.FindItemData(-1, mapidx) if idx != -1: widget.SetStringItem(idx, 0, str(int(widget.GetItemText(idx)) + num)) else: self.ListAddCard(widget, card, mapidx, num)
def UpdateCards(self): filter = self.panelFilters.GetFilter() self.cardMap = [] self.lstCards.DeleteAllItems() for card in database.get(): if not filter(card): continue idx = self.lstCards.InsertStringItem(self.CARDLIST_COL_NAME, card.name) #self.lstCards.SetStringItem(idx, self.CARDLIST_COL_ID, card.id) self.lstCards.SetStringItem(idx, self.CARDLIST_COL_TYPE, card.type.capitalize()) # Type self.lstCards.SetStringItem( idx, self.CARDLIST_COL_CLANS, ', '.join(clan.capitalize() for clan in card.clans)) # Clans self.lstCards.SetStringItem(idx, self.CARDLIST_COL_COST, card.cost) # Cost if card.type in ['personality', 'item', 'follower', 'ancestor']: self.lstCards.SetStringItem(idx, self.CARDLIST_COL_FORCECHI, '%sF/%sC' % (card.force, card.chi)) self.lstCards.SetStringItem(idx, self.CARDLIST_COL_PH, card.personal_honor) self.lstCards.SetStringItem(idx, self.CARDLIST_COL_HR, card.honor_req) #ctext = re.sub('< */? *\w+ */?\ *>', '', card.text.replace('<br>', '\n')) #self.lstCards.SetStringItem(idx, self.CARDLIST_COL_TEXT, ctext) # Text -- simple regex to strip simple HTML self.lstCards.SetStringItem(idx, self.CARDLIST_COL_FOCUS, card.focus) self.lstCards.SetItemData(idx, len(self.cardMap)) self.cardMap.append(card.id) self.lstCards.SortItems(CardNameSorter(self.cardMap))
def Remove(self, cdid, num=1, inPlay=False): try: card = database.get()[cdid] except KeyError: return if inPlay == True: widget = self.lstInPlay else: if card.isDynasty(): widget = self.lstDynasty else: widget = self.lstFate try: mapidx = self.cardMap.index(cdid) except ValueError: return # It can't possibly be in our decks. idx = widget.FindItemData(-1, mapidx) if idx != -1: newcount = int(widget.GetItemText(idx)) - num if newcount <= 0: widget.DeleteItem(idx) self.lastCardId = None else: widget.SetStringItem(idx, 0, str(newcount))
def Remove(self, cdid, num=1, inPlay=False): try: card = database.get()[cdid] except KeyError: return if inPlay==True: widget = self.lstInPlay else: if card.isDynasty(): widget = self.lstDynasty else: widget = self.lstFate try: mapidx = self.cardMap.index(cdid) except ValueError: return # It can't possibly be in our decks. idx = widget.FindItemData(-1, mapidx) if idx != -1: newcount = int(widget.GetItemText(idx)) - num if newcount <= 0: widget.DeleteItem(idx) self.lastCardId = None else: widget.SetStringItem(idx, 0, str(newcount))
def NumFate(self): """Return the number of fate cards in the deck.""" cardDB = database.get() return sum([ count for count, id, inplay in self.cards if ((inplay != True) and (cardDB[id].isFate())) ])
def oldload(cls, fp): """Read a deck from a list of strings (or a file-like object) and parse it. Returns a deck object. """ foundInPlay = True cardErrors = [] cardDB = database.get() deck = Deck() for c in fp: if '# Dynasty' in c: foundInPlay = False if not c.startswith('#') and c.strip() != '': (count, cardname) = c.strip().split(' ', 1) cardname = cardname.strip() if foundInPlay: print '%s starts in play.' % (cardname) try: deck.cards.append( (int(count), cardDB.FindCardByName(cardname).id, foundInPlay)) except (ValueError, KeyError): cardErrors.append(cardname) if len(cardErrors) > 0: raise LoadCardsNotFoundError(cardErrors, deck) return deck
def SetCard(self, cdid): try: self.previewCard = database.get()[cdid] self.previewFacedown = False except KeyError: self.previewCard = None self.Refresh()
def SetCard(self, cdid): try: self.previewCard = database.get()[cdid]; self.previewFacedown = False except KeyError: self.previewCard = None self.Refresh()
def UpdateStatus(self): cardDB = database.get() self.SetStatusText('%d Fate/%d Dynasty' % (self.deck.NumFate(), self.deck.NumDynasty()), 1) self.SetStatusText('%d Holdings' % sum([num for num, c, inplay in self.deck if cardDB[c].type == "holding"]), 2) if self.deckName is not None: self.SetTitle(MAIN_TITLE + ' - %s%s' % (self.deckName, '*' if self.deck.modified else '')) else: self.SetTitle(MAIN_TITLE)
def categoryItemsJSON(categoryId): """Returns a JSON object representing a category and its items. Args: categoryId : The id of the category we want to retrieve. Returns : JSON object representing a category and its items. """ category = getOne(Category, 'id', categoryId) items = get(Item, 'categoryId', categoryId) return jsonify(category.serialize, items=[i.serialize for i in items])
def hello(): params = {} params["subreddit"] = request.args.get('subreddit') params["from_time"] = request.args.get('from') params["to_time"] = request.args.get('to') if params["subreddit"] is None or params["from_time"] is None or params["to_time"] is None: return "{\"error\": \"Operation failed\"}" if not ( params["from_time"].isdigit() and params["to_time"].isdigit() ): return "{\"error\": \"Operation failed\"}" params["keyword"] = request.args.get('keyword') res = database.get(params) return "<pre>"+dumps(list(res), indent=2, separators=(',', ':'))+"</pre>"
def item(itemId): """Returns a page for a specified item. Retrieves a specified item renders the item's webpage. Args: itemId : the id of the item to display. Returns : Returns a HTTP response with the item template. """ item = get(Item, "id", itemId)[0] return render('item.html', title=item.category.name, titleUrl=url_for('category', categoryId=item.category.id), item=item)
def UpdateStatus(self): cardDB = database.get() self.SetStatusText( '%d Fate/%d Dynasty' % (self.deck.NumFate(), self.deck.NumDynasty()), 1) self.SetStatusText( '%d Holdings' % sum([ num for num, c, inplay in self.deck if cardDB[c].type == "holding" ]), 2) if self.deckName is not None: self.SetTitle(MAIN_TITLE + ' - %s%s' % (self.deckName, '*' if self.deck.modified else '')) else: self.SetTitle(MAIN_TITLE)
def category(categoryId): """Returns a page for a specified category. Retrieves items belonging to the specified category and renders them as the category's page. Args: categoryId : the id of the category to display. Returns : Returns a HTTP response with the category template. """ items = get(Item, "categoryId", categoryId) category = getOne(Category, "id", categoryId).name return render('category.html', title=category, items=items)
def loadFromClipboard(cls, data): #set up a holder for unknown cards cardErrors = [] importLineHeaders = [ 'stronghold', 'dynasty', 'holdings', 'regions', 'personalities', 'events', 'celestials', 'fate', 'strategies', 'spells', 'items', 'followers', 'rings' ] cardDB = database.get() deck = Deck() #Look for a card line, not a header, not a space, and not the EOF (\x00) line. for line in data.splitlines(): if not line.startswith('#') \ and line.find('\x00') == -1 \ and line.find(':') == -1 \ and line.strip() != '' \ and not line.isspace(): try: #check that the first item is an integer cardStr = line.strip().split(' ', 1) cardLower = cardStr[0].lower() if cardLower in importLineHeaders: continue count = cardStr[0].strip('x') if count.isdigit(): cardname = cardStr[1].strip() else: count = 1 cardname = line.strip() except (ValueError, IndexError): count = 1 cardname = line.strip() try: deck.cards.append( (int(count), cardDB.FindCardByName(cardname).id, False)) except (ValueError, KeyError): cardErrors.append(cardname) #If there are errors throw an import error. if len(cardErrors) > 0: raise ImportCardsNotFoundError(cardErrors, deck) return deck
def hello(): params = {} params["subreddit"] = request.args.get('subreddit') params["from_time"] = request.args.get('from') params["to_time"] = request.args.get('to') if params["subreddit"] is None or params["from_time"] is None or params[ "to_time"] is None: return "{\"error\": \"Operation failed\"}" if not (params["from_time"].isdigit() and params["to_time"].isdigit()): return "{\"error\": \"Operation failed\"}" params["keyword"] = request.args.get('keyword') res = database.get(params) return "<pre>" + dumps(list(res), indent=2, separators=(',', ':')) + "</pre>"
def SetDeck(self, deck_): self.cardMap = [] self.deck = deck_ self.lstFate.DeleteAllItems() self.lstDynasty.DeleteAllItems() self.lstInPlay.DeleteAllItems() cardDB = database.get() for num, cdid, inplay in self.deck: card = cardDB[cdid] if (inplay == True): widget = self.lstInPlay else: if card.isDynasty(): widget = self.lstDynasty else: widget = self.lstFate self.ListAddCard(widget, card, len(self.cardMap), num) self.cardMap.append(cdid)
def loadFromClipboard(cls, data): #set up a holder for unknown cards cardErrors= [] importLineHeaders = ['stronghold','dynasty','holdings','regions','personalities','events', 'celestials', 'fate','strategies','spells','items','followers','rings'] cardDB = database.get() deck = Deck() #Look for a card line, not a header, not a space, and not the EOF (\x00) line. for line in data.splitlines(): if not line.startswith('#') \ and line.find('\x00') == -1 \ and line.find(':') == -1 \ and line.strip() != '' \ and not line.isspace(): try: #check that the first item is an integer cardStr = line.strip().split(' ', 1) cardLower = cardStr[0].lower() if cardLower in importLineHeaders: continue count = cardStr[0].strip('x') if count.isdigit(): cardname = cardStr[1].strip() else: count = 1 cardname = line.strip() except (ValueError, IndexError): count = 1 cardname = line.strip() try: deck.cards.append((int(count), cardDB.FindCardByName(cardname).id, False)) except (ValueError,KeyError): cardErrors.append(cardname) #If there are errors throw an import error. if len(cardErrors) > 0: raise ImportCardsNotFoundError(cardErrors, deck) return deck
def SetDeck(self, deck_): self.cardMap = [] self.deck = deck_ self.lstFate.DeleteAllItems() self.lstDynasty.DeleteAllItems() self.lstInPlay.DeleteAllItems() cardDB = database.get() for num, cdid, inplay in self.deck: card = cardDB[cdid] if (inplay == True): widget = self.lstInPlay else: if card.isDynasty(): widget = self.lstDynasty else: widget = self.lstFate self.ListAddCard(widget, card, len(self.cardMap), num) self.cardMap.append(cdid)
def SetCard(self, cdid): """Show a faceup card.""" if self.previewCard == cdid: return self.previewCard = cdid self.oglCanvas.SetCard(cdid) try: card = database.get()[cdid] except KeyError: print cdid return # HTML card text html = ['<html><body bgcolor="#ffffa0"><center>'] html.append('<font size="+1"><b>%s</b></font>' % card.name) # Everything has a name. try: html.append('<br>%s' % typeNames[card.type]) except KeyError: pass if card.type in ('personality', 'follower', 'item'): # Force and chi. html.append('<br>Force: <b>%s</b> Chi: <b>%s</b>' % (card.force, card.chi)) elif card.type == 'holding' and card.gold_production != '': html.append('<br>Gold Production: <b>%s</b>' % card.gold_production) if card.type == 'personality': # Gold cost, honor req, phonor. html.append('<br>HR: <b>%s</b> GC: <b>%s</b> PH: <b>%s</b>' % (card.honor_req, card.cost, card.personal_honor)) elif card.type == 'follower': # Gold cost, honor req. html.append('<br>HR: <b>%s</b> GC: <b>%s</b>' % (card.honor_req, card.cost)) elif card.type == 'stronghold': # Production, honor, etc. html.append('<br>Province Strength: <b>%s</b><br>Gold Production: <b>%s</b><br>Starting Honor: <b>%s</b>' % \ (card.province_strength, card.gold_production, card.starting_honor)) elif card.hasGoldCost(): # Gold cost. html.append('<br>Gold Cost: <b>%s</b>' % card.cost) textArr = [] for text in card.text.split("<br>"): textArr.append('<p>%s</p>' % text) textArr.append('<p><font size="-1"><i>%s</i></font></p>' % card.flavor) cardText = '<hr><font size="-1">%s</font><hr>' % ('\n'.join(textArr)) html.append(cardText) if card.isFate(): html.append('<br>Focus Value: <b>%s</b>' % card.focus) html.append('<br><font size="-1">Legal in <b>%s</b></font>' % ', '.join(card.legal)) if card.id[0] == '_': html.append('<br><font size="-1">Created card</font>') else: html.append('<br><font size="-1">%s</font>' % card.id) if card.rarity != "": html.append('<img src=\'' + locationsettings.data_dir + '/' + 'images/rarity_%s.png\' />' % card.rarity) if card.artist != "": html.append('<br><font size="-1">Artist: %s</font>' % card.artist) #rarity flavor and artist to go in. html.append('</center></body></html>') self.cardText.SetPage('\n'.join(html)) self.cardText.Refresh() # Rulings try: if card.rulings: self.EnableRulings() txt = '\n'.join('* ' + ruling for ruling in card.rulings) self.cardRulings.SetValue(txt) else: self.EnableRulings(False) except AttributeError: self.EnableRulings(False) self.Layout()
def __init__(self, parent): wx.Panel.__init__(self, parent) db = database.get() panelsizer = wx.BoxSizer(wx.VERTICAL) #Database # ------- sbsizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Current Database'), wx.VERTICAL) sbsizer.Add(wx.StaticText(self, label='%s (%d cards)' % (db.date, len(db))), 0, wx.EXPAND|wx.ALL, 5) if settings.cardsource: cs = settings.cardsource else: cs = '(no card source)' self.lblCardDB = wx.StaticText(self, label=cs) sbsizer.Add(self.lblCardDB, 0, wx.EXPAND|wx.ALL, 5) self.btnReload = wx.Button(self, label='Reload') self.Bind(wx.EVT_BUTTON, self.OnReloadDatabase, self.btnReload) self.btnChangeSource = wx.Button(self, label='Change Database') self.Bind(wx.EVT_BUTTON, self.OnChangeDatabase, self.btnChangeSource) sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(self.btnReload, 0, wx.RIGHT, 5) sizer.Add(self.btnChangeSource, 0, 0, 0) sbsizer.Add(sizer, 0, wx.ALIGN_RIGHT|wx.ALL, 5) panelsizer.Add(sbsizer, 0, wx.CENTRE|wx.EXPAND|wx.ALL, 4) #Image Packs # ------- sbsizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Image Packs'), wx.VERTICAL) sizer = wx.BoxSizer(wx.HORIZONTAL) sbsizer.Add(wx.StaticText(self, label='Egg of P\'an Ku will look in the below directory for card images.'), 0, wx.ALL, 5) self.dirImagePacks = wx.TextCtrl(self, value=settings.dir_imagepacks) sbsizer.Add(self.dirImagePacks, 0, wx.EXPAND|wx.ALL, 5) self.btnDefaultImagesPath = wx.Button(self, label='Default') self.btnGetImagesPath = wx.Button(self, label='Browse') self.Bind(wx.EVT_BUTTON, self.OnDefaultImagesPath, self.btnDefaultImagesPath) self.Bind(wx.EVT_BUTTON, self.OnGetImagesPath, self.btnGetImagesPath) sizer.Add(self.btnDefaultImagesPath, 0, wx.RIGHT, 5) sizer.Add(self.btnGetImagesPath, 0, wx.RIGHT, 5) sbsizer.Add(sizer,0, wx.ALIGN_RIGHT|wx.ALL, 5) panelsizer.Add(sbsizer, 0, wx.EXPAND|wx.ALL, 4) #Data Dir # ------- sbsizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Data Directory'), wx.VERTICAL) sizer = wx.BoxSizer(wx.HORIZONTAL) sbsizer.Add(wx.StaticText(self, label='Egg of P\'an Ku will look in the below directory for it\'s data.'), 0, wx.ALL, 5) self.dirData = wx.TextCtrl(self, value=locationsettings.data_dir) sbsizer.Add(self.dirData, 0, wx.EXPAND|wx.ALL, 5) self.btnDefaultDataDir = wx.Button(self, label='Default') self.btnGetDataDir = wx.Button(self, label='Browse') #Renable changing data_dir #self.btnDefaultDataDir.Disable() #self.btnGetDataDir.Disable() self.Bind(wx.EVT_BUTTON, self.OnDefaultDataDir, self.btnDefaultDataDir) self.Bind(wx.EVT_BUTTON, self.OnGetDataDir, self.btnGetDataDir) sizer.Add(self.btnDefaultDataDir, 0, wx.RIGHT, 5) sizer.Add(self.btnGetDataDir, 0, wx.RIGHT, 5) sbsizer.Add(sizer,0, wx.ALIGN_RIGHT|wx.ALL, 5) panelsizer.Add(sbsizer, 0, wx.EXPAND|wx.ALL, 4) self.SetSizer(panelsizer)
def __init__(self, cardmap): self.cardDB = database.get() self.cardmap = cardmap
def __init__(self, parent): wx.Panel.__init__(self, parent) db = database.get() panelsizer = wx.BoxSizer(wx.VERTICAL) #Database # ------- sbsizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Current Database'), wx.VERTICAL) sbsizer.Add( wx.StaticText(self, label='%s (%d cards)' % (db.date, len(db))), 0, wx.EXPAND | wx.ALL, 5) if settings.cardsource: cs = settings.cardsource else: cs = '(no card source)' self.lblCardDB = wx.StaticText(self, label=cs) sbsizer.Add(self.lblCardDB, 0, wx.EXPAND | wx.ALL, 5) self.btnReload = wx.Button(self, label='Reload') self.Bind(wx.EVT_BUTTON, self.OnReloadDatabase, self.btnReload) self.btnChangeSource = wx.Button(self, label='Change Database') self.Bind(wx.EVT_BUTTON, self.OnChangeDatabase, self.btnChangeSource) sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(self.btnReload, 0, wx.RIGHT, 5) sizer.Add(self.btnChangeSource, 0, 0, 0) sbsizer.Add(sizer, 0, wx.ALIGN_RIGHT | wx.ALL, 5) panelsizer.Add(sbsizer, 0, wx.CENTRE | wx.EXPAND | wx.ALL, 4) #Image Packs # ------- sbsizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Image Packs'), wx.VERTICAL) sizer = wx.BoxSizer(wx.HORIZONTAL) sbsizer.Add( wx.StaticText( self, label= 'Egg of P\'an Ku will look in the below directory for card images.' ), 0, wx.ALL, 5) self.dirImagePacks = wx.TextCtrl(self, value=settings.dir_imagepacks) sbsizer.Add(self.dirImagePacks, 0, wx.EXPAND | wx.ALL, 5) self.btnDefaultImagesPath = wx.Button(self, label='Default') self.btnGetImagesPath = wx.Button(self, label='Browse') self.Bind(wx.EVT_BUTTON, self.OnDefaultImagesPath, self.btnDefaultImagesPath) self.Bind(wx.EVT_BUTTON, self.OnGetImagesPath, self.btnGetImagesPath) sizer.Add(self.btnDefaultImagesPath, 0, wx.RIGHT, 5) sizer.Add(self.btnGetImagesPath, 0, wx.RIGHT, 5) sbsizer.Add(sizer, 0, wx.ALIGN_RIGHT | wx.ALL, 5) panelsizer.Add(sbsizer, 0, wx.EXPAND | wx.ALL, 4) #Data Dir # ------- sbsizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Data Directory'), wx.VERTICAL) sizer = wx.BoxSizer(wx.HORIZONTAL) sbsizer.Add( wx.StaticText( self, label= 'Egg of P\'an Ku will look in the below directory for it\'s data.' ), 0, wx.ALL, 5) self.dirData = wx.TextCtrl(self, value=locationsettings.data_dir) sbsizer.Add(self.dirData, 0, wx.EXPAND | wx.ALL, 5) self.btnDefaultDataDir = wx.Button(self, label='Default') self.btnGetDataDir = wx.Button(self, label='Browse') #Renable changing data_dir #self.btnDefaultDataDir.Disable() #self.btnGetDataDir.Disable() self.Bind(wx.EVT_BUTTON, self.OnDefaultDataDir, self.btnDefaultDataDir) self.Bind(wx.EVT_BUTTON, self.OnGetDataDir, self.btnGetDataDir) sizer.Add(self.btnDefaultDataDir, 0, wx.RIGHT, 5) sizer.Add(self.btnGetDataDir, 0, wx.RIGHT, 5) sbsizer.Add(sizer, 0, wx.ALIGN_RIGHT | wx.ALL, 5) panelsizer.Add(sbsizer, 0, wx.EXPAND | wx.ALL, 4) self.SetSizer(panelsizer)
def load(cls, fp): """Read a deck from a list of strings (or a file-like object) and parse it. Returns a deck object. """ foundInPlay = True cardErrors = [] cardDB = database.get() deck = Deck() for line in fp: #Look for Pre-Game cards first if '# Pre-Game' in line: numPreGame = deck.numCardsInDeckFileSubSection(line) break #Look for a combination of Stronghold,Sensei,Winds to match numPreGame i = 0 while i < numPreGame: if '# Stronghold' in line: numStronghold = deck.numCardsInDeckFileSubSection(line) if numStronghold != 1: print "More than one stronghold not allowed, only taking the first one." line = fp.next() i += 1 #Add Stronghold to Deck (count, cardname) = line.strip().split(' ', 1) cardname = cardname.strip() print '%s starts in play.' % (cardname) try: deck.cards.append( (int(count), cardDB.FindCardByName(cardname).id, foundInPlay)) except (ValueError, KeyError): cardErrors.append(cardname) if numStronghold != 1: for x in range(numStronghold - 1): i += 1 fp.next() if '# Sensei' in line: numSensei = deck.numCardsInDeckFileSubSection(line) if numSensei != 1: print "More than one sensei not allowed, only taking the first one." line = fp.next() i += 1 #Add Sensei to Deck (count, cardname) = line.strip().split(' ', 1) cardname = cardname.strip() print '%s starts in play.' % (cardname) try: deck.cards.append( (int(count), cardDB.FindCardByName(cardname).id, foundInPlay)) except (ValueError, KeyError): cardErrors.append(cardname) if numSensei != 1: for x in range(numSensei - 1): i += 1 fp.next() if '# Wind' in line: numWind = deck.numCardsInDeckFileSubSection(line) if numWind != 1: print "More than one wind not allowed, only taking the first one." line = fp.next() i += 1 #Add Wind to Deck (count, cardname) = line.strip().split(' ', 1) cardname = cardname.strip() print '%s starts in play.' % (cardname) try: deck.cards.append( (int(count), cardDB.FindCardByName(cardname).id, foundInPlay)) except (ValueError, KeyError): cardErrors.append(cardname) if numWind != 1: for x in range(numWind - 1): i += 1 fp.next() #Go to next line before end of loop line = fp.next() foundInPlay = False for line in fp: if '# Dynasty' in line: numDynasty = deck.numCardsInDeckFileSubSection(line) if '# Fate' in line: numFate = deck.numCardsInDeckFileSubSection(line) if not line.startswith('#') and line.strip() != '': (count, cardname) = line.strip().split(' ', 1) cardname = cardname.strip() if foundInPlay: print '%s starts in play.' % (cardname) try: deck.cards.append( (int(count), cardDB.FindCardByName(cardname).id, foundInPlay)) except (ValueError, KeyError): cardErrors.append(cardname) if len(cardErrors) > 0: raise LoadCardsNotFoundError(cardErrors, deck) return deck
def SetCard(self, cdid): """Show a faceup card.""" if self.previewCard == cdid: return self.previewCard = cdid self.oglCanvas.SetCard(cdid) try: card = database.get()[cdid] except KeyError: print cdid return # HTML card text html = ['<html><body bgcolor="#ffffa0"><center>'] html.append('<font size="+1"><b>%s</b></font>' % card.name) # Everything has a name. try: html.append('<br>%s' % typeNames[card.type]) except KeyError: pass if card.type in ('personality', 'follower', 'item'): # Force and chi. html.append('<br>Force: <b>%s</b> Chi: <b>%s</b>' % (card.force, card.chi)) elif card.type == 'holding' and card.gold_production != '': html.append('<br>Gold Production: <b>%s</b>' % card.gold_production) if card.type == 'personality': # Gold cost, honor req, phonor. html.append('<br>HR: <b>%s</b> GC: <b>%s</b> PH: <b>%s</b>' % (card.honor_req, card.cost, card.personal_honor)) elif card.type == 'follower': # Gold cost, honor req. html.append('<br>HR: <b>%s</b> GC: <b>%s</b>' % (card.honor_req, card.cost)) elif card.type == 'stronghold': # Production, honor, etc. html.append('<br>Province Strength: <b>%s</b><br>Gold Production: <b>%s</b><br>Starting Honor: <b>%s</b>' % \ (card.province_strength, card.gold_production, card.starting_honor)) elif card.hasGoldCost(): # Gold cost. html.append('<br>Gold Cost: <b>%s</b>' % card.cost) textArr = [] for text in card.text.split("<br>"): textArr.append('<p>%s</p>' % text) textArr.append('<p><font size="-1"><i>%s</i></font></p>' % card.flavor) cardText = '<hr><font size="-1">%s</font><hr>' % ('\n'.join(textArr)) html.append(cardText) if card.isFate(): html.append('<br>Focus Value: <b>%s</b>' % card.focus) html.append('<br><font size="-1">Legal in <b>%s</b></font>' % ', '.join(card.legal)) if card.id[0] == '_': html.append('<br><font size="-1">Created card</font>') else: html.append('<br><font size="-1">%s</font>' % card.id) if card.rarity != "": html.append('<img src=\'' + locationsettings.data_dir + '/' + 'images/rarity_%s.png\' />' % card.rarity) if card.artist != "": html.append('<br><font size="-1">Artist: %s</font>' % card.artist) #rarity flavor and artist to go in. html.append('</center></body></html>') self.cardText.SetPage('\n'.join(html)) self.cardText.Refresh() # Rulings try: if card.rulings: self.EnableRulings() txt = '\n'.join('* ' + ruling for ruling in card.rulings) self.cardRulings.SetValue(txt) else: self.EnableRulings(False) except AttributeError: self.EnableRulings(False) self.Layout()
def Save(self, fp, savetype): cardDB = database.get() headerString = '' headerString = { OUTPUT_TYPES.Text: '\n# %s (%d)\n', OUTPUT_TYPES.HTML: '\n<h3><u>%s (%d)</u></h3>\n', OUTPUT_TYPES.BBCode: '\n[size=150]%s (%d)[/size]\n', OUTPUT_TYPES.EnhText: '\n# %s (%d)\n' }[savetype] #Oracle refers to the Stronghold and Sensei as Pre-Game cards #Pre-Game Cards inPlayCards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if inPlay == True] inPlayCount = 0 for item in inPlayCards: inPlayCount += int(item[0]) fp.write(headerString % ('Pre-Game', inPlayCount)) stronghold = [ (count, cardDB[cdid]) for count, cdid, inPlay in self if ((inPlay == True) and cardDB[cdid].type == "stronghold") ] self.WriteCardsToTypeList(fp, stronghold, 'Stronghold', savetype) sensei = [(count, cardDB[cdid]) for count, cdid, inPlay in self if ((inPlay == True) and cardDB[cdid].isSensei())] self.WriteCardsToTypeList(fp, sensei, 'Sensei', savetype) wind = [(count, cardDB[cdid]) for count, cdid, inPlay in self if ((inPlay == True) and cardDB[cdid].isWind())] self.WriteCardsToTypeList(fp, wind, 'Wind', savetype) #Dynasty Deck dyncards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if ((inPlay != True) and (cardDB[cdid].isDynasty()))] dynCount = 0 for item in dyncards: dynCount += int(item[0]) fp.write(headerString % ('Dynasty', dynCount)) celestialcards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if ((inPlay != True) and cardDB[cdid].isCelestial())] self.WriteCardsToTypeList(fp, celestialcards, 'Celestials', savetype) eventcards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if ((inPlay != True) and cardDB[cdid].isEvent())] self.WriteCardsToTypeList(fp, eventcards, 'Events', savetype) holdingcards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if ((inPlay != True) and cardDB[cdid].isHolding())] self.WriteCardsToTypeList(fp, holdingcards, 'Holdings', savetype) personalitycards = [ (count, cardDB[cdid]) for count, cdid, inPlay in self if ((inPlay != True) and cardDB[cdid].isPersonality()) ] self.WriteCardsToTypeList(fp, personalitycards, 'Personalities', savetype) regioncards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if ((inPlay != True) and cardDB[cdid].isRegion())] self.WriteCardsToTypeList(fp, regioncards, 'Regions', savetype) #Fate Deck fatecards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if ((inPlay != True) and (cardDB[cdid].isFate()))] fateCount = 0 for item in fatecards: fateCount += int(item[0]) #fatecards.sort(lambda a, b: cmp(a[1].type, b[1].type)) fp.write(headerString % ('Fate', fateCount)) ancestorcards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if ((inPlay != True) and cardDB[cdid].isAncestor())] self.WriteCardsToTypeList(fp, ancestorcards, 'Ancestors', savetype) followercards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if ((inPlay != True) and cardDB[cdid].isFollower())] self.WriteCardsToTypeList(fp, followercards, 'Followers', savetype) itemcards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if ((inPlay != True) and cardDB[cdid].isItem())] self.WriteCardsToTypeList(fp, itemcards, 'Items', savetype) ringcards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if ((inPlay != True) and cardDB[cdid].isRing())] self.WriteCardsToTypeList(fp, ringcards, 'Rings', savetype) spellcards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if ((inPlay != True) and cardDB[cdid].isSpell())] self.WriteCardsToTypeList(fp, spellcards, 'Spells', savetype) strategycards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if ((inPlay != True) and cardDB[cdid].isStrategy())] self.WriteCardsToTypeList(fp, strategycards, 'Strategy', savetype) senseicards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if ((inPlay != True) and cardDB[cdid].isSensei())] self.WriteCardsToTypeList(fp, senseicards, 'Senseis', savetype)
def __init__(self, cardmap): self.cardDB = database.get() self.cardmap = cardmap
def NumInPlay(self): cardDB = database.get() return sum( [count for count, id, inplay in self.cards if inplay == True])
def load(cls, fp): """Read a deck from a list of strings (or a file-like object) and parse it. Returns a deck object. """ foundInPlay = True cardErrors=[] cardDB = database.get() deck = Deck() for line in fp: #Look for Pre-Game cards first if '# Pre-Game' in line: numPreGame = deck.numCardsInDeckFileSubSection(line) break #Look for a combination of Stronghold,Sensei,Winds to match numPreGame i = 0 while i < numPreGame: if '# Stronghold' in line: numStronghold = deck.numCardsInDeckFileSubSection(line) if numStronghold != 1: print "More than one stronghold not allowed, only taking the first one." line = fp.next() i += 1 #Add Stronghold to Deck (count, cardname) = line.strip().split(' ', 1) cardname = cardname.strip() print '%s starts in play.' % (cardname) try: deck.cards.append((int(count), cardDB.FindCardByName(cardname).id, foundInPlay)) except (ValueError, KeyError): cardErrors.append(cardname) if numStronghold != 1: for x in range(numStronghold-1): i += 1 fp.next() if '# Sensei' in line: numSensei = deck.numCardsInDeckFileSubSection(line) if numSensei != 1: print "More than one sensei not allowed, only taking the first one." line = fp.next() i += 1 #Add Sensei to Deck (count, cardname) = line.strip().split(' ', 1) cardname = cardname.strip() print '%s starts in play.' % (cardname) try: deck.cards.append((int(count), cardDB.FindCardByName(cardname).id, foundInPlay)) except (ValueError, KeyError): cardErrors.append(cardname) if numSensei != 1: for x in range(numSensei-1): i += 1 fp.next() if '# Wind' in line: numWind = deck.numCardsInDeckFileSubSection(line) if numWind != 1: print "More than one wind not allowed, only taking the first one." line = fp.next() i += 1 #Add Wind to Deck (count, cardname) = line.strip().split(' ', 1) cardname = cardname.strip() print '%s starts in play.' % (cardname) try: deck.cards.append((int(count), cardDB.FindCardByName(cardname).id, foundInPlay)) except (ValueError, KeyError): cardErrors.append(cardname) if numWind != 1: for x in range(numWind-1): i += 1 fp.next() #Go to next line before end of loop line = fp.next() foundInPlay = False for line in fp: if '# Dynasty' in line: numDynasty = deck.numCardsInDeckFileSubSection(line) if '# Fate' in line: numFate = deck.numCardsInDeckFileSubSection(line) if not line.startswith('#') and line.strip() != '': (count, cardname) = line.strip().split(' ', 1) cardname = cardname.strip() if foundInPlay: print '%s starts in play.' % (cardname) try: deck.cards.append((int(count), cardDB.FindCardByName(cardname).id, foundInPlay)) except (ValueError, KeyError): cardErrors.append(cardname) if len(cardErrors) >0: raise LoadCardsNotFoundError(cardErrors, deck) return deck
def Save(self, fp, savetype): cardDB = database.get() headerString = '' headerString = {OUTPUT_TYPES.Text:'\n# %s (%d)\n', OUTPUT_TYPES.HTML:'\n<h3><u>%s (%d)</u></h3>\n', OUTPUT_TYPES.BBCode:'\n[size=150]%s (%d)[/size]\n', OUTPUT_TYPES.EnhText:'\n# %s (%d)\n'}[savetype] #Oracle refers to the Stronghold and Sensei as Pre-Game cards #Pre-Game Cards inPlayCards =[(count, cardDB[cdid]) for count, cdid, inPlay in self if inPlay==True] inPlayCount = 0 for item in inPlayCards: inPlayCount += int(item[0]) fp.write(headerString % ('Pre-Game',inPlayCount)) stronghold = [(count, cardDB[cdid]) for count, cdid, inPlay in self if((inPlay==True) and cardDB[cdid].type=="stronghold")] self.WriteCardsToTypeList(fp,stronghold,'Stronghold', savetype) sensei = [(count, cardDB[cdid]) for count, cdid, inPlay in self if((inPlay==True) and cardDB[cdid].isSensei())] self.WriteCardsToTypeList(fp,sensei,'Sensei', savetype) wind = [(count, cardDB[cdid]) for count, cdid, inPlay in self if((inPlay==True) and cardDB[cdid].isWind())] self.WriteCardsToTypeList(fp,wind,'Wind', savetype) #Dynasty Deck dyncards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if((inPlay!=True) and (cardDB[cdid].isDynasty()))] dynCount = 0 for item in dyncards: dynCount += int(item[0]) fp.write(headerString % ('Dynasty',dynCount)) celestialcards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if((inPlay!=True) and cardDB[cdid].isCelestial())] self.WriteCardsToTypeList(fp,celestialcards,'Celestials', savetype) eventcards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if((inPlay!=True) and cardDB[cdid].isEvent())] self.WriteCardsToTypeList(fp,eventcards,'Events', savetype) holdingcards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if((inPlay!=True) and cardDB[cdid].isHolding())] self.WriteCardsToTypeList(fp,holdingcards,'Holdings', savetype) personalitycards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if((inPlay!=True) and cardDB[cdid].isPersonality())] self.WriteCardsToTypeList(fp,personalitycards,'Personalities', savetype) regioncards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if((inPlay!=True) and cardDB[cdid].isRegion())] self.WriteCardsToTypeList(fp,regioncards,'Regions', savetype) #Fate Deck fatecards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if ((inPlay!=True) and (cardDB[cdid].isFate()))] fateCount = 0 for item in fatecards: fateCount += int(item[0]) #fatecards.sort(lambda a, b: cmp(a[1].type, b[1].type)) fp.write(headerString % ('Fate',fateCount)) ancestorcards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if((inPlay!=True) and cardDB[cdid].isAncestor())] self.WriteCardsToTypeList(fp,ancestorcards,'Ancestors', savetype) followercards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if((inPlay!=True) and cardDB[cdid].isFollower())] self.WriteCardsToTypeList(fp,followercards,'Followers', savetype) itemcards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if((inPlay!=True) and cardDB[cdid].isItem())] self.WriteCardsToTypeList(fp,itemcards,'Items', savetype) ringcards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if((inPlay!=True) and cardDB[cdid].isRing())] self.WriteCardsToTypeList(fp,ringcards,'Rings', savetype) spellcards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if((inPlay!=True) and cardDB[cdid].isSpell())] self.WriteCardsToTypeList(fp,spellcards,'Spells', savetype) strategycards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if((inPlay!=True) and cardDB[cdid].isStrategy())] self.WriteCardsToTypeList(fp,strategycards,'Strategy', savetype) senseicards = [(count, cardDB[cdid]) for count, cdid, inPlay in self if((inPlay!=True) and cardDB[cdid].isSensei())] self.WriteCardsToTypeList(fp,senseicards,'Senseis', savetype)
def NumFate(self): """Return the number of fate cards in the deck.""" cardDB = database.get() return sum([count for count, id, inplay in self.cards if((inplay!=True) and (cardDB[id].isFate()))])
def NumInPlay(self): cardDB = database.get() return sum([count for count,id, inplay in self.cards if inplay == True])