use of com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings in project ultimate-java by pantinor.
the class SpriteAtlasTool method makeAtlas.
public void makeAtlas() {
Settings settings = new Settings();
AtlasWriter mrp = new AtlasWriter(settings);
Collections.sort(gridItems);
ArrayList<Rect> packedRects = new ArrayList<>();
String last = null;
int idx = 0;
for (MyListItem it : gridItems) {
Rect rect = new Rect(it.x * dim, it.y * dim, dim, dim);
rect.name = it.name;
if (rect.name.equals(last)) {
idx++;
} else {
idx = 0;
}
rect.index = idx;
packedRects.add(rect);
last = rect.name;
}
System.out.println("Writing: number of sprites: " + packedRects.size());
try {
mrp.writePackFileWithRects(new File("."), "sprites-atlas.txt", packedRects, "assets/tilemaps/latest.png");
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("done");
}
use of com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings in project ultimate-java by pantinor.
the class TexturePackerFileProcessor method process.
public ArrayList<Entry> process(File inputFile, File outputRoot) throws Exception {
root = inputFile;
// Collect pack.json setting files.
final ArrayList<File> settingsFiles = new ArrayList();
FileProcessor settingsProcessor = new FileProcessor() {
protected void processFile(Entry inputFile) throws Exception {
settingsFiles.add(inputFile.inputFile);
}
};
settingsProcessor.addInputRegex("pack\\.json");
settingsProcessor.process(inputFile, null);
// Sort parent first.
Collections.sort(settingsFiles, new Comparator<File>() {
public int compare(File file1, File file2) {
return file1.toString().length() - file2.toString().length();
}
});
for (File settingsFile : settingsFiles) {
// Find first parent with settings, or use defaults.
Settings settings = null;
File parent = settingsFile.getParentFile();
while (true) {
if (parent.equals(root)) {
break;
}
parent = parent.getParentFile();
settings = dirToSettings.get(parent);
if (settings != null) {
settings = new Settings(settings);
break;
}
}
if (settings == null) {
settings = new Settings(defaultSettings);
}
// Merge settings from current directory.
merge(settings, settingsFile);
dirToSettings.put(settingsFile.getParentFile(), settings);
}
// Do actual processing.
return super.process(inputFile, outputRoot);
}
use of com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings in project ultimate-java by pantinor.
the class TexturePackerFileProcessor method process.
public ArrayList<Entry> process(File[] files, File outputRoot) throws Exception {
// Delete pack file and images.
if (outputRoot.exists()) {
// Load root settings to get scale.
File settingsFile = new File(root, "pack.json");
Settings rootSettings = defaultSettings;
if (settingsFile.exists()) {
rootSettings = new Settings(rootSettings);
merge(rootSettings, settingsFile);
}
for (int i = 0, n = rootSettings.scale.length; i < n; i++) {
FileProcessor deleteProcessor = new FileProcessor() {
protected void processFile(Entry inputFile) throws Exception {
inputFile.inputFile.delete();
}
};
deleteProcessor.setRecursive(false);
String scaledPackFileName = rootSettings.getScaledPackFileName(packFileName, i);
File packFile = new File(scaledPackFileName);
String prefix = packFile.getName();
int dotIndex = prefix.lastIndexOf('.');
if (dotIndex != -1) {
prefix = prefix.substring(0, dotIndex);
}
deleteProcessor.addInputRegex("(?i)" + prefix + "\\d*\\.(png|jpg)");
deleteProcessor.addInputRegex("(?i)" + prefix + "\\.atlas");
String dir = packFile.getParent();
if (dir == null) {
deleteProcessor.process(outputRoot, null);
} else if (//
new File(outputRoot + "/" + dir).exists()) {
deleteProcessor.process(outputRoot + "/" + dir, null);
}
}
}
return super.process(files, outputRoot);
}
use of com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings in project bladecoder-adventure-engine by bladecoder.
the class ImageUtils method createAtlas.
public static void createAtlas(String inDir, String outdir, String name, float scale, TextureFilter filterMin, TextureFilter filterMag, String outputFormat) throws IOException {
Settings settings = new Settings();
settings.pot = false;
settings.paddingX = 2;
settings.paddingY = 2;
settings.duplicatePadding = true;
settings.edgePadding = true;
settings.rotation = false;
settings.minWidth = 16;
settings.minWidth = 16;
settings.stripWhitespaceX = true;
settings.stripWhitespaceY = true;
settings.alphaThreshold = 0;
settings.filterMin = filterMin;
settings.filterMag = filterMag;
settings.wrapX = Texture.TextureWrap.ClampToEdge;
settings.wrapY = Texture.TextureWrap.ClampToEdge;
settings.format = Format.RGBA8888;
settings.alias = true;
settings.outputFormat = outputFormat;
settings.jpegQuality = 0.9f;
settings.ignoreBlankImages = true;
settings.fast = false;
settings.debug = false;
int wWidth = World.getInstance().getWidth();
settings.maxWidth = MathUtils.nextPowerOfTwo((int) (wWidth * scale * 2f));
settings.maxHeight = MathUtils.nextPowerOfTwo((int) (wWidth * scale * 2f));
EditorLogger.debug("ATLAS MAXWIDTH: " + settings.maxWidth);
File inTmpDir = new File(inDir);
// Resize images to create atlas for diferent resolutions
if (scale != 1.0f) {
inTmpDir = DesktopUtils.createTempDirectory();
ImageUtils.scaleDirFiles(new File(inDir), inTmpDir, scale);
}
TexturePacker.process(settings, inTmpDir.getAbsolutePath(), outdir, name.endsWith(".atlas") ? name : name + ".atlas");
if (scale != 1.0f) {
DesktopUtils.removeDir(inTmpDir.getAbsolutePath());
}
}
use of com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings in project Eidolons by IDemiurge.
the class TexturePackerLaunch method packWeaponSprites.
public static void packWeaponSprites(String[] args) {
Settings settings = getSetting();
String outputDir = POTIONS ? OUTPUT_DIR_POTION : OUTPUT_DIR;
for (String sub : args) {
String dir = POTIONS ? WORKSPACE_PATH_POTIONS : WORKSPACE_PATH + sub;
List<File> subFolders = FileManager.getFilesFromDirectory(dir, true);
boolean processed = false;
for (File subFolder : subFolders) {
if (!subFolder.isDirectory())
continue;
String inputDir = // + sub + "//" +
subFolder.getPath();
String packFileName = subFolder.getName();
TexturePacker.process(settings, inputDir, outputDir, packFileName);
processed = true;
}
if (!processed) {
TexturePacker.process(settings, dir, outputDir, sub);
}
}
return;
// TexturePacker.process(inputDir, outputDir, packFileName);
}
Aggregations