More fixes

This commit is contained in:
James Clarke 2024-01-13 16:25:03 +00:00 committed by the-real-herowl
parent bb29dade32
commit 1a2b9e5930
2 changed files with 79 additions and 78 deletions

View File

@ -21,65 +21,71 @@ def convert_standard_textures(
output_dir_name, output_dir_name,
mineclone2_path, mineclone2_path,
PXSIZE): PXSIZE):
failed_conversions = 0 failed_conversions = 0
with open("Conversion_Table.csv", newline="") as csvfile: with open("Conversion_Table.csv", newline="") as csvfile:
reader = csv.reader(csvfile, delimiter=",", quotechar='"') reader = csv.reader(csvfile, delimiter=",", quotechar='"')
first_row = True first_row = True
for row in reader: for row in reader:
# Skip first row # Skip first row
if first_row: if first_row:
first_row = False first_row = False
continue continue
src_dir = row[0] src_dir = row[0]
src_filename = row[1] src_filename = row[1]
dst_dir = './textures' dst_dir = './textures'
dst_filename = row[2] dst_filename = row[2]
if row[4] != "": if row[4] != "":
xs = int(row[3]) xs = int(row[3])
ys = int(row[4]) ys = int(row[4])
xl = int(row[5]) xl = int(row[5])
yl = int(row[6]) yl = int(row[6])
xt = int(row[7]) xt = int(row[7])
yt = int(row[8]) yt = int(row[8])
else: else:
xs = None xs = None
blacklisted = row[9] blacklisted = row[9]
if blacklisted == "y": if blacklisted == "y":
# Skip blacklisted files # Skip blacklisted files
continue continue
if make_texture_pack == False and dst_dir == "": if make_texture_pack == False and dst_dir == "":
# If destination dir is empty, this texture is not supposed to be used in MCL2 # If destination dir is empty, this texture is not supposed to be used in MCL2
# (but maybe an external mod). It should only be used in texture packs. # (but maybe an external mod). It should only be used in texture packs.
# Otherwise, it must be ignored. # Otherwise, it must be ignored.
# Example: textures for mcl_supplemental # Example: textures for mcl_supplemental
continue continue
src_file = base_dir + src_dir + "/" + src_filename # source file src_file = base_dir + src_dir + "/" + src_filename # source file
src_file_exists = os.path.isfile(src_file) src_file_exists = os.path.isfile(src_file)
dst_file = target_dir(dst_dir, make_texture_pack, output_dir, output_dir_name, dst_file = target_dir(dst_dir, make_texture_pack, output_dir, output_dir_name,
mineclone2_path) + "/" + dst_filename # destination file mineclone2_path) + "/" + dst_filename # destination file
if src_file_exists == False: if src_file_exists == False:
print("WARNING: Source file does not exist: " + src_file) print("WARNING: Source file does not exist: " + src_file)
failed_conversions = failed_conversions + 1 failed_conversions = failed_conversions + 1
continue continue
if xs != None:
if xs != None: # Crop and copy images
# Crop and copy images if not dry_run:
if not dry_run: crop_width = int(xl)
os.system("convert " + src_file + " -crop " + xl + crop_height = int(yl)
"x" + yl + "+" + xs + "+" + ys + " " + dst_file) offset_x = int(xs)
if verbose: offset_y = int(ys)
print(src_file + "" + dst_file) with Image(filename=src_file) as img:
else: # Crop the image
img.crop(left=offset_x, top=offset_y, width=crop_width, height=crop_height)
# Save the result
img.save(filename=dst_file)
if verbose:
print(src_file + "" + dst_file)
else:
# Copy image verbatim # Copy image verbatim
if not dry_run: if not dry_run:
shutil.copy2(src_file, dst_file) shutil.copy2(src_file, dst_file)
if verbose: if verbose:
print(src_file + "" + dst_file) print(src_file + "" + dst_file)
return failed_conversions return failed_conversions
def convert_textures(make_texture_pack, dry_run, verbose, base_dir, tex_dir, tempfile1, tempfile2, output_dir, output_dir_name, mineclone2_path, PXSIZE): def convert_textures(make_texture_pack, dry_run, verbose, base_dir, tex_dir, tempfile1, tempfile2, output_dir, output_dir_name, mineclone2_path, PXSIZE):

View File

@ -202,31 +202,26 @@ def convert_armor_textures(
if os.path.isfile(layer_2): if os.path.isfile(layer_2):
leggings = adir + "/" + a[5] leggings = adir + "/" + a[5]
os.system("convert -size " + with Image(width=APXSIZE * 4, height=APXSIZE * 2, background=Color('none')) as img:
str(APXSIZE * with Image(filename=layer_2) as layer2:
4) + # Scale the image
"x" + layer2.resize(APXSIZE * 4, APXSIZE * 2)
str(APXSIZE *
2) + # Apply geometry and crop
" xc:none \\( " + crop_width = int(APXSIZE * 2.5)
layer_2 + crop_height = APXSIZE
" -scale " + crop_x = 0
str(APXSIZE * crop_y = APXSIZE
4) + layer2.crop(left=crop_x, top=crop_y, width=crop_width, height=crop_height)
"x" +
str(APXSIZE * # Composite the cropped image over the transparent image
2) + img.composite(layer2, 0, APXSIZE)
" -geometry +0+" +
str(APXSIZE) + # Apply channel operation
" -crop " + img.fx("a > 0.0 ? 1.0 : 0.0", channel='alpha')
str(APXSIZE *
2.5) + # Save the result
"x" + img.save(filename=leggings)
str(APXSIZE) +
"+0+" +
str(APXSIZE) +
" \\) -composite -channel A -fx \"(a > 0.0) ? 1.0 : 0.0\" " +
leggings)
# Convert chest textures # Convert chest textures