[tiled] r604 - in trunk/src/tiled: core io/xml mapeditor/util/cutter

svn@biggeruniverse.com svn at biggeruniverse.com
Sun Apr 9 14:21:23 PDT 2006


Author: bjorn
Date: 2006-04-09 16:21:22 -0500 (Sun, 09 Apr 2006)
New Revision: 604

Modified:
   trunk/src/tiled/core/TileSet.java
   trunk/src/tiled/io/xml/XMLMapTransformer.java
   trunk/src/tiled/mapeditor/util/cutter/BasicTileCutter.java
Log:
Fixed an off by one error causing the basic cutter to miss the bottom row of the tileset image.

Modified: trunk/src/tiled/core/TileSet.java
===================================================================
--- trunk/src/tiled/core/TileSet.java	2006-04-09 19:41:21 UTC (rev 603)
+++ trunk/src/tiled/core/TileSet.java	2006-04-09 21:21:22 UTC (rev 604)
@@ -15,7 +15,6 @@
 import java.awt.*;
 import java.awt.image.BufferedImage;
 import java.io.File;
-import java.io.IOException;
 import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.Properties;
@@ -70,17 +69,13 @@
     public void importTileBitmap(String imgFilename, TileCutter cutter,
                                  boolean createTiles) throws Exception
     {
-        File imgFile = null;
-        try {
-            imgFile = new File(imgFilename);
-            tilebmpFile = imgFile.getCanonicalPath();
-        } catch (IOException e) {
-            tilebmpFile = imgFilename;
-        }
+        // IOException will propagate upwards when file cannot be found
+        File imgFile = new File(imgFilename);
+        tilebmpFile = imgFile.getCanonicalPath();
 
         System.out.println("Importing " + imgFilename + "...");
 
-        importTileBitmap(ImageIO.read(imgFile.toURL()), cutter, createTiles);
+        importTileBitmap(ImageIO.read(imgFile), cutter, createTiles);
     }
 
     /**
@@ -112,7 +107,7 @@
         try {
             BufferedImage tile;
 	        while ((tile = (BufferedImage) cutter.getNextTile()) != null) {
-	        	int newId = addImage(tile);
+                int newId = addImage(tile);
 	        	if (createTiles) {
                     Tile newTile = new Tile();
                     newTile.setImage(newId);

Modified: trunk/src/tiled/io/xml/XMLMapTransformer.java
===================================================================
--- trunk/src/tiled/io/xml/XMLMapTransformer.java	2006-04-09 19:41:21 UTC (rev 603)
+++ trunk/src/tiled/io/xml/XMLMapTransformer.java	2006-04-09 21:21:22 UTC (rev 604)
@@ -384,8 +384,10 @@
                                         sourcePath + ")");
                             }
                         } else {
-                            set.importTileBitmap(sourcePath, new BasicTileCutter(
-                                    tileWidth, tileHeight, tileSpacing, 0), !hasTileElements);
+                            set.importTileBitmap(sourcePath,
+                                    new BasicTileCutter(tileWidth, tileHeight,
+                                            tileSpacing, 0),
+                                    !hasTileElements);
                         }
 
                     } else {

Modified: trunk/src/tiled/mapeditor/util/cutter/BasicTileCutter.java
===================================================================
--- trunk/src/tiled/mapeditor/util/cutter/BasicTileCutter.java	2006-04-09 19:41:21 UTC (rev 603)
+++ trunk/src/tiled/mapeditor/util/cutter/BasicTileCutter.java	2006-04-09 21:21:22 UTC (rev 604)
@@ -26,13 +26,15 @@
     private BufferedImage image;
     private int tileWidth, tileHeight, frame, offset;
 
-    public BasicTileCutter(int width, int height, int frame, int offset) {
-        this.tileWidth = width;
-        this.tileHeight = height;
+    public BasicTileCutter(int tileWidth, int tileHeight, int frame,
+                           int offset)
+    {
+        this.tileWidth = tileWidth;
+        this.tileHeight = tileHeight;
         this.frame = frame;
         this.offset = offset;
 
-        //do initial setup
+        // Do initial setup
         nextX = offset + frame;
         nextY = offset + frame;
     }
@@ -40,7 +42,7 @@
     public String getName() {
     	return "Basic";
     }
-    
+
     public void setImage(Image image) {
         int iw = image.getWidth(null);
         int ih = image.getHeight(null);
@@ -59,14 +61,14 @@
     }
 
     public Image getNextTile() throws Exception {
-        if (nextY + tileHeight < image.getHeight()) {
+        if (nextY + tileHeight <= image.getHeight()) {
             BufferedImage tile =
                 image.getSubimage(nextX, nextY, tileWidth, tileHeight);
-            nextX += tileWidth+frame;
+            nextX += tileWidth + frame;
 
             if (nextX + tileWidth > image.getWidth()) {
                 nextX = offset + frame;
-                nextY += tileHeight+frame;
+                nextY += tileHeight + frame;
             }
 
             return tile;




More information about the tiled-commit mailing list