Skip to content
Open
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 PyTexturePacker/MaxRectsPacker/MaxRectsAtlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def rank(self, main_rect, sub_rect, method=RANK_BSSF):
return tmp

def find_best_rank(self, image_rect, enable_rotated=False):
if enable_rotated:
if enable_rotated and image_rect.width != image_rect.height:
return self.find_best_rank_with_rotate(image_rect)
else:
return self.find_best_rank_without_rotate(image_rect)
Expand Down
6 changes: 5 additions & 1 deletion PyTexturePacker/PackerInterface/AtlasInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, width=1, height=1, max_width=MAX_WIDTH, max_height=MAX_HEIGHT

self.image_rect_list = []

def dump_plist(self, texture_file_name="", input_base_path=None, atlas_format=ATLAS_FORMAT_PLIST):
def dump_plist(self, texture_file_name="", input_base_path=None, atlas_format=ATLAS_FORMAT_PLIST, trim_sprite_names=False):
import os

plist_data = {}
Expand All @@ -59,6 +59,10 @@ def dump_plist(self, texture_file_name="", input_base_path=None, atlas_format=AT
else:
path = os.path.relpath(os.path.abspath(
path), os.path.abspath(input_base_path))
path = path.replace('\\', '/') # for windows path

if trim_sprite_names:
path, _ = os.path.splitext(path)

if atlas_format == ATLAS_FORMAT_PLIST:
frames[path] = dict(
Expand Down
5 changes: 3 additions & 2 deletions PyTexturePacker/PackerInterface/PackerInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class PackerInterface(object):

def __init__(self, bg_color=0x00000000, texture_format=".png", max_width=4096, max_height=4096, enable_rotated=True,
force_square=False, border_padding=2, shape_padding=2, inner_padding=0, trim_mode=0,
reduce_border_artifacts=False, extrude=0, atlas_format=Utils.ATLAS_FORMAT_PLIST, atlas_ext=None):
reduce_border_artifacts=False, extrude=0, atlas_format=Utils.ATLAS_FORMAT_PLIST, atlas_ext=None, trim_sprite_names=False):
"""
init a packer
:param bg_color: background color of output image.
Expand Down Expand Up @@ -66,6 +66,7 @@ def __init__(self, bg_color=0x00000000, texture_format=".png", max_width=4096, m
self.reduce_border_artifacts = reduce_border_artifacts
self.atlas_format = atlas_format
self.atlas_ext = atlas_ext
self.trim_sprite_names = trim_sprite_names

@staticmethod
def _calculate_area(image_rect_list, inner_padding):
Expand Down Expand Up @@ -192,7 +193,7 @@ def pack(self, input_images, output_name, output_path="", input_base_path=None):
texture_file_name = output_name if "%d" not in output_name else output_name % i

packed_plist = atlas.dump_plist("%s%s" % (texture_file_name, self.texture_format), input_base_path,
self.atlas_format)
self.atlas_format, trim_sprite_names = self.trim_sprite_names)
packed_image = atlas.dump_image(self.bg_color)

if self.reduce_border_artifacts:
Expand Down
7 changes: 6 additions & 1 deletion docs/2_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ atlas_ext
-------

Forces the atlas to use this extension regardless of the format.
If not provided, the atlas will use the default extension for the chosen format.
If not provided, the atlas will use the default extension for the chosen format.

trim_sprite_names
-----------------

Removes the file extension from the sprite names in the atlas.
6 changes: 3 additions & 3 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def load_test_suite():
test_path = os.path.abspath(TEST_MODULE)
files = os.listdir(test_path)

test_file_re = re.compile(TEST_CASE_NAME, re.IGNORECASE)
files = filter(test_file_re.match, files)

# test_file_re = re.compile(TEST_CASE_NAME, re.IGNORECASE)
# files = filter(test_file_re.match, files)
files = [f for f in files if re.match(TEST_CASE_NAME, f, re.IGNORECASE)]
module_names = map(lambda f: os.path.splitext(f)[0], files)
modules = map(lambda x: __import__("%s.%s" % (TEST_MODULE, x), fromlist=[TEST_MODULE]), module_names)

Expand Down
Loading
Loading