📄 tileset.java
字号:
*/ public Vector generateGaplessVector() { Vector gapless = new Vector(); for (int i = 0; i < getMaxTileId(); i++) { if (getTile(i) != null) gapless.add(getTile(i)); } return gapless; } /** * Returns the width of tiles in this tileset. All tiles in a tileset * should be the same width, and the same as the tile width of the map the * tileset is used with. * * @return int - The maximum tile width */ public int getTileWidth() { return tileDimensions.width; } /** * Returns the tile height of tiles in this tileset. Not all tiles in a * tileset are required to have the same height, but the height should be * at least the tile height of the map the tileset is used with. * * If there are tiles with varying heights in this tileset, the returned * height will be the maximum. * * @return the max height of the tiles in the set */ public int getTileHeight() { return tileDimensions.height; } /** * Returns the spacing between the tiles on the tileset image. * @return the spacing in pixels between the tiles on the tileset image */ public int getTileSpacing() { return tileSpacing; } /** * Gets the tile with <b>local</b> id <code>i</code>. * * @param i local id of tile * @return A tile with local id <code>i</code> or <code>null</code> if no * tile exists with that id */ public Tile getTile(int i) { try { return (Tile)tiles.get(i); } catch (ArrayIndexOutOfBoundsException a) {} return null; } /** * Returns the first non-null tile in the set. * * @return The first tile in this tileset, or <code>null</code> if none * exists. */ public Tile getFirstTile() { Tile ret = null; final Iterator itr = iterator(); if (itr.hasNext()) { ret = (Tile)itr.next(); } return ret; } /** * Returns the source of this tileset. * * @return a filename if tileset is external or <code>null</code> if * tileset is internal. */ public String getSource() { return externalSource; } /** * Returns the base directory for the tileset * * @return a directory in native format as given in the tileset file or tag */ public String getBaseDir() { return base; } /** * Returns the filename of the tileset image. * * @return the filename of the tileset image, or <code>null</code> if this * tileset doesn't reference a tileset image */ public String getTilebmpFile() { if (tilebmpFile != null) { try { return tilebmpFile.getCanonicalPath(); } catch (IOException e) { } } return null; } /** * Returns the first global id connected to this tileset. * * @return first global id */ public int getFirstGid() { return firstGid; } /** * @return the name of this tileset. */ public String getName() { return name; } /** * Returns the transparent color of the tileset image, or <code>null</code> * if none is set. * * @return Color - The transparent color of the set */ public Color getTransparentColor() { return transparentColor; } /** * @return the name of the tileset, and the total tiles */ public String toString() { return getName() + " [" + size() + "]"; } /** * Returns the number of images in the set. * * @return the number of images in the set */ public int getTotalImages() { return images.size(); } /** * @return an Enumeration of the image ids */ public Enumeration getImageIds() { Vector v = new Vector(); for (int id = 0; id <= images.getMaxId(); ++id) { if (images.containsId(id)) v.add(Integer.toString(id)); } return v.elements(); } // TILE IMAGE CODE /** * This function uses the CRC32 checksums to find the cached version of the * image supplied. * * @param i an Image object * @return returns the id of the given image, or -1 if the image is not in * the set */ public int getIdByImage(Image i) { return images.indexOf(i); } /** * @param id * @return the image identified by the key, or <code>null</code> when * there is no such image */ public Image getImageById(int id) { return (Image) images.get(id); } /** * Overlays the image in the set referred to by the given key. * * @param id * @param i */ public void overlayImage(int id, Image i) { images.put(id, i); } /** * Returns the dimensions of an image as specified by the id. * * @deprecated Unless somebody can explain the purpose of this function in * its documentation, I consider this function deprecated. It * is only used by tiles, but they should in my opinion just * use their "internalImage". - Bjorn * @param id the image id * @return dimensions of image with referenced by given key */ public Dimension getImageDimensions(int id) { Image i = (Image) images.get(id); if (i != null) { return new Dimension(i.getWidth(null), i.getHeight(null)); } else { return new Dimension(0, 0); } } /** * Adds the specified image to the image cache. If the image already exists * in the cache, returns the id of the existing image. If it does not exist, * this function adds the image and returns the new id. * * @param image the java.awt.Image to add to the image cache * @return the id as an <code>int</code> of the image in the cache */ public int addImage(Image image) { return images.findOrAdd(image); } public int addImage(Image image, int id) { return images.put(id, image); } public void removeImage(int id) { images.remove(id); } /** * Returns whether the tileset is derived from a tileset image. * * @return tileSetImage != null */ public boolean isSetFromImage() { return tileSetImage != null; } /** * Checks whether each image has a one to one relationship with the tiles. * * @deprecated * @return <code>true</code> if each image is associated with one and only * one tile, <code>false</code> otherwise. */ public boolean isOneForOne() { Iterator itr = iterator(); //[ATURK] I don't think that this check makes complete sense... /* while (itr.hasNext()) { Tile t = (Tile)itr.next(); if (t.countAnimationFrames() != 1 || t.getImageId() != t.getId() || t.getImageOrientation() != 0) { return false; } } */ for (int id = 0; id <= images.getMaxId(); ++id) { int relations = 0; itr = iterator(); while (itr.hasNext()) { Tile t = (Tile)itr.next(); // todo: move the null check back into the iterator? if (t != null && t.getImageId() == id) { relations++; } } if (relations != 1) { return false; } } return true; } public void setDefaultProperties(Properties defaultSetProperties) { defaultTileProperties = defaultSetProperties; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -