forked from stride3d/stride
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Editor] Rework plugins initialization
- Loading branch information
1 parent
076f32f
commit c98c72e
Showing
15 changed files
with
224 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 0 additions & 97 deletions
97
sources/editor/Stride.Core.Assets.Editor/AssetsEditorPlugin.cs
This file was deleted.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
sources/editor/Stride.Core.Assets.Editor/CoreAssetsEditorPlugin.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
sources/editor/Stride.Core.Assets.Editor/Services/AssetsEditorPlugin.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.