use of com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData in project ultimate-java by pantinor.
the class UltMapTmxConvert method create.
@Override
public void create() {
try {
File file2 = new File("assets/xml/tileset-base.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(TileSet.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
TileSet ts = (TileSet) jaxbUnmarshaller.unmarshal(file2);
ts.setMaps();
File file3 = new File("assets/xml/maps.xml");
jaxbContext = JAXBContext.newInstance(MapSet.class);
jaxbUnmarshaller = jaxbContext.createUnmarshaller();
MapSet ms = (MapSet) jaxbUnmarshaller.unmarshal(file3);
ms.init(ts);
// load the atlas and determine the tile indexes per tilemap position
FileHandle f = new FileHandle("assets/tilemaps/latest-atlas.txt");
TextureAtlasData atlas = new TextureAtlasData(f, f.parent(), false);
int png_grid_width = 24;
Tile[] mapTileIds = new Tile[png_grid_width * Constants.tilePixelWidth + 1];
for (Region r : atlas.getRegions()) {
int x = r.left / r.width;
int y = r.top / r.height;
int i = x + (y * png_grid_width) + 1;
mapTileIds[i] = ts.getTileByName(r.name);
}
for (BaseMap map : ms.getMaps()) {
if (!map.getFname().endsWith("ult")) {
continue;
}
FileInputStream is = new FileInputStream("assets/data/" + map.getFname());
byte[] bytes = IOUtils.toByteArray(is);
Tile[] tiles = new Tile[map.getWidth() * map.getHeight()];
int pos = 0;
for (int y = 0; y < map.getHeight(); y++) {
for (int x = 0; x < map.getWidth(); x++) {
// convert a byte to an unsigned int value
int index = bytes[pos] & 0xff;
pos++;
Tile tile = ts.getTileByIndex(index);
if (tile == null) {
System.out.println("Tile index cannot be found: " + index + " using index 129 for black space.");
tile = ts.getTileByIndex(129);
}
tiles[x + y * map.getWidth()] = tile;
}
}
// map layer
StringBuilder data = new StringBuilder();
int count = 1;
int total = 1;
for (int i = 0; i < tiles.length; i++) {
Tile t = tiles[i];
data.append(findTileMapId(mapTileIds, t.getName())).append(",");
count++;
total++;
if (count > 32) {
data.append("\n");
count = 1;
}
}
String d = data.toString();
d = d.substring(0, d.length() - 2);
List<Person> people = map.getCity().getPeople();
StringBuilder peopleBuffer = new StringBuilder();
if (people != null) {
for (int y = 0; y < map.getHeight(); y++) {
for (int x = 0; x < map.getWidth(); x++) {
Person p = findPersonAtCoords(people, x, y);
if (p == null) {
peopleBuffer.append("0,");
} else {
peopleBuffer.append(findTileMapId(mapTileIds, p.getTile().getName())).append(",");
}
}
peopleBuffer.append("\n");
}
}
String p = peopleBuffer.toString();
if (p == null || p.length() < 1) {
count = 1;
// make empty
for (int i = 0; i < map.getWidth() * map.getHeight(); i++) {
peopleBuffer.append("0,");
count++;
if (count > map.getWidth()) {
peopleBuffer.append("\n");
count = 1;
}
}
p = peopleBuffer.toString();
}
p = p.substring(0, p.length() - 2);
Formatter c = new Formatter(map.getFname(), "latest.png", map.getWidth(), map.getHeight(), Constants.tilePixelWidth, Constants.tilePixelWidth, d, p, people);
String tmxFName = String.format("tmx/map_%s_%s.tmx", map.getId(), map.getCity().getName().replace(" ", ""));
FileUtils.writeStringToFile(new File(tmxFName), c.toString());
System.out.printf("Wrote: %s\n", tmxFName);
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("DONE");
}
use of com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData in project bladecoder-adventure-engine by bladecoder.
the class ImageUtils method unpackAtlas.
public static void unpackAtlas(File orgAtlas, File destDir) {
CustomTextureUnpacker unpacker = new CustomTextureUnpacker();
String atlasParentPath = orgAtlas.getParentFile().getAbsolutePath();
TextureAtlasData atlas = new TextureAtlasData(new FileHandle(orgAtlas), new FileHandle(atlasParentPath), false);
unpacker.splitAtlas(atlas, destDir.getAbsolutePath());
}
use of com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData in project libgdx by libgdx.
the class TextureUnpacker method main.
public static void main(String[] args) {
TextureUnpacker unpacker = new TextureUnpacker();
String atlasFile = null, imageDir = null, outputDir = null;
// parse the arguments and display the help text if there is a problem with the command line arguments
switch(unpacker.parseArguments(args)) {
case 0:
System.out.println(HELP);
return;
case 3:
outputDir = args[2];
case 2:
imageDir = args[1];
case 1:
atlasFile = args[0];
}
File atlasFileHandle = new File(atlasFile);
String atlasParentPath = atlasFileHandle.getParentFile().getAbsolutePath();
// Set the directory variables to a default when they weren't given in the variables
if (imageDir == null)
imageDir = atlasParentPath;
if (outputDir == null)
outputDir = (new File(atlasParentPath, DEFAULT_OUTPUT_PATH)).getAbsolutePath();
// Opens the atlas file from the specified filename
TextureAtlasData atlas = new TextureAtlasData(new FileHandle(atlasFile), new FileHandle(imageDir), false);
unpacker.splitAtlas(atlas, outputDir);
}
use of com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData in project libgdx by libgdx.
the class TextureAtlasLoader method getDependencies.
@Override
public Array<AssetDescriptor> getDependencies(String fileName, FileHandle atlasFile, TextureAtlasParameter parameter) {
FileHandle imgDir = atlasFile.parent();
if (parameter != null)
data = new TextureAtlasData(atlasFile, imgDir, parameter.flip);
else {
data = new TextureAtlasData(atlasFile, imgDir, false);
}
Array<AssetDescriptor> dependencies = new Array();
for (Page page : data.getPages()) {
TextureParameter params = new TextureParameter();
params.format = page.format;
params.genMipMaps = page.useMipMaps;
params.minFilter = page.minFilter;
params.magFilter = page.magFilter;
dependencies.add(new AssetDescriptor(page.textureFile, Texture.class, params));
}
return dependencies;
}
use of com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData in project skin-composer by raeleus.
the class TexturePacker method writePackFile.
private void writePackFile(File outputDir, String scaledPackFileName, Array<Page> pages) throws IOException {
File packFile = new File(outputDir, scaledPackFileName + settings.atlasExtension);
File packDir = packFile.getParentFile();
packDir.mkdirs();
if (packFile.exists()) {
// Make sure there aren't duplicate names.
TextureAtlasData textureAtlasData = new TextureAtlasData(new FileHandle(packFile), new FileHandle(packFile), false);
for (Page page : pages) {
for (Rect rect : page.outputRects) {
String rectName = Rect.getAtlasName(rect.name, settings.flattenPaths);
for (Region region : textureAtlasData.getRegions()) {
if (region.name.equals(rectName)) {
throw new GdxRuntimeException("A region with the name \"" + rectName + "\" has already been packed: " + rect.name);
}
}
}
}
}
Writer writer = new OutputStreamWriter(new FileOutputStream(packFile, true), "UTF-8");
for (Page page : pages) {
writer.write("\n" + page.imageName + "\n");
writer.write("size: " + page.imageWidth + "," + page.imageHeight + "\n");
writer.write("format: " + settings.format + "\n");
writer.write("filter: " + settings.filterMin + "," + settings.filterMag + "\n");
writer.write("repeat: " + getRepeatValue() + "\n");
page.outputRects.sort();
for (Rect rect : page.outputRects) {
writeRect(writer, page, rect, rect.name);
Array<Alias> aliases = new Array(rect.aliases.toArray());
aliases.sort();
for (Alias alias : aliases) {
Rect aliasRect = new Rect();
aliasRect.set(rect);
alias.apply(aliasRect);
writeRect(writer, page, aliasRect, alias.name);
}
}
}
writer.close();
}
Aggregations