Ejemplo n.º 1
0
	def get_name(self, instance):
		active_locales = filter(lambda locale: not locale.unused, enums.Locale)
		return dict(
			(locale.name, enums.get_localized_name(instance["player_class"], locale.name))
			for locale in active_locales
		)
Ejemplo n.º 2
0
def make_reply(decks, locale="enUS"):
    db, _ = load_dbf(locale=locale)
    if locale != "enUS":
        english_db, _ = load_dbf(locale="enUS")  # For Gamepedia links
    else:
        english_db = db

    reply = []

    for deck in decks:
        reply_chunks = []

        card_includes = deck.cards
        cards = [(db[dbf_id], count) for dbf_id, count in card_includes]
        cards.sort(key=lambda include: (include[0].cost, include[0].name))
        try:
            hero = db[deck.heroes[0]]
            class_name = get_localized_name(hero.card_class, locale=locale)
            hero_name = f"{class_name} ({hero.name})"
        except KeyError:
            hero_name = "Unknown"

        format_name = get_localized_name(deck.format, locale=locale)
        standard_year_name = pretty_zodiac_year(ZodiacYear.as_of_date())

        reply_chunks.append(
            f"**Format:** {format_name} ({standard_year_name})\n")
        reply_chunks.append(f"**Class:** {hero_name}\n")

        rows = []

        for card, count in cards:
            english_card = english_db[card.dbf_id]
            image = get_card_image(card, locale)
            rows.append((
                card.cost,
                markdown_link(card.name, image),
                count,
                get_card_links(card, english_card, locale),
            ))

        total_dust = sum(card.crafting_costs[0] * count
                         for card, count in cards)

        table = tabulate(rows, headers=("Mana", "Card Name", "Qty", "Links"))
        reply_chunks.append(table)

        reply_chunks.append("\n")
        reply_chunks.append(f"**Total Dust:** {total_dust}")
        reply_chunks.append("\n")

        reply_chunks.append(f"**Deck Code:** {deck.as_deckstring}")
        reply_chunks.append("\n")
        reply_chunks.append("*****")
        reply_chunks.append("\n")

        if calculate_reply_length(reply + reply_chunks) > MAX_CHARACTERS:
            # Stop adding decks
            break

        reply += reply_chunks

    reply.append(I_AM_A_BOT)
    return "\n".join(reply)
        locale = 'enUS'
        deck = Deck.from_deckstring(hs_deck)
        db, _ = load_dbf(locale=locale)
        english_db = db

        card_includes = deck.cards
        cards = []
        for dbf_id, count in card_includes:
            try:
                cards.append((db[dbf_id], count))
            except KeyError:
                unknown += 1
        cards.sort(key=lambda include: (include[0].cost, include[0].name))
        try:
            hero = db[deck.heroes[0]]
            class_name = get_localized_name(hero.card_class, locale=locale)
            hero_name = f"{class_name} ({hero.name})"
        except KeyError:
            hero_name = "Unknown"

        card_list = PrettyTable()
        card_list.field_names = ['Card Cost', 'Card Name', 'Card Count']
        for card, count in cards:
            card_list.add_row([card.cost, card.name, count])

        print(hero_name)
        print(card_list)
        if unknown:
            print(unknown, 'unrecognized cards')
        print('Deckstring: ', hs_deck)
Ejemplo n.º 4
0
def render(card, locale, loc_code, premium, theme_data, theme_dir, art_dir,
           out_dir, font_map, width):
    card_type, card_class = fix_card_props(card, premium)
    if card_type in theme_data:
        data = theme_data[card_type]
    else:
        print("{} : '{}' is unsupported in '{}' theme".format(
            card.id, card_type, theme_data["name"]))
        return
    # get all the components and sort by the layer attribute
    components = []
    for k, v in data.items():
        try:
            ctype = ComponentType[k]
        except KeyError:
            ctype = ComponentType.unknown
        components.append(Component(v, ctype, font_map))
    components.sort(key=attrgetter("layer"))

    ctx, surface = setup_context(theme_data["width"], theme_data["height"],
                                 width)
    rendered_comps = 0

    for c in components:
        cdata = None
        # match each component to a known type
        if c.type == ComponentType.name:
            cdata = ComponentData(text=card.name)
        elif c.type == ComponentType.elite and card.elite:
            cdata = ComponentData()
        elif (c.type == ComponentType.rarity and card.rarity.craftable
              and card.card_set != CardSet.CORE):
            cdata = ComponentData(card.rarity.name.lower())
        elif (c.type == ComponentType.cardSet):
            cdata = ComponentData(card.card_set.name.lower())
        elif (c.type == ComponentType.multiClass
              and card.multi_class_group != MultiClassGroup.INVALID):
            cdata = ComponentData(card.multi_class_group.name.lower())
        elif c.type == ComponentType.classDecoration:
            cdata = ComponentData(card_class, card_class)
        elif c.type == ComponentType.cost:
            cdata = ComponentData(text=str(card.cost))
        elif c.type == ComponentType.health:
            health = str(card.health)
            if card.type == CardType.WEAPON:
                health = str(card.durability)
            cdata = ComponentData(text=health)
        elif c.type == ComponentType.attack:
            cdata = ComponentData(text=str(card.atk))
        elif c.type == ComponentType.race and card.race.visible:
            cdata = ComponentData(
                text=get_localized_name(card.race, locale.name))
        elif c.type == ComponentType.portrait:
            cdata = ComponentData(None, None, card.id + ".png")
        elif c.type == ComponentType.base:
            cdata = ComponentData()
        elif c.type == ComponentType.description:
            cdata = ComponentData(
                text=clean_description_text(card.description, locale))
        elif c.type == ComponentType.custom:
            cdata = ComponentData(
                obj={
                    "card": card,
                    "dir": theme_dir,
                    "premium": premium,
                    "cardtype": card_type
                })
        elif c.type == ComponentType.unknown:
            cdata = ComponentData()
        # render any component matched
        if cdata:
            render_component(ctx, art_dir, theme_dir, loc_code, c, cdata)
            rendered_comps += 1
    # save the image to file if any components have been rendered
    if rendered_comps > 0:
        surface.flush()
        filename = "{}{}.png".format(card.id, PREM_SUFFIX if premium else "")
        surface.write_to_png(os.path.join(out_dir, filename))