diff --git a/DEV.md b/DEV.md index 6b6a09c..8d1d7e5 100644 --- a/DEV.md +++ b/DEV.md @@ -1,4 +1,4 @@ python -m build --wheel python setup.py bdist_wheel -pip install .\dist\deppth2-0.1.5.0-py3-none-any.whl \ No newline at end of file +pip install .\dist\deppth2-0.1.6.0-py3-none-any.whl diff --git a/deppth2/deppth2.py b/deppth2/deppth2.py index 23fcc7e..dbed175 100644 --- a/deppth2/deppth2.py +++ b/deppth2/deppth2.py @@ -1,6 +1,6 @@ """Top-level API exposure of package actions""" -__version__ = "0.1.5.0" +__version__ = "0.1.6.0" import os import sys diff --git a/deppth2/texpacking.py b/deppth2/texpacking.py index d425f16..4aa1f28 100644 --- a/deppth2/texpacking.py +++ b/deppth2/texpacking.py @@ -36,7 +36,7 @@ def build_atlases(source_dir, target_dir, basename, size, include_hulls=False): return (hulls, namemap) def build_atlases_hades(source_dir, target_dir, deppth2_pack=True, include_hulls=False, logger=lambda s: None, codec='RGBA'): - """ + """ Build texture atlases from images within a source directory. Args: @@ -50,67 +50,67 @@ def build_atlases_hades(source_dir, target_dir, deppth2_pack=True, include_hulls Returns: None - """ - - print(target_dir) - basename = os.path.splitext(os.path.basename(target_dir))[0] - print(basename) - - # Regex check to make sure user inserts a mod guid type basename - regexpattern = r"^[a-z0-9]+(\w+[a-z0-9])?-\w+$" - - if re.match(regexpattern, basename, flags=re.I|re.A): - pass - else: - print("Please provide a target with your mod guid, example ThunderstoreTeamName-Modname") - return - - if os.path.isdir(target_dir) == True: - print(f"Target directory {target_dir} already exists, deleting it.") - shutil.rmtree(target_dir) + """ + + print(target_dir) + basename = os.path.splitext(os.path.basename(target_dir))[0] + print(basename) + + # Regex check to make sure user inserts a mod guid type basename + regexpattern = r"^[a-z0-9]+(\w+[a-z0-9])?-\w+$" - os.mkdir(target_dir, 0o666) - os.mkdir(os.path.join(target_dir, "manifest"), 0o666) - os.mkdir(os.path.join(target_dir, "textures"), 0o666) - os.mkdir(os.path.join(target_dir, "textures", "atlases"), 0o666) - - files = find_files(source_dir) - hulls = {} - namemap = {} - for filename in files: - # Build hulls for each image so we can store them later - if include_hulls: - hulls[filename.name] = get_hull_points(filename) + if re.match(regexpattern, basename, flags=re.I|re.A): + pass else: - hulls[filename.name] = [] - namemap[filename.name] = str(filename) - - # Perfom the packing. This will create the spritesheets and primitive atlases, which we'll need to turn to usable ones - packer = PyTexturePacker.Packer.create(max_width=4096, max_height=4096, bg_color=0x00000000, atlas_format='json', - enable_rotated=False, trim_mode=1, border_padding=0, shape_padding=0) - packer.pack(files, f'{basename}%d') - - # Now, loop through the atlases made and transform them to be the right format - index = 0 - atlases = [] - manifest_paths = [] # Manifest Path Start - while os.path.exists(f'{basename}{index}.json'): - atlases.append(transform_atlas(target_dir, basename, f'{basename}{index}.json', namemap, hulls, source_dir, manifest_paths)) - os.remove(f'{basename}{index}.json') - index += 1 - - # Now, loop through the atlas images made and move them to the package folder - index = 0 - while os.path.exists(f'{basename}{index}.png') or os.path.exists(f'{basename}{index}.dds'): - try: - os.rename(f'{basename}{index}.png', os.path.join(target_dir, "textures", "atlases", f'{basename}{index}.png')) - except: - pass - try: - os.rename(f'{basename}{index}.dds', os.path.join(target_dir, "textures", "atlases", f'{basename}{index}.dds')) - except: - pass - index += 1 + print("Please provide a target with your mod guid, example ThunderstoreTeamName-Modname") + return + + if os.path.isdir(target_dir) == True: + print(f"Target directory {target_dir} already exists, deleting it.") + shutil.rmtree(target_dir) + + os.mkdir(target_dir, 0o666) + os.mkdir(os.path.join(target_dir, "manifest"), 0o666) + os.mkdir(os.path.join(target_dir, "textures"), 0o666) + os.mkdir(os.path.join(target_dir, "textures", "atlases"), 0o666) + + files = find_files(source_dir) + hulls = {} + namemap = {} + for filename in files: + # Build hulls for each image so we can store them later + if include_hulls: + hulls[filename.name] = get_hull_points(filename) + else: + hulls[filename.name] = [] + namemap[filename.name] = str(filename) + + # Perfom the packing. This will create the spritesheets and primitive atlases, which we'll need to turn to usable ones + packer = PyTexturePacker.Packer.create(max_width=4096, max_height=4096, bg_color=0x00000000, atlas_format='json', + enable_rotated=False, trim_mode=1, border_padding=0, shape_padding=1) + packer.pack(files, f'{basename}%d') + + # Now, loop through the atlases made and transform them to be the right format + index = 0 + atlases = [] + manifest_paths = [] # Manifest Path Start + while os.path.exists(f'{basename}{index}.json'): + atlases.append(transform_atlas(target_dir, basename, f'{basename}{index}.json', namemap, hulls, source_dir, manifest_paths)) + os.remove(f'{basename}{index}.json') + index += 1 + + # Now, loop through the atlas images made and move them to the package folder + index = 0 + while os.path.exists(f'{basename}{index}.png') or os.path.exists(f'{basename}{index}.dds'): + try: + os.rename(f'{basename}{index}.png', os.path.join(target_dir, "textures", "atlases", f'{basename}{index}.png')) + except: + pass + try: + os.rename(f'{basename}{index}.dds', os.path.join(target_dir, "textures", "atlases", f'{basename}{index}.dds')) + except: + pass + index += 1 # Create the packages if deppth2_pack: @@ -118,9 +118,9 @@ def build_atlases_hades(source_dir, target_dir, deppth2_pack=True, include_hulls pack(target_dir, f'{target_dir}.pkg', *[], logger=lambda s: print(s), codec=codec) # print the manifest paths, so its easy to see the game path - print("\nManifest Paths - Use in Codebase:") + print("\nManifest Paths, _PLUGIN.guid followed by directory paths - Use in Codebase:\n") for path in manifest_paths: - print(path, "\n") + print(path) @requires('scipy.spatial') def get_hull_points(path):