Exemplo n.º 1
0
def test_dbf():
    path = get_resource("DECK_RULESET_RULE_SUBSET.xml")

    dbf = Dbf.load(path)
    assert dbf.name == "DECK_RULESET_RULE_SUBSET"
    assert dbf.source_fingerprint == "ziY6RY+E/zCQ496Av7HKSCR+zls="
    assert dbf.columns == OrderedDict([
        ("DECK_RULESET_RULE_ID", "Int"),
        ("SUBSET_ID", "Int"),
    ])
    assert dbf.records == [
        {
            "DECK_RULESET_RULE_ID": 5,
            "SUBSET_ID": 6
        },
        {
            "DECK_RULESET_RULE_ID": 15,
            "SUBSET_ID": 6
        },
    ]

    dbf2 = Dbf()
    dbf2.populate(BytesIO(dbf.to_xml()))
    assert dbf2.source_fingerprint == dbf.source_fingerprint
    assert dbf2.columns == dbf.columns

    for r1, r2 in zip(dbf.records, dbf2.records):
        assert r1 == r2
Exemplo n.º 2
0
    def load_dbf(self, filename):
        self.stdout.write("Parsing %s" % (filename))
        dbf = Dbf.load(filename)
        if dbf.name not in self.tables:
            self.stderr.write("No handler for %r (%r)" % (filename, dbf.name))
            return

        cls = self.tables[dbf.name]
        for record in dbf.records:
            values = self.get_values(record, cls.dbf_columns)
            try:
                instance = cls.objects.get(id=record["ID"])
            except cls.DoesNotExist:
                instance = cls.objects.create(**values)
                self.stdout.write("Created %r (build %r)" %
                                  (instance, self.build))
            else:
                if self.force or instance.build < self.build:
                    self.stdout.write("Updating %r to build %r" %
                                      (instance, self.build))
                    for k, v in values.items():
                        setattr(instance, k, v)
                    instance.save()
                else:
                    self.stdout.write("Skipping %r (up to date)" % (instance))
Exemplo n.º 3
0
def main():
	parser = ArgumentParser()
	parser.add_argument(
		"-o", "--output-dir",
		type=str,
		dest="output_dir",
		default="out",
		help="Output directory"
	)
	parser.add_argument(
		"-i", "--input-dir",
		type=str,
		dest="input_dir",
		default="hsdata",
		help="Input hsdata directory"
	)
	args = parser.parse_args(sys.argv[1:])

	db, xml = load(os.path.join(args.input_dir, "CardDefs.xml"))
	dbf_path = os.path.join(args.input_dir, "DBF", "CARD_BACK.xml")
	if not os.path.exists(dbf_path):
		print("Skipping card back generation (%s does not exist)" % (dbf_path))
		dbf = None
	else:
		dbf = Dbf.load(dbf_path)

	cards = db.values()
	collectible_cards = [card for card in cards if card.collectible]

	for locale in Locale:
		if locale.unused:
			continue

		basedir = os.path.join(args.output_dir, locale.name)
		if not os.path.exists(basedir):
			os.makedirs(basedir)

		filename = os.path.join(basedir, "cards.json")
		export_cards_to_file(cards, filename, locale.name)

		filename = os.path.join(basedir, "cards.collectible.json")
		export_cards_to_file(collectible_cards, filename, locale.name)

		if dbf is not None:
			filename = os.path.join(basedir, "cardbacks.json")
			write_cardbacks(dbf, filename, locale)

	# Generate merged locales
	basedir = os.path.join(args.output_dir, "all")
	if not os.path.exists(basedir):
		os.makedirs(basedir)
	filename = os.path.join(basedir, "cards.json")
	export_all_locales_cards_to_file(cards, filename)
	filename = os.path.join(basedir, "cards.collectible.json")
	export_all_locales_cards_to_file(collectible_cards, filename)
Exemplo n.º 4
0
	def parse_card_tag_dbf(self, path):
		self.info("Processing CARD_TAG DBF %r" % (path))
		dbf = Dbf.load(path)

		for record in dbf.records:
			dbf_id = record["CARD_ID"]
			tag = record["TAG_ID"]
			value = record["TAG_VALUE"]
			is_reference = record["IS_REFERENCE_TAG"]
			is_power = record["IS_POWER_KEYWORD_TAG"]
			self.record_card_tag(dbf_id, tag, value, is_reference, is_power)
Exemplo n.º 5
0
    def parse_card_tag_dbf(self, path):
        self.info("Processing CARD_TAG DBF %r" % (path))
        dbf = Dbf.load(path)

        for record in dbf.records:
            dbf_id = record["CARD_ID"]
            tag = record["TAG_ID"]
            value = record["TAG_VALUE"]
            is_reference = record["IS_REFERENCE_TAG"]
            is_power = record["IS_POWER_KEYWORD_TAG"]
            self.record_card_tag(dbf_id, tag, value, is_reference, is_power)
Exemplo n.º 6
0
def main():
    parser = ArgumentParser()
    parser.add_argument("-o",
                        "--output-dir",
                        type=str,
                        dest="output_dir",
                        default="out",
                        help="Output directory")
    parser.add_argument("-i",
                        "--input-dir",
                        type=str,
                        dest="input_dir",
                        default="hsdata",
                        help="Input hsdata directory")
    args = parser.parse_args(sys.argv[1:])

    db, xml = load(os.path.join(args.input_dir, "CardDefs.xml"))
    dbf_path = os.path.join(args.input_dir, "DBF", "CARD_BACK.xml")
    if not os.path.exists(dbf_path):
        print("Skipping card back generation (%s does not exist)" % (dbf_path))
        dbf = None
    else:
        dbf = Dbf.load(dbf_path)

    cards = db.values()
    collectible_cards = [card for card in cards if card.collectible]

    for locale in Locale:
        if locale.unused:
            continue

        basedir = os.path.join(args.output_dir, locale.name)
        if not os.path.exists(basedir):
            os.makedirs(basedir)

        filename = os.path.join(basedir, "cards.json")
        export_cards_to_file(cards, filename, locale.name)

        filename = os.path.join(basedir, "cards.collectible.json")
        export_cards_to_file(collectible_cards, filename, locale.name)

        if dbf is not None:
            filename = os.path.join(basedir, "cardbacks.json")
            write_cardbacks(dbf, filename, locale)

    # Generate merged locales
    basedir = os.path.join(args.output_dir, "all")
    if not os.path.exists(basedir):
        os.makedirs(basedir)
    filename = os.path.join(basedir, "cards.json")
    export_all_locales_cards_to_file(cards, filename)
    filename = os.path.join(basedir, "cards.collectible.json")
    export_all_locales_cards_to_file(collectible_cards, filename)
Exemplo n.º 7
0
	def parse_card_tag_dbf(self, path):
		self.info("Processing CARD_TAG DBF %r" % (path))
		dbf = Dbf.load(path)

		for record in dbf.records:
			dbf_id = record["CARD_ID"]
			card_id = self.dbf_ids[dbf_id]
			tag = record["TAG_ID"]
			value = record["TAG_VALUE"]
			is_reference = record["IS_REFERENCE_TAG"]
			# ispower = record["IS_POWER_KEYWORD_TAG"]
			if card_id not in self.entities:
				self.warn("Entity %r not found in card defs but present in CARD_TAG.xml" % (card_id))
			elif is_reference:
				self.entities[card_id].referenced_tags[tag] = value
			else:
				self.entities[card_id].tags[tag] = value
Exemplo n.º 8
0
def main():
	for locale in Locale:
		if locale.unused:
			continue

		db, xml = load("hs-data/CardDefs.xml", locale=locale.name)

		basedir = os.path.join("out", "latest", locale.name)
		if not os.path.exists(basedir):
			os.makedirs(basedir)

		filename = os.path.join(basedir, "cards.json")
		export_cards_to_file(db.values(), filename)

		filename = os.path.join(basedir, "cards.collectible.json")
		export_cards_to_file([card for card in db.values() if card.collectible], filename)

		filename = os.path.join(basedir, "cardbacks.json")
		dbf = Dbf.load("hs-data/DBF/CARD_BACK.xml")
		write_cardbacks(dbf, filename, locale)
Exemplo n.º 9
0
    def parse_card_dbf(self, path):
        self.info("Processing CARD DBF %r" % (path))
        dbf = Dbf.load(path)

        # Whether we'll set the CARD_TAG dbf-style (post-15590) string tags
        apply_locstrings = "NAME" in dbf.columns

        for record in dbf.records:
            id = record["ID"]
            card_id = record["NOTE_MINI_GUID"]
            long_guid = record.get("LONG_GUID", "")
            hero_power_id = record.get("HERO_POWER_ID")
            artist = record.get("ARTIST_NAME", "") or ""

            if apply_locstrings:
                self.entity_strings[card_id] = {}
                for tag, column, _ in self.tag_dbf_localized_columns:
                    r = record.get(column) or {}
                    self.entity_strings[card_id][tag] = r

            self.record_card(id, card_id, long_guid, hero_power_id, artist)
Exemplo n.º 10
0
	def parse_card_dbf(self, path):
		self.info("Processing CARD DBF %r" % (path))
		dbf = Dbf.load(path)

		# Whether we'll set the CARD_TAG dbf-style (post-15590) string tags
		apply_locstrings = "NAME" in dbf.columns

		for record in dbf.records:
			id = record["ID"]
			card_id = record["NOTE_MINI_GUID"]
			long_guid = record.get("LONG_GUID", "")
			hero_power_id = record.get("HERO_POWER_ID")
			artist = record.get("ARTIST_NAME", "") or ""

			if apply_locstrings:
				self.entity_strings[card_id] = {}
				for tag, column, _ in self.tag_dbf_localized_columns:
					r = record.get(column) or {}
					self.entity_strings[card_id][tag] = r

			self.record_card(id, card_id, long_guid, hero_power_id, artist)
Exemplo n.º 11
0
	def load_dbf(self, filename):
		self.stdout.write("Parsing %s" % (filename))
		dbf = Dbf.load(filename)
		if dbf.name not in self.tables:
			self.stderr.write("No handler for %r (%r)" % (filename, dbf.name))
			return

		cls = self.tables[dbf.name]
		for record in dbf.records:
			values = self.get_values(record, cls.dbf_columns)
			try:
				instance = cls.objects.get(id=record["ID"])
			except cls.DoesNotExist:
				instance = cls.objects.create(**values)
				self.stdout.write("Created %r (build %r)" % (instance, self.build))
			else:
				if self.force or instance.build < self.build:
					self.stdout.write("Updating %r to build %r" % (instance, self.build))
					for k, v in values.items():
						setattr(instance, k, v)
					instance.save()
				else:
					self.stdout.write("Skipping %r (up to date)" % (instance))
Exemplo n.º 12
0
	def parse_card_dbf(self, path):
		self.info("Processing CARD DBF %r" % (path))
		dbf = Dbf.load(path)

		# Whether we'll set the CARD_TAG dbf-style (post-15590) string tags
		apply_locstrings = "NAME" in dbf.columns

		for record in dbf.records:
			id = record["ID"]
			card_id = record["NOTE_MINI_GUID"]
			self.dbf_ids[id] = card_id

			long_guid = record.get("LONG_GUID")
			if long_guid:
				self.guids[long_guid] = card_id

			if apply_locstrings:
				self.entity_strings[card_id] = {}
				for tag, column in self.tag_dbf_localized_columns:
					r = record.get(column) or {}
					self.entity_strings[card_id][tag] = r

				# Artist name is not localized in the new layout
				artist = record.get("ARTIST_NAME") or ""
				self.entity_strings[card_id][GameTag.ARTISTNAME] = {"enUS": artist}

			if card_id not in self.entities:
				self.warn("Entity %r not found in card defs but present in CARD.xml" % (card_id))
				continue

			entity = self.entities[card_id]
			entity.dbf_id = id

			hero_power_id = record.get("HERO_POWER_ID")
			if hero_power_id:
				entity.tags[GameTag.HERO_POWER] = hero_power_id
Exemplo n.º 13
0
 def dbf_from_unity_object(self, obj):
     dbf = Dbf()
     dbf.populate_from_unity_object(obj)
     return dbf
Exemplo n.º 14
0
	def dbf_from_unity_object(self, obj):
		dbf = Dbf()
		dbf.populate_from_unity_object(obj)
		return dbf