示例#1
0
    def __createDeckImage(self,
                          cardset,
                          name,
                          suffix="",
                          width=5,
                          quality=100):
        filename = None

        if name == "":
            name = self.name + suffix

        self.cards.sort(key=lambda x: (-x.rarity, x.type, x.name, -x.level))
        start_time = time.time()

        self.drawAllCards(cardset)
        end_time = time.time()
        print('Created images in {0}'.format(end_time - start_time))

        master = self.compileImages(cardset, width)

        if master is not None:
            print("Saving image...")
            filename = getFullPath(self.config.paths.savePath,
                                   "{0}.png".format(name))
            master.save(filename, quality=quality)

        return filename
示例#2
0
    def getCardFromCache(self, card):
        name = self.getNameFromCard(card)

        if name in self.files:
            image = Image.open(getFullPath(self.cachePath, name))
        else:
            image = None
        return image
示例#3
0
    def saveCardToCache(self, card):
        if self.cacheEnabled:
            name = self.getNameFromCard(card)

            card.image.save(
                getFullPath(self.cachePath, name),
                quality=self.defaultImageQuality)

            self.updateFileList()
示例#4
0
    def updateXMLFiles(self):
        for parser in self.config.xmlFiles:
            f = urllib.urlopen(str(self.config.assetsUrl + parser))
            response = f.read()

            target = open(getFullPath('resources', 'xml_files', parser), 'wb')
            target.truncate()
            target.write(response)
            target.close()
            f.close()
示例#5
0
    def __getXmlFile(self, fileType):
        filePath = getFullPath('resources', 'xml_files',
                               self.config.xmlFiles[fileType])

        if (not (os.path.isfile(filePath))):
            self.updateXMLFiles()

        xmlFile = ET.parse(filePath)

        return xmlFile.getroot()
示例#6
0
 def updateFileList(self):
     self.files = os.listdir(getFullPath(self.cachePath))
     self.files.sort()
示例#7
0
 def __getUserInitFilePath(self, userId):
     initFilename = "{0}_{1}".format(userId, self.config.initDataFile)
     return getFullPath('resources', 'init_files', initFilename)
示例#8
0
    def getBGESpreadsheets(self, bge="athletic"):
        cards = self.api.getCards()
        combos = self.api.getCombos()

        # Gets all combo bge cards
        combo_list = self.searchXML(xml_files=[cards],
                                    musthave=[('trait', bge), ('set', '1001')])
        exp_two_list = self.searchXML(xml_files=[cards],
                                      musthave=[('trait', bge),
                                                ('set', '1002')])
        combo_list.extend(exp_two_list)

        combo_deck = Deck()

        input_list = []
        for card_id in combo_list:
            for card in combos.findall('combo'):
                if int(card.find('card_id').text) == card_id:
                    cards = card.find('cards')

                    if cards.get('card1') == '' or cards.get('card2') == '':
                        continue

                    card_one_id = int(cards.get('card1'))
                    card_two_id = int(cards.get('card2'))

                    # Skip mythics
                    if card_one_id > 1000000:
                        continue

                    one_index = combo_deck.getCardIndex(card_one_id)
                    two_index = combo_deck.getCardIndex(card_two_id)

                    if one_index is None:
                        one_index = len(combo_deck.cards)
                        combo_deck.addCard(card_id=card_one_id)

                    if two_index is None:
                        two_index = len(combo_deck.cards)
                        combo_deck.addCard(card_id=card_two_id)

                    new_combo = Combo(combo_deck.cards[one_index],
                                      combo_deck.cards[two_index], card_id)
                    combo_deck.combos.append(new_combo)

        if len(combo_deck.combos) <= 0:
            # print("No combos found for {0}".format(bge))
            return

        combo_deck.updateDeckFromXML()
        combo_deck.updateCombosFromXML()

        # Create 2d array of items on left and chars on top
        combo_deck.cards.sort(key=lambda x: (x.type, -x.rarity, x.name))

        # Count columns and rows
        col_count = 0
        row_count = 0

        while col_count < len(combo_deck.cards) and \
                (combo_deck.cards[col_count].type == constants.CHAR or
                 combo_deck.cards[col_count].type == constants.MYTHIC):
            col_count += 1

        while col_count + row_count < len(combo_deck.cards) and \
                combo_deck.cards[row_count + col_count].type == constants.ITEM:
            row_count += 1

        col_count += 1
        row_count += 1
        arr = [["-"] * col_count for x in range(row_count)]

        m = 1
        while m - 1 < len(combo_deck.cards) and \
                (combo_deck.cards[m - 1].type == constants.CHAR or
                 combo_deck.cards[m - 1].type == constants.MYTHIC):
            arr[0][m] = combo_deck.cards[m - 1].name
            m += 1

        i = 1
        while (i + m - 2) < len(combo_deck.cards) and combo_deck.cards[
                i + m - 2].type == constants.ITEM:
            arr[i][0] = combo_deck.cards[i + m - 2].name
            i += 1

        for x in range(len(combo_deck.combos)):
            # find column
            a = 1
            while arr[0][a].lower() != combo_deck.combos[x].char.name.lower():
                a += 1

            # find row
            b = 1
            while arr[b][0].lower() != combo_deck.combos[x].item.name.lower():
                b += 1

            arr[b][a] = combo_deck.combos[x].name

        # Write combos to file

        target = open(
            getFullPath(self.savePath, "{0}_combos_table.csv".format(bge)),
            'w')
        target.truncate()

        for i in range(len(arr)):
            for j in range(len(arr[i])):
                target.write("\"" + arr[i][j] + "\", ")
            target.write("\n")
        target.close()

        target = open(
            getFullPath(self.savePath, "{0}_combos_list.csv".format(bge)), 'w')
        target.truncate()

        for i in range(len(combo_deck.combos)):
            target.write("\"" + combo_deck.combos[i].char.name + "\", " +
                         "\"" + combo_deck.combos[i].item.name + "\", " +
                         "\"" + combo_deck.combos[i].name + "\", \n")
        target.close()