2 using System.Collections;
7 public class ImageRegion {
8 public String ImageFile;
9 public Rectangle Region;
27 public string EditorImage;
28 public ArrayList Images = new ArrayList();
36 public void Write(LispWriter writer) {
37 writer.StartList("tile");
38 writer.Write("id", ID);
40 if(Images.Count > 0) {
41 writer.StartList("images");
42 foreach(ImageRegion region in Images) {
43 if(region.Region.Width != 0) {
44 writer.WriteVerbatimLine(
45 String.Format("(region \"{0}\" {1} {2} {3} {4})",
46 region.ImageFile, region.Region.Left,
47 region.Region.Top, region.Region.Width,
48 region.Region.Height));
50 writer.WriteVerbatimLine(
51 "\"" + region.ImageFile + "\"");
54 writer.EndList("images");
56 Console.WriteLine("no images on tile " + ID);
60 writer.Write("solid", true);
62 writer.Write("unisolid", true);
64 writer.Write("ice", true);
66 writer.Write("water", true);
68 writer.Write("slope-type", Data);
70 writer.Write("spike", true);
72 writer.Write("distro", true);
74 writer.Write("fullbox", true);
76 writer.Write("brick", true);
78 writer.Write("next-tile", NextTile);
80 writer.Write("goal", true);
81 if(EditorImage != null)
82 writer.Write("editor-images", EditorImage);
84 writer.Write("data", Data);
85 if(Images.Count > 1) {
88 writer.Write("anim-fps", AnimFps);
90 writer.EndList("tile");
93 public void Parse(Lisp.Parser parser) {
95 while(parser.Parse() && parser.Depth >= d) {
96 if(parser.Depth == d+1) {
97 if(parser.Type != Parser.LispType.SYMBOL)
98 throw new Exception("expected SYMBOL");
99 string symbol = parser.SymbolValue;
103 ID = parser.IntegerValue;
106 ParseTileImages(parser);
108 case "editor-images":
109 EditorImage = parser.StringValue;
112 Solid = parser.BoolValue;
115 UniSolid = parser.BoolValue;
118 Ice = parser.BoolValue;
121 Water = parser.BoolValue;
125 Data = parser.IntegerValue;
128 AnimFps = parser.FloatValue;
131 Spike = parser.BoolValue;
134 Data = parser.IntegerValue;
137 NextTile = parser.IntegerValue;
140 Brick = parser.BoolValue;
143 FullBox = parser.BoolValue;
146 Coin = parser.BoolValue;
149 Goal = parser.BoolValue;
152 Console.WriteLine("Unknown tile element " + symbol);
159 private void ParseTileImages(Lisp.Parser parser) {
160 if(parser.Type == Parser.LispType.END_LIST)
163 int d = parser.Depth;
165 ImageRegion region = new ImageRegion();
166 if(parser.Type == Parser.LispType.STRING) {
167 region.ImageFile = parser.StringValue;
168 } else if(parser.Type == Parser.LispType.START_LIST) {
169 ParseImageRegion(parser, region);
171 throw new Exception("unexpected lisp data: " + parser.Type);
174 } while(parser.Parse() && parser.Depth >= d);
177 private void ParseImageRegion(Lisp.Parser parser, ImageRegion region) {
179 if(parser.Type != Parser.LispType.SYMBOL)
180 throw new Exception("expected symbol");
181 if(parser.SymbolValue != "region")
182 throw new Exception("expected region symbol");
184 if(parser.Type != Parser.LispType.STRING)
185 throw new Exception("expected string");
186 region.ImageFile = parser.StringValue;
189 if(parser.Type != Parser.LispType.INTEGER)
190 throw new Exception("expected integer");
191 region.Region.X = parser.IntegerValue;
194 if(parser.Type != Parser.LispType.INTEGER)
195 throw new Exception("expected integer");
196 region.Region.Y = parser.IntegerValue;
199 if(parser.Type != Parser.LispType.INTEGER)
200 throw new Exception("expected integer");
201 region.Region.Width = parser.IntegerValue;
204 if(parser.Type != Parser.LispType.INTEGER)
205 throw new Exception("expected integer");
206 region.Region.Height = parser.IntegerValue;
209 if(parser.Type != Parser.LispType.END_LIST)
210 throw new Exception("expected END_LIST");