Skip to content

Commit 573f7b0

Browse files
committed
Added CppTypeMapping class.
1 parent ea72aaf commit 573f7b0

File tree

6 files changed

+105
-1
lines changed

6 files changed

+105
-1
lines changed

ReClass.NET/DataExchange/ReClass/ReClassNetFile.Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public partial class ReClassNetFile
1515

1616
public const string XmlRootElement = "reclass";
1717
public const string XmlCustomDataElement = "custom_data";
18+
public const string XmlTypeMappingElement = "type_mapping";
1819
public const string XmlClassesElement = "classes";
1920
public const string XmlClassElement = "class";
2021
public const string XmlNodeElement = "node";

ReClass.NET/DataExchange/ReClass/ReClassNetFile.Read.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ public void Load(Stream input, ILogger logger)
6161
project.CustomData.Deserialize(customDataElement);
6262
}
6363

64+
var typeMappingElement = document.Root.Element(XmlTypeMappingElement);
65+
if (typeMappingElement != null)
66+
{
67+
project.TypeMapping.Deserialize(typeMappingElement);
68+
}
69+
6470
var classes = new List<Tuple<XElement, ClassNode>>();
6571

6672
foreach (var element in document.Root

ReClass.NET/DataExchange/ReClass/ReClassNetFile.Write.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public void Save(Stream output, ILogger logger)
3535
new XAttribute(XmlVersionAttribute, FileVersion),
3636
new XAttribute(XmlPlatformAttribute, Constants.Platform),
3737
new XElement(XmlClassesElement, CreateClassElements(project.Classes, logger)),
38-
project.CustomData.Serialize(XmlCustomDataElement)
38+
project.CustomData.Serialize(XmlCustomDataElement),
39+
project.TypeMapping.Serialize(XmlTypeMappingElement)
3940
)
4041
);
4142

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using System.Xml.Linq;
2+
using ReClassNET.Util;
3+
4+
namespace ReClassNET.Project
5+
{
6+
public class CppTypeMapping
7+
{
8+
public string TypeBool { get; set; } = "bool";
9+
10+
public string TypeInt8 { get; set; } = "int8_t";
11+
public string TypeInt16 { get; set; } = "int16_t";
12+
public string TypeInt32 { get; set; } = "int32_t";
13+
public string TypeInt64 { get; set; } = "int64_t";
14+
15+
public string TypeUInt8 { get; set; } = "uint8_t";
16+
public string TypeUInt16 { get; set; } = "uint16_t";
17+
public string TypeUInt32 { get; set; } = "uint32_t";
18+
public string TypeUInt64 { get; set; } = "uint64_t";
19+
20+
public string TypeFloat { get; set; } = "float";
21+
public string TypeDouble { get; set; } = "double";
22+
23+
public string TypeVector2 { get; set; } = "Vector2";
24+
public string TypeVector3 { get; set; } = "Vector3";
25+
public string TypeVector4 { get; set; } = "Vector4";
26+
27+
public string TypeMatrix3x3 { get; set; } = "Matrix3x3";
28+
public string TypeMatrix3x4 { get; set; } = "Matrix3x4";
29+
public string TypeMatrix4x4 { get; set; } = "Matrix4x4";
30+
31+
public string TypeUtf8Text { get; set; } = "char";
32+
public string TypeUtf16Text { get; set; } = "wchar_t"; // Should be char16_t, but this type isn't well supported at the moment.
33+
public string TypeUtf32Text { get; set; } = "char32_t";
34+
35+
public string TypeFunctionPtr { get; set; } = "void*";
36+
37+
internal XElement Serialize(string name)
38+
{
39+
return new XElement(
40+
name,
41+
XElementSerializer.ToXml(nameof(TypeBool), TypeBool),
42+
XElementSerializer.ToXml(nameof(TypeInt8), TypeInt8),
43+
XElementSerializer.ToXml(nameof(TypeInt16), TypeInt16),
44+
XElementSerializer.ToXml(nameof(TypeInt32), TypeInt32),
45+
XElementSerializer.ToXml(nameof(TypeInt64), TypeInt64),
46+
XElementSerializer.ToXml(nameof(TypeUInt8), TypeUInt8),
47+
XElementSerializer.ToXml(nameof(TypeUInt16), TypeUInt16),
48+
XElementSerializer.ToXml(nameof(TypeUInt32), TypeUInt32),
49+
XElementSerializer.ToXml(nameof(TypeUInt64), TypeUInt64),
50+
XElementSerializer.ToXml(nameof(TypeFloat), TypeFloat),
51+
XElementSerializer.ToXml(nameof(TypeDouble), TypeDouble),
52+
XElementSerializer.ToXml(nameof(TypeVector2), TypeVector2),
53+
XElementSerializer.ToXml(nameof(TypeVector3), TypeVector3),
54+
XElementSerializer.ToXml(nameof(TypeVector4), TypeVector4),
55+
XElementSerializer.ToXml(nameof(TypeMatrix3x3), TypeMatrix3x3),
56+
XElementSerializer.ToXml(nameof(TypeMatrix3x4), TypeMatrix3x4),
57+
XElementSerializer.ToXml(nameof(TypeMatrix4x4), TypeMatrix4x4),
58+
XElementSerializer.ToXml(nameof(TypeUtf8Text), TypeUtf8Text),
59+
XElementSerializer.ToXml(nameof(TypeUtf16Text), TypeUtf16Text),
60+
XElementSerializer.ToXml(nameof(TypeUtf32Text), TypeUtf32Text),
61+
XElementSerializer.ToXml(nameof(TypeFunctionPtr), TypeFunctionPtr)
62+
);
63+
}
64+
65+
internal void Deserialize(XElement element)
66+
{
67+
XElementSerializer.TryRead(element, nameof(TypeBool), e => TypeBool = XElementSerializer.ToString(e));
68+
XElementSerializer.TryRead(element, nameof(TypeInt8), e => TypeInt8 = XElementSerializer.ToString(e));
69+
XElementSerializer.TryRead(element, nameof(TypeInt16), e => TypeInt16 = XElementSerializer.ToString(e));
70+
XElementSerializer.TryRead(element, nameof(TypeInt32), e => TypeInt32 = XElementSerializer.ToString(e));
71+
XElementSerializer.TryRead(element, nameof(TypeInt64), e => TypeInt64 = XElementSerializer.ToString(e));
72+
XElementSerializer.TryRead(element, nameof(TypeUInt8), e => TypeUInt8 = XElementSerializer.ToString(e));
73+
XElementSerializer.TryRead(element, nameof(TypeUInt16), e => TypeUInt16 = XElementSerializer.ToString(e));
74+
XElementSerializer.TryRead(element, nameof(TypeUInt32), e => TypeUInt32 = XElementSerializer.ToString(e));
75+
XElementSerializer.TryRead(element, nameof(TypeUInt64), e => TypeUInt64 = XElementSerializer.ToString(e));
76+
XElementSerializer.TryRead(element, nameof(TypeFloat), e => TypeFloat = XElementSerializer.ToString(e));
77+
XElementSerializer.TryRead(element, nameof(TypeDouble), e => TypeDouble = XElementSerializer.ToString(e));
78+
XElementSerializer.TryRead(element, nameof(TypeVector2), e => TypeVector2 = XElementSerializer.ToString(e));
79+
XElementSerializer.TryRead(element, nameof(TypeVector3), e => TypeVector3 = XElementSerializer.ToString(e));
80+
XElementSerializer.TryRead(element, nameof(TypeVector4), e => TypeVector4 = XElementSerializer.ToString(e));
81+
XElementSerializer.TryRead(element, nameof(TypeMatrix3x3), e => TypeMatrix3x3 = XElementSerializer.ToString(e));
82+
XElementSerializer.TryRead(element, nameof(TypeMatrix3x4), e => TypeMatrix3x4 = XElementSerializer.ToString(e));
83+
XElementSerializer.TryRead(element, nameof(TypeMatrix4x4), e => TypeMatrix4x4 = XElementSerializer.ToString(e));
84+
XElementSerializer.TryRead(element, nameof(TypeUtf8Text), e => TypeUtf8Text = XElementSerializer.ToString(e));
85+
XElementSerializer.TryRead(element, nameof(TypeUtf16Text), e => TypeUtf16Text = XElementSerializer.ToString(e));
86+
XElementSerializer.TryRead(element, nameof(TypeUtf32Text), e => TypeUtf32Text = XElementSerializer.ToString(e));
87+
XElementSerializer.TryRead(element, nameof(TypeFunctionPtr), e => TypeFunctionPtr = XElementSerializer.ToString(e));
88+
}
89+
}
90+
}

ReClass.NET/Project/ReClassNetProject.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public class ReClassNetProject : IDisposable
2525
/// </summary>
2626
public CustomDataMap CustomData { get; } = new CustomDataMap();
2727

28+
/// <summary>
29+
/// List of data types to use while generating C++ code for nodes.
30+
/// </summary>
31+
public CppTypeMapping TypeMapping { get; } = new CppTypeMapping();
32+
2833
public void Dispose()
2934
{
3035
Clear();

ReClass.NET/ReClass.NET.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@
257257
<Compile Include="Nodes\FunctionNode.cs" />
258258
<Compile Include="Nodes\NodeUuid.cs" />
259259
<Compile Include="Nodes\PointerNode.cs" />
260+
<Compile Include="Project\CppTypeMapping.cs" />
260261
<Compile Include="Project\ReClassNetProject.cs" />
261262
<Compile Include="UI\BannerBox.cs">
262263
<SubType>Component</SubType>

0 commit comments

Comments
 (0)