mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-12-22 16:09:33 +01:00
More fixes
This commit is contained in:
parent
bb29dade32
commit
1a2b9e5930
2 changed files with 79 additions and 78 deletions
|
@ -21,65 +21,71 @@ def convert_standard_textures(
|
|||
output_dir_name,
|
||||
mineclone2_path,
|
||||
PXSIZE):
|
||||
failed_conversions = 0
|
||||
with open("Conversion_Table.csv", newline="") as csvfile:
|
||||
reader = csv.reader(csvfile, delimiter=",", quotechar='"')
|
||||
first_row = True
|
||||
for row in reader:
|
||||
# Skip first row
|
||||
if first_row:
|
||||
first_row = False
|
||||
continue
|
||||
src_dir = row[0]
|
||||
src_filename = row[1]
|
||||
dst_dir = './textures'
|
||||
dst_filename = row[2]
|
||||
if row[4] != "":
|
||||
xs = int(row[3])
|
||||
ys = int(row[4])
|
||||
xl = int(row[5])
|
||||
yl = int(row[6])
|
||||
xt = int(row[7])
|
||||
yt = int(row[8])
|
||||
else:
|
||||
xs = None
|
||||
blacklisted = row[9]
|
||||
failed_conversions = 0
|
||||
with open("Conversion_Table.csv", newline="") as csvfile:
|
||||
reader = csv.reader(csvfile, delimiter=",", quotechar='"')
|
||||
first_row = True
|
||||
for row in reader:
|
||||
# Skip first row
|
||||
if first_row:
|
||||
first_row = False
|
||||
continue
|
||||
src_dir = row[0]
|
||||
src_filename = row[1]
|
||||
dst_dir = './textures'
|
||||
dst_filename = row[2]
|
||||
if row[4] != "":
|
||||
xs = int(row[3])
|
||||
ys = int(row[4])
|
||||
xl = int(row[5])
|
||||
yl = int(row[6])
|
||||
xt = int(row[7])
|
||||
yt = int(row[8])
|
||||
else:
|
||||
xs = None
|
||||
blacklisted = row[9]
|
||||
|
||||
if blacklisted == "y":
|
||||
# Skip blacklisted files
|
||||
continue
|
||||
if blacklisted == "y":
|
||||
# Skip blacklisted files
|
||||
continue
|
||||
|
||||
if make_texture_pack == False and dst_dir == "":
|
||||
# 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.
|
||||
# Otherwise, it must be ignored.
|
||||
# Example: textures for mcl_supplemental
|
||||
continue
|
||||
if make_texture_pack == False and dst_dir == "":
|
||||
# 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.
|
||||
# Otherwise, it must be ignored.
|
||||
# Example: textures for mcl_supplemental
|
||||
continue
|
||||
|
||||
src_file = base_dir + src_dir + "/" + src_filename # source file
|
||||
src_file_exists = os.path.isfile(src_file)
|
||||
dst_file = target_dir(dst_dir, make_texture_pack, output_dir, output_dir_name,
|
||||
src_file = base_dir + src_dir + "/" + src_filename # source file
|
||||
src_file_exists = os.path.isfile(src_file)
|
||||
dst_file = target_dir(dst_dir, make_texture_pack, output_dir, output_dir_name,
|
||||
mineclone2_path) + "/" + dst_filename # destination file
|
||||
|
||||
if src_file_exists == False:
|
||||
print("WARNING: Source file does not exist: " + src_file)
|
||||
failed_conversions = failed_conversions + 1
|
||||
continue
|
||||
|
||||
if xs != None:
|
||||
# Crop and copy images
|
||||
if not dry_run:
|
||||
os.system("convert " + src_file + " -crop " + xl +
|
||||
"x" + yl + "+" + xs + "+" + ys + " " + dst_file)
|
||||
if verbose:
|
||||
print(src_file + " → " + dst_file)
|
||||
else:
|
||||
if src_file_exists == False:
|
||||
print("WARNING: Source file does not exist: " + src_file)
|
||||
failed_conversions = failed_conversions + 1
|
||||
continue
|
||||
if xs != None:
|
||||
# Crop and copy images
|
||||
if not dry_run:
|
||||
crop_width = int(xl)
|
||||
crop_height = int(yl)
|
||||
offset_x = int(xs)
|
||||
offset_y = int(ys)
|
||||
with Image(filename=src_file) as img:
|
||||
# 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
|
||||
if not dry_run:
|
||||
shutil.copy2(src_file, dst_file)
|
||||
if verbose:
|
||||
print(src_file + " → " + dst_file)
|
||||
return failed_conversions
|
||||
if not dry_run:
|
||||
shutil.copy2(src_file, dst_file)
|
||||
if verbose:
|
||||
print(src_file + " → " + dst_file)
|
||||
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):
|
||||
|
|
|
@ -202,31 +202,26 @@ def convert_armor_textures(
|
|||
|
||||
if os.path.isfile(layer_2):
|
||||
leggings = adir + "/" + a[5]
|
||||
os.system("convert -size " +
|
||||
str(APXSIZE *
|
||||
4) +
|
||||
"x" +
|
||||
str(APXSIZE *
|
||||
2) +
|
||||
" xc:none \\( " +
|
||||
layer_2 +
|
||||
" -scale " +
|
||||
str(APXSIZE *
|
||||
4) +
|
||||
"x" +
|
||||
str(APXSIZE *
|
||||
2) +
|
||||
" -geometry +0+" +
|
||||
str(APXSIZE) +
|
||||
" -crop " +
|
||||
str(APXSIZE *
|
||||
2.5) +
|
||||
"x" +
|
||||
str(APXSIZE) +
|
||||
"+0+" +
|
||||
str(APXSIZE) +
|
||||
" \\) -composite -channel A -fx \"(a > 0.0) ? 1.0 : 0.0\" " +
|
||||
leggings)
|
||||
with Image(width=APXSIZE * 4, height=APXSIZE * 2, background=Color('none')) as img:
|
||||
with Image(filename=layer_2) as layer2:
|
||||
# Scale the image
|
||||
layer2.resize(APXSIZE * 4, APXSIZE * 2)
|
||||
|
||||
# Apply geometry and crop
|
||||
crop_width = int(APXSIZE * 2.5)
|
||||
crop_height = APXSIZE
|
||||
crop_x = 0
|
||||
crop_y = APXSIZE
|
||||
layer2.crop(left=crop_x, top=crop_y, width=crop_width, height=crop_height)
|
||||
|
||||
# Composite the cropped image over the transparent image
|
||||
img.composite(layer2, 0, APXSIZE)
|
||||
|
||||
# Apply channel operation
|
||||
img.fx("a > 0.0 ? 1.0 : 0.0", channel='alpha')
|
||||
|
||||
# Save the result
|
||||
img.save(filename=leggings)
|
||||
|
||||
# Convert chest textures
|
||||
|
||||
|
|
Loading…
Reference in a new issue