Skip to content

Commit

Permalink
[Editor] Rework plugins initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Kryptos-FR committed Feb 29, 2024
1 parent 076f32f commit c98c72e
Show file tree
Hide file tree
Showing 15 changed files with 224 additions and 202 deletions.
3 changes: 2 additions & 1 deletion sources/editor/Stride.Assets.Presentation/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System.Runtime.CompilerServices;
using Stride.Core.Assets.Quantum;
using Stride.Core;
using Stride.Core.Reflection;
using Stride.Core.Translation;
using Stride.Core.Translation.Providers;
Expand All @@ -11,6 +10,7 @@
using Stride.Assets.SpriteFont;
using Stride.Rendering;
using Stride.Rendering.Materials;
using Stride.Core.Assets.Editor.Services;

namespace Stride.Assets.Presentation
{
Expand All @@ -26,6 +26,7 @@ public static void Initialize()
AssemblyRegistry.Register(typeof(Module).Assembly, AssemblyCommonCategories.Assets);
// We need access to the AssetQuantumRegistry from the SessionTemplateGenerator so for now we register graph types in the module initializer.
AssetQuantumRegistry.RegisterAssembly(typeof(Module).Assembly);
AssetsPlugin.RegisterPlugin(typeof(StrideDefaultAssetsPlugin));
// Register default template
StrideTemplates.Register();
// Initialize translation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public sealed class StrideDefaultAssetsPlugin : StrideAssetsPlugin
/// </summary>
private class ComponentTypeComparer : EqualityComparer<Type>
{
public new static readonly ComponentTypeComparer Default = new ComponentTypeComparer();
public static new readonly ComponentTypeComparer Default = new ComponentTypeComparer();

/// <summary>
/// Compares two component types and returns <c>true</c> if the types match, i.e.:
Expand Down
97 changes: 0 additions & 97 deletions sources/editor/Stride.Core.Assets.Editor/AssetsEditorPlugin.cs

This file was deleted.

72 changes: 72 additions & 0 deletions sources/editor/Stride.Core.Assets.Editor/CoreAssetsEditorPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Windows;
using Stride.Core.Assets.Editor.Services;
using Stride.Core.Assets.Editor.ViewModel;
using Stride.Core.Assets.Editor.ViewModel.CopyPasteProcessors;
using Stride.Core.Diagnostics;
using Stride.Core.Presentation.View;

#nullable enable

namespace Stride.Core.Assets.Editor;

internal sealed class CoreAssetsEditorPlugin : AssetsEditorPlugin
{
private ResourceDictionary? imageDictionary;

/// <inheritdoc />
public override void InitializePlugin(ILogger logger)
{
imageDictionary ??= (ResourceDictionary)Application.LoadComponent(new Uri("/Stride.Core.Assets.Editor;component/View/ImageDictionary.xaml", UriKind.RelativeOrAbsolute));
}

/// <inheritdoc />
public override void InitializeSession(SessionViewModel session)
{
}

/// <inheritdoc />
public override void RegisterPrimitiveTypes(ICollection<Type> primitiveTypes)
{
}

/// <inheritdoc />
public override void RegisterEnumImages(IDictionary<object, object> enumImages)
{
if (imageDictionary is null) return;

foreach (var entry in imageDictionary.Keys)
{
if (entry is Enum && imageDictionary[entry] is { } image)
{
enumImages.Add(entry, image);
}
}
}

/// <inheritdoc />
public override void RegisterCopyProcessors(ICollection<ICopyProcessor> copyProcessors, SessionViewModel session)
{
}

/// <inheritdoc />
public override void RegisterPasteProcessors(ICollection<IPasteProcessor> pasteProcessors, SessionViewModel session)
{
pasteProcessors.Add(new AssetPropertyPasteProcessor());
pasteProcessors.Add(new AssetItemPasteProcessor(session));
}

/// <inheritdoc />
public override void RegisterPostPasteProcessors(ICollection<IAssetPostPasteProcessor> postePasteProcessors, SessionViewModel session)
{
}

/// <inheritdoc />
public override void RegisterTemplateProviders(ICollection<ITemplateProvider> templateProviders)
{
}
}
2 changes: 2 additions & 0 deletions sources/editor/Stride.Core.Assets.Editor/Module.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System.Reflection;
using Stride.Core.Assets.Editor.Services;
using Stride.Core.Reflection;
using Stride.Core.Translation;
using Stride.Core.Translation.Providers;
Expand All @@ -13,6 +14,7 @@ internal class Module
public static void Initialize()
{
AssemblyRegistry.Register(typeof(Module).GetTypeInfo().Assembly, AssemblyCommonCategories.Assets);
AssetsPlugin.RegisterPlugin(typeof(CoreAssetsEditorPlugin));
// Initialize translation
TranslationManager.Instance.RegisterProvider(new GettextTranslationProvider());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Reflection;
using Stride.Core.Assets.Editor.Annotations;
using Stride.Core.Assets.Editor.Components.Properties;
using Stride.Core.Assets.Editor.ViewModel;
using Stride.Core.Presentation.View;

#nullable enable

namespace Stride.Core.Assets.Editor.Services;

public abstract class AssetsEditorPlugin : AssetsPlugin
{
protected static readonly Dictionary<Type, object> TypeImages = [];

// TODO: give access to this differently
public readonly List<PackageSettingsEntry> ProfileSettings = [];

public static IReadOnlyDictionary<Type, object> TypeImagesDictionary => TypeImages;

public void RegisterAssetEditorViewModelTypes(IDictionary<Type, Type> assetEditorViewModelTypes)
{
var pluginAssembly = GetType().Assembly;
foreach (var type in pluginAssembly.GetTypes())
{
if (typeof(IAssetEditorViewModel).IsAssignableFrom(type) &&
type.GetCustomAttribute<AssetEditorViewModelAttribute>() is { } attribute)
{
assetEditorViewModelTypes.Add(attribute.ViewModelType, type);
}
}
}

public void RegisterAssetEditorViewTypes(IDictionary<Type, Type> assetEditorViewTypes)
{
var pluginAssembly = GetType().Assembly;
foreach (var type in pluginAssembly.GetTypes())
{
if (typeof(IEditorView).IsAssignableFrom(type) &&
type.GetCustomAttribute<AssetEditorViewAttribute>() is { } attribute)
{
assetEditorViewTypes.Add(attribute.EditorViewModelType, type);
}
}
}

public abstract void RegisterEnumImages(IDictionary<object, object> enumImages);

public abstract void RegisterCopyProcessors(ICollection<ICopyProcessor> copyProcessors, SessionViewModel session);

public abstract void RegisterPasteProcessors(ICollection<IPasteProcessor> pasteProcessors, SessionViewModel session);

public abstract void RegisterPostPasteProcessors(ICollection<IAssetPostPasteProcessor> postePasteProcessors, SessionViewModel session);

public abstract void RegisterTemplateProviders(ICollection<ITemplateProvider> templateProviders);
}
Loading

0 comments on commit c98c72e

Please sign in to comment.