From 99d3aa1d55bf421525b4265913f64ee3680af864 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Milo=C5=A1=20Klou=C4=8Dek?= Date: Sun, 26 Oct 2008 20:02:19 +0000 Subject: [PATCH] A bit of work for current SVN support for tilemanager (can read "tiles" block now, but can't count image regions or save data yet...) But it still should work for 0.1.x tilesets... SVN-Revision: 5809 --- tools/tilemanager/Application.cs | 6 +-- tools/tilemanager/Makefile | 2 +- tools/tilemanager/Parser.cs | 8 ++++ tools/tilemanager/TileSet.cs | 98 +++++++++++++++++++++++++++++++++++++--- 4 files changed, 103 insertions(+), 11 deletions(-) diff --git a/tools/tilemanager/Application.cs b/tools/tilemanager/Application.cs index 2b0c5ae7e..4a402fefe 100644 --- a/tools/tilemanager/Application.cs +++ b/tools/tilemanager/Application.cs @@ -93,12 +93,12 @@ public class Application { fileChooser.DefaultResponse = Gtk.ResponseType.Ok; Gtk.FileFilter filter; filter = new Gtk.FileFilter(); - filter.Name = "Supertux 0.1.x tilesets"; + filter.Name = "Supertux tilesets"; + filter.AddPattern("*.strf"); filter.AddPattern("*.stgt"); fileChooser.AddFilter( filter ); filter = new Gtk.FileFilter(); - filter.Name = "Supertux tilesets"; - filter.AddPattern("*.strf"); + filter.Name = "Supertux 0.1.x tilesets"; filter.AddPattern("*.stgt"); fileChooser.AddFilter( filter ); filter = new Gtk.FileFilter(); diff --git a/tools/tilemanager/Makefile b/tools/tilemanager/Makefile index e483bd213..f65bbef42 100644 --- a/tools/tilemanager/Makefile +++ b/tools/tilemanager/Makefile @@ -5,7 +5,7 @@ RESOURCES=tiler.glade CSFLAGS+=$(foreach file,$(RESOURCES),-resource:$(file) ) $(GOAL): $(SOURCES) $(RESOURCES) - mcs $(CSFLAGS) $(SOURCES) -out:$(GOAL) + gmcs $(CSFLAGS) $(SOURCES) -out:$(GOAL) clean: rm -f $(GOAL) diff --git a/tools/tilemanager/Parser.cs b/tools/tilemanager/Parser.cs index 163a75e10..6a70eeff4 100644 --- a/tools/tilemanager/Parser.cs +++ b/tools/tilemanager/Parser.cs @@ -63,6 +63,14 @@ public class Parser { return true; } + public static void ParseIntList(Parser parser, System.Collections.Generic.List intList) { + int d = parser.Depth; + while(parser.Depth >= d) { + intList.Add(parser.IntegerValue); + parser.Parse(); + } + } + private LispType type; public LispType Type { get { return type; } diff --git a/tools/tilemanager/TileSet.cs b/tools/tilemanager/TileSet.cs index 071876098..88c85ac46 100644 --- a/tools/tilemanager/TileSet.cs +++ b/tools/tilemanager/TileSet.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Collections; +using System.Collections.Generic; using Lisp; public class TileGroup { @@ -21,7 +22,7 @@ public class TileGroup { while(parser.Parse() && parser.Depth >= d) { if(parser.Depth == d+1) { if(parser.Type != Parser.LispType.SYMBOL) - throw new Exception("expected SYMBOL"); + throw new Exception("expected SYMBOL at supertux-tiles level, but got \"" + parser.StringValue + "\""); string symbol = parser.SymbolValue; parser.Parse(); switch(symbol) { @@ -129,7 +130,7 @@ public class TileSet { Tiles[tile.ID] = tile; break; case "tiles": - SkipList(parser); + ParseMoreTiles(parser); tooNew = true; Console.WriteLine( "Warning: new syntax of \"More tiles in one image\" file isn't currently supported"); @@ -144,9 +145,92 @@ public class TileSet { } } - private void SkipList(Lisp.Parser parser) { - int d = parser.Depth; - while(parser.Parse() && parser.Depth >= d) - ; - } + public void ParseMoreTiles(Lisp.Parser parser) + { + int blockWidth = 0; + int blockHeight = 0; + List ids = new List(); + List attributes = new List(); + List datas = new List(); + List imageNames = new List(); + ArrayList images = new ArrayList(); + int animFps = 0; + + int d = parser.Depth; + while(parser.Parse() && parser.Depth >= d) { + if(parser.Depth == d+1) { + if(parser.Type != Parser.LispType.SYMBOL) + throw new Exception("expected SYMBOL at supertux-tiles---tiles level, but got \"" + parser.StringValue + "\""); + string symbol = parser.SymbolValue; + parser.Parse(); + switch(symbol) { + case "width": + blockWidth = parser.IntegerValue; + break; + case "height": + blockHeight = parser.IntegerValue; + break; + case "ids": + Parser.ParseIntList(parser, ids); + break; + case "attributes": + Parser.ParseIntList(parser, attributes); + break; + case "datas": + Parser.ParseIntList(parser, datas); + break; + case "anim-fps": + animFps = parser.IntegerValue; + 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; + default: + Console.WriteLine("Unknown tiles element " + symbol); + break; + } + } + } + if(ids.Count != blockWidth * blockHeight) + throw new ApplicationException("Must have width*height ids in tiles block, but found " + ids.Count.ToString()); + if((attributes.Count != blockWidth * blockHeight) && attributes.Count > 0) //missing atributes == all-are-0-attributes + throw new ApplicationException("Must have width*height attributes in tiles block"); + if((datas.Count != blockWidth * blockHeight) && datas.Count > 0) //missing DATAs == all-are-0-DATAs + throw new ApplicationException("Must have width*height DATAs in tiles block"); + + int id = 0; + for(int y = 0; y < blockHeight; ++y) { + for(int x = 0; x < blockWidth; ++x) { + if (ids[id] != 0) { + Tile tile = new Tile(); + + tile.Images = new ArrayList(images); + 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 + + while(Tiles.Count <= tile.ID) + Tiles.Add(null); + + Tiles[tile.ID] = tile; + } + + id++; + } + } + } + + private void SkipList(Lisp.Parser parser) + { + int d = parser.Depth; + while(parser.Parse() && parser.Depth >= d) + ; + } } -- 2.11.0