STBrian / MC3DS-Texture-Maker

A python app that helps with the creation of new texture packs for Minecraft New 3DS Edition
GNU General Public License v3.0
8 stars 1 forks source link

Added new Tool Option (atlas color extractor), and made the List Updating faster. #4

Closed Cracko298 closed 6 months ago

Cracko298 commented 6 months ago
    def extract_colors(self):
        if os.path.exists(f"{self.app_path}\\MC3DS\\atlas"):
            pass
        else:
            print(f"No Atlas Avaliable...")
            return IndexError

        for i in range(2):
            if i == 0:
                image_path = f"{self.app_path}\\MC3DS\\atlas\\atlas.items.meta_79954554_0.3dst"
                print("Extracting colors from Items Atlas...")
            elif i == 1:
                image_path = f"{self.app_path}\\MC3DS\\atlas\\atlas.terrain.meta_79954554_0.3dst"
                print("Extracting colors from Blocks Atlas...")

            tmp0 = image_path.replace('.3dst','')
            output_path = f"colors_{os.path.basename(tmp0)}.txt"
            existing_colors = set()

            try:
                with open(output_path, "r") as existing_file:
                    existing_colors = {line.strip() for line in existing_file}
            except FileNotFoundError:
                pass

            with open(image_path, "rb") as image_file:
                image_file.seek(0x20)
                abgr_data = image_file.read()

                rgb_hex_values = []
                for i in range(0, len(abgr_data), 4):
                    _, b, g, r = abgr_data[i:i+4]
                    rgb_hex = "#{:02X}{:02X}{:02X}".format(r, g, b)

                    if rgb_hex not in existing_colors:
                        existing_colors.add(rgb_hex)
                        rgb_hex_values.append(rgb_hex)

            with open(output_path, "a") as output_file:
                for hex_value in rgb_hex_values:
                    output_file.write(hex_value + "\n")
                    time.sleep(0.000001)

            print("Success")

And changed the timing in the List Updating Itself.

Cracko298 commented 6 months ago

If need be, the timer is to make it seem like it's doing something and not instant. Disable it when merging if you want it to be instantaneous.

STBrian commented 6 months ago

I'm sorry, but I'm not sure if the tool fits the rest of the app.

Cracko298 commented 6 months ago

I'll remove the Extra Tool, any ideas for what you might want to implement that haven't been?