def main(): from hearthstone.cardxml import load from fireplace.utils import _custom_cards, get_script_definition if len(sys.argv) < 3: print("Usage: %s <in> <out/CardDefs.xml>" % (sys.argv[0])) exit(1) db, xml = load(os.path.join(sys.argv[1], "CardDefs.xml")) guids, hero_powers = load_dbf(os.path.join(sys.argv[1], "DBF", "CARD.xml")) for id, card in db.items(): if id in hero_powers: add_hero_power(card, hero_powers[id]) if card.tags.get(GameTag.SPELLPOWER): guess_spellpower(card) if card.tags.get(GameTag.RECALL): guess_overload(card) if "Can't be targeted by spells or Hero Powers." in card.description: set_tag(card, GameTag.CANT_BE_TARGETED_BY_ABILITIES, True) set_tag(card, GameTag.CANT_BE_TARGETED_BY_HERO_POWERS, True) if "50% chance to attack the wrong enemy." in card.description: if not card.forgetful and id != "GVG_112": set_tag(card, GameTag.FORGETFUL, True) # xml = db[next(db.__iter__())].xml path = os.path.realpath(sys.argv[2]) with open(path, "w", encoding="utf8") as f: root = ElementTree.Element("CardDefs") for e in xml.findall("Entity"): # We want to retain the order so we can't just use db.keys() id = e.attrib["CardID"] card = db[id] root.append(card.xml) # dummy call get_script_definition("") # Create all registered custom cards for id, cls in _custom_cards.items(): e = create_card(id, cls.tags) root.append(e) outstr = ElementTree.tostring(root) # Reparse for clean indentation outstr = minidom.parseString(outstr).toprettyxml(indent="\t") outstr = "\n".join(line for line in outstr.split("\n") if line.strip()) f.write(outstr) print("Written to", path)
def main(): impl = 0 unimpl = 0 p = argparse.ArgumentParser() p.add_argument( "--implemented", action="store_true", dest="implemented", help="Show only implemented cards" ) p.add_argument( "--unimplemented", action="store_true", dest="unimplemented", help="Show only unimplemented cards" ) args = p.parse_args(sys.argv[1:]) if not args.implemented and not args.unimplemented: args.implemented = True args.unimplemented = True cards.db.initialize() for id in sorted(cards.db): card = cards.db[id] description = cleanup_description(card.description) implemented = False if not description: # Minions without card text or with basic abilities are implemented implemented = True elif card.card_set == CardSet.CREDITS: implemented = True if id in DUMMY_CARDS: implemented = True carddef = get_script_definition(id) if carddef: implemented = True color = GREEN if implemented else RED name = color + "%s: %s" % (PREFIXES[color], card.name) + ENDC if implemented: impl += 1 if args.implemented: print("%s (%s)" % (name, id)) else: unimpl += 1 if args.unimplemented: print("%s (%s)" % (name, id)) total = impl + unimpl print("%i / %i cards implemented (%i%%)" % (impl, total, (impl / total) * 100))
def main(): impl = 0 unimpl = 0 p = argparse.ArgumentParser() p.add_argument( "--implemented", action="store_true", dest="implemented", help="Show only implemented cards" ) p.add_argument( "--unimplemented", action="store_true", dest="unimplemented", help="Show only unimplemented cards" ) args = p.parse_args(sys.argv[1:]) if not args.implemented and not args.unimplemented: args.implemented = True args.unimplemented = True for id in sorted(cards.db): card = cards.db[id] description = cleanup_description(card.description) implemented = False if not description: # Minions without card text or with basic abilities are implemented implemented = True elif card.card_set == CardSet.CREDITS: implemented = True if id in DUMMY_CARDS: implemented = True carddef = get_script_definition(id) if carddef: implemented = True color = GREEN if implemented else RED name = color + "%s: %s" % (PREFIXES[color], card.name) + ENDC if implemented: impl += 1 if args.implemented: print("%s (%s)" % (name, id)) else: unimpl += 1 if args.unimplemented: print("%s (%s)" % (name, id)) total = impl + unimpl print("%i / %i cards implemented (%i%%)" % (impl, total, (impl / total) * 100))
def main(): from hearthstone.cardxml import load from fireplace.utils import _custom_cards, get_script_definition if len(sys.argv) < 3: print("Usage: %s <in> <out/CardDefs.xml>" % (sys.argv[0])) exit(1) db, xml = load(os.path.join(sys.argv[1], "CardDefs.xml")) guids, hero_powers = load_dbf(os.path.join(sys.argv[1], "DBF", "CARD.xml")) for id, card in db.items(): carddef = get_script_definition(id) if carddef: if hasattr(carddef, "tags"): for tag, value in carddef.tags.items(): set_tag(card, tag, value) if hasattr(carddef, "choose"): add_chooseone_tags(card, carddef.choose) if id in hero_powers: add_hero_power(card, hero_powers[id]) if re.match(r"^PART_\d+$", id): # Hearthstone uses entourage data to identify Spare Parts # We're better than that. set_tag(card, GameTag.SPARE_PART, True) if card.tags.get(GameTag.SPELLPOWER): guess_spellpower(card) if card.tags.get(GameTag.RECALL): guess_overload(card) if "Can't attack." in card.description: set_tag(card, GameTag.CANT_ATTACK, True) if "Can't be targeted by spells or Hero Powers." in card.description: set_tag(card, GameTag.CANT_BE_TARGETED_BY_ABILITIES, True) set_tag(card, GameTag.CANT_BE_TARGETED_BY_HERO_POWERS, True) # xml = db[next(db.__iter__())].xml with open(sys.argv[2], "w", encoding="utf8") as f: root = ElementTree.Element("CardDefs") for e in xml.findall("Entity"): # We want to retain the order so we can't just use db.keys() id = e.attrib["CardID"] card = db[id] root.append(card.xml) # Create all registered custom cards for id, cls in _custom_cards.items(): e = create_card(id, cls.tags) root.append(e) outstr = ElementTree.tostring(root) # Reparse for clean indentation outstr = minidom.parseString(outstr).toprettyxml(indent="\t") outstr = "\n".join(line for line in outstr.split("\n") if line.strip()) f.write(outstr) print("Written to", f.name)