From 4424b3b220f2aae6812f398f2b69fcad2184adf7 Mon Sep 17 00:00:00 2001 From: matt Date: Wed, 19 May 2021 22:02:55 +1200 Subject: [PATCH] Check if atlasRegion has splits data when editing ninepatch If the atlasRegion does not have splits data, it will be added to the atlasRegion and the .atlas file will be updated as well. --- .../plugin/ninepatch/MainPanelMediator.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/plugin-9patch/src/main/java/games/rednblack/editor/plugin/ninepatch/MainPanelMediator.java b/plugin-9patch/src/main/java/games/rednblack/editor/plugin/ninepatch/MainPanelMediator.java index 3aa369f2..9860a572 100644 --- a/plugin-9patch/src/main/java/games/rednblack/editor/plugin/ninepatch/MainPanelMediator.java +++ b/plugin-9patch/src/main/java/games/rednblack/editor/plugin/ninepatch/MainPanelMediator.java @@ -149,8 +149,34 @@ public class MainPanelMediator extends Mediator { private void loadRegion(String name) { TextureAtlas atlas = plugin.getAPI().getProjectTextureAtlas(); + validateNinePatchTextureRegion(atlas.findRegion(name)); viewComponent.setTexture(atlas.findRegion(name)); viewComponent.setListeners(plugin.getAPI().getUIStage()); } + + private void validateNinePatchTextureRegion(TextureAtlas.AtlasRegion texture) { + int[] s = texture.findValue("split"); + if (s == null) { + // Add splits to the atlasRegion if they are missing + fixNinePatch(texture); + } + } + + private void fixNinePatch(TextureAtlas.AtlasRegion texture) { + int[] splits = {0, 0, 0, 0}; + int[] pad = {0, 0, 0, 0}; + texture.names = new String[] {"split", "pad"}; + texture.values = new int[][] {splits, pad}; + + //remove original image + File originalImg = new File(plugin.getAPI().getProjectPath() + "/assets/orig/images/"+texture.name+".png"); + originalImg.delete(); + + //save project + plugin.getAPI().saveProject(); + + //save split data + addSplitsToImageInAtlas(texture.name, splits); + } }