use of com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData in project libgdx by libgdx.
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();
}
use of com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData in project ultimate-java by pantinor.
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);
}
}
}
}
}
FileWriter writer = new FileWriter(packFile, true);
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");
for (Rect rect : page.outputRects) {
writeRect(writer, page, rect, rect.name);
for (Alias alias : rect.aliases) {
Rect aliasRect = new Rect();
aliasRect.set(rect);
alias.apply(aliasRect);
writeRect(writer, page, aliasRect, alias.name);
}
}
}
writer.close();
}
use of com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData in project ultimate-java by pantinor.
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 ultimate-java by pantinor.
the class CombatMapTmxConvert method main.
public static void main(String[] args) throws Exception {
File file2 = new File("target/classes/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("target/classes/xml/maps.xml");
jaxbContext = JAXBContext.newInstance(MapSet.class);
jaxbUnmarshaller = jaxbContext.createUnmarshaller();
MapSet ms = (MapSet) jaxbUnmarshaller.unmarshal(file3);
ms.init(ts);
int TILE_SIZE = 16;
boolean foundShrine = false;
for (BaseMap map : ms.getMaps()) {
String tmxmapname = null;
boolean isShrine = false;
if (map.getType() == MapType.combat || (map.getType() == MapType.shrine && !foundShrine)) {
if (map.getType() == MapType.shrine && !foundShrine) {
foundShrine = true;
tmxmapname = "shrine.tmx";
isShrine = true;
} else if (map.getType() == MapType.combat) {
tmxmapname = "combat_" + map.getId() + ".tmx";
}
} else {
continue;
}
InputStream is = TestMain.class.getResourceAsStream("/data/" + map.getFname());
byte[] bytes = IOUtils.toByteArray(is);
Tile[] tiles = new Tile[map.getWidth() * map.getHeight()];
int pos = isShrine ? 0 : 64;
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;
}
}
// load the atlas and determine the tile indexes per tilemap position
FileHandle f = new FileHandle("target/classes/tilemaps/tile-atlas.txt");
TextureAtlasData atlas = new TextureAtlasData(f, f.parent(), false);
Tile[] mapTileIds = new Tile[atlas.getRegions().size + 1];
for (Region r : atlas.getRegions()) {
int x = r.left / r.width;
int y = r.top / r.height;
int i = y * TILE_SIZE + x + 1;
mapTileIds[i] = ts.getTileByName(r.name);
}
// map layer
StringBuffer data = new StringBuffer();
int count = 1;
int total = 1;
for (int i = 0; i < tiles.length; i++) {
Tile t = tiles[i];
data.append(findTileId(mapTileIds, t.getName()) + ",");
count++;
total++;
if (count > map.getWidth()) {
data.append("\n");
count = 1;
}
if (total > map.getWidth() * map.getHeight()) {
break;
}
}
String d = data.toString();
d = d.substring(0, d.length() - 2);
Position[] monPos = new Position[16];
for (int i = 0; i < 16; i++) {
monPos[i] = new Position(i, (int) bytes[i], 0);
}
for (int i = 0; i < 16; i++) {
monPos[i].startY = (int) bytes[i + 16];
}
Position[] playerPos = new Position[8];
for (int i = 0; i < 8; i++) {
playerPos[i] = new Position(i, (int) bytes[i + 32], 0);
}
for (int i = 0; i < 8; i++) {
playerPos[i].startY = (int) bytes[i + 40];
}
CombatMapTmxConvert c = new CombatMapTmxConvert(map.getFname(), "tiles.png", map.getWidth(), map.getHeight(), TILE_SIZE, TILE_SIZE, TILE_SIZE ^ 2, TILE_SIZE ^ 2, d, monPos, playerPos);
FileUtils.writeStringToFile(new File("src/main/resources/tilemaps/" + tmxmapname), c.toString());
}
}
use of com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData in project ultimate-java by pantinor.
the class DungeonMapTmxConvert method main.
public static void main(String[] args) throws Exception {
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);
int TILE_SIZE = 16;
for (BaseMap map : ms.getMaps()) {
String tmxmapname = null;
boolean isAbyss = false;
if (map.getType() == MapType.dungeon) {
if (map.getFname().equals("abyss.dng")) {
tmxmapname = "abyss.tmx";
isAbyss = true;
} else {
tmxmapname = "dungeon_" + map.getId() + ".tmx";
}
} else {
continue;
}
InputStream is = new FileInputStream("assets/data/" + map.getFname());
byte[] bytes = IOUtils.toByteArray(is);
List<DungeonTile[]> dungeonTiles = new ArrayList<>();
int pos = 0;
for (int i = 0; i < 8; i++) {
DungeonTile[] tiles = new DungeonTile[64];
for (int y = 0; y < map.getHeight(); ++y) {
for (int x = 0; x < map.getWidth(); ++x) {
int index = bytes[pos] & 0xff;
pos++;
DungeonTile tile = DungeonTile.getTileByValue(index);
tiles[x + y * map.getWidth()] = tile;
}
}
dungeonTiles.add(tiles);
}
// load the atlas and determine the tile indexes per tilemap position
FileHandle f = new FileHandle("assets/tilemaps/tiles-vga-atlas.txt");
TextureAtlasData atlas = new TextureAtlasData(f, f.parent(), false);
Tile[] mapTileIds = new Tile[atlas.getRegions().size + 1];
for (Region r : atlas.getRegions()) {
int x = r.left / r.width;
int y = r.top / r.height;
int i = y * TILE_SIZE + x + 1;
mapTileIds[i] = ts.getTileByName(r.name);
}
// map layers
List<String> layers = new ArrayList<>();
for (int j = 0; j < 8; j++) {
DungeonTile[] tiles = dungeonTiles.get(j);
StringBuilder data = new StringBuilder();
int count = 1;
int total = 1;
for (int i = 0; i < tiles.length; i++) {
DungeonTile t = tiles[i];
data.append(findTileId(mapTileIds, t.getTileName()) + ",");
count++;
total++;
if (count > map.getWidth()) {
data.append("\n");
count = 1;
}
if (total > map.getWidth() * map.getHeight()) {
break;
}
}
String d = data.toString();
d = d.substring(0, d.length() - 2);
layers.add(d);
}
System.out.println("writing");
DungeonMapTmxConvert c = new DungeonMapTmxConvert(map.getFname(), "tiles-vga.png", map.getWidth(), map.getHeight(), TILE_SIZE, TILE_SIZE, TILE_SIZE ^ 2, TILE_SIZE ^ 2, layers);
FileUtils.writeStringToFile(new File(tmxmapname), c.toString());
}
}
Aggregations