From afd23f0021011c26c121bb47513be20350deabfe Mon Sep 17 00:00:00 2001 From: UncertainProd Date: Sat, 16 Jul 2022 01:36:32 +0530 Subject: [PATCH] Had to remove no-merge option for now + some bugfixes --- src/engine/xmlpngengine.py | 116 +++++++++++++++++++------------------ src/settingswindow.py | 9 ++- 2 files changed, 66 insertions(+), 59 deletions(-) diff --git a/src/engine/xmlpngengine.py b/src/engine/xmlpngengine.py index fe8e4a4..5df59f9 100644 --- a/src/engine/xmlpngengine.py +++ b/src/engine/xmlpngengine.py @@ -25,7 +25,7 @@ def make_png_xml(frames, save_dir, character_name="Result", progressupdatefn=Non must_use_prefix = settings.get('must_use_prefix', 0) != 0 # use the custom prefix even if frame is from existing spritesheet padding_pixels = settings.get('frame_padding', 0) packing_algorithm = settings.get('packing_algo', 0) # 0 = Growing Packer, 1 = Ordered Packer - no_merge = settings.get('no_merge', 0) != 0 # no merging lookalike frames + # no_merge = settings.get('no_merge', 0) != 0 # no merging lookalike frames # print(len(imghashes)) # print(len(frames)) @@ -54,23 +54,25 @@ def make_png_xml(frames, save_dir, character_name="Result", progressupdatefn=Non frame_dict_arr = [] current_img_hashes = set([x.data.img_hash for x in frames]) - if no_merge: - for f in frames: + # Doesn't quite work yet, still a WIP + # if no_merge: + # for f in frames: + # frame_dict_arr.append({ + # "id": f.data.img_hash, + # "w": imghashes.get(f.data.img_hash).width + 2*padding_pixels, + # "h": imghashes.get(f.data.img_hash).height + 2*padding_pixels, + # "frame": f # this comes in handy later on + # }) + # else: + # pass + # add the padding to width and height, then actually padding the images (kind of a hack but it works TODO: work out a better way to do this) + for imhash, img in imghashes.items(): + if imhash in current_img_hashes: frame_dict_arr.append({ - "id": f.data.img_hash, - "w": imghashes.get(f.data.img_hash).width + 2*padding_pixels, - "h": imghashes.get(f.data.img_hash).height + 2*padding_pixels, - "frame": f # this comes in handy later on + "id": imhash, + "w": img.width + 2*padding_pixels, + "h": img.height + 2*padding_pixels }) - else: - # add the padding to width and height, then actually padding the images (kind of a hack but it works TODO: work out a better way to do this) - for imhash, img in imghashes.items(): - if imhash in current_img_hashes: - frame_dict_arr.append({ - "id": imhash, - "w": img.width + 2*padding_pixels, - "h": img.height + 2*padding_pixels - }) if packing_algorithm == 1: packer = OrderedPacker() @@ -94,47 +96,49 @@ def make_png_xml(frames, save_dir, character_name="Result", progressupdatefn=Non prgs += 1 progressupdatefn(prgs, "Adding images to spritesheet...") - if no_merge: - for framedict in frame_dict_arr: - frame = framedict['frame'] - subtexture_element = ET.Element("SubTexture") - subtexture_element.tail = linesep - w, h = imghashes.get(frame.data.img_hash).size - subtexture_element.attrib = { - "name" : frame.data.xml_pose_name, - "x": str(framedict['fit']['x']), - "y": str(framedict['fit']['y']), - "width": str(w + 2*padding_pixels), - "height": str(h + 2*padding_pixels), - "frameX": str(frame.data.framex), - "frameY": str(frame.data.framey), - "frameWidth": str(frame.data.framew), - "frameHeight": str(frame.data.frameh), - } - root.append(subtexture_element) - prgs += 1 - progressupdatefn(prgs, f"Saving {frame.data.xml_pose_name} to XML...") - else: + # Doesn't quite work yet, still a WIP + # if no_merge: + # for framedict in frame_dict_arr: + # frame = framedict['frame'] + # subtexture_element = ET.Element("SubTexture") + # subtexture_element.tail = linesep + # w, h = imghashes.get(frame.data.img_hash).size + # subtexture_element.attrib = { + # "name" : frame.data.xml_pose_name, + # "x": str(framedict['fit']['x']), + # "y": str(framedict['fit']['y']), + # "width": str(w + 2*padding_pixels), + # "height": str(h + 2*padding_pixels), + # "frameX": str(frame.data.framex), + # "frameY": str(frame.data.framey), + # "frameWidth": str(frame.data.framew), + # "frameHeight": str(frame.data.frameh), + # } + # root.append(subtexture_element) + # prgs += 1 + # progressupdatefn(prgs, f"Saving {frame.data.xml_pose_name} to XML...") + # else: + # pass # convert frame_dict_arr into a dict[image_hash -> position in spritesheet]: - imghash_dict = { rect['id']: (rect['fit']['x'], rect['fit']['y']) for rect in frame_dict_arr } - for frame in frames: - subtexture_element = ET.Element("SubTexture") - subtexture_element.tail = linesep - w, h = imghashes.get(frame.data.img_hash).size - subtexture_element.attrib = { - "name" : frame.data.xml_pose_name, - "x": str(imghash_dict[frame.data.img_hash][0]), - "y": str(imghash_dict[frame.data.img_hash][1]), - "width": str(w + 2*padding_pixels), - "height": str(h + 2*padding_pixels), - "frameX": str(frame.data.framex), - "frameY": str(frame.data.framey), - "frameWidth": str(frame.data.framew), - "frameHeight": str(frame.data.frameh), - } - root.append(subtexture_element) - prgs += 1 - progressupdatefn(prgs, f"Saving {frame.data.xml_pose_name} to XML...") + imghash_dict = { rect['id']: (rect['fit']['x'], rect['fit']['y']) for rect in frame_dict_arr } + for frame in frames: + subtexture_element = ET.Element("SubTexture") + subtexture_element.tail = linesep + w, h = imghashes.get(frame.data.img_hash).size + subtexture_element.attrib = { + "name" : frame.data.xml_pose_name, + "x": str(imghash_dict[frame.data.img_hash][0]), + "y": str(imghash_dict[frame.data.img_hash][1]), + "width": str(w + 2*padding_pixels), + "height": str(h + 2*padding_pixels), + "frameX": str(frame.data.framex), + "frameY": str(frame.data.framey), + "frameWidth": str(frame.data.framew), + "frameHeight": str(frame.data.frameh), + } + root.append(subtexture_element) + prgs += 1 + progressupdatefn(prgs, f"Saving {frame.data.xml_pose_name} to XML...") # im.close() print("Saving XML...") xmltree = ET.ElementTree(root) diff --git a/src/settingswindow.py b/src/settingswindow.py index 940f583..6b12137 100644 --- a/src/settingswindow.py +++ b/src/settingswindow.py @@ -24,6 +24,9 @@ def __init__(self, *args, **kwargs): self.ui.custom_prefix_radiobtn.toggled.connect(lambda is_toggled: self.ui.custom_prefix_text.setEnabled(is_toggled)) self.ui.save_settings_btn.clicked.connect(lambda: self.saveSettings()) # make sure event related parameters don't get accidentally sent to self.saveSettings self.ui.settings_cancel_btn.clicked.connect(self.restoreToNormal) + + # hide the no_merge checkbox for now as it is a WIP + self.ui.no_merge_checkbox.setVisible(False) def _get_prefix_type(self): if self.ui.custom_prefix_radiobtn.isChecked(): @@ -45,7 +48,7 @@ def restoreToNormal(self): self.ui.insist_prefix_checkbox.setCheckState(self.must_use_prefix) self.ui.frame_padding_spinbox.setValue(self.frame_padding) self.ui.packingalgo_combobox.setCurrentIndex(self.packing_algo) - self.ui.no_merge_checkbox.setCheckState(self.no_merge) + # self.ui.no_merge_checkbox.setCheckState(self.no_merge) self.close() def saveSettings(self, shouldclose=True): @@ -56,7 +59,7 @@ def saveSettings(self, shouldclose=True): self.must_use_prefix = self.ui.insist_prefix_checkbox.checkState() self.frame_padding = self.ui.frame_padding_spinbox.value() self.packing_algo = self.ui.packingalgo_combobox.currentIndex() - self.no_merge = self.ui.no_merge_checkbox.checkState() + # self.no_merge = self.ui.no_merge_checkbox.checkState() # saving to global settings obj g_settings['isclip'] = self.isclip g_settings['prefix_type'] = self.prefix_type @@ -64,7 +67,7 @@ def saveSettings(self, shouldclose=True): g_settings['must_use_prefix'] = self.must_use_prefix g_settings['frame_padding'] = self.frame_padding g_settings['packing_algo'] = self.packing_algo - g_settings['no_merge'] = self.no_merge + # g_settings['no_merge'] = self.no_merge if shouldclose: self.close()