2 using System.Collections;
7 public class ImageRegion {
8 public String ImageFile;
9 public Rectangle Region;
28 public string EditorImage;
29 public ArrayList Images = new ArrayList();
37 public void Write(LispWriter writer) {
38 writer.StartList("tile");
39 writer.Write("id", ID);
41 if(Images.Count > 0) {
42 writer.StartList("images");
43 foreach(ImageRegion region in Images) {
44 if(region.Region.Width != 0) {
45 writer.WriteVerbatimLine(
46 String.Format("(region \"{0}\" {1} {2} {3} {4})",
47 region.ImageFile, region.Region.Left,
48 region.Region.Top, region.Region.Width,
49 region.Region.Height));
51 writer.WriteVerbatimLine(
52 "\"" + region.ImageFile + "\"");
55 writer.EndList("images");
57 Console.WriteLine("no images on tile " + ID);
61 writer.Write("solid", true);
63 writer.Write("unisolid", true);
65 writer.Write("ice", true);
67 writer.Write("water", true);
69 writer.Write("slope-type", Data);
71 writer.Write("hurts", true);
73 writer.Write("hidden", true);
75 writer.Write("coin", true);
77 writer.Write("fullbox", true);
79 writer.Write("brick", true);
81 writer.Write("next-tile", NextTile);
83 writer.Write("goal", true);
84 if(EditorImage != null)
85 writer.Write("editor-images", EditorImage);
87 writer.Write("data", Data);
88 if(Images.Count > 1) {
91 writer.Write("anim-fps", AnimFps);
93 writer.EndList("tile");
96 public void Parse(Lisp.Parser parser) {
98 while(parser.Parse() && parser.Depth >= d) {
99 if(parser.Depth == d+1) {
100 if(parser.Type != Parser.LispType.SYMBOL)
101 throw new Exception("expected SYMBOL");
102 string symbol = parser.SymbolValue;
106 ID = parser.IntegerValue;
109 ParseTileImages(parser);
111 case "editor-images":
112 EditorImage = parser.StringValue;
115 Solid = parser.BoolValue;
118 UniSolid = parser.BoolValue;
121 Ice = parser.BoolValue;
124 Water = parser.BoolValue;
128 Data = parser.IntegerValue;
131 AnimFps = parser.FloatValue;
134 Hurts = parser.BoolValue;
137 Hidden = parser.BoolValue;
140 Data = parser.IntegerValue;
143 NextTile = parser.IntegerValue;
146 Brick = parser.BoolValue;
149 FullBox = parser.BoolValue;
152 Coin = parser.BoolValue;
155 Goal = parser.BoolValue;
158 Console.WriteLine("Unknown tile element " + symbol);
165 private void ParseTileImages(Lisp.Parser parser) {
166 if(parser.Type == Parser.LispType.END_LIST)
169 int d = parser.Depth;
171 ImageRegion region = new ImageRegion();
172 if(parser.Type == Parser.LispType.STRING) {
173 region.ImageFile = parser.StringValue;
174 } else if(parser.Type == Parser.LispType.START_LIST) {
175 ParseImageRegion(parser, region);
177 throw new Exception("unexpected lisp data: " + parser.Type);
180 } while(parser.Parse() && parser.Depth >= d);
183 private void ParseImageRegion(Lisp.Parser parser, ImageRegion region) {
185 if(parser.Type != Parser.LispType.SYMBOL)
186 throw new Exception("expected symbol");
187 if(parser.SymbolValue != "region")
188 throw new Exception("expected region symbol");
190 if(parser.Type != Parser.LispType.STRING)
191 throw new Exception("expected string");
192 region.ImageFile = parser.StringValue;
195 if(parser.Type != Parser.LispType.INTEGER)
196 throw new Exception("expected integer");
197 region.Region.X = parser.IntegerValue;
200 if(parser.Type != Parser.LispType.INTEGER)
201 throw new Exception("expected integer");
202 region.Region.Y = parser.IntegerValue;
205 if(parser.Type != Parser.LispType.INTEGER)
206 throw new Exception("expected integer");
207 region.Region.Width = parser.IntegerValue;
210 if(parser.Type != Parser.LispType.INTEGER)
211 throw new Exception("expected integer");
212 region.Region.Height = parser.IntegerValue;
215 if(parser.Type != Parser.LispType.END_LIST)
216 throw new Exception("expected END_LIST");