forked from VoxeLibre/VoxeLibre
Added --all flag.
This commit is contained in:
parent
0584fc4ebf
commit
e04f4d3b2a
|
@ -12,7 +12,7 @@ import shutil, csv, os, tempfile, sys, argparse, glob
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from collections import Counter
|
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.convert import convert_textures
|
||||||
from libtextureconverter.config import SUPPORTED_MINECRAFT_VERSION, working_dir, mineclone2_path, appname, home
|
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("-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("-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("-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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
### SETTINGS ###
|
### SETTINGS ###
|
||||||
|
@ -47,7 +48,7 @@ make_texture_pack = True # Adjust as needed
|
||||||
if args.default:
|
if args.default:
|
||||||
base_dir = handle_default_minecraft_texture(home, output_dir)
|
base_dir = handle_default_minecraft_texture(home, output_dir)
|
||||||
|
|
||||||
if base_dir == None:
|
if base_dir == None and not args.all:
|
||||||
print(
|
print(
|
||||||
"""ERROR: You didn't tell me the path to the Minecraft resource pack.
|
"""ERROR: You didn't tell me the path to the Minecraft resource pack.
|
||||||
Mind-reading has not been implemented yet.
|
Mind-reading has not been implemented yet.
|
||||||
|
@ -61,29 +62,43 @@ For the full help, use:
|
||||||
|
|
||||||
### END OF SETTINGS ###
|
### END OF SETTINGS ###
|
||||||
|
|
||||||
if PXSIZE is None:
|
|
||||||
PXSIZE = detect_pixel_size(base_dir)
|
|
||||||
|
|
||||||
tex_dir = base_dir + "/assets/minecraft/textures"
|
resource_packs = []
|
||||||
|
|
||||||
# Get texture pack name (from directory name)
|
if args.all:
|
||||||
bdir_split = base_dir.split("/")
|
for resource_path in find_all_minecraft_resourcepacks():
|
||||||
output_dir_name = bdir_split[-1]
|
resource_packs.append(resource_path)
|
||||||
if len(output_dir_name) == 0:
|
|
||||||
if len(bdir_split) >= 2:
|
|
||||||
output_dir_name = base_dir.split("/")[-2]
|
|
||||||
else:
|
|
||||||
# Fallback
|
|
||||||
output_dir_name = "New_MineClone_2_Texture_Pack"
|
|
||||||
|
|
||||||
# ENTRY POINT
|
if make_texture_pack and args.input:
|
||||||
if make_texture_pack and not os.path.isdir(output_dir+"/"+output_dir_name):
|
resource_packs.append(args.input)
|
||||||
os.mkdir(output_dir+"/"+output_dir_name)
|
|
||||||
|
|
||||||
tempfile1 = tempfile.NamedTemporaryFile()
|
for base_dir in resource_packs:
|
||||||
tempfile2 = tempfile.NamedTemporaryFile()
|
tex_dir = base_dir + "/assets/minecraft/textures"
|
||||||
|
|
||||||
convert_textures(make_texture_pack, dry_run, verbose, base_dir, tex_dir, tempfile1, tempfile2, output_dir, output_dir_name, mineclone2_path, PXSIZE)
|
# Get texture pack name (from directory name)
|
||||||
|
bdir_split = base_dir.split("/")
|
||||||
|
output_dir_name = bdir_split[-1]
|
||||||
|
if len(output_dir_name) == 0:
|
||||||
|
if len(bdir_split) >= 2:
|
||||||
|
output_dir_name = base_dir.split("/")[-2]
|
||||||
|
else:
|
||||||
|
# Fallback
|
||||||
|
output_dir_name = "New_MineClone_2_Texture_Pack"
|
||||||
|
|
||||||
tempfile1.close()
|
# ENTRY POINT
|
||||||
tempfile2.close()
|
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()
|
||||||
|
|
||||||
|
convert_textures(make_texture_pack, dry_run, verbose, base_dir, tex_dir, tempfile1, tempfile2, output_dir, output_dir_name, mineclone2_path, PXSIZE)
|
||||||
|
|
||||||
|
tempfile1.close()
|
||||||
|
tempfile2.close()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import shutil, csv, os, tempfile, sys, argparse, glob, re, zipfile
|
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 PIL import Image
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
|
|
||||||
|
@ -39,6 +39,26 @@ def find_highest_minecraft_version(home, supported_version):
|
||||||
highest_version = folder
|
highest_version = folder
|
||||||
return highest_version
|
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):
|
def handle_default_minecraft_texture(home, output_dir):
|
||||||
version = find_highest_minecraft_version(home, SUPPORTED_MINECRAFT_VERSION)
|
version = find_highest_minecraft_version(home, SUPPORTED_MINECRAFT_VERSION)
|
||||||
if not version:
|
if not version:
|
||||||
|
|
Loading…
Reference in New Issue