use of com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings in project skin-composer by raeleus.
the class TexturePackerFileProcessor method processDir.
protected void processDir(Entry inputDir, ArrayList<Entry> files) throws Exception {
if (ignoreDirs.contains(inputDir.inputFile))
return;
// Find first parent with settings, or use defaults.
Settings settings = null;
File parent = inputDir.inputFile;
while (true) {
settings = dirToSettings.get(parent);
if (settings != null)
break;
if (parent == null || parent.equals(root))
break;
parent = parent.getParentFile();
}
if (settings == null)
settings = defaultSettings;
if (settings.ignore)
return;
if (settings.combineSubdirectories) {
// Collect all files under subdirectories and ignore subdirectories so they won't be packed twice.
files = new FileProcessor(this) {
protected void processDir(Entry entryDir, ArrayList<Entry> files) {
ignoreDirs.add(entryDir.inputFile);
}
protected void processFile(Entry entry) {
addProcessedFile(entry);
}
}.process(inputDir.inputFile, null);
}
if (files.isEmpty())
return;
// Sort by name using numeric suffix, then alpha.
Collections.sort(files, new Comparator<Entry>() {
final Pattern digitSuffix = Pattern.compile("(.*?)(\\d+)$");
public int compare(Entry entry1, Entry entry2) {
String full1 = entry1.inputFile.getName();
int dotIndex = full1.lastIndexOf('.');
if (dotIndex != -1)
full1 = full1.substring(0, dotIndex);
String full2 = entry2.inputFile.getName();
dotIndex = full2.lastIndexOf('.');
if (dotIndex != -1)
full2 = full2.substring(0, dotIndex);
String name1 = full1, name2 = full2;
int num1 = 0, num2 = 0;
Matcher matcher = digitSuffix.matcher(full1);
if (matcher.matches()) {
try {
num1 = Integer.parseInt(matcher.group(2));
name1 = matcher.group(1);
} catch (Exception ignored) {
}
}
matcher = digitSuffix.matcher(full2);
if (matcher.matches()) {
try {
num2 = Integer.parseInt(matcher.group(2));
name2 = matcher.group(1);
} catch (Exception ignored) {
}
}
int compare = name1.compareTo(name2);
if (compare != 0 || num1 == num2)
return compare;
return num1 - num2;
}
});
// Pack.
if (!settings.silent)
System.out.println(inputDir.inputFile.getName());
TexturePacker packer = new TexturePacker(root, settings);
for (Entry file : files) packer.addImage(file.inputFile);
packer.pack(inputDir.outputDir, packFileName);
}
use of com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings in project skin-composer by raeleus.
the class DesktopLauncher method texturePack.
@Override
public void texturePack(Array<FileHandle> handles, FileHandle localFile, FileHandle targetFile) {
// copy defaults.json to temp folder if it doesn't exist
FileHandle fileHandle = Gdx.files.local("texturepacker/defaults.json");
if (!fileHandle.exists()) {
Gdx.files.internal("defaults.json").copyTo(fileHandle);
}
Json json = new Json();
Settings settings = json.fromJson(Settings.class, fileHandle);
TexturePacker p = new TexturePacker(settings);
for (FileHandle handle : handles) {
if (handle.exists()) {
p.addImage(handle.file());
} else {
if (localFile != null) {
FileHandle localHandle = localFile.sibling(localFile.nameWithoutExtension() + "_data/" + handle.name());
if (localHandle.exists()) {
p.addImage(localHandle.file());
} else {
Gdx.app.error(getClass().getName(), "File does not exist error while creating texture atlas: " + handle.path());
}
} else {
Gdx.app.error(getClass().getName(), "File does not exist error while creating texture atlas: " + handle.path());
}
}
}
p.pack(targetFile.parent().file(), targetFile.nameWithoutExtension());
}
use of com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings in project ultimate-java by pantinor.
the class PackImagesUtil method main4.
public static void main4(String[] argv) throws Exception {
ImageFrame[] frames = readGif(new File("C:\\Users\\Paul\\Desktop\\water\\lava.gif"));
Map<String, BufferedImage> imgMap = new TreeMap<>();
for (int i = 0, count = frames.length; i < count; i++) {
BufferedImage fr = frames[i].image;
String name = "w_" + i;
imgMap.put(name, fr);
}
System.out.println("Writing: number of images: " + imgMap.size());
Settings settings = new Settings();
settings.maxWidth = 128 * 3;
settings.maxHeight = 128 * 6;
settings.paddingX = 0;
settings.paddingY = 0;
settings.fast = true;
settings.pot = false;
settings.grid = true;
TexturePacker tp = new TexturePacker(settings);
for (String name : imgMap.keySet()) {
BufferedImage image = imgMap.get(name);
tp.addImage(image, name);
}
tp.pack(new File("C:\\Users\\Paul\\Desktop\\water\\"), "lava");
System.out.println("done");
}
use of com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings in project ultimate-java by pantinor.
the class PackImagesUtil method main2.
public static void main2(String[] argv) throws Exception {
List<File> files = listFileTree(new File("C:\\Users\\Paul\\Desktop\\water\\worlds\\greenland"));
Collections.sort(files);
List<File> files2 = listFileTree(new File("C:\\Users\\Paul\\Desktop\\water\\worlds\\desert"));
Collections.sort(files2);
List<File> files3 = listFileTree(new File("C:\\Users\\Paul\\Desktop\\water\\worlds\\winterland"));
Collections.sort(files3);
Map<String, BufferedImage> imgMap = new TreeMap<>();
for (File file : files) {
if (file.isDirectory() || !file.getName().endsWith("png")) {
continue;
}
String name = "greenland_" + file.getName();
BufferedImage fr = ImageIO.read(file);
// BufferedImage sub = fr.getSubimage(11, 11, 32, 32);
imgMap.put(name, fr);
}
for (File file : files2) {
if (file.isDirectory() || !file.getName().endsWith("png")) {
continue;
}
String name = "desert_" + file.getName();
BufferedImage fr = ImageIO.read(file);
imgMap.put(name, fr);
}
for (File file : files3) {
if (file.isDirectory() || !file.getName().endsWith("png")) {
continue;
}
String name = "winterland_" + file.getName();
BufferedImage fr = ImageIO.read(file);
imgMap.put(name, fr);
}
System.out.println("Writing: number of images: " + imgMap.size());
Settings settings = new Settings();
settings.maxWidth = 32 * 12;
settings.maxHeight = 32 * 32;
settings.paddingX = 0;
settings.paddingY = 0;
settings.fast = true;
settings.pot = false;
settings.grid = true;
TexturePacker tp = new TexturePacker(settings);
for (String name : imgMap.keySet()) {
BufferedImage image = imgMap.get(name);
tp.addImage(image, name);
}
tp.pack(new File("C:\\Users\\Paul\\Desktop\\water\\"), "water_anims");
// java.awt.Color[] col = {java.awt.Color.MAGENTA};
// ImageTransparency.convert("monsters.png", "monsters-trans.png", col);
System.out.println("done");
}
use of com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings in project ultimate-java by pantinor.
the class TexturePackerFileProcessor method processDir.
protected void processDir(Entry inputDir, ArrayList<Entry> files) throws Exception {
if (ignoreDirs.contains(inputDir.inputFile)) {
return;
}
// Find first parent with settings, or use defaults.
Settings settings = null;
File parent = inputDir.inputFile;
while (true) {
settings = dirToSettings.get(parent);
if (settings != null) {
break;
}
if (parent.equals(root)) {
break;
}
parent = parent.getParentFile();
}
if (settings == null) {
settings = defaultSettings;
}
if (settings.combineSubdirectories) {
// Collect all files under subdirectories and ignore subdirectories so they won't be packed twice.
files = new FileProcessor(this) {
protected void processDir(Entry entryDir, ArrayList<Entry> files) {
ignoreDirs.add(entryDir.inputFile);
}
protected void processFile(Entry entry) {
addProcessedFile(entry);
}
}.process(inputDir.inputFile, null);
}
if (files.isEmpty()) {
return;
}
// Sort by name using numeric suffix, then alpha.
Collections.sort(files, new Comparator<Entry>() {
final Pattern digitSuffix = Pattern.compile("(.*?)(\\d+)$");
public int compare(Entry entry1, Entry entry2) {
String full1 = entry1.inputFile.getName();
int dotIndex = full1.lastIndexOf('.');
if (dotIndex != -1) {
full1 = full1.substring(0, dotIndex);
}
String full2 = entry2.inputFile.getName();
dotIndex = full2.lastIndexOf('.');
if (dotIndex != -1) {
full2 = full2.substring(0, dotIndex);
}
String name1 = full1, name2 = full2;
int num1 = 0, num2 = 0;
Matcher matcher = digitSuffix.matcher(full1);
if (matcher.matches()) {
try {
num1 = Integer.parseInt(matcher.group(2));
name1 = matcher.group(1);
} catch (Exception ignored) {
}
}
matcher = digitSuffix.matcher(full2);
if (matcher.matches()) {
try {
num2 = Integer.parseInt(matcher.group(2));
name2 = matcher.group(1);
} catch (Exception ignored) {
}
}
int compare = name1.compareTo(name2);
if (compare != 0 || num1 == num2) {
return compare;
}
return num1 - num2;
}
});
// Pack.
System.out.println(inputDir.inputFile.getName());
TexturePacker packer = new TexturePacker(root, settings);
for (Entry file : files) {
packer.addImage(file.inputFile);
}
packer.pack(inputDir.outputDir, packFileName);
}
Aggregations