Pack Spine and Sprite animation into main project atlas (finally!)

This commit is contained in:
fgnm
2021-05-30 00:03:33 +02:00
parent 05a899c57e
commit 72a3d4c087
18 changed files with 83 additions and 314 deletions
Binary file not shown.
@@ -86,7 +86,7 @@ public class ResourcesManager {
region = tiledPlugin.getAPI().getSceneLoader().getRm().getTextureRegion(name);
break;
case EntityFactory.SPRITE_TYPE:
region = tiledPlugin.getAPI().getSceneLoader().getRm().getSpriteAnimation(name).getRegions().get(0);
region = tiledPlugin.getAPI().getSceneLoader().getRm().getSpriteAnimation(name).get(0);
break;
}
}
@@ -95,7 +95,7 @@ public class ResourcesManager {
public SpineDrawable getSpineDrawable(String name) {
if (spineDrawableCache.get(name) == null) {
SkeletonJson skeletonJson = new SkeletonJson(tiledPlugin.getAPI().getSceneLoader().getRm().getSkeletonAtlas(name));
SkeletonJson skeletonJson = new SkeletonJson(tiledPlugin.getAPI().getSceneLoader().getRm().getMainPack());
SkeletonData skeletonData = skeletonJson.readSkeletonData(tiledPlugin.getAPI().getSceneLoader().getRm().getSkeletonJSON(name));
Skeleton skeleton = new Skeleton(skeletonData);
@@ -47,7 +47,7 @@ public class SpineDrawStrategy extends BasicDrawStrategy {
replaceSpineCommandBuilder.begin(entity);
String animName = tiledPlugin.getSelectedTileName();
replaceSpineCommandBuilder.setAnimationName(animName);
SkeletonJson skeletonJson = new SkeletonJson(tiledPlugin.getAPI().getSceneLoader().getRm().getSkeletonAtlas(animName));
SkeletonJson skeletonJson = new SkeletonJson(tiledPlugin.getAPI().getSceneLoader().getRm().getMainPack());
replaceSpineCommandBuilder.setSkeletonJson(skeletonJson);
SkeletonData skeletonData = skeletonJson.readSkeletonData((tiledPlugin.getAPI().getSceneLoader().getRm().getSkeletonJSON(animName)));
replaceSpineCommandBuilder.setSkeleton(new Skeleton(skeletonData));
@@ -51,7 +51,7 @@ public class SpriteDrawStrategy extends BasicDrawStrategy {
private Array<TextureAtlas.AtlasRegion> getRegions(String filter) {
// filtering regions by name
Array<TextureAtlas.AtlasRegion> allRegions = tiledPlugin.getAPI().getSceneLoader().getRm().getSpriteAnimation(filter).getRegions();
Array<TextureAtlas.AtlasRegion> allRegions = tiledPlugin.getAPI().getSceneLoader().getRm().getSpriteAnimation(filter);
Array<TextureAtlas.AtlasRegion> regions = new Array<>();
for(TextureAtlas.AtlasRegion region: allRegions) {
if(region.name.contains(filter)) {
@@ -43,9 +43,9 @@ public class ProjectVersionMigrator {
/**
* this is the current supported version, change when data format is changed, and add migration script
*/
public static String dataFormatVersion = "0.1.1";
public static String dataFormatVersion = "0.2.0";
private Json json = new Json();
private final Json json = new Json();
public ProjectVersionMigrator (String projectPath, ProjectVO projectVo) {
this.projectPath = projectPath;
@@ -57,7 +57,6 @@ public class VersionMigTo005 implements IVersionMigrator {
@Override
public boolean doMigration() {
// Rename folder animations to spine-animations in orig (if exist);
File animationsDir = new File(projectPath + File.separator + "assets" + File.separator + "orig" + File.separator + "animations");
if (animationsDir.exists() && animationsDir.isDirectory()) {
@@ -73,12 +72,6 @@ public class VersionMigTo005 implements IVersionMigrator {
projectInfoContents = FileUtils.readFileToString(projectInfoFile.file(), "utf-8");
ProjectInfoVO currentProjectInfoVO = json.fromJson(ProjectInfoVO.class, projectInfoContents);
projectManager.currentProjectInfoVO = currentProjectInfoVO;
// run through all resolutions and remake animations for all
for (ResolutionEntryVO resolutionEntryVO : currentProjectInfoVO.resolutions) {
ResolutionManager resolutionManager = facade.retrieveProxy(ResolutionManager.NAME);
resolutionManager.createResizedAnimations(resolutionEntryVO);
}
} catch (IOException e) {
e.printStackTrace();
}
@@ -131,6 +131,12 @@ public class ProjectManager extends Proxy {
ProjectVO projVo = new ProjectVO();
projVo.projectName = projectName;
projVo.projectVersion = ProjectVersionMigrator.dataFormatVersion;
TexturePackVO mainPack = new TexturePackVO();
mainPack.name = "main";
projVo.imagesPacks.put("main", mainPack);
TexturePackVO mainAnimPack = new TexturePackVO();
mainAnimPack.name = "main";
projVo.animationsPacks.put("main", mainAnimPack);
// create project info file
ProjectInfoVO projInfoVo = new ProjectInfoVO();
@@ -187,19 +193,6 @@ public class ProjectManager extends Proxy {
File prjFile = new File(prjFilePath);
if (!prjFile.isDirectory()) {
if (!prjFile.exists()) {
ProjectVO projVoEmpty = new ProjectVO();
projVoEmpty.projectName = prjFile.getName();
projVoEmpty.projectVersion = ProjectVersionMigrator.dataFormatVersion;
try {
FileUtils.writeStringToFile(prjFile, projVoEmpty.constructJsonString(), "utf-8");
} catch (IOException e) {
e.printStackTrace();
}
}
String projectContents = null;
try {
projectContents = FileUtils.readFileToString(projectFile.file(), "utf-8");
@@ -526,10 +519,8 @@ public class ProjectManager extends Proxy {
private void exportAnimations(String targetPath) {
exportSpineAnimationForResolution("orig", targetPath);
exportSpriteAnimationForResolution("orig", targetPath);
for (ResolutionEntryVO resolutionEntryVO : currentProjectInfoVO.resolutions) {
exportSpineAnimationForResolution(resolutionEntryVO.name, targetPath);
exportSpriteAnimationForResolution(resolutionEntryVO.name, targetPath);
}
}
@@ -548,21 +539,6 @@ public class ProjectManager extends Proxy {
}
}
private void exportSpriteAnimationForResolution(String res, String targetPath) {
String spineSrcPath = currentProjectPath + "/assets/" + res + File.separator + "sprite-animations";
try {
FileUtils.forceMkdir(new File(targetPath + File.separator + res + File.separator + "sprite_animations"));
File fileSrc = new File(spineSrcPath);
String finalTarget = targetPath + File.separator + res + File.separator + "sprite_animations";
File fileTargetSprite = new File(finalTarget);
FileUtils.copyDirectory(fileSrc, fileTargetSprite);
} catch (IOException e) {
e.printStackTrace();
}
}
private void exportPacks(String targetPath) {
String srcPath = currentProjectPath + "/assets";
FileHandle assetDirectoryHandle = Gdx.files.absolute(srcPath);
@@ -152,7 +152,6 @@ public class ResolutionManager extends Proxy {
copyTexturesFromTo(sourcePath, targetPath);
int resizeWarnings = resizeTextures(targetPath, resolutionEntryVO);
rePackProjectImages(resolutionEntryVO);
createResizedAnimations(resolutionEntryVO);
changePercentBy(5);
if (resizeWarnings > 0) {
Dialogs.showOKDialog(Sandbox.getInstance().getUIStage(), "Warning", resizeWarnings + " images were not resized for smaller resolutions due to already small size ( < 3px )");
@@ -177,138 +176,6 @@ public class ResolutionManager extends Proxy {
//handler.progressChanged(currentPercent);
}
public void createResizedAnimations(ResolutionEntryVO resolution) {
ProjectManager projectManager = facade.retrieveProxy(ProjectManager.NAME);
String currProjectPath = projectManager.getCurrentProjectPath();
// Unpack spine orig
File spineSourceDir = new File(currProjectPath + File.separator + "assets/orig/spine-animations");
if (spineSourceDir.exists()) {
for (File entry : spineSourceDir.listFiles()) {
if (entry.isDirectory()) {
String animName = FilenameUtils.removeExtension(entry.getName());
createResizedSpineAnimation(animName, resolution);
}
}
}
//Unpack sprite orig
File spriteSourceDir = new File(currProjectPath + File.separator + "assets/orig/sprite-animations");
if (spriteSourceDir.exists()) {
for (File entry : spriteSourceDir.listFiles()) {
if (entry.isDirectory()) {
String animName = FilenameUtils.removeExtension(entry.getName());
createResizedSpriteAnimation(animName, resolution);
}
}
}
}
public void createResizedSpriteAnimation(String animName, ResolutionEntryVO resolution) {
ProjectManager projectManager = facade.retrieveProxy(ProjectManager.NAME);
String currProjectPath = projectManager.getCurrentProjectPath();
File animAtlasFile = new File(currProjectPath + File.separator + "assets/orig/sprite-animations/" + animName + "/" + animName + ".atlas");
String tmpPath = currProjectPath + File.separator + "assets/orig/sprite-animations/" + animName + "/tmp";
File tmpFolder = new File(tmpPath);
try {
FileUtils.forceMkdir(new File(currProjectPath + File.separator + "assets/" + resolution.name + "/sprite-animations/"));
FileUtils.forceMkdir(new File(currProjectPath + File.separator + "assets/" + resolution.name + "/spine-animations/" + animName));
String targetPath = currProjectPath + File.separator + "assets/" + resolution.name + "/sprite-animations/" + animName;
File targetFolder = new File(targetPath);
unpackAtlasIntoTmpFolder(animAtlasFile, tmpPath);
resizeImagesTmpDirToResolution(animName, tmpFolder, resolution, targetFolder);
FileUtils.deleteDirectory(tmpFolder);
} catch (IOException e) {
e.printStackTrace();
}
}
public void unpackAtlasIntoTmpFolder(File atlasFile, String tmpDir) {
FileHandle atlasFileHandle = new FileHandle(atlasFile);
TextureAtlas.TextureAtlasData atlasData = new TextureAtlas.TextureAtlasData(atlasFileHandle, atlasFileHandle.parent(), false);
TextureUnpacker unpacker = new TextureUnpacker();
unpacker.splitAtlas(atlasData, tmpDir);
}
public void createResizedSpineAnimation(String animName, ResolutionEntryVO resolution) {
ProjectManager projectManager = facade.retrieveProxy(ProjectManager.NAME);
String currProjectPath = projectManager.getCurrentProjectPath();
File animAtlasFile = new File(currProjectPath + File.separator + "assets/orig/spine-animations/" + animName + "/" + animName + ".atlas");
String tmpPath = currProjectPath + File.separator + "assets/orig/spine-animations/" + animName + "/tmp";
File tmpFolder = new File(tmpPath);
try {
FileUtils.forceMkdir(new File(currProjectPath + File.separator + "assets/" + resolution.name + "/spine-animations/"));
FileUtils.forceMkdir(new File(currProjectPath + File.separator + "assets/" + resolution.name + "/spine-animations/" + animName));
String targetPath = currProjectPath + File.separator + "assets/" + resolution.name + "/spine-animations/" + animName;
File targetFolder = new File(targetPath);
unpackAtlasIntoTmpFolder(animAtlasFile, tmpPath);
resizeImagesTmpDirToResolution(animName, tmpFolder, resolution, targetFolder);
FileUtils.deleteDirectory(tmpFolder);
} catch (IOException e) {
e.printStackTrace();
}
}
public void resizeSpriteAnimationForAllResolutions(String animName, ProjectInfoVO currentProjectInfoVO) {
ProjectManager projectManager = facade.retrieveProxy(ProjectManager.NAME);
String currProjectPath = projectManager.getCurrentProjectPath();
File atlasFile = new File(currProjectPath + File.separator + "assets" + File.separator + "orig" + File.separator + "sprite-animations" + File.separator + animName + File.separator + animName + ".atlas");
String tmpDir = currProjectPath + File.separator + "assets" + File.separator + "orig" + File.separator + "sprite-animations" + File.separator + animName + File.separator + "tmp";
File sourceFolder = new File(tmpDir);
unpackAtlasIntoTmpFolder(atlasFile, tmpDir);
try {
for (ResolutionEntryVO resolutionEntryVO : currentProjectInfoVO.resolutions) {
String spriteAnimationsRoot = currProjectPath + File.separator + "assets" + File.separator + resolutionEntryVO.name + File.separator + "sprite-animations";
FileUtils.forceMkdir(new File(spriteAnimationsRoot));
String targetPath = spriteAnimationsRoot + File.separator + animName;
File targetFolder = new File(targetPath);
resizeImagesTmpDirToResolution(animName, sourceFolder, resolutionEntryVO, targetFolder);
}
FileUtils.deleteDirectory(sourceFolder);
} catch (IOException e) {
e.printStackTrace();
}
}
public void resizeSpineAnimationForAllResolutions(File atlasFile, ProjectInfoVO currentProjectInfoVO) {
String fileNameWithOutExt = FilenameUtils.removeExtension(atlasFile.getName());
ProjectManager projectManager = facade.retrieveProxy(ProjectManager.NAME);
String tmpDir = projectManager.getCurrentProjectPath() + "/assets/orig/spine-animations" + File.separator + fileNameWithOutExt + File.separator + "tmp";
File sourceFolder = new File(tmpDir);
unpackAtlasIntoTmpFolder(atlasFile, tmpDir);
try {
for (ResolutionEntryVO resolutionEntryVO : currentProjectInfoVO.resolutions) {
FileUtils.forceMkdir(new File(projectManager.getCurrentProjectPath() + File.separator +
"assets" + File.separator + resolutionEntryVO.name + File.separator + "spine-animations"));
String targetPath = projectManager.getCurrentProjectPath() + File.separator + "assets" +
File.separator + resolutionEntryVO.name + File.separator + "spine-animations" + File.separator + fileNameWithOutExt;
FileUtils.forceMkdir(new File(targetPath));
File targetFolder = new File(targetPath);
resizeImagesTmpDirToResolution(atlasFile.getName(), sourceFolder, resolutionEntryVO, targetFolder);
}
FileUtils.deleteDirectory(sourceFolder);
} catch (IOException e) {
e.printStackTrace();
}
}
public void rePackProjectImages(ResolutionEntryVO resEntry) {
ProjectManager projectManager = facade.retrieveProxy(ProjectManager.NAME);
TexturePacker.Settings settings = projectManager.getTexturePackerSettings();
@@ -18,6 +18,7 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.*;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ObjectMap;
import com.kotcrab.vis.ui.VisUI;
import com.talosvfx.talos.runtime.ParticleEffectDescriptor;
@@ -60,7 +61,7 @@ public class ResourceManager extends Proxy implements IResourceRetriever {
private TextureAtlas currentProjectAtlas;
private final HashMap<String, SpineAnimData> spineAnimAtlases = new HashMap<>();
private final HashMap<String, TextureAtlas> spriteAnimAtlases = new HashMap<>();
private final HashMap<String, Array<TextureAtlas.AtlasRegion>> spriteAnimAtlases = new HashMap<>();
private final HashMap<FontSizePair, BitmapFont> bitmapFonts = new HashMap<>();
private final HashMap<String, ShaderProgram> shaderPrograms = new HashMap<>(1);
@@ -167,12 +168,6 @@ public class ResourceManager extends Proxy implements IResourceRetriever {
return talosVFXsFiles.get(name);
}
@Override
public TextureAtlas getSkeletonAtlas(String animationName) {
SpineAnimData animData = spineAnimAtlases.get(animationName);
return animData.atlas;
}
/**
* Sets working resolution, please set before doing any loading
* @param resolution String resolution name, default is "orig" later use resolution names created in editor
@@ -192,7 +187,7 @@ public class ResourceManager extends Proxy implements IResourceRetriever {
}
@Override
public TextureAtlas getSpriteAnimation(String animationName) {
public Array<TextureAtlas.AtlasRegion> getSpriteAnimation(String animationName) {
return spriteAnimAtlases.get(animationName);
}
@@ -229,7 +224,6 @@ public class ResourceManager extends Proxy implements IResourceRetriever {
public void loadCurrentProjectData(String projectPath, String curResolution) {
packResolutionName = curResolution;
loadCurrentProjectAssets(projectPath + "/assets/" + curResolution + "/pack/pack.atlas");
loadCurrentProjectSkin(projectPath + "/assets/orig/styles");
loadCurrentProjectParticles(projectPath + "/assets/orig/particles");
loadCurrentProjectTalosVFXs(projectPath + "/assets/orig/talos-vfx");
loadCurrentProjectSpineAnimations(projectPath + "/assets/", curResolution);
@@ -309,10 +303,9 @@ public class ResourceManager extends Proxy implements IResourceRetriever {
for (FileHandle entry : sourceDir.list()) {
if (entry.file().isDirectory()) {
String animName = FilenameUtils.removeExtension(entry.file().getName());
TextureAtlas atlas = new TextureAtlas(Gdx.files.internal(path + curResolution + "/spine-animations/" + File.separator + animName + File.separator + animName + ".atlas"));
FileHandle animJsonFile = Gdx.files.internal(entry.file().getAbsolutePath() + File.separator + animName + ".json");
SpineAnimData data = new SpineAnimData();
data.atlas = atlas;
data.atlas = currentProjectAtlas;
data.jsonFile = animJsonFile;
data.animName = animName;
spineAnimAtlases.put(animName, data);
@@ -327,15 +320,7 @@ public class ResourceManager extends Proxy implements IResourceRetriever {
for (FileHandle entry : sourceDir.list()) {
if (entry.file().isDirectory()) {
String animName = FilenameUtils.removeExtension(entry.file().getName());
FileHandle atlasFile = Gdx.files.internal(entry.file().getAbsolutePath() + File.separator + animName + ".atlas");
if (!atlasFile.exists())
continue;
try {
TextureAtlas atlas = new TextureAtlas(atlasFile);
spriteAnimAtlases.put(animName, atlas);
} catch (Exception e) {
e.printStackTrace();
}
spriteAnimAtlases.put(animName, currentProjectAtlas.findRegions(animName));
}
}
}
@@ -432,27 +417,6 @@ public class ResourceManager extends Proxy implements IResourceRetriever {
}
}
/**
* @param fontPath
* TODO currently useless, but could be reworked to include stuff from Skin Composer
* @deprecated
*/
@Deprecated
private void loadCurrentProjectSkin(String fontPath) {
/*
File styleFile = new File(fontPath, "styles.dt");
FileHandle f = new FileHandle(styleFile);
if (styleFile.isFile() && styleFile.exists()) {
projectSkin = new MySkin(f);
ObjectMap<String, BitmapFont> map = projectSkin.getAll(BitmapFont.class);
for (ObjectMap.Entry<String, BitmapFont> entry : map.entries()) {
projectSkin.getFont(entry.key).getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
}
}
*/
}
public FileHandle getTTFSafely(String fontName) throws IOException {
FontManager fontManager = facade.retrieveProxy(FontManager.NAME);
@@ -517,7 +481,7 @@ public class ResourceManager extends Proxy implements IResourceRetriever {
return spineAnimAtlases;
}
public HashMap<String, TextureAtlas> getProjectSpriteAnimationsList() {
public HashMap<String, Array<TextureAtlas.AtlasRegion>> getProjectSpriteAnimationsList() {
return spriteAnimAtlases;
}
@@ -20,9 +20,9 @@ package games.rednblack.editor.utils;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.tools.texturepacker.TextureUnpacker;
import com.badlogic.gdx.utils.Array;
import com.kotcrab.vis.ui.widget.file.FileTypeFilter;
import org.apache.commons.io.FilenameUtils;
import java.io.BufferedReader;
import java.io.File;
@@ -138,23 +138,11 @@ public class ImportUtils {
return regions.get(regions.size - 1).index == regions.size - 1;
}
public static Array<File> getAtlasPages(FileHandle fileHandle) {
Array<File> imgs = new Array<>();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(fileHandle.read()), 64);
while (true) {
String line = reader.readLine();
if (line == null) break;
//In atlas file format the name of the png is is preceded by an empty line
if (line.trim().length() == 0) {
line = reader.readLine();
imgs.add(new File(FilenameUtils.getFullPath(fileHandle.path()) + line));
}
}
} catch (IOException e) {
e.printStackTrace();
}
return imgs;
public static void unpackAtlasIntoTmpFolder(File atlasFile, String tmpDir) {
FileHandle atlasFileHandle = new FileHandle(atlasFile);
TextureAtlas.TextureAtlasData atlasData = new TextureAtlas.TextureAtlasData(atlasFileHandle, atlasFileHandle.parent(), false);
TextureUnpacker unpacker = new TextureUnpacker();
unpacker.splitAtlas(atlasData, tmpDir);
}
public static String getAtlasName(FileHandle fileHandle) {
@@ -175,15 +163,4 @@ public class ImportUtils {
}
return name;
}
public static Array<FileHandle> getAtlasPageHandles(FileHandle fileHandle) {
Array<File> imgs = getAtlasPages(fileHandle);
Array<FileHandle> imgHandles = new Array<>();
for (int i = 0; i < imgs.size; i++) {
imgHandles.add(new FileHandle(imgs.get(i)));
}
return imgHandles;
}
}
@@ -57,6 +57,7 @@ public abstract class Asset implements IAsset {
executor.execute(() -> importAsset(files, progressHandler, skipRepack));
executor.execute(() -> {
progressHandler.progressChanged(100);
projectManager.saveCurrentProject();
try {
Thread.sleep(300);
} catch (InterruptedException e) {
@@ -51,5 +51,9 @@ public class ImageAsset extends Asset {
ResolutionManager resolutionManager = facade.retrieveProxy(ResolutionManager.NAME);
resolutionManager.rePackProjectImagesForAllResolutionsSync();
}
for (FileHandle handle : new Array.ArrayIterator<>(files)) {
projectManager.getCurrentProjectVO().imagesPacks.get("main").regions.add(handle.nameWithoutExtension());
}
}
}
@@ -1,6 +1,7 @@
package games.rednblack.editor.utils.asset.impl;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.utils.Array;
import com.kotcrab.vis.ui.util.dialog.Dialogs;
import games.rednblack.editor.proxy.ProjectManager;
@@ -57,8 +58,8 @@ public class SpineAsset extends Asset {
if (copiedFile == null)
continue;
if (copiedFile.getName().toLowerCase().endsWith(".atlas")) {
resolutionManager.resizeSpineAnimationForAllResolutions(copiedFile, projectManager.getCurrentProjectInfoVO());
if (copiedFile.getName().toLowerCase().endsWith(".json")) {
resolutionManager.rePackProjectImagesForAllResolutionsSync();
}
}
}
@@ -85,11 +86,12 @@ public class SpineAsset extends Asset {
"\nCould not find '" + atlasFileSource.name() +"'.\nCheck if the file exists in the same directory.").padBottom(20).pack();
return null;
}
Array<File> imageFiles = ImportUtils.getAtlasPages(atlasFileSource);
for (File imageFile : new Array.ArrayIterator<>(imageFiles)) {
if (!imageFile.exists()) {
TextureAtlas.TextureAtlasData atlas = new TextureAtlas.TextureAtlasData(atlasFileSource, atlasFileSource.parent(), false);
for (TextureAtlas.TextureAtlasData.Page imageFile : new Array.ArrayIterator<>(atlas.getPages())) {
if (!imageFile.textureFile.exists()) {
Dialogs.showErrorDialog(Sandbox.getInstance().getUIStage(),
"\nCould not find " + imageFile.getName() + ".\nCheck if the file exists in the same directory.").padBottom(20).pack();
"\nCould not find " + imageFile.textureFile.name() + ".\nCheck if the file exists in the same directory.").padBottom(20).pack();
return null;
}
}
@@ -103,19 +105,16 @@ public class SpineAsset extends Asset {
FileUtils.forceMkdir(new File(targetPath));
File jsonFileTarget = new File(targetPath + File.separator + fileNameWithOutExt + ".json");
File atlasFileTarget = new File(targetPath + File.separator + fileNameWithOutExt + ".atlas");
FileUtils.copyFile(animationFileSource.file(), jsonFileTarget);
FileUtils.copyFile(atlasFileSource.file(), atlasFileTarget);
ImportUtils.unpackAtlasIntoTmpFolder(atlasFileSource.file(), projectManager.getCurrentProjectPath() + File.separator
+ ProjectManager.IMAGE_DIR_PATH);
for (File imageFile : new Array.ArrayIterator<>(imageFiles)) {
FileHandle imgFileTarget = new FileHandle(targetPath + File.separator + imageFile.getName());
FileUtils.copyFile(imageFile, imgFileTarget.file());
for (TextureAtlas.TextureAtlasData.Region region : new Array.ArrayIterator<>(atlas.getRegions())) {
projectManager.getCurrentProjectVO().animationsPacks.get("main").regions.add(region.name);
}
return atlasFileTarget;
return jsonFileTarget;
}
} catch (IOException e) {
e.printStackTrace();
@@ -44,10 +44,9 @@ public class SpriteAnimationAtlasAsset extends Asset {
@Override
public void importAsset(Array<FileHandle> files, ProgressHandler progressHandler, boolean skipRepack) {
for (FileHandle fileHandle : new Array.ArrayIterator<>(files)) {
String newAnimName = null;
String newAnimName;
try {
Array<File> imgs = ImportUtils.getAtlasPages(fileHandle);
String fileNameWithoutExt = ImportUtils.getAtlasName(fileHandle);
String targetPath = projectManager.getCurrentProjectPath() + "/assets/orig/sprite-animations" + File.separator + fileNameWithoutExt;
@@ -55,9 +54,10 @@ public class SpriteAnimationAtlasAsset extends Asset {
if (targetDir.exists()) {
FileUtils.deleteDirectory(targetDir);
}
for (File img : imgs) {
FileUtils.copyFileToDirectory(img, targetDir);
}
ImportUtils.unpackAtlasIntoTmpFolder(fileHandle.file(), projectManager.getCurrentProjectPath() + File.separator
+ ProjectManager.IMAGE_DIR_PATH);
File atlasTargetPath = new File(targetPath + File.separator + fileNameWithoutExt + ".atlas");
FileUtils.copyFile(fileHandle.file(), atlasTargetPath);
newAnimName = fileNameWithoutExt;
@@ -68,7 +68,13 @@ public class SpriteAnimationAtlasAsset extends Asset {
}
if (newAnimName != null) {
resolutionManager.resizeSpriteAnimationForAllResolutions(newAnimName, projectManager.getCurrentProjectInfoVO());
TextureAtlas.TextureAtlasData atlas = new TextureAtlas.TextureAtlasData(fileHandle, fileHandle.parent(), false);
for (TextureAtlas.TextureAtlasData.Region region : new Array.ArrayIterator<>(atlas.getRegions())) {
projectManager.getCurrentProjectVO().animationsPacks.get("main").regions.add(region.name);
}
resolutionManager.rePackProjectImagesForAllResolutionsSync();
}
}
}
@@ -1,10 +1,8 @@
package games.rednblack.editor.utils.asset.impl;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.tools.texturepacker.TexturePacker;
import com.badlogic.gdx.utils.Array;
import games.rednblack.editor.proxy.ProjectManager;
import games.rednblack.editor.utils.HyperLap2DUtils;
import games.rednblack.editor.utils.ImportUtils;
import games.rednblack.editor.utils.asset.Asset;
import games.rednblack.h2d.common.ProgressHandler;
@@ -49,7 +47,6 @@ public class SpriteAnimationSequenceAsset extends Asset {
String newAnimName;
String rawFileName = files.get(0).name();
TexturePacker texturePacker = new TexturePacker(projectManager.getTexturePackerSettings());
String fileNameWithoutExt = FilenameUtils.removeExtension(rawFileName);
String fileNameWithoutFrame = fileNameWithoutExt.replaceAll("\\d*$", "").replace("_", "");
@@ -61,15 +58,24 @@ public class SpriteAnimationSequenceAsset extends Asset {
}
String targetPath = projectManager.getCurrentProjectPath() + "/assets/orig/sprite-animations" + File.separator + fileNameWithoutFrame;
try {
FileUtils.writeStringToFile(new File(targetPath + File.separator + fileNameWithoutFrame + ".atlas"), fileNameWithoutFrame, "utf-8");
} catch (IOException e) {
e.printStackTrace();
progressHandler.progressFailed();
return;
}
String imagesPath = projectManager.getCurrentProjectPath() + File.separator + ProjectManager.IMAGE_DIR_PATH;
for (FileHandle file : new Array.ArrayIterator<>(files)) {
File src = file.file();
String destName;
if (noFileNameWithoutFrame) {
destName = targetPath + "Tmp" + File.separator + fileNameWithoutFrame + src.getName().replaceAll("[_](?=.*[_])", "");
destName = imagesPath + File.separator + fileNameWithoutFrame + src.getName().replaceAll("[_](?=.*[_])", "");
} else {
destName = targetPath + "Tmp" + File.separator + src.getName().replaceAll("[_](?=.*[_])", "");
destName = imagesPath + File.separator + src.getName().replaceAll("[_](?=.*[_])", "");
}
File dest = new File(destName);
@@ -82,42 +88,11 @@ public class SpriteAnimationSequenceAsset extends Asset {
}
}
FileHandle pngsDir = new FileHandle(targetPath + "Tmp");
for (FileHandle entry : pngsDir.list(HyperLap2DUtils.PNG_FILTER)) {
texturePacker.addImage(entry.file());
}
File targetDir = new File(targetPath);
if (targetDir.exists()) {
try {
FileUtils.deleteDirectory(targetDir);
} catch (IOException e) {
e.printStackTrace();
progressHandler.progressFailed();
return;
}
}
try {
texturePacker.pack(targetDir, fileNameWithoutFrame);
} catch (Exception e) {
progressHandler.progressFailed();
return;
}
//delete newly created directory and images
try {
FileUtils.deleteDirectory(pngsDir.file());
} catch (IOException e) {
e.printStackTrace();
progressHandler.progressFailed();
return;
}
newAnimName = fileNameWithoutFrame;
if (newAnimName != null) {
resolutionManager.resizeSpriteAnimationForAllResolutions(newAnimName, projectManager.getCurrentProjectInfoVO());
projectManager.getCurrentProjectVO().animationsPacks.get("main").regions.add(newAnimName);
resolutionManager.rePackProjectImagesForAllResolutionsSync();
}
}
}
@@ -21,11 +21,12 @@ package games.rednblack.editor.view.ui.box.resourcespanel;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.utils.Array;
import games.rednblack.editor.controller.commands.resource.DeleteImageResource;
import games.rednblack.editor.view.stage.Sandbox;
import games.rednblack.editor.proxy.ProjectManager;
import games.rednblack.editor.factory.ItemFactory;
import games.rednblack.editor.proxy.ResourceManager;
import games.rednblack.editor.view.ui.box.resourcespanel.draggable.DraggableResource;
import games.rednblack.editor.view.ui.box.resourcespanel.draggable.box.ImageResource;
import games.rednblack.h2d.common.vo.ProjectVO;
import org.apache.commons.lang3.ArrayUtils;
import org.puremvc.java.interfaces.INotification;
@@ -66,13 +67,18 @@ public class UIImagesTabMediator extends UIResourcesTabMediator<UIImagesTab> {
@Override
protected void initList(String searchText) {
ResourceManager resourceManager = facade.retrieveProxy(ResourceManager.NAME);
ProjectManager projectManager = facade.retrieveProxy(ProjectManager.NAME);
ProjectVO projectVO = projectManager.getCurrentProjectVO();
TextureAtlas atlas = resourceManager.getProjectAssetsList();
Array<DraggableResource> thumbnailBoxes = new Array<>();
Array<TextureAtlas.AtlasRegion> atlasRegions = atlas.getRegions();
for (TextureAtlas.AtlasRegion region : new Array.ArrayIterator<>(atlasRegions)) {
if(!region.name.contains(searchText))continue;
if(!projectVO.imagesPacks.get("main").regions.contains(region.name)
|| !region.name.contains(searchText)) continue;
boolean is9patch = region.findValue("split") != null;
DraggableResource draggableResource = new DraggableResource(new ImageResource(region));
if (is9patch) {
@@ -80,7 +80,7 @@ public class SpineActor extends Actor {
}
private void initSkeletonData() {
skeletonJson = new SkeletonJson(irr.getSkeletonAtlas(animationName));
skeletonJson = new SkeletonJson(irr.getMainPack());
skeletonData = skeletonJson.readSkeletonData((irr.getSkeletonJSON(animationName)));
}
@@ -2,6 +2,7 @@ package games.rednblack.editor.view.ui.widget.actors;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import games.rednblack.editor.renderer.resources.IResourceRetriever;
@@ -11,10 +12,10 @@ import games.rednblack.editor.renderer.resources.IResourceRetriever;
*/
public class SpriteAnimationActor extends Actor {
private String animationName;
private IResourceRetriever rm;
private final String animationName;
private final IResourceRetriever rm;
private Animation animation;
private final Animation<TextureAtlas.AtlasRegion> animation;
private float stateTime = 0;
private int fps;
@@ -24,17 +25,17 @@ public class SpriteAnimationActor extends Actor {
public SpriteAnimationActor(String animationName, IResourceRetriever rm) {
this.animationName = animationName;
this.rm = rm;
animation = new Animation(1/24f, rm.getSpriteAnimation(animationName).getRegions());
animation = new Animation<>(1/24f, rm.getSpriteAnimation(animationName));
animation.setPlayMode(Animation.PlayMode.LOOP);
TextureRegion region = (TextureRegion) animation.getKeyFrame(stateTime);
TextureRegion region = animation.getKeyFrame(stateTime);
setWidth(region.getRegionWidth());
setHeight(region.getRegionHeight());
}
@Override
public void draw(Batch batch, float parentAlpha) {
TextureRegion region = (TextureRegion) animation.getKeyFrame(stateTime);
TextureRegion region = animation.getKeyFrame(stateTime);
setWidth(region.getRegionWidth());
setHeight(region.getRegionHeight());