Files
sbox-public/engine/Sandbox.Generator/Units/ComponentSubscriberInterfaces.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

39 lines
1.1 KiB
C#

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System.Collections.Generic;
namespace Sandbox.Generator;
internal static class ComponentSubscriberInterfaces
{
internal static Dictionary<string, string> Map = new()
{
{ "OnUpdate", "Sandbox.Internal.IUpdateSubscriber" },
{ "OnFixedUpdate", "Sandbox.Internal.IFixedUpdateSubscriber" },
{ "OnPreRender", "Sandbox.Internal.IPreRenderSubscriber" }
};
/// <summary>
/// Find anything implementing callback methods, and add an interface to them.
/// </summary>
internal static void VisitMethod( MethodDeclarationSyntax node, IMethodSymbol symbol, Worker master )
{
if ( !symbol.ContainingType.DerivesFrom( "global::Sandbox.Component" ) )
return;
if ( symbol.IsVirtual )
return;
if ( !Map.ContainsKey( symbol.Name ) )
return;
// Must be implemented
if ( (node.Body == null && node.ExpressionBody == null) || symbol.IsAbstract )
return;
//Console.WriteLine( $"AddBaseTypeToCurrentClass: {symbol.Name}" );
master.AddBaseTypeToCurrentClass( Map[symbol.Name] );
}
}