Skip to content

Commit 512a043

Browse files
authored
Merge pull request #7 from SGG-Modding/fix-bleedover-issue
Fix bleedover when packing textures (thread linked)
2 parents e272263 + 5c8b7a3 commit 512a043

3 files changed

Lines changed: 64 additions & 64 deletions

File tree

DEV.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
python -m build --wheel
22
python setup.py bdist_wheel
33

4-
pip install .\dist\deppth2-0.1.5.0-py3-none-any.whl
4+
pip install .\dist\deppth2-0.1.6.0-py3-none-any.whl

deppth2/deppth2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Top-level API exposure of package actions"""
22

3-
__version__ = "0.1.5.0"
3+
__version__ = "0.1.6.0"
44

55
import os
66
import sys

deppth2/texpacking.py

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def build_atlases(source_dir, target_dir, basename, size, include_hulls=False):
3636
return (hulls, namemap)
3737

3838
def 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("\nManifest Paths - Use in Codebase:")
121+
print("\nManifest 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')
126126
def get_hull_points(path):

0 commit comments

Comments
 (0)