2024-01-10 09:16:36 +01:00
from . special_convert_cases import convert_map_textures , convert_armor_textures , convert_chest_textures , convert_rail_textures , convert_banner_overlays , convert_grass_textures
2024-01-09 18:28:43 +01:00
from . utils import target_dir , colorize , colorize_alpha
2024-01-10 09:16:36 +01:00
import shutil
import csv
import os
import tempfile
import sys
import argparse
import glob
def convert_standard_textures (
make_texture_pack ,
dry_run ,
verbose ,
base_dir ,
tex_dir ,
tempfile1 ,
tempfile2 ,
output_dir ,
output_dir_name ,
mineclone2_path ,
PXSIZE ) :
2024-01-09 18:28:43 +01:00
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 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
2024-01-10 09:16:36 +01:00
src_file = base_dir + src_dir + " / " + src_filename # source file
2024-01-09 18:28:43 +01:00
src_file_exists = os . path . isfile ( src_file )
2024-01-10 09:16:36 +01:00
dst_file = target_dir ( dst_dir , make_texture_pack , output_dir , output_dir_name ,
mineclone2_path ) + " / " + dst_filename # destination file
2024-01-09 18:28:43 +01:00
if src_file_exists == False :
2024-01-10 09:16:36 +01:00
print ( " WARNING: Source file does not exist: " + src_file )
2024-01-09 18:28:43 +01:00
failed_conversions = failed_conversions + 1
continue
if xs != None :
# Crop and copy images
if not dry_run :
2024-01-10 09:16:36 +01:00
os . system ( " convert " + src_file + " -crop " + xl +
" x " + yl + " + " + xs + " + " + ys + " " + dst_file )
2024-01-09 18:28:43 +01:00
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 )
2024-01-10 09:16:36 +01:00
return failed_conversions
2024-01-09 18:28:43 +01:00
2024-01-10 09:16:36 +01:00
def convert_textures ( make_texture_pack , dry_run , verbose , base_dir , tex_dir , tempfile1 , tempfile2 , output_dir , output_dir_name , mineclone2_path , PXSIZE ) :
print ( " Texture conversion BEGINS NOW! " )
2024-01-09 18:28:43 +01:00
2024-01-10 09:16:36 +01:00
# Convert textures listed in the Conversion_Table.csv
failed_conversions = convert_standard_textures ( make_texture_pack , dry_run , verbose , base_dir , tex_dir ,
tempfile1 , tempfile2 , output_dir , output_dir_name , mineclone2_path , PXSIZE )
2024-01-09 18:28:43 +01:00
2024-01-10 09:16:36 +01:00
# Conversion of map backgrounds
convert_map_textures ( make_texture_pack , dry_run , verbose , base_dir , tex_dir ,
tempfile1 , tempfile2 , output_dir , output_dir_name , mineclone2_path , PXSIZE )
2024-01-09 18:28:43 +01:00
2024-01-10 09:16:36 +01:00
# Convert armor textures
convert_armor_textures ( make_texture_pack , dry_run , verbose , base_dir , tex_dir , tempfile1 , tempfile2 , output_dir , output_dir_name , mineclone2_path , PXSIZE )
2024-01-09 18:28:43 +01:00
2024-01-10 09:16:36 +01:00
# Convert chest textures
convert_chest_textures ( make_texture_pack , dry_run , verbose , base_dir , tex_dir , tempfile1 , tempfile2 , output_dir , output_dir_name , mineclone2_path , PXSIZE )
2024-01-09 18:28:43 +01:00
2024-01-10 09:16:36 +01:00
# Generate railway crossings and t-junctions
convert_rail_textures ( make_texture_pack , dry_run , verbose , base_dir , tex_dir , tempfile1 , tempfile2 , output_dir , output_dir_name , mineclone2_path , PXSIZE )
2024-01-09 18:28:43 +01:00
2024-01-10 09:16:36 +01:00
# Convert banner overlays
convert_banner_overlays ( make_texture_pack , dry_run , verbose , base_dir , tex_dir , tempfile1 , tempfile2 , output_dir , output_dir_name , mineclone2_path , PXSIZE )
2024-01-09 18:28:43 +01:00
2024-01-10 09:16:36 +01:00
# Convert grass and related textures
convert_grass_textures ( make_texture_pack , dry_run , verbose , base_dir , tex_dir , tempfile1 , tempfile2 , output_dir , output_dir_name , mineclone2_path , PXSIZE )
2024-01-09 18:28:43 +01:00
2024-01-10 09:16:36 +01:00
# Metadata
if make_texture_pack :
# Create description file
description = " Texture pack for MineClone 2. Automatically converted from a Minecraft resource pack by the MineClone 2 Texture Converter. Size: " + str ( PXSIZE ) + " × " + str ( PXSIZE )
description_file = open ( target_dir ( " / " , make_texture_pack , output_dir , output_dir_name , mineclone2_path ) + " /description.txt " , " w " )
description_file . write ( description )
description_file . close ( )
2024-01-09 18:28:43 +01:00
2024-01-10 09:16:36 +01:00
# Create preview image (screenshot.png)
os . system ( " convert -size 300x200 canvas:transparent " + target_dir ( " / " , make_texture_pack , output_dir , output_dir_name , mineclone2_path ) + " /screenshot.png " )
os . system ( " composite " + base_dir + " /pack.png " + target_dir ( " / " , make_texture_pack , output_dir , output_dir_name , mineclone2_path ) + " /screenshot.png -gravity center " + target_dir ( " / " , make_texture_pack , output_dir , output_dir_name , mineclone2_path ) + " /screenshot.png " )
2024-01-09 18:28:43 +01:00
2024-01-10 09:16:36 +01:00
print ( " Textures conversion COMPLETE! " )
if failed_conversions > 0 :
print ( " WARNING: Number of missing files in original resource pack: " + str ( failed_conversions ) )
print ( " NOTE: Please keep in mind this script does not reliably convert all the textures yet. " )
if make_texture_pack :
print ( " You can now retrieve the texture pack in " + output_dir + " / " + output_dir_name + " / " )