Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SimpleStructure.cs
Go to the documentation of this file.
2
4
6{
7 private int[,] _data;
8
9 private int _width;
10
11 private int _height;
12
14
15 private bool _xMirror;
16
17 private bool _yMirror;
18
19 public int Width => _width;
20
21 public int Height => _height;
22
23 public SimpleStructure(params string[] data)
24 {
25 ReadData(data);
26 }
27
28 public SimpleStructure(string data)
29 {
30 ReadData(data.Split('\n'));
31 }
32
33 private void ReadData(string[] lines)
34 {
35 _height = lines.Length;
36 _width = lines[0].Length;
37 _data = new int[_width, _height];
38 for (int i = 0; i < _height; i++)
39 {
40 for (int j = 0; j < _width; j++)
41 {
42 int num = lines[i][j];
43 if (num >= 48 && num <= 57)
44 {
45 _data[j, i] = num - 48;
46 }
47 else
48 {
49 _data[j, i] = -1;
50 }
51 }
52 }
53 }
54
55 public SimpleStructure SetActions(params GenAction[] actions)
56 {
57 _actions = actions;
58 return this;
59 }
60
61 public SimpleStructure Mirror(bool horizontalMirror, bool verticalMirror)
62 {
63 _xMirror = horizontalMirror;
64 _yMirror = verticalMirror;
65 return this;
66 }
67
68 public override bool Place(Point origin, StructureMap structures)
69 {
70 if (!structures.CanPlace(new Rectangle(origin.X, origin.Y, _width, _height)))
71 {
72 return false;
73 }
74 for (int i = 0; i < _width; i++)
75 {
76 for (int j = 0; j < _height; j++)
77 {
78 int num = (_xMirror ? (-i) : i);
79 int num2 = (_yMirror ? (-j) : j);
80 if (_data[i, j] != -1 && !_actions[_data[i, j]].Apply(origin, num + origin.X, num2 + origin.Y))
81 {
82 return false;
83 }
84 }
85 }
86 structures.AddProtectedStructure(new Rectangle(origin.X, origin.Y, _width, _height));
87 return true;
88 }
89}
SimpleStructure SetActions(params GenAction[] actions)
override bool Place(Point origin, StructureMap structures)
SimpleStructure Mirror(bool horizontalMirror, bool verticalMirror)
void AddProtectedStructure(Rectangle area, int padding=0)
bool CanPlace(Rectangle area, int padding=0)