Example usage for com.badlogic.gdx.maps.tiled TiledMapTileLayer getName

List of usage examples for com.badlogic.gdx.maps.tiled TiledMapTileLayer getName

Introduction

In this page you can find the example usage for com.badlogic.gdx.maps.tiled TiledMapTileLayer getName.

Prototype

public String getName() 

Source Link

Usage

From source file:com.stercore.code.net.dermetfan.utils.libgdx.maps.TmxMapWriter.java

License:Apache License

/** @param layer the {@link TiledMapTileLayer} to write in TMX format
 *  @param format the {@link Format} to use
 *  @return this {@link TmxMapWriter} */
public TmxMapWriter tmx(TiledMapTileLayer layer, Format format) throws IOException {
    element("layer");
    attribute("name", layer.getName());
    attribute("width", layer.getWidth());
    attribute("height", layer.getHeight());
    attribute("visible", layer.isVisible() ? 1 : 0);
    attribute("opacity", layer.getOpacity());

    tmx(layer.getProperties());/*from   ww  w .  j  a  v a  2s.  c  o m*/

    element("data");
    if (format == XML) {
        attribute("encoding", "xml");
        for (int y = layer.getHeight() - 1; y > -1; y--)
            for (int x = 0; x < layer.getWidth(); x++) {
                Cell cell = layer.getCell(x, y);
                if (cell != null) {
                    TiledMapTile tile = cell.getTile();
                    if (tile == null)
                        continue;
                    element("tile");
                    attribute("gid", tile.getId());
                    pop();
                }
            }
    } else if (format == CSV) {
        attribute("encoding", "csv");
        StringBuilder csv = new StringBuilder();
        for (int y = layer.getHeight() - 1; y > -1; y--) {
            for (int x = 0; x < layer.getWidth(); x++) {
                Cell cell = layer.getCell(x, y);
                TiledMapTile tile = cell != null ? cell.getTile() : null;
                csv.append(tile != null ? tile.getId() : 0);
                if (x + 1 < layer.getWidth() || y - 1 > -1)
                    csv.append(',');
            }
            csv.append('\n');
        }
        append('\n').append(csv);
    } else if (format == Base64 || format == Base64Zlib || format == Base64Gzip) {
        attribute("encoding", "base64");
        if (format == Base64Zlib)
            attribute("compression", "zlib");
        else if (format == Base64Gzip)
            attribute("compression", "gzip");
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        OutputStream out = format == Base64Zlib ? new DeflaterOutputStream(baos)
                : format == Base64Gzip ? new GZIPOutputStream(baos) : baos;
        final short LAST_BYTE = 0xFF;
        for (int y = layer.getHeight() - 1; y > -1; y--)
            for (int x = 0; x < layer.getWidth(); x++) {
                Cell cell = layer.getCell(x, y);
                TiledMapTile tile = cell != null ? cell.getTile() : null;
                int gid = tile != null ? tile.getId() : 0;
                out.write(gid & LAST_BYTE);
                out.write(gid >> 8 & LAST_BYTE);
                out.write(gid >> 16 & LAST_BYTE);
                out.write(gid >> 24 & LAST_BYTE);
            }
        if (out instanceof DeflaterOutputStream)
            ((DeflaterOutputStream) out).finish();
        out.close();
        baos.close();
        append('\n').append(String.valueOf(Base64Coder.encode(baos.toByteArray()))).append('\n');
    }
    pop();

    pop();
    return this;
}

From source file:de.fhkoeln.game.utils.libgdx.maps.TmxMapWriter.java

License:Apache License

/** @param layer the {@link com.badlogic.gdx.maps.tiled.TiledMapTileLayer} to write in TMX format
 *  @param format the {@link de.fhkoeln.game.utils.libgdx.maps.TmxMapWriter.Format} to use
 *  @return this {@link de.fhkoeln.game.utils.libgdx.maps.TmxMapWriter} */
public TmxMapWriter tmx(TiledMapTileLayer layer, Format format) throws IOException {
    element("layer");
    attribute("name", layer.getName());
    attribute("width", layer.getWidth());
    attribute("height", layer.getHeight());
    attribute("visible", layer.isVisible() ? 1 : 0);
    attribute("opacity", layer.getOpacity());

    tmx(layer.getProperties());//from  w w  w  . j a  v  a 2  s . c  o  m

    element("data");
    if (format == Format.XML) {
        attribute("encoding", "xml");
        for (int y = layer.getHeight() - 1; y > -1; y--)
            for (int x = 0; x < layer.getWidth(); x++) {
                Cell cell = layer.getCell(x, y);
                if (cell != null) {
                    TiledMapTile tile = cell.getTile();
                    if (tile == null)
                        continue;
                    element("tile");
                    attribute("gid", tile.getId());
                    pop();
                }
            }
    } else if (format == Format.CSV) {
        attribute("encoding", "csv");
        StringBuilder csv = new StringBuilder();
        for (int y = layer.getHeight() - 1; y > -1; y--) {
            for (int x = 0; x < layer.getWidth(); x++) {
                Cell cell = layer.getCell(x, y);
                TiledMapTile tile = cell != null ? cell.getTile() : null;
                csv.append(tile != null ? tile.getId() : 0);
                if (x + 1 < layer.getWidth() || y - 1 > -1)
                    csv.append(',');
            }
            csv.append('\n');
        }
        append('\n').append(csv);
    } else if (format == Format.Base64 || format == Format.Base64Zlib || format == Format.Base64Gzip) {
        attribute("encoding", "base64");
        if (format == Format.Base64Zlib)
            attribute("compression", "zlib");
        else if (format == Format.Base64Gzip)
            attribute("compression", "gzip");
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        OutputStream out = format == Format.Base64Zlib ? new DeflaterOutputStream(baos)
                : format == Format.Base64Gzip ? new GZIPOutputStream(baos) : baos;
        final short LAST_BYTE = 0xFF;
        for (int y = layer.getHeight() - 1; y > -1; y--)
            for (int x = 0; x < layer.getWidth(); x++) {
                Cell cell = layer.getCell(x, y);
                TiledMapTile tile = cell != null ? cell.getTile() : null;
                int gid = tile != null ? tile.getId() : 0;
                out.write(gid & LAST_BYTE);
                out.write(gid >> 8 & LAST_BYTE);
                out.write(gid >> 16 & LAST_BYTE);
                out.write(gid >> 24 & LAST_BYTE);
            }
        if (out instanceof DeflaterOutputStream)
            ((DeflaterOutputStream) out).finish();
        out.close();
        baos.close();
        append('\n').append(String.valueOf(Base64Coder.encode(baos.toByteArray()))).append('\n');
    }
    pop();

    pop();
    return this;
}