Files
MovementTests/addons/forge/editor/cues/CueHandlerInspectorPlugin.cs
2026-02-13 11:11:03 +01:00

59 lines
1.3 KiB
C#

// Copyright © Gamesmiths Guild.
#if TOOLS
using System;
using Gamesmiths.Forge.Godot.Nodes;
using Godot;
namespace Gamesmiths.Forge.Godot.Editor.Cues;
[Tool]
public partial class CueHandlerInspectorPlugin : EditorInspectorPlugin
{
public override bool _CanHandle(GodotObject @object)
{
// Find out if its an implementation of CueHandler without having to add [Tool] attribute to them.
try
{
if (@object.GetScript().As<CSharpScript>() is not { }) return false;
}
catch (Exception e)
{
return false;
}
var script = @object.GetScript().As<CSharpScript>();
StringName className = script.GetGlobalName();
Type baseType = typeof(ForgeCueHandler);
System.Reflection.Assembly assembly = baseType.Assembly;
Type? implementationType =
Array.Find(assembly.GetTypes(), x =>
x.Name == className &&
baseType.IsAssignableFrom(x));
return implementationType is not null;
}
public override bool _ParseProperty(
GodotObject @object,
Variant.Type type,
string name,
PropertyHint hintType,
string hintString,
PropertyUsageFlags usageFlags,
bool wide)
{
if (name == "CueTag")
{
var cueKeyEditorProperty = new CueKeyEditorProperty();
AddPropertyEditor(name, cueKeyEditorProperty);
return true;
}
return base._ParseProperty(@object, type, name, hintType, hintString, usageFlags, wide);
}
}
#endif