This is now a python libary for the gui script

This commit is contained in:
chmodsayshello 2022-02-10 14:08:50 +00:00
parent bce95a3ddc
commit cb3572fc24
1 changed files with 386 additions and 434 deletions

View File

@ -11,15 +11,27 @@ __status__ = "Development"
import shutil, csv, os, tempfile, sys, getopt
# Helper vars
home = os.environ["HOME"]
mineclone2_path = home + "/.minetest/games/mineclone2"
working_dir = os.getcwd()
initial_path = os.getcwd()
mineclone2_path = str(os.pardir)
os.chdir(os.pardir) # could be done with for i in range(1,3)
os.chdir(os.pardir)
os.chdir(os.pardir)
print(str(os.getcwd))
os.chdir("textures")
working_dir =str(os.getcwd())
print(working_dir)
appname = "Texture_Converter.py"
### SETTINGS ###
output_dir = working_dir
base_dir = None
# If True, will only make console output but not convert anything.
dry_run = False
@ -31,98 +43,40 @@ make_texture_pack = True
# If True, prints all copying actions
verbose = False
PXSIZE = 16
syntax_help = appname+""" -i <input dir> [-o <output dir>] [-d] [-v|-q] [-h]
Mandatory argument:
-i <input directory>
Directory of Minecraft resource pack to convert
Optional arguments:
-p <texture size>
Specify the size (in pixels) of the original textures (default: 16)
-o <output directory>
Directory in which to put the resulting Minetest texture pack
(default: working directory)
-d
Just pretend to convert textures and just print output, but do not actually
change any files.
-v
Print out all copying actions
-h
Show this help and exit"""
try:
opts, args = getopt.getopt(sys.argv[1:],"hi:o:p:dv")
except getopt.GetoptError:
print(
"""ERROR! The options you gave me make no sense!
Here's the syntax reference:""")
print(syntax_help)
sys.exit(2)
for opt, arg in opts:
if opt == "-h":
print(
"""This is the official MineClone 2 Texture Converter.
This will convert textures from Minecraft resource packs to
a Minetest texture pack.
Supported Minecraft version: 1.12 (Java Edition)
Syntax:""")
print(syntax_help)
sys.exit()
elif opt == "-d":
dry_run = True
elif opt == "-v":
verbose = True
elif opt == "-i":
base_dir = arg
elif opt == "-o":
output_dir = arg
elif opt == "-p":
PXSIZE = int(arg)
if base_dir == None:
print(
"""ERROR: You didn't tell me the path to the Minecraft resource pack.
Mind-reading has not been implemented yet.
Try this:
"""+appname+""" -i <path to resource pack> -p <texture size>
For the full help, use:
"""+appname+""" -h""")
sys.exit(2);
### END OF SETTINGS ###
Conversion_Table = None
def init(mcversion, path, pixels, name):
global Conversion_Table
if mcversion == 1:
Conversion_Table = str(initial_path) + "/Conversion_Table_112.csv"
if mcversion == 2:
Conversion_Table = str(initial_path) + "/Conversion_Table_118.csv"
global PXSIZE
global base_dir
global output_dir
global tex_dir
PXSIZE = pixels
base_dir = path
output_dir = working_dir + "/"+name
tex_dir = base_dir + "/assets/minecraft/textures"
print(
"""What is the Minecraft Version the resource pack is intended for
1: 1.12 and below
2: 1.13 and above
""")
version = input("Please enter 1 or 2: ")
Conversion_Table = ""
if version != "1" and version != "2":
print("Invalid Input, please restart the script and enter 1 or 2!")
sys.exit(2)
else:
if version == "1":
Conversion_Table = "Conversion_Table_112.csv"
else:
print("WARNING: 1.18 Textures can break when loaded in Mineclone, do you wish to continue (y/n): ")
if input("Enter y for yes ir n for no: ") == "y":
Conversion_Table = "Conversion_Table_118.csv"
else:
print("Stopped by user")
sys.exit(2)
# Get texture pack name (from directory name)
def convertit():
if os.path.isdir(output_dir) == False:
os.mkdir(output_dir)
if Conversion_Table == None:
return("error")
sys.exit(4)
bdir_split = base_dir.split("/")
output_dir_name = bdir_split[-1]
if len(output_dir_name) == 0:
@ -143,7 +97,7 @@ def colorize_alpha(colormap, source, colormap_pixel, texture_size, destination):
def target_dir(directory):
if make_texture_pack:
return output_dir + "/" + output_dir_name
return output_dir + "/"
else:
return mineclone2_path + directory
@ -485,8 +439,6 @@ def convert_textures():
print("You can now retrieve the texture pack in "+output_dir+"/"+output_dir_name+"/")
# ENTRY POINT
if make_texture_pack and not os.path.isdir(output_dir+"/"+output_dir_name):
os.mkdir(output_dir+"/"+output_dir_name)
tempfile1 = tempfile.NamedTemporaryFile()
tempfile2 = tempfile.NamedTemporaryFile()