@@ -36,7 +36,7 @@ def build_atlases(source_dir, target_dir, basename, size, include_hulls=False):
3636 return (hulls , namemap )
3737
3838def build_atlases_hades (source_dir , target_dir , deppth2_pack = True , include_hulls = False , logger = lambda s : None , codec = 'RGBA' ):
39- """
39+ """
4040 Build texture atlases from images within a source directory.
4141
4242 Args:
@@ -50,77 +50,77 @@ def build_atlases_hades(source_dir, target_dir, deppth2_pack=True, include_hulls
5050
5151 Returns:
5252 None
53- """
54-
55- print (target_dir )
56- basename = os .path .splitext (os .path .basename (target_dir ))[0 ]
57- print (basename )
58-
59- # Regex check to make sure user inserts a mod guid type basename
60- regexpattern = r"^[a-z0-9]+(\w+[a-z0-9])?-\w+$"
61-
62- if re .match (regexpattern , basename , flags = re .I | re .A ):
63- pass
64- else :
65- print ("Please provide a target with your mod guid, example ThunderstoreTeamName-Modname" )
66- return
67-
68- if os .path .isdir (target_dir ) == True :
69- print (f"Target directory { target_dir } already exists, deleting it." )
70- shutil .rmtree (target_dir )
53+ """
54+
55+ print (target_dir )
56+ basename = os .path .splitext (os .path .basename (target_dir ))[0 ]
57+ print (basename )
58+
59+ # Regex check to make sure user inserts a mod guid type basename
60+ regexpattern = r"^[a-z0-9]+(\w+[a-z0-9])?-\w+$"
7161
72- os .mkdir (target_dir , 0o666 )
73- os .mkdir (os .path .join (target_dir , "manifest" ), 0o666 )
74- os .mkdir (os .path .join (target_dir , "textures" ), 0o666 )
75- os .mkdir (os .path .join (target_dir , "textures" , "atlases" ), 0o666 )
76-
77- files = find_files (source_dir )
78- hulls = {}
79- namemap = {}
80- for filename in files :
81- # Build hulls for each image so we can store them later
82- if include_hulls :
83- hulls [filename .name ] = get_hull_points (filename )
62+ if re .match (regexpattern , basename , flags = re .I | re .A ):
63+ pass
8464 else :
85- hulls [filename .name ] = []
86- namemap [filename .name ] = str (filename )
87-
88- # Perfom the packing. This will create the spritesheets and primitive atlases, which we'll need to turn to usable ones
89- packer = PyTexturePacker .Packer .create (max_width = 4096 , max_height = 4096 , bg_color = 0x00000000 , atlas_format = 'json' ,
90- enable_rotated = False , trim_mode = 1 , border_padding = 0 , shape_padding = 0 )
91- packer .pack (files , f'{ basename } %d' )
92-
93- # Now, loop through the atlases made and transform them to be the right format
94- index = 0
95- atlases = []
96- manifest_paths = [] # Manifest Path Start
97- while os .path .exists (f'{ basename } { index } .json' ):
98- atlases .append (transform_atlas (target_dir , basename , f'{ basename } { index } .json' , namemap , hulls , source_dir , manifest_paths ))
99- os .remove (f'{ basename } { index } .json' )
100- index += 1
101-
102- # Now, loop through the atlas images made and move them to the package folder
103- index = 0
104- while os .path .exists (f'{ basename } { index } .png' ) or os .path .exists (f'{ basename } { index } .dds' ):
105- try :
106- os .rename (f'{ basename } { index } .png' , os .path .join (target_dir , "textures" , "atlases" , f'{ basename } { index } .png' ))
107- except :
108- pass
109- try :
110- os .rename (f'{ basename } { index } .dds' , os .path .join (target_dir , "textures" , "atlases" , f'{ basename } { index } .dds' ))
111- except :
112- pass
113- index += 1
65+ print ("Please provide a target with your mod guid, example ThunderstoreTeamName-Modname" )
66+ return
67+
68+ if os .path .isdir (target_dir ) == True :
69+ print (f"Target directory { target_dir } already exists, deleting it." )
70+ shutil .rmtree (target_dir )
71+
72+ os .mkdir (target_dir , 0o666 )
73+ os .mkdir (os .path .join (target_dir , "manifest" ), 0o666 )
74+ os .mkdir (os .path .join (target_dir , "textures" ), 0o666 )
75+ os .mkdir (os .path .join (target_dir , "textures" , "atlases" ), 0o666 )
76+
77+ files = find_files (source_dir )
78+ hulls = {}
79+ namemap = {}
80+ for filename in files :
81+ # Build hulls for each image so we can store them later
82+ if include_hulls :
83+ hulls [filename .name ] = get_hull_points (filename )
84+ else :
85+ hulls [filename .name ] = []
86+ namemap [filename .name ] = str (filename )
87+
88+ # Perfom the packing. This will create the spritesheets and primitive atlases, which we'll need to turn to usable ones
89+ packer = PyTexturePacker .Packer .create (max_width = 4096 , max_height = 4096 , bg_color = 0x00000000 , atlas_format = 'json' ,
90+ enable_rotated = False , trim_mode = 1 , border_padding = 0 , shape_padding = 1 )
91+ packer .pack (files , f'{ basename } %d' )
92+
93+ # Now, loop through the atlases made and transform them to be the right format
94+ index = 0
95+ atlases = []
96+ manifest_paths = [] # Manifest Path Start
97+ while os .path .exists (f'{ basename } { index } .json' ):
98+ atlases .append (transform_atlas (target_dir , basename , f'{ basename } { index } .json' , namemap , hulls , source_dir , manifest_paths ))
99+ os .remove (f'{ basename } { index } .json' )
100+ index += 1
101+
102+ # Now, loop through the atlas images made and move them to the package folder
103+ index = 0
104+ while os .path .exists (f'{ basename } { index } .png' ) or os .path .exists (f'{ basename } { index } .dds' ):
105+ try :
106+ os .rename (f'{ basename } { index } .png' , os .path .join (target_dir , "textures" , "atlases" , f'{ basename } { index } .png' ))
107+ except :
108+ pass
109+ try :
110+ os .rename (f'{ basename } { index } .dds' , os .path .join (target_dir , "textures" , "atlases" , f'{ basename } { index } .dds' ))
111+ except :
112+ pass
113+ index += 1
114114
115115 # Create the packages
116116 if deppth2_pack :
117117 from .deppth2 import pack
118118 pack (target_dir , f'{ target_dir } .pkg' , * [], logger = lambda s : print (s ), codec = codec )
119119
120120 # print the manifest paths, so its easy to see the game path
121- print ("\n Manifest Paths - Use in Codebase:" )
121+ print ("\n Manifest Paths, _PLUGIN.guid followed by directory paths - Use in Codebase:\n " )
122122 for path in manifest_paths :
123- print (path , " \n " )
123+ print (path )
124124
125125@requires ('scipy.spatial' )
126126def get_hull_points (path ):
0 commit comments