[tiled] r563 - in trunk: . tiled/core tiled/mapeditor tiled/mapeditor/util/cutter tiled/util

svn@biggeruniverse.com svn at biggeruniverse.com
Wed Jan 25 20:33:46 PST 2006


Author: aturk
Date: 2006-01-25 22:33:46 -0600 (Wed, 25 Jan 2006)
New Revision: 563

Modified:
   trunk/CHANGES
   trunk/tiled/core/TileSet.java
   trunk/tiled/mapeditor/MapEditor.java
   trunk/tiled/mapeditor/util/cutter/BasicTileCutter.java
   trunk/tiled/mapeditor/util/cutter/BorderTileCutter.java
   trunk/tiled/mapeditor/util/cutter/TileCutter.java
   trunk/tiled/util/TileMergeHelper.java
Log:
+ Fix for the NPE reported by Nader Akhres
+ Modifications to the new TileCutter code


Modified: trunk/CHANGES
===================================================================
--- trunk/CHANGES	2006-01-25 23:42:44 UTC (rev 562)
+++ trunk/CHANGES	2006-01-26 04:33:46 UTC (rev 563)
@@ -2,6 +2,8 @@
 
 + Added support for localization/internationalization
 + Added a navigation minimap
++ Added full support for animated tiles
++ Rewrote main mapeditor code
 + Fixed memory problems when loading several maps with many tilesets in a row
 
 0.5.2 - TBD (+ means planned change)
@@ -12,7 +14,7 @@
 * For pencil, right-click, drag now creates a stamp for easy copying
 + Added ability to select multiple layers from layer table
 + Added the ability to merge tile images when layers are merged
-* Added support for animated tiles
+* Added core support for animated tiles
 * Added more error-checking to XMLMapTransformer, the default map reader
 + Added "global properties" for tilesets (properties set for all tiles)
 * Added support for "tile cutters"
@@ -22,6 +24,7 @@
 + Fixed tile palette bug of displaying multiple tilesets over eachother
 * Fixed tile palette bug of not accounting for gaps in tile ids (old bug)
 * Fixed bug of adding a new tile even if cancelling out of new tile dialog
+* Fixed NPE when saving a map with no extension - default to .tmx
 
 0.5.1 - June 15th, 2005
 

Modified: trunk/tiled/core/TileSet.java
===================================================================
--- trunk/tiled/core/TileSet.java	2006-01-25 23:42:44 UTC (rev 562)
+++ trunk/tiled/core/TileSet.java	2006-01-26 04:33:46 UTC (rev 563)
@@ -24,7 +24,6 @@
 
 import javax.imageio.ImageIO;
 
-import tiled.mapeditor.util.cutter.BasicTileCutter;
 import tiled.mapeditor.util.cutter.TileCutter;
 import tiled.util.Util;
 import tiled.util.NumberedSet;
@@ -56,14 +55,16 @@
     private String base;
     private NumberedSet tiles, images;
     private int firstGid;
-    private int tileHeight, maxTileHeight=0;
+    private int tileHeight;
     private int tileWidth;
-    private Image setImage;
     private String externalSource, tilebmpFile;
     private String name;
     private Map map;
     private Color transparentColor;
 
+    /**
+     * Default constructor
+     */
     public TileSet() {
         tiles = new NumberedSet();
         images = new NumberedSet();
@@ -71,8 +72,12 @@
 
     /**
      * Creates a tileset from a tile bitmap file.
-     *
-     * @see TileSet#importTileBitmap(BufferedImage,TileCutter,int,int,int,boolean)
+     * 
+     * @param imgFilename
+     * @param cutter
+     * @param createTiles
+     * @throws Exception
+     * @see TileSet#importTileBitmap(BufferedImage, TileCutter, boolean)
      */
     public void importTileBitmap(String imgFilename, TileCutter cutter, boolean createTiles) throws Exception
     {
@@ -96,9 +101,6 @@
      *
      * @param tilebmp     the image to be used
      * @param cutter
-     * @param tileWidth   the tile width
-     * @param tileHeight  the tile height
-     * @param spacing     the amount of spacing between the tiles
      * @param createTiles set to <code>true</code> to have the function create
      *                    Tiles
      * @throws Exception
@@ -113,6 +115,9 @@
         	throw new Exception("No cutter!");
         }
         
+        tileHeight = cutter.getDimensions().height;
+        tileWidth = cutter.getDimensions().width;
+        
         BufferedImage tile;
         
         cutter.setImage(tilebmp);
@@ -153,8 +158,12 @@
         }*/
     }
 
+    /**
+     * @deprecated
+     * @param i
+     */
     public void setTilesetImage(Image i) {
-        setImage = i;
+        //setImage = i;
     }
 
     /**
@@ -179,6 +188,8 @@
     /**
      * Sets the filename of the tileset image. Doesn't change the tileset in
      * any other way.
+     * 
+     * @param name
      */
     public void setTilesetImageFilename(String name) {
         tilebmpFile = name;
@@ -204,6 +215,9 @@
 
     /**
      * Sets the map this tileset is part of.
+     * 
+     * @param map
+     * @deprecated
      */
     public void setMap(Map map) {
         this.map = map;
@@ -211,6 +225,8 @@
 
     /**
      * Sets the transparent color in the tileset image.
+     * 
+     * @param color
      */
     public void setTransparentColor(Color color) {
         transparentColor = color;
@@ -230,10 +246,6 @@
         
         if (tileHeight < t.getHeight()) {
             tileHeight = t.getHeight();
-        } 
-        
-        if (maxTileHeight < tileHeight) {
-        	maxTileHeight = tileHeight;
         }
 
         if (tileWidth < t.getWidth()) {
@@ -302,6 +314,8 @@
      * 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 tileWidth;
@@ -314,13 +328,19 @@
      *
      * If there are tiles with varying heights in this tileset, the returned
      * height will be the maximum.
+     * 
+     * @return int - The max height of the tiles in the set
      */
     public int getTileHeight() {
         return tileHeight;
     }
 
+    /**
+     * @deprecated
+     * @return int
+     */
     public int getMaxTileHeight() {
-    	return maxTileHeight;
+    	return getTileHeight();
     }
     
     /**
@@ -397,6 +417,8 @@
 
     /**
      * Returns the map this tileset is part of.
+     * @deprecated
+     * @return int
      */
     public Map getMap() {
         return map;
@@ -405,6 +427,8 @@
     /**
      * 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;
@@ -495,13 +519,22 @@
 
     /**
      * @param key a key identifying the image to get
-     * @return the imagine identified by the key, or <code>null</code> when
+     * @return the image identified by the key, or <code>null</code> when
      *         there is no such image
+     * @see TileSet#getImageByIdAndOrientation(Object, int)
      */
     public Image getImageById(Object key) {
         return getImageByIdAndOrientation(key, 0);
     }
 
+    /**
+     * Returns the image referred to by the given key, and automatically
+     * sets it to the given orientation.
+     * 
+     * @param key
+     * @param orientation
+     * @return Image
+     */
     public Image getImageByIdAndOrientation(Object key, int orientation) {
         int img_id = Integer.parseInt((String)key);
         ImageGroup img = (ImageGroup)images.get(img_id);
@@ -509,6 +542,12 @@
         return img.getImage(orientation);
     }
 
+    /**
+     * Overlays the image in the set referred to by the given key.
+     * 
+     * @param key
+     * @param i
+     */
     public void overlayImage(Object key, Image i) {
         int img_id = Integer.parseInt((String)key);
         images.put(img_id, new ImageGroup(i));
@@ -519,6 +558,7 @@
      * <code>key</code>.
      *
      * @param key
+     * @param orientation
      * @return dimensions of image with referenced by given key
      */
     public Dimension getImageDimensions(Object key, int orientation) {
@@ -601,7 +641,7 @@
     public boolean isOneForOne() {
         Iterator itr = iterator();
 
-        //[ATURK] I don't that this check makes complete sense...
+        //[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()

Modified: trunk/tiled/mapeditor/MapEditor.java
===================================================================
--- trunk/tiled/mapeditor/MapEditor.java	2006-01-25 23:42:44 UTC (rev 562)
+++ trunk/tiled/mapeditor/MapEditor.java	2006-01-26 04:33:46 UTC (rev 563)
@@ -522,7 +522,6 @@
     }
 
     private void createData() {
-        JButton b;
         JToolBar tabsPanel = new JToolBar();
         JTabbedPane paintPanel = new JTabbedPane();
 
@@ -836,8 +835,7 @@
                 }
             }
         } else if (command.equals("Merge All")) {
-            //TODO: put this back in for 0.5.2
-            /*if( JOptionPane.showConfirmDialog(appFrame,
+            if( JOptionPane.showConfirmDialog(appFrame,
                     "Do you wish to merge tile images, and create a new tile set?",
                     "Merge Tiles?", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION ) {
                 TileMergeHelper tmh = new TileMergeHelper(currentMap);
@@ -847,14 +845,14 @@
                 currentMap.removeAllLayers();
                 currentMap.addLayer(newLayer);
                 currentMap.addTileset(tmh.getSet());
-            } else {*/
+            } else {
                 while (currentMap.getTotalLayers() > 1) {
                     try {
                         currentMap.mergeLayerDown(
                                 currentMap.getTotalLayers() - 1);
                     } catch (Exception ex) {}
                 }
-            //}
+            }
             setCurrentLayer(0);
         }
 
@@ -1836,6 +1834,13 @@
             }
         }
 
+        // Make sure that the file has an extension. If not, append .tmx
+        // NOTE: we can't know anything more than the filename has at least
+        //		 one '.' in it...
+        if(filename.lastIndexOf('.') == -1) {
+        	filename = filename.concat(".tmx");
+        }
+        
         try {
             // Check if file exists
             File exist = new File(filename);

Modified: trunk/tiled/mapeditor/util/cutter/BasicTileCutter.java
===================================================================
--- trunk/tiled/mapeditor/util/cutter/BasicTileCutter.java	2006-01-25 23:42:44 UTC (rev 562)
+++ trunk/tiled/mapeditor/util/cutter/BasicTileCutter.java	2006-01-26 04:33:46 UTC (rev 563)
@@ -1,5 +1,6 @@
 package tiled.mapeditor.util.cutter;
 
+import java.awt.Dimension;
 import java.awt.Graphics2D;
 import java.awt.Image;
 import java.awt.image.BufferedImage;
@@ -55,4 +56,7 @@
 		return null;
 	}
 
+	public Dimension getDimensions() {
+		return new Dimension(tileWidth, tileHeight);
+	}
 }

Modified: trunk/tiled/mapeditor/util/cutter/BorderTileCutter.java
===================================================================
--- trunk/tiled/mapeditor/util/cutter/BorderTileCutter.java	2006-01-25 23:42:44 UTC (rev 562)
+++ trunk/tiled/mapeditor/util/cutter/BorderTileCutter.java	2006-01-26 04:33:46 UTC (rev 563)
@@ -1,5 +1,6 @@
 package tiled.mapeditor.util.cutter;
 
+import java.awt.Dimension;
 import java.awt.Image;
 
 public class BorderTileCutter implements TileCutter {
@@ -14,4 +15,9 @@
 		return null;
 	}
 
+	public Dimension getDimensions() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
 }

Modified: trunk/tiled/mapeditor/util/cutter/TileCutter.java
===================================================================
--- trunk/tiled/mapeditor/util/cutter/TileCutter.java	2006-01-25 23:42:44 UTC (rev 562)
+++ trunk/tiled/mapeditor/util/cutter/TileCutter.java	2006-01-26 04:33:46 UTC (rev 563)
@@ -1,8 +1,10 @@
 package tiled.mapeditor.util.cutter;
 
+import java.awt.Dimension;
 import java.awt.Image;
 
 public interface TileCutter {
 	public void setImage(Image image);
 	public Image getNextTile() throws Exception;
+	public Dimension getDimensions();
 }

Modified: trunk/tiled/util/TileMergeHelper.java
===================================================================
--- trunk/tiled/util/TileMergeHelper.java	2006-01-25 23:42:44 UTC (rev 562)
+++ trunk/tiled/util/TileMergeHelper.java	2006-01-26 04:33:46 UTC (rev 563)
@@ -71,7 +71,8 @@
             GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
         Image tileImg = config.createCompatibleImage(c.getWidth(), c.getHeight());
         c.render(tileImg.getGraphics());
-        int image_id = myTs.addImage(tileImg);
+        tile.setImage(tileImg);
+        //int image_id = myTs.addImage(tileImg);
         //tile.setAppearance(image_id, 0);
 
         myTs.addTile(tile);




More information about the tiled-commit mailing list