Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DEV.md
Original file line number Diff line number Diff line change
@@ -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
pip install .\dist\deppth2-0.1.6.0-py3-none-any.whl
2 changes: 1 addition & 1 deletion deppth2/deppth2.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
124 changes: 62 additions & 62 deletions deppth2/texpacking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -50,77 +50,77 @@ 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:
from .deppth2 import pack
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):
Expand Down