Skip to content

Commit 3ce074c

Browse files
committed
Added Comments.
Implemented CodeGenerator.
1 parent f26d403 commit 3ce074c

File tree

5 files changed

+69
-12
lines changed

5 files changed

+69
-12
lines changed

FrostbitePlugin.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<DesignTime>True</DesignTime>
7272
<DependentUpon>Resources.resx</DependentUpon>
7373
</Compile>
74+
<Compile Include="WeakPtrCodeGenerator.cs" />
7475
<Compile Include="WeakPtrNode.cs" />
7576
<Compile Include="WeakPtrSchemaConverter.cs" />
7677
</ItemGroup>

FrostbitePluginExt.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class FrostbitePluginExt : Plugin
1717
private INodeInfoReader reader;
1818

1919
private WeakPtrSchemaConverter converter;
20+
private WeakPtrCodeGenerator generator;
2021

2122
public override Image Icon => Properties.Resources.logo_frostbite;
2223

@@ -44,14 +45,15 @@ public override bool Initialize(IPluginHost host)
4445

4546
// Register the WeakPtr node
4647
converter = new WeakPtrSchemaConverter();
47-
host.RegisterNodeType(typeof(WeakPtrNode), converter, "Frostbite WeakPtr", Icon);
48+
generator = new WeakPtrCodeGenerator();
49+
host.RegisterNodeType(typeof(WeakPtrNode), "Frostbite WeakPtr", Icon, converter, generator);
4850

4951
return true;
5052
}
5153

5254
public override void Terminate()
5355
{
54-
host.UnregisterNodeType(typeof(WeakPtrNode), converter);
56+
host.UnregisterNodeType(typeof(WeakPtrNode), converter, generator);
5557

5658
host.UnregisterNodeInfoReader(reader);
5759

WeakPtrCodeGenerator.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using ReClassNET.CodeGenerator;
2+
using ReClassNET.Nodes;
3+
4+
namespace FrostbitePlugin
5+
{
6+
class WeakPtrCodeGenerator : ICustomCodeGenerator
7+
{
8+
/// <summary>Checks if the language is C++ and the node is a WeakPtrNode.</summary>
9+
/// <param name="node">The node to check.</param>
10+
/// <param name="language">The language to check.</param>
11+
/// <returns>True if we can generate code, false if not.</returns>
12+
public bool CanGenerateCode(BaseNode node, Language language) => language == Language.Cpp && node is WeakPtrNode;
13+
14+
/// <summary>Gets the member definition of the node.</summary>
15+
/// <param name="node">The member node.</param>
16+
/// <param name="language">The language to generate.</param>
17+
/// <returns>The member definition of the node.</returns>
18+
public MemberDefinition GetMemberDefinition(BaseNode node, Language language)
19+
{
20+
return new MemberDefinition(node, "fb::WeakPtr");
21+
}
22+
}
23+
}

WeakPtrNode.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class WeakPtrNode : BaseReferenceNode
1313
/// <summary>Size of the node in bytes.</summary>
1414
public override int MemorySize => IntPtr.Size;
1515

16+
/// <summary>Called when the node was created. Creates a new class as inner node.</summary>
1617
public override void Intialize()
1718
{
1819
var node = ClassManager.CreateClass();

WeakPtrSchemaConverter.cs

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace FrostbitePlugin
99
{
10+
/// <summary>A schema for the WeakPtrNode.</summary>
1011
class WeakPtrSchemaNode : SchemaCustomNode
1112
{
1213
public SchemaClassNode InnerNode { get; }
@@ -21,15 +22,30 @@ public WeakPtrSchemaNode(SchemaClassNode inner)
2122

2223
class WeakPtrSchemaConverter : ICustomSchemaConverter
2324
{
25+
/// <summary>Name of the type used in the XML data.</summary>
2426
private const string XmlType = "FrostBite::WeakPtr";
2527

26-
public bool CanReadNode(BaseNode node) => node is WeakPtrNode;
28+
/// <summary>Checks if the node can be handled.</summary>
29+
/// <param name="node">The node to check.</param>
30+
/// <returns>True if we can handle the node, false if not.</returns>
31+
public bool CanHandleNode(BaseNode node) => node is WeakPtrNode;
2732

28-
public bool CanReadNode(XElement element) => element.Attribute(ReClassNetFile.XmlTypeAttribute)?.Value == XmlType;
33+
/// <summary>Checks if the element can be handled.</summary>
34+
/// <param name="element">The element to check.</param>
35+
/// <returns>True if we can read node, false if not.</returns>
36+
public bool CanHandleElement(XElement element) => element.Attribute(ReClassNetFile.XmlTypeAttribute)?.Value == XmlType;
2937

30-
public bool CanWriteNode(SchemaCustomNode node) => node is WeakPtrSchemaNode;
38+
/// <summary>Checks if the schema can be handled.</summary>
39+
/// <param name="schema">The schema to check.</param>
40+
/// <returns>True if we can handle schema, false if not.</returns>
41+
public bool CanHandleSchema(SchemaCustomNode schema) => schema is WeakPtrSchemaNode;
3142

32-
public SchemaCustomNode ReadFromNode(BaseNode node, IReadOnlyDictionary<ClassNode, SchemaClassNode> classes, ILogger logger)
43+
/// <summary>Creates the schema which represents the node.</summary>
44+
/// <param name="node">The node to convert.</param>
45+
/// <param name="classes">The mapping from classes to their schema.</param>
46+
/// <param name="logger">The logger.</param>
47+
/// <returns>The schema which represents the node.</returns>
48+
public SchemaCustomNode CreateSchemaFromNode(BaseNode node, IReadOnlyDictionary<ClassNode, SchemaClassNode> classes, ILogger logger)
3349
{
3450
return new WeakPtrSchemaNode(classes[(node as WeakPtrNode).InnerNode as ClassNode])
3551
{
@@ -38,7 +54,12 @@ public SchemaCustomNode ReadFromNode(BaseNode node, IReadOnlyDictionary<ClassNod
3854
};
3955
}
4056

41-
public SchemaCustomNode ReadFromXml(XElement element, IReadOnlyDictionary<string, SchemaClassNode> classes, ILogger logger)
57+
/// <summary>Creates the schema which represents the element.</summary>
58+
/// <param name="element">The element to convert.</param>
59+
/// <param name="classes">The mapping from class names to their schema.</param>
60+
/// <param name="logger">The logger.</param>
61+
/// <returns>The schema which represents the element.</returns>
62+
public SchemaCustomNode CreateSchemaFromElement(XElement element, IReadOnlyDictionary<string, SchemaClassNode> classes, ILogger logger)
4263
{
4364
var reference = element.Attribute(ReClassNetFile.XmlReferenceAttribute)?.Value;
4465
if (reference == null || !classes.ContainsKey(reference))
@@ -56,7 +77,12 @@ public SchemaCustomNode ReadFromXml(XElement element, IReadOnlyDictionary<string
5677
};
5778
}
5879

59-
public BaseNode WriteToNode(SchemaCustomNode schema, IReadOnlyDictionary<SchemaClassNode, ClassNode> classes, ILogger logger)
80+
/// <summary>Creates the node which is represented by the schema.</summary>
81+
/// <param name="schema">The schema to convert.</param>
82+
/// <param name="classes">The mapping from class schemas to their nodes.</param>
83+
/// <param name="logger">The logger.</param>
84+
/// <returns>The node which is represented by the schema.</returns>
85+
public BaseNode CreateNodeFromSchema(SchemaCustomNode schema, IReadOnlyDictionary<SchemaClassNode, ClassNode> classes, ILogger logger)
6086
{
6187
return new WeakPtrNode()
6288
{
@@ -66,14 +92,18 @@ public BaseNode WriteToNode(SchemaCustomNode schema, IReadOnlyDictionary<SchemaC
6692
};
6793
}
6894

69-
public XElement WriteToXml(SchemaCustomNode node, ILogger logger)
95+
/// <summary>Creates the element which represents the schema.</summary>
96+
/// <param name="schema">The schema to convert.</param>
97+
/// <param name="logger">The logger.</param>
98+
/// <returns>The element which represents the schema.</returns>
99+
public XElement CreateElementFromSchema(SchemaCustomNode schema, ILogger logger)
70100
{
71101
return new XElement(
72102
ReClassNetFile.XmlNodeElement,
73-
new XAttribute(ReClassNetFile.XmlNameAttribute, node.Name ?? string.Empty),
74-
new XAttribute(ReClassNetFile.XmlCommentAttribute, node.Comment ?? string.Empty),
103+
new XAttribute(ReClassNetFile.XmlNameAttribute, schema.Name ?? string.Empty),
104+
new XAttribute(ReClassNetFile.XmlCommentAttribute, schema.Comment ?? string.Empty),
75105
new XAttribute(ReClassNetFile.XmlTypeAttribute, XmlType),
76-
new XAttribute(ReClassNetFile.XmlReferenceAttribute, (node as WeakPtrSchemaNode).InnerNode.Name ?? string.Empty)
106+
new XAttribute(ReClassNetFile.XmlReferenceAttribute, (schema as WeakPtrSchemaNode).InnerNode.Name ?? string.Empty)
77107
);
78108
}
79109
}

0 commit comments

Comments
 (0)