Skip to content

Commit

Permalink
Fix field generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Frozenreflex committed Apr 18, 2024
1 parent 6bb25a2 commit 7a6deeb
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions ProjectObsidian.SourceGenerators/BindingGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,20 @@ public override N Instantiate<N>()
private string _category;
private string _nodeNameOverride = "";

private void TypedFieldDetection(string type, string name, string targetTypeName, string declarationFormat, OrderedCount counter)
private bool TypedFieldDetection(string type, string name, string targetTypeName, string declarationFormat, OrderedCount counter)
{
if (!type.Contains(targetTypeName)) return;
if (!type.Contains(targetTypeName)) return false;
var t = type.TrimEnds((targetTypeName + "<").Length, 1);
counter.Add(name);
_declarations.Add(string.Format(" new public readonly " + declarationFormat + " {0};\n", name, t));
return true;
}
private void UntypedFieldDetection(string type, string name, string targetTypeName, string declarationFormat, OrderedCount counter)
private bool UntypedFieldDetection(string type, string name, string targetTypeName, string declarationFormat, OrderedCount counter)
{
if (!type.Contains(targetTypeName)) return;
if (!type.Contains(targetTypeName)) return false;
counter.Add(name);
_declarations.Add(string.Format(declarationFormat, name));
_declarations.Add(string.Format(" new public readonly " + declarationFormat + " {0};\n", name));
return true;
}
public override void VisitFieldDeclaration(FieldDeclarationSyntax node)
{
Expand All @@ -211,9 +213,11 @@ public override void VisitFieldDeclaration(FieldDeclarationSyntax node)
TypedFieldDetection(type, name, "ValueOutput", "NodeValueOutput<{1}>", _outputCount);

//impulses
UntypedFieldDetection(type, name, "Call", "SyncRef<ISyncNodeOperation>", _impulseCount);
if (!UntypedFieldDetection(type, name, "Call", "SyncRef<ISyncNodeOperation>", _impulseCount))
{
UntypedFieldDetection(type, name, "AsyncCall", "SyncRef<INodeOperation>", _impulseCount);
}
UntypedFieldDetection(type, name, "Continuation", "SyncRef<INodeOperation>", _impulseCount);
UntypedFieldDetection(type, name, "AsyncCall", "SyncRef<INodeOperation>", _impulseCount);
UntypedFieldDetection(type, name, "AsyncResumption", "SyncRef<INodeOperation>", _impulseCount);

//operations
Expand Down

0 comments on commit 7a6deeb

Please sign in to comment.