Пример #1
0
  /**
   * Returns the maximum tile height. This is the height of the highest tile in all tilesets or the
   * tile height used by this map if it's smaller.
   *
   * @return int The maximum tile height
   */
  public int getTileHeightMax() {
    int maxHeight = tileHeight;

    for (TileSet tileset : tilesets) {
      int height = tileset.getTileHeight();
      if (height > maxHeight) {
        maxHeight = height;
      }
    }

    return maxHeight;
  }
Пример #2
0
  private void writeTileset(TileSet set, XMLWriter w, String wp) throws IOException {

    String tileBitmapFile = set.getTilebmpFile();
    String name = set.getName();

    w.startElement("tileset");
    w.writeAttribute("firstgid", getFirstGidForTileset(set));

    if (name != null) {
      w.writeAttribute("name", name);
    }

    if (tileBitmapFile != null) {
      w.writeAttribute("tilewidth", set.getTileWidth());
      w.writeAttribute("tileheight", set.getTileHeight());

      final int tileSpacing = set.getTileSpacing();
      final int tileMargin = set.getTileMargin();
      if (tileSpacing != 0) {
        w.writeAttribute("spacing", tileSpacing);
      }
      if (tileMargin != 0) {
        w.writeAttribute("margin", tileMargin);
      }
    }

    if (set.getBaseDir() != null) {
      w.writeAttribute("basedir", set.getBaseDir());
    }

    if (tileBitmapFile != null) {
      w.startElement("image");
      w.writeAttribute("source", getRelativePath(wp, tileBitmapFile));

      Color trans = set.getTransparentColor();
      if (trans != null) {
        w.writeAttribute("trans", Integer.toHexString(trans.getRGB()).substring(2));
      }
      w.endElement();

      // Write tile properties when necessary.
      for (Tile tile : set) {
        // todo: move the null check back into the iterator?
        if (tile != null && !tile.getProperties().isEmpty()) {
          w.startElement("tile");
          w.writeAttribute("id", tile.getId());
          writeProperties(tile.getProperties(), w);
          w.endElement();
        }
      }
    } else {
      // Check to see if there is a need to write tile elements
      boolean needWrite = false;

      // As long as one has properties, they all need to be written.
      // TODO: This shouldn't be necessary
      for (Tile tile : set) {
        if (!tile.getProperties().isEmpty() || tile.getSource() != null) {
          needWrite = true;
          break;
        }
      }

      if (needWrite) {
        w.writeAttribute("tilewidth", set.getTileWidth());
        w.writeAttribute("tileheight", set.getTileHeight());
        w.writeAttribute("tilecount", set.size());
        w.writeAttribute("columns", set.getTilesPerRow());

        for (Tile tile : set) {
          // todo: move this check back into the iterator?
          if (tile != null) {
            writeTile(tile, w, wp);
          }
        }
      }
    }
    w.endElement();
  }