This repository was archived by the owner on May 10, 2018. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathTile.cs
More file actions
executable file
·223 lines (207 loc) · 7.23 KB
/
Copy pathTile.cs
File metadata and controls
executable file
·223 lines (207 loc) · 7.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/**
* From supertux/tools/tilemanager
*/
using System;
using System.Collections;
using System.IO;
using System.Drawing;
using Lisp;
public class ImageRegion {
public String ImageFile = null;
public Rectangle Region = Rectangle.Empty;
public RectangleF RelativeRegion = RectangleF.Empty;
}
public class Tile {
public int ID;
public bool Solid;
public bool UniSolid;
public bool Ice;
public bool Water;
public bool Slope;
public bool Hidden;
public bool Hurts;
public bool FullBox;
public bool Brick;
public bool Coin;
public bool Goal;
public int NextTile;
public int Data;
public float AnimFps;
public string EditorImage;
public ArrayList Images = new ArrayList();
public Tile() {
ID = -1;
NextTile = -1;
AnimFps = 1;
}
public void Write(LispWriter writer) {
writer.StartList("tile");
writer.Write("id", ID);
if(Images.Count > 0) {
writer.StartList("images");
foreach(ImageRegion region in Images) {
if(region.Region.Width != 0) {
writer.WriteVerbatimLine(
String.Format("(region \"{0}\" {1} {2} {3} {4})",
region.ImageFile, region.Region.Left,
region.Region.Top, region.Region.Width,
region.Region.Height));
} else {
writer.WriteVerbatimLine(
"\"" + region.ImageFile + "\"");
}
}
writer.EndList("images");
} else {
Console.WriteLine("no images on tile " + ID);
}
if(Solid)
writer.Write("solid", true);
if(UniSolid)
writer.Write("unisolid", true);
if(Ice)
writer.Write("ice", true);
if(Water)
writer.Write("water", true);
if(Slope)
writer.Write("slope-type", Data);
if(Hurts)
writer.Write("hurts", true);
if(Hidden)
writer.Write("hidden", true);
if(Coin)
writer.Write("coin", true);
if(FullBox)
writer.Write("fullbox", true);
if(Brick)
writer.Write("brick", true);
if(NextTile >= 0)
writer.Write("next-tile", NextTile);
if(Goal)
writer.Write("goal", true);
if(EditorImage != null)
writer.Write("editor-images", EditorImage);
if(Data != 0)
writer.Write("data", Data);
if(Images.Count > 1) {
if(AnimFps == 1.0)
AnimFps = 40;
writer.Write("anim-fps", AnimFps);
}
writer.EndList("tile");
}
public void Parse(Lisp.Parser parser) {
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");
string symbol = parser.SymbolValue;
parser.Parse();
switch(symbol) {
case "id":
ID = parser.IntegerValue;
break;
case "images":
ParseTileImages(parser);
break;
case "editor-images":
EditorImage = parser.StringValue;
break;
case "solid":
Solid = parser.BoolValue;
break;
case "unisolid":
UniSolid = parser.BoolValue;
break;
case "ice":
Ice = parser.BoolValue;
break;
case "water":
Water = parser.BoolValue;
break;
case "slope-type":
Slope = true;
Data = parser.IntegerValue;
break;
case "anim-fps":
AnimFps = parser.FloatValue;
break;
case "hurts":
Hurts = parser.BoolValue;
break;
case "hidden":
Hidden = parser.BoolValue;
break;
case "data":
Data = parser.IntegerValue;
break;
case "next-tile":
NextTile = parser.IntegerValue;
break;
case "brick":
Brick = parser.BoolValue;
break;
case "fullbox":
FullBox = parser.BoolValue;
break;
case "coin":
Coin = parser.BoolValue;
break;
case "goal":
Goal = parser.BoolValue;
break;
default:
Console.WriteLine("Unknown tile element " + symbol);
break;
}
}
}
}
private void ParseTileImages(Lisp.Parser parser) {
if(parser.Type == Parser.LispType.END_LIST)
return;
int d = parser.Depth;
do {
ImageRegion region = new ImageRegion();
if(parser.Type == Parser.LispType.STRING) {
region.ImageFile = parser.StringValue;
} else if(parser.Type == Parser.LispType.START_LIST) {
ParseImageRegion(parser, region);
} else {
throw new Exception("unexpected lisp data: " + parser.Type);
}
Images.Add(region);
} while(parser.Parse() && parser.Depth >= d);
}
private void ParseImageRegion(Lisp.Parser parser, ImageRegion region) {
parser.Parse();
if(parser.Type != Parser.LispType.SYMBOL)
throw new Exception("expected symbol");
if(parser.SymbolValue != "region")
throw new Exception("expected region symbol");
parser.Parse();
if(parser.Type != Parser.LispType.STRING)
throw new Exception("expected string");
region.ImageFile = parser.StringValue;
parser.Parse();
if(parser.Type != Parser.LispType.INTEGER)
throw new Exception("expected integer");
region.Region.X = parser.IntegerValue;
parser.Parse();
if(parser.Type != Parser.LispType.INTEGER)
throw new Exception("expected integer");
region.Region.Y = parser.IntegerValue;
parser.Parse();
if(parser.Type != Parser.LispType.INTEGER)
throw new Exception("expected integer");
region.Region.Width = parser.IntegerValue;
parser.Parse();
if(parser.Type != Parser.LispType.INTEGER)
throw new Exception("expected integer");
region.Region.Height = parser.IntegerValue;
parser.Parse();
if(parser.Type != Parser.LispType.END_LIST)
throw new Exception("expected END_LIST");
}
}