Created
December 2, 2016 13:49
-
-
Save cypherdare/aa99ca9a5b63a64010da25cf0065c6dd to your computer and use it in GitHub Desktop.
Example of using staging directory for texture packing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.badlogic.gdx.tools.FileProcessor; | |
import com.badlogic.gdx.tools.texturepacker.TexturePacker; | |
import com.cyphercove.cavecat.Assets; | |
import org.apache.commons.io.FileUtils; | |
import org.apache.commons.io.filefilter.RegexFileFilter; | |
import org.apache.commons.io.filefilter.TrueFileFilter; | |
import java.io.File; | |
import java.util.Collection; | |
public class MyPacker { | |
static final String SOURCE_DIR = "graphics work/Texture atlases"; | |
static final String STAGING_DIR = "graphics work/tmp"; | |
static final String TARGET_DIR = "android/assets"; | |
public static void main (String[] args) throws Exception { | |
//Delete old pack | |
File oldPackFile = new File(TARGET_DIR + "/" + Assets.MAIN_ATLAS + Assets.ATLAS_EXTENSION); | |
if (oldPackFile.exists()){ | |
System.out.println("Deleting old pack file"); | |
oldPackFile.delete(); | |
} | |
//Clear staging directory | |
File stagingDirectory = new File(STAGING_DIR); | |
if (stagingDirectory.exists()){ | |
System.out.println("Deleting old pack file"); | |
FileUtils.cleanDirectory(stagingDirectory); | |
} | |
//Preprocess by moving stuff to staging area. | |
FileProcessor moveAllButGifsProcessor = new FileProcessor(){ | |
protected void processFile (Entry entry) throws Exception { | |
FileUtils.copyFileToDirectory(entry.inputFile, entry.outputDir); | |
} | |
}; | |
moveAllButGifsProcessor.addInputSuffix(".json", ".png", "jpg", ".fnt"); | |
moveAllButGifsProcessor.process(SOURCE_DIR, STAGING_DIR); | |
GifProcessor gifProcessor = new GifProcessor(0.015f); | |
gifProcessor.process(SOURCE_DIR, STAGING_DIR); | |
FileProcessor stripSuffixesProcessor = new FileProcessor(){ | |
protected void processFile (Entry entry) throws Exception { | |
String fileName = entry.inputFile.getName(); | |
if (fileName.contains("-export")){ | |
File newFile = new File(entry.inputFile.getParentFile(), fileName.replace("-export", "")); | |
entry.inputFile.renameTo(newFile); | |
} | |
} | |
}; | |
stripSuffixesProcessor.process(STAGING_DIR, ""); | |
//Pack them | |
TexturePacker.Settings settings = new TexturePacker.Settings(); | |
settings.atlasExtension = Assets.ATLAS_EXTENSION; | |
TexturePacker.process( | |
settings, | |
STAGING_DIR, | |
TARGET_DIR, | |
Assets.MAIN_ATLAS); | |
//Copy over any fonts | |
Collection<File> fontFiles = FileUtils.listFiles( | |
new File(STAGING_DIR), | |
new RegexFileFilter(".*\\.fnt"), | |
TrueFileFilter.INSTANCE | |
); | |
File destDir = new File(TARGET_DIR); | |
for (File file : fontFiles){ | |
System.out.println("Copying font file: " + file.getName()); | |
FileUtils.copyFileToDirectory(file, destDir); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment