-
Notifications
You must be signed in to change notification settings - Fork 2
/
SlopeVertex.cs
99 lines (77 loc) · 2.32 KB
/
SlopeVertex.cs
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
#region ================== Namespaces
using System;
using System.Reflection;
using System.Collections.Generic;
using CodeImp.DoomBuilder.Geometry;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Types;
#endregion
namespace CodeImp.DoomBuilder.ThreeDFloorMode
{
public class SlopeVertex
{
#region ================== Variables
// private Vector2D pos;
private float x;
private float y;
private float z;
private bool selected;
#endregion
#region ================== Constructors
public SlopeVertex(Sector sector, int svgid, int vertexid)
{
string identifier;
List<string> list = new List<string> { "x", "y", "z" };
Type type = typeof(SlopeVertex);
this.x = 0;
this.y = 0;
this.z = 0;
this.selected = false;
// Read the x, y and z values
foreach (string str in list)
{
identifier = String.Format("user_svg{0}_v{1}_{2}", svgid, vertexid, str);
// Use reflection to set the variable to the value
type.GetField(str, BindingFlags.Instance | BindingFlags.NonPublic).SetValue(this, sector.Fields.GetValue(identifier, 0.0f));
}
}
public SlopeVertex(Vector2D p, float z)
{
// this.pos = new Vector2D(p);
this.x = p.x;
this.y = p.y;
this.z = z;
this.selected = false;
}
#endregion
#region ================== Properties
public Vector2D Pos { get { return new Vector2D(x, y); } set { x = value.x; y = value.y; } }
public float Z { get { return z; } set { z = value; } }
public bool Selected { get { return selected; } set { selected = value; } }
#endregion
#region ================== Methods
public void StoreInSector(Sector sector, int svgid, int vertexid)
{
string identifier;
Dictionary<String, float> dict = new Dictionary<string, float>
{
{ "x", x },
{ "y", y },
{ "z", z }
};
// Make sure the field work with undo/redo
sector.Fields.BeforeFieldsChange();
// Process the x, y and z fields
foreach (KeyValuePair<string, float> kvp in dict)
{
identifier = String.Format("user_svg{0}_v{1}_{2}", svgid, vertexid, kvp.Key);
// Add or update the vertex field
if (sector.Fields.ContainsKey(identifier))
sector.Fields[identifier] = new UniValue(UniversalType.Float, kvp.Value);
else
sector.Fields.Add(identifier, new UniValue(UniversalType.Float, kvp.Value));
}
}
#endregion
}
}