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);
86 writer.Write("anim-speed", AnimSpeed);
87 writer.EndList("tile");
90 public void Parse(Lisp.Parser parser) {
92 while(parser.Parse() && parser.Depth >= d) {
93 if(parser.Depth == d+1) {
94 if(parser.Type != Parser.LispType.SYMBOL)
95 throw new Exception("expected SYMBOL");
96 string symbol = parser.SymbolValue;
100 ID = parser.IntegerValue;
103 ParseTileImages(parser);
105 case "editor-images":
106 EditorImage = parser.StringValue;
109 Solid = parser.BoolValue;
112 UniSolid = parser.BoolValue;
115 Ice = parser.BoolValue;
118 Water = parser.BoolValue;
122 Data = parser.IntegerValue;
125 AnimSpeed = parser.IntegerValue;
128 Spike = parser.BoolValue;
131 Data = parser.IntegerValue;
134 NextTile = parser.IntegerValue;
137 Brick = parser.BoolValue;
140 FullBox = parser.BoolValue;
143 Coin = parser.BoolValue;
146 Goal = parser.BoolValue;
149 Console.WriteLine("Unknown tile element " + symbol);
156 private void ParseTileImages(Lisp.Parser parser) {
157 if(parser.Type == Parser.LispType.END_LIST)
160 int d = parser.Depth;
162 ImageRegion region = new ImageRegion();
163 if(parser.Type == Parser.LispType.STRING) {
164 region.ImageFile = parser.StringValue;
165 } else if(parser.Type == Parser.LispType.START_LIST) {
166 ParseImageRegion(parser, region);
168 throw new Exception("unexpected lisp data: " + parser.Type);
171 } while(parser.Parse() && parser.Depth >= d);
174 private void ParseImageRegion(Lisp.Parser parser, ImageRegion region) {
176 if(parser.Type != Parser.LispType.SYMBOL)
177 throw new Exception("expected symbol");
178 if(parser.SymbolValue != "region")
179 throw new Exception("expected region symbol");
181 if(parser.Type != Parser.LispType.STRING)
182 throw new Exception("expected string");
183 region.ImageFile = parser.StringValue;
186 if(parser.Type != Parser.LispType.INTEGER)
187 throw new Exception("expected integer");
188 region.Region.X = parser.IntegerValue;
191 if(parser.Type != Parser.LispType.INTEGER)
192 throw new Exception("expected integer");
193 region.Region.Y = parser.IntegerValue;
196 if(parser.Type != Parser.LispType.INTEGER)
197 throw new Exception("expected integer");
198 region.Region.Width = parser.IntegerValue;
201 if(parser.Type != Parser.LispType.INTEGER)
202 throw new Exception("expected integer");
203 region.Region.Height = parser.IntegerValue;
206 if(parser.Type != Parser.LispType.END_LIST)
207 throw new Exception("expected END_LIST");