Changed the project structure to reflect a shift from `Ghost.App` to `Ghost.Editor`, updating namespaces and class names throughout. Changed the application class in `App.xaml` and `App.xaml.cs` from `GhostApplication` to `EditorApplication`. Changed several service interfaces to reside under `Ghost.Editor.Services.Contracts`, including `IInspectorService`, `INotificationService`, and `IProgressService`. Added `InspectorView` and `InspectorViewModel` classes to manage inspector functionality. Added `NavigationTabView` and `NavigationTabPage` classes to facilitate navigation within the editor. Enhanced `WorldNode` and `EntityNode` classes to support scene graph functionality, including serialization and entity management. Updated the project file `Ghost.Editor.csproj` to reflect the new structure and removed old references. Modified the solution file `GhostEngine.sln` to remove references to `Ghost.App` and include `Ghost.Editor`. Updated unit tests to align with the new namespaces and project structure.
60 lines
1.8 KiB
C#
60 lines
1.8 KiB
C#
using System.Diagnostics;
|
|
using System.Reflection;
|
|
|
|
namespace Ghost.Editor.Core.AssetHandle;
|
|
|
|
public static class AssetDatabase
|
|
{
|
|
private static readonly Dictionary<string, Action<string>> _assetOpenHandlers = new(StringComparer.OrdinalIgnoreCase);
|
|
|
|
static AssetDatabase()
|
|
{
|
|
Initialize();
|
|
}
|
|
|
|
internal static void Initialize()
|
|
{
|
|
RegisterAssetHandles();
|
|
}
|
|
|
|
private static void RegisterAssetHandles()
|
|
{
|
|
var methods = AppDomain.CurrentDomain.GetAssemblies()
|
|
.SelectMany(a => a.GetTypes())
|
|
.SelectMany(t => t.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
|
|
.Where(m => m.GetCustomAttribute<AssetOpenHandlerAttribute>() != null &&
|
|
m.GetParameters().Length == 1 &&
|
|
m.GetParameters()[0].ParameterType == typeof(string));
|
|
|
|
foreach (var method in methods)
|
|
{
|
|
var attr = method.GetCustomAttribute<AssetOpenHandlerAttribute>()!;
|
|
var del = (Action<string>)Delegate.CreateDelegate(typeof(Action<string>), method);
|
|
foreach (var ext in attr.Extensions)
|
|
{
|
|
if (_assetOpenHandlers.ContainsKey(ext))
|
|
{
|
|
throw new InvalidOperationException($"Duplicate handler for extension '{ext}'");
|
|
}
|
|
|
|
_assetOpenHandlers[ext] = del;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void OpenAsset(string path)
|
|
{
|
|
var extension = Path.GetExtension(path);
|
|
if (_assetOpenHandlers.TryGetValue(extension, out var handler))
|
|
{
|
|
handler(path);
|
|
}
|
|
else
|
|
{
|
|
Process.Start(new ProcessStartInfo(path)
|
|
{
|
|
UseShellExecute = true
|
|
});
|
|
}
|
|
}
|
|
} |