Added constants for tile_width and tile_height.
authorMiloš Klouček <m.kloucek.m@atlas.cz>
Mon, 27 Oct 2008 12:53:04 +0000 (12:53 +0000)
committerMiloš Klouček <m.kloucek.m@atlas.cz>
Mon, 27 Oct 2008 12:53:04 +0000 (12:53 +0000)
Completed current SVN tilesets LOADING (I hope so and LOADING only...)

SVN-Revision: 5810

tools/tilemanager/Application.cs
tools/tilemanager/TileSet.cs

index 4a402fe..1025046 100644 (file)
@@ -169,7 +169,7 @@ public class Application {
                 tile.ID = startid + i;
                 ImageRegion region = new ImageRegion();
                 region.ImageFile = currentimage;
-                region.Region = new System.Drawing.Rectangle(x*32, y*32, 32, 32);
+                region.Region = new System.Drawing.Rectangle(x*TileSet.TILE_WIDTH, y*TileSet.TILE_HEIGHT, TileSet.TILE_WIDTH, TileSet.TILE_HEIGHT);
                 tile.Images.Add(region);
                 if(Tiles[i] != null) {
                     Console.WriteLine(
@@ -191,15 +191,15 @@ public class Application {
         }
         try {
             pixbuf = new Pixbuf(tilesetdir + "/" + file);
-            if(pixbuf.Width % 32 != 0 || pixbuf.Height % 32 != 0)
+            if(pixbuf.Width % TileSet.TILE_WIDTH != 0 || pixbuf.Height % TileSet.TILE_HEIGHT != 0)
                 Console.WriteLine("Warning: Image Width or Height is not a multiple of 32");
         } catch(Exception e) {
             ShowException(e);
             return;
         }
         currentimage = new FileInfo(file).Name;
-        TilesX = pixbuf.Width / 32;
-        TilesY = pixbuf.Height / 32;
+        TilesX = pixbuf.Width / TileSet.TILE_WIDTH;
+        TilesY = pixbuf.Height / TileSet.TILE_HEIGHT;
         SelectionArray = new bool[TilesX * TilesY];
         Tiles = new Tile[TilesX * TilesY];
 
@@ -211,8 +211,8 @@ public class Application {
                 continue;
             ImageRegion region = (ImageRegion) tile.Images[0];
             if(region.ImageFile == currentimage) {
-                int px = region.Region.X / 32;
-                int py = region.Region.Y / 32;
+                int px = region.Region.X / TileSet.TILE_WIDTH;
+                int py = region.Region.Y / TileSet.TILE_HEIGHT;
                 int i = py*TilesX+px;
                 if(i < 0 || i >= Tiles.Length) {
                     Console.WriteLine("Invalid Imageregion at tile " +
@@ -221,7 +221,7 @@ public class Application {
                 }
                 if(Tiles[i] != null) {
                     Console.WriteLine("Multiple tiles for region " +
-                            px*32 + " , " + py*32);
+                            px*TileSet.TILE_WIDTH + " , " + py*TileSet.TILE_HEIGHT);
                     continue;
                 }
                 Tiles[i] = tile;
@@ -373,7 +373,7 @@ public class Application {
     }
 
     private void select(int x, int y) {
-        int tile = y/32 * TilesX + x/32;
+        int tile = y/TileSet.TILE_HEIGHT * TilesX + x/TileSet.TILE_WIDTH;
         if(tile < 0 || tile >= SelectionArray.Length)
             return;
 
index 88c85ac..6719edd 100644 (file)
@@ -45,6 +45,9 @@ public class TileGroup {
 }
 
 public class TileSet {
+    public const int TILE_WIDTH = 32;
+    public const int TILE_HEIGHT = 32;
+
     private bool tooNew = false;
 
     /// <summary>Whether version of tileset file is too new</summary>
@@ -153,8 +156,7 @@ public class TileSet {
                List<int> attributes = new List<int>();
                List<int> datas = new List<int>();
                List<string> imageNames = new List<string>();
-               ArrayList images = new ArrayList();
-               int animFps = 0;
+               float animFps = 0;
 
                int d = parser.Depth;
                while(parser.Parse() && parser.Depth >= d) {
@@ -180,15 +182,12 @@ public class TileSet {
                                                Parser.ParseIntList(parser, datas);
                                                break;
                                        case "anim-fps":
-                                               animFps = parser.IntegerValue;
+                                               animFps = parser.FloatValue;
                                                break;
                                        case "image":
                                                int subDepth = parser.Depth;
                                                while(parser.Depth >= subDepth) {
                                                        imageNames.Add(parser.StringValue);
-                                                       ImageRegion region = new ImageRegion();
-                                                       region.ImageFile = parser.StringValue;
-                                                       images.Add(region);
                                                        parser.Parse();
                                                }
                                                break;
@@ -211,10 +210,21 @@ public class TileSet {
                                if (ids[id] != 0) {
                                        Tile tile = new Tile();
 
-                                       tile.Images = new ArrayList(images);
+                                       tile.Images = new ArrayList();
+                                       foreach (string str in imageNames)
+                                       {
+                                               ImageRegion region = new ImageRegion();
+                                               region.ImageFile = str;
+                                               region.Region.X = x * TILE_WIDTH;
+                                               region.Region.Y = y * TILE_HEIGHT;
+                                               region.Region.Width = TILE_WIDTH;
+                                               region.Region.Height = TILE_HEIGHT;
+                                               tile.Images.Add(region);
+                                       }
                                        tile.ID = ids[id];
                                        tile.Attributes = (attributes.Count > 0)?attributes[id]:0;      //missing atributes == all-are-0-attributes
                                        tile.Data = (datas.Count > 0)?datas[id]:0;      //missing DATAs == all-are-0-DATAs
+                                       tile.AnimFps = animFps;
 
                                        while(Tiles.Count <= tile.ID)
                                                Tiles.Add(null);