1
0
Fork 0

Added --all flag.

This commit is contained in:
James Clarke 2024-01-10 04:08:30 +00:00 committed by the-real-herowl
parent 0584fc4ebf
commit e04f4d3b2a
2 changed files with 58 additions and 23 deletions

View File

@ -12,7 +12,7 @@ import shutil, csv, os, tempfile, sys, argparse, glob
from PIL import Image
from collections import Counter
from libtextureconverter.utils import detect_pixel_size, target_dir, colorize, colorize_alpha, handle_default_minecraft_texture
from libtextureconverter.utils import detect_pixel_size, target_dir, colorize, colorize_alpha, handle_default_minecraft_texture, find_all_minecraft_resourcepacks
from libtextureconverter.convert import convert_textures
from libtextureconverter.config import SUPPORTED_MINECRAFT_VERSION, working_dir, mineclone2_path, appname, home
@ -30,6 +30,7 @@ parser.add_argument("-p", "--pixelsize", type=int, help="Size (in pixels) of the
parser.add_argument("-d", "--dry_run", action="store_true", help="Pretend to convert textures without changing any files")
parser.add_argument("-v", "--verbose", action="store_true", help="Print out all copying actions")
parser.add_argument("-def", "--default", action="store_true", help="Use the default Minecraft texture pack")
parser.add_argument("-a", "--all", action="store_true", help="Convert all known Minecraft texturepacks")
args = parser.parse_args()
### SETTINGS ###
@ -47,7 +48,7 @@ make_texture_pack = True # Adjust as needed
if args.default:
base_dir = handle_default_minecraft_texture(home, output_dir)
if base_dir == None:
if base_dir == None and not args.all:
print(
"""ERROR: You didn't tell me the path to the Minecraft resource pack.
Mind-reading has not been implemented yet.
@ -61,9 +62,17 @@ For the full help, use:
### END OF SETTINGS ###
if PXSIZE is None:
PXSIZE = detect_pixel_size(base_dir)
resource_packs = []
if args.all:
for resource_path in find_all_minecraft_resourcepacks():
resource_packs.append(resource_path)
if make_texture_pack and args.input:
resource_packs.append(args.input)
for base_dir in resource_packs:
tex_dir = base_dir + "/assets/minecraft/textures"
# Get texture pack name (from directory name)
@ -80,6 +89,12 @@ if len(output_dir_name) == 0:
if make_texture_pack and not os.path.isdir(output_dir+"/"+output_dir_name):
os.mkdir(output_dir+"/"+output_dir_name)
# If, set to convert all resourcepacks, then autodetect pixel size
if args.all:
PXSIZE = None
if PXSIZE is None:
PXSIZE = detect_pixel_size(base_dir)
tempfile1 = tempfile.NamedTemporaryFile()
tempfile2 = tempfile.NamedTemporaryFile()

View File

@ -1,5 +1,5 @@
import shutil, csv, os, tempfile, sys, argparse, glob, re, zipfile
from .config import SUPPORTED_MINECRAFT_VERSION
from .config import SUPPORTED_MINECRAFT_VERSION, home
from PIL import Image
from collections import Counter
@ -39,6 +39,26 @@ def find_highest_minecraft_version(home, supported_version):
highest_version = folder
return highest_version
def find_all_minecraft_resourcepacks():
resourcepacks_dir = os.path.join(home, '.minecraft', 'resourcepacks')
if not os.path.isdir(resourcepacks_dir):
print(f"Resource packs directory not found: {resourcepacks_dir}")
return
resourcepacks = []
for folder in os.listdir(resourcepacks_dir):
folder_path = os.path.join(resourcepacks_dir, folder)
if os.path.isdir(folder_path):
pack_png_path = os.path.join(folder_path, 'pack.png')
if os.path.isfile(pack_png_path):
print(f"Adding resourcepack '{folder}'")
resourcepacks.append(folder_path)
else:
print(f"pack.png not found in resourcepack '{folder}', not converting")
return resourcepacks
def handle_default_minecraft_texture(home, output_dir):
version = find_highest_minecraft_version(home, SUPPORTED_MINECRAFT_VERSION)
if not version: