mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 21:38:38 +00:00
Merge branch 'development'
This commit is contained in:
commit
577daff445
@ -42,9 +42,9 @@
|
||||
<PackageReference Include="LiteDB" Version="5.0.12" />
|
||||
<PackageReference Include="McMaster.NETCore.Plugins" Version="1.4.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="RGB.NET.Core" Version="1.0.0" />
|
||||
<PackageReference Include="RGB.NET.Layout" Version="1.0.0" />
|
||||
<PackageReference Include="RGB.NET.Presets" Version="1.0.0" />
|
||||
<PackageReference Include="RGB.NET.Core" Version="2.0.0-prerelease.12" />
|
||||
<PackageReference Include="RGB.NET.Layout" Version="2.0.0-prerelease.12" />
|
||||
<PackageReference Include="RGB.NET.Presets" Version="2.0.0-prerelease.12" />
|
||||
<PackageReference Include="Serilog" Version="2.11.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
|
||||
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0" />
|
||||
|
||||
66
src/Artemis.Core/DryIoc/ContainerExtensions.cs
Normal file
66
src/Artemis.Core/DryIoc/ContainerExtensions.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Artemis.Core.DryIoc.Factories;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Storage;
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using Artemis.Storage.Repositories.Interfaces;
|
||||
using DryIoc;
|
||||
|
||||
namespace Artemis.Core.DryIoc;
|
||||
|
||||
/// <summary>
|
||||
/// Provides an extension method to register services onto a DryIoc <see cref="IContainer"/>.
|
||||
/// </summary>
|
||||
public static class ContainerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers core services into the container.
|
||||
/// </summary>
|
||||
/// <param name="container">The builder building the current container</param>
|
||||
public static void RegisterCore(this IContainer container)
|
||||
{
|
||||
Assembly[] coreAssembly = {typeof(IArtemisService).Assembly};
|
||||
Assembly[] storageAssembly = {typeof(IRepository).Assembly};
|
||||
|
||||
// Bind all services as singletons
|
||||
container.RegisterMany(coreAssembly, type => type.IsAssignableTo<IArtemisService>(), Reuse.Singleton);
|
||||
container.RegisterMany(coreAssembly, type => type.IsAssignableTo<IProtectedArtemisService>(), Reuse.Singleton, setup: Setup.With(condition: HasAccessToProtectedService));
|
||||
|
||||
// Bind storage
|
||||
container.RegisterDelegate(() => StorageManager.CreateRepository(Constants.DataFolder), Reuse.Singleton);
|
||||
container.Register<StorageMigrationService>(Reuse.Singleton);
|
||||
container.RegisterMany(storageAssembly, type => type.IsAssignableTo<IRepository>(), Reuse.Singleton);
|
||||
|
||||
// Bind migrations
|
||||
container.RegisterMany(storageAssembly, type => type.IsAssignableTo<IStorageMigration>(), Reuse.Singleton, nonPublicServiceTypes: true);
|
||||
|
||||
container.Register<IPluginSettingsFactory, PluginSettingsFactory>(Reuse.Singleton);
|
||||
container.Register(made: Made.Of(_ => ServiceInfo.Of<IPluginSettingsFactory>(), f => f.CreatePluginSettings(Arg.Index<Type>(0)), r => r.Parent.ImplementationType));
|
||||
container.Register<ILoggerFactory, LoggerFactory>(Reuse.Singleton);
|
||||
container.Register(made: Made.Of(_ => ServiceInfo.Of<ILoggerFactory>(), f => f.CreateLogger(Arg.Index<Type>(0)), r => r.Parent.ImplementationType));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers plugin services into the container, this is typically a child container.
|
||||
/// </summary>
|
||||
/// <param name="container">The builder building the current container</param>
|
||||
/// <param name="plugin">The plugin to register</param>
|
||||
public static void RegisterPlugin(this IContainer container, Plugin plugin)
|
||||
{
|
||||
container.RegisterInstance(plugin, setup: Setup.With(preventDisposal: true));
|
||||
|
||||
// Bind plugin service interfaces, DryIoc expects at least one match when calling RegisterMany so ensure there is something to register first
|
||||
if (plugin.Assembly != null && plugin.Assembly.GetTypes().Any(t => t.IsAssignableTo<IPluginService>()))
|
||||
container.RegisterMany(new[] {plugin.Assembly}, type => type.IsAssignableTo<IPluginService>(), Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep);
|
||||
}
|
||||
|
||||
private static bool HasAccessToProtectedService(Request request)
|
||||
{
|
||||
// Plugin assembly locations may not be set for some reason, that case it's also not allowed >:(
|
||||
return request.Parent.ImplementationType != null &&
|
||||
!string.IsNullOrWhiteSpace(request.Parent.ImplementationType.Assembly.Location) &&
|
||||
!request.Parent.ImplementationType.Assembly.Location.StartsWith(Constants.PluginsFolder);
|
||||
}
|
||||
}
|
||||
@ -1,48 +0,0 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Artemis.Core.DryIoc.Factories;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Storage;
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using Artemis.Storage.Repositories.Interfaces;
|
||||
using DryIoc;
|
||||
|
||||
namespace Artemis.Core.DryIoc;
|
||||
|
||||
/// <summary>
|
||||
/// The main <see cref="IModule" /> of the Artemis Core that binds all services
|
||||
/// </summary>
|
||||
public class CoreModule : IModule
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public void Load(IRegistrator builder)
|
||||
{
|
||||
Assembly coreAssembly = typeof(IArtemisService).Assembly;
|
||||
Assembly storageAssembly = typeof(IRepository).Assembly;
|
||||
|
||||
// Bind all services as singletons
|
||||
builder.RegisterMany(new[] {coreAssembly}, type => type.IsAssignableTo<IArtemisService>(), Reuse.Singleton);
|
||||
builder.RegisterMany(new[] {coreAssembly}, type => type.IsAssignableTo<IProtectedArtemisService>(), Reuse.Singleton, setup: Setup.With(condition: HasAccessToProtectedService));
|
||||
|
||||
// Bind storage
|
||||
builder.RegisterDelegate(() => StorageManager.CreateRepository(Constants.DataFolder), Reuse.Singleton);
|
||||
builder.Register<StorageMigrationService>(Reuse.Singleton);
|
||||
builder.RegisterMany(new[] {storageAssembly}, type => type.IsAssignableTo<IRepository>(), Reuse.Singleton);
|
||||
|
||||
// Bind migrations
|
||||
builder.RegisterMany(new[] { storageAssembly }, type => type.IsAssignableTo<IStorageMigration>(), Reuse.Singleton, nonPublicServiceTypes: true);
|
||||
|
||||
builder.Register<IPluginSettingsFactory, PluginSettingsFactory>(Reuse.Singleton);
|
||||
builder.Register(made: Made.Of(_ => ServiceInfo.Of<IPluginSettingsFactory>(), factory => factory.CreatePluginSettings(Arg.Index<Type>(0)), r => r.Parent.ImplementationType));
|
||||
builder.Register<ILoggerFactory, LoggerFactory>(Reuse.Singleton);
|
||||
builder.Register(made: Made.Of(_ => ServiceInfo.Of<ILoggerFactory>(), f => f.CreateLogger(Arg.Index<Type>(0)), r => r.Parent.ImplementationType));
|
||||
}
|
||||
|
||||
private bool HasAccessToProtectedService(Request request)
|
||||
{
|
||||
// Plugin assembly locations may not be set for some reason, that case it's also not allowed >:(
|
||||
return request.Parent.ImplementationType != null &&
|
||||
!string.IsNullOrWhiteSpace(request.Parent.ImplementationType.Assembly.Location) &&
|
||||
!request.Parent.ImplementationType.Assembly.Location.StartsWith(Constants.PluginsFolder);
|
||||
}
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
using DryIoc;
|
||||
|
||||
namespace Artemis.Core.DryIoc;
|
||||
|
||||
/**
|
||||
* Represents a service module.
|
||||
*/
|
||||
public interface IModule
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers the services provided by the module.
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder to register the services with.</param>
|
||||
void Load(IRegistrator builder);
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Services;
|
||||
using DryIoc;
|
||||
|
||||
namespace Artemis.Core.DryIoc;
|
||||
|
||||
internal class PluginModule : IModule
|
||||
{
|
||||
public PluginModule(Plugin plugin)
|
||||
{
|
||||
Plugin = plugin ?? throw new ArgumentNullException(nameof(plugin));
|
||||
}
|
||||
|
||||
public Plugin Plugin { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Load(IRegistrator builder)
|
||||
{
|
||||
builder.RegisterInstance(Plugin, setup: Setup.With(preventDisposal: true));
|
||||
|
||||
// Bind plugin service interfaces, DryIoc expects at least one match when calling RegisterMany so ensure there is something to register first
|
||||
if (Plugin.Assembly != null && Plugin.Assembly.GetTypes().Any(t => t.IsAssignableTo<IPluginService>()))
|
||||
builder.RegisterMany(new[] {Plugin.Assembly}, type => type.IsAssignableTo<IPluginService>(), Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep);
|
||||
}
|
||||
}
|
||||
@ -435,7 +435,7 @@ internal class PluginManagementService : IPluginManagementService
|
||||
plugin.Container = _container.CreateChild(newRules: _container.Rules.WithConcreteTypeDynamicRegistrations());
|
||||
try
|
||||
{
|
||||
new PluginModule(plugin).Load(plugin.Container);
|
||||
plugin.Container.RegisterPlugin(plugin);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Linux.DryIoc;
|
||||
using Artemis.UI.Linux.Providers.Input;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
@ -17,7 +18,7 @@ public class App : Application
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
_container = ArtemisBootstrapper.Bootstrap(this);
|
||||
_container = ArtemisBootstrapper.Bootstrap(this, c => c.RegisterProviders());
|
||||
Program.CreateLogger(_container);
|
||||
RxApp.MainThreadScheduler = AvaloniaScheduler.Instance;
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
|
||||
20
src/Artemis.UI.Linux/DryIoc/ContainerExtensions.cs
Normal file
20
src/Artemis.UI.Linux/DryIoc/ContainerExtensions.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Linux.Providers.Input;
|
||||
using DryIoc;
|
||||
|
||||
namespace Artemis.UI.Linux.DryIoc;
|
||||
|
||||
/// <summary>
|
||||
/// Provides an extension method to register services onto a DryIoc <see cref="IContainer"/>.
|
||||
/// </summary>
|
||||
public static class UIContainerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers providers into the container.
|
||||
/// </summary>
|
||||
/// <param name="container">The builder building the current container</param>
|
||||
public static void RegisterProviders(this IContainer container)
|
||||
{
|
||||
container.Register<InputProvider, LinuxInputProvider>(serviceKey: LinuxInputProvider.Id);
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
using Artemis.Core.DryIoc;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Linux.Providers.Input;
|
||||
using DryIoc;
|
||||
|
||||
namespace Artemis.UI.Linux.DryIoc;
|
||||
|
||||
public class LinuxModule : IModule
|
||||
{
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Load(IRegistrator builder)
|
||||
{
|
||||
builder.Register<InputProvider, LinuxInputProvider>(serviceKey: LinuxInputProvider.Id);
|
||||
}
|
||||
|
||||
}
|
||||
@ -20,7 +20,7 @@
|
||||
<PackageReference Include="Material.Icons.Avalonia" Version="1.1.10" />
|
||||
<PackageReference Include="ReactiveUI" Version="17.1.50" />
|
||||
<PackageReference Include="ReactiveUI.Validation" Version="2.2.1" />
|
||||
<PackageReference Include="RGB.NET.Core" Version="1.0.0" />
|
||||
<PackageReference Include="RGB.NET.Core" Version="2.0.0-prerelease.12" />
|
||||
<PackageReference Include="SkiaSharp" Version="2.88.1-preview.108" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
21
src/Artemis.UI.Shared/DryIoc/ContainerExtensions.cs
Normal file
21
src/Artemis.UI.Shared/DryIoc/ContainerExtensions.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System.Reflection;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using DryIoc;
|
||||
|
||||
namespace Artemis.UI.Shared.DryIoc;
|
||||
|
||||
/// <summary>
|
||||
/// Provides an extension method to register services onto a DryIoc <see cref="IContainer"/>.
|
||||
/// </summary>
|
||||
public static class ContainerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers shared UI services into the container.
|
||||
/// </summary>
|
||||
/// <param name="container">The builder building the current container</param>
|
||||
public static void RegisterSharedUI(this IContainer container)
|
||||
{
|
||||
Assembly artemisShared = typeof(IArtemisSharedUIService).GetAssembly();
|
||||
container.RegisterMany(new[] { artemisShared }, type => type.IsAssignableTo<IArtemisSharedUIService>(), Reuse.Singleton);
|
||||
}
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
using System.Reflection;
|
||||
using Artemis.Core.DryIoc;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using DryIoc;
|
||||
|
||||
namespace Artemis.UI.Shared.DryIoc;
|
||||
|
||||
/// <summary>
|
||||
/// The main <see cref="IModule" /> of the Artemis Shared UI toolkit that binds all services
|
||||
/// </summary>
|
||||
public class SharedUIModule : IModule
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public void Load(IRegistrator builder)
|
||||
{
|
||||
Assembly artemisShared = typeof(IArtemisSharedUIService).GetAssembly();
|
||||
builder.RegisterMany(new[] { artemisShared }, type => type.IsAssignableTo<IArtemisSharedUIService>(), Reuse.Singleton);
|
||||
}
|
||||
}
|
||||
@ -56,7 +56,7 @@ public class DuplicateNode : INodeEditorCommand, IDisposable
|
||||
if (targetCollection == null)
|
||||
continue;
|
||||
while (targetCollection.Count() < sourceCollection.Count())
|
||||
targetCollection.CreatePin();
|
||||
targetCollection.Add(targetCollection.CreatePin());
|
||||
}
|
||||
|
||||
// Copy the storage
|
||||
|
||||
@ -33,7 +33,7 @@ public class App : Application
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
_container = ArtemisBootstrapper.Bootstrap(this, new WindowsModule());
|
||||
_container = ArtemisBootstrapper.Bootstrap(this, c => c.RegisterProviders());
|
||||
Program.CreateLogger(_container);
|
||||
RxApp.MainThreadScheduler = AvaloniaScheduler.Instance;
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
|
||||
27
src/Artemis.UI.Windows/DryIoc/ContainerExtensions.cs
Normal file
27
src/Artemis.UI.Windows/DryIoc/ContainerExtensions.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using Artemis.Core.Providers;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Shared.Providers;
|
||||
using Artemis.UI.Windows.Providers;
|
||||
using Artemis.UI.Windows.Providers.Input;
|
||||
using DryIoc;
|
||||
|
||||
namespace Artemis.UI.Windows.DryIoc;
|
||||
|
||||
/// <summary>
|
||||
/// Provides an extension method to register services onto a DryIoc <see cref="IContainer"/>.
|
||||
/// </summary>
|
||||
public static class UIContainerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers providers into the container.
|
||||
/// </summary>
|
||||
/// <param name="container">The builder building the current container</param>
|
||||
public static void RegisterProviders(this IContainer container)
|
||||
{
|
||||
container.Register<ICursorProvider, CursorProvider>(Reuse.Singleton);
|
||||
container.Register<IGraphicsContextProvider, GraphicsContextProvider>(Reuse.Singleton);
|
||||
container.Register<IUpdateProvider, UpdateProvider>(Reuse.Singleton);
|
||||
container.Register<IAutoRunProvider, AutoRunProvider>();
|
||||
container.Register<InputProvider, WindowsInputProvider>(serviceKey: WindowsInputProvider.Id);
|
||||
}
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
using Artemis.Core.DryIoc;
|
||||
using Artemis.Core.Providers;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Shared.Providers;
|
||||
using Artemis.UI.Windows.Providers;
|
||||
using Artemis.UI.Windows.Providers.Input;
|
||||
using DryIoc;
|
||||
|
||||
namespace Artemis.UI.Windows.DryIoc;
|
||||
|
||||
public class WindowsModule : IModule
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public void Load(IRegistrator builder)
|
||||
{
|
||||
builder.Register<ICursorProvider, CursorProvider>(Reuse.Singleton);
|
||||
builder.Register<IGraphicsContextProvider, GraphicsContextProvider>(Reuse.Singleton);
|
||||
builder.Register<IUpdateProvider, UpdateProvider>(Reuse.Singleton);
|
||||
builder.Register<IAutoRunProvider, AutoRunProvider>();
|
||||
builder.Register<InputProvider, WindowsInputProvider>(serviceKey: WindowsInputProvider.Id);
|
||||
}
|
||||
}
|
||||
@ -31,8 +31,8 @@
|
||||
<PackageReference Include="Material.Icons.Avalonia" Version="1.1.10" />
|
||||
<PackageReference Include="ReactiveUI" Version="17.1.50" />
|
||||
<PackageReference Include="ReactiveUI.Validation" Version="2.2.1" />
|
||||
<PackageReference Include="RGB.NET.Core" Version="1.0.0" />
|
||||
<PackageReference Include="RGB.NET.Layout" Version="1.0.0" />
|
||||
<PackageReference Include="RGB.NET.Core" Version="2.0.0-prerelease.12" />
|
||||
<PackageReference Include="RGB.NET.Layout" Version="2.0.0-prerelease.12" />
|
||||
<PackageReference Include="SkiaSharp" Version="2.88.1-preview.108" />
|
||||
<PackageReference Include="Splat.DryIoc" Version="14.6.1" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Reactive;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.DryIoc;
|
||||
using Artemis.UI.DryIoc;
|
||||
@ -25,7 +26,7 @@ public static class ArtemisBootstrapper
|
||||
private static Container? _container;
|
||||
private static Application? _application;
|
||||
|
||||
public static IContainer Bootstrap(Application application, params IModule[] modules)
|
||||
public static IContainer Bootstrap(Application application, Action<IContainer>? configureServices = null)
|
||||
{
|
||||
if (_application != null || _container != null)
|
||||
throw new ArtemisUIException("UI already bootstrapped");
|
||||
@ -33,18 +34,18 @@ public static class ArtemisBootstrapper
|
||||
Utilities.PrepareFirstLaunch();
|
||||
|
||||
_application = application;
|
||||
_container = new Container(rules => rules.WithConcreteTypeDynamicRegistrations()
|
||||
.WithoutThrowOnRegisteringDisposableTransient());
|
||||
_container = new Container(rules => rules
|
||||
.WithMicrosoftDependencyInjectionRules()
|
||||
.WithConcreteTypeDynamicRegistrations()
|
||||
.WithoutThrowOnRegisteringDisposableTransient());
|
||||
|
||||
new CoreModule().Load(_container);
|
||||
new UIModule().Load(_container);
|
||||
new SharedUIModule().Load(_container);
|
||||
new NoStringDryIocModule().Load(_container);
|
||||
foreach (IModule module in modules)
|
||||
module.Load(_container);
|
||||
_container.RegisterCore();
|
||||
_container.RegisterUI();
|
||||
_container.RegisterSharedUI();
|
||||
_container.RegisterNoStringEvaluating();
|
||||
configureServices?.Invoke(_container);
|
||||
|
||||
_container.UseDryIocDependencyResolver();
|
||||
|
||||
return _container;
|
||||
}
|
||||
|
||||
|
||||
42
src/Artemis.UI/DryIoc/ContainerExtensions.cs
Normal file
42
src/Artemis.UI/DryIoc/ContainerExtensions.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System.Reflection;
|
||||
using Artemis.UI.DryIoc.Factories;
|
||||
using Artemis.UI.DryIoc.InstanceProviders;
|
||||
using Artemis.UI.Screens;
|
||||
using Artemis.UI.Screens.VisualScripting;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services.NodeEditor;
|
||||
using Artemis.UI.Shared.Services.ProfileEditor;
|
||||
using Avalonia.Platform;
|
||||
using Avalonia.Shared.PlatformSupport;
|
||||
using DryIoc;
|
||||
|
||||
namespace Artemis.UI.DryIoc;
|
||||
|
||||
/// <summary>
|
||||
/// Provides an extension method to register services onto a DryIoc <see cref="IContainer"/>.
|
||||
/// </summary>
|
||||
public static class ContainerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers UI services into the container.
|
||||
/// </summary>
|
||||
/// <param name="container">The builder building the current container</param>
|
||||
public static void RegisterUI(this IContainer container)
|
||||
{
|
||||
Assembly[] thisAssembly = {typeof(ContainerExtensions).Assembly};
|
||||
|
||||
container.RegisterInstance(new AssetLoader(), IfAlreadyRegistered.Throw);
|
||||
container.Register<IAssetLoader, AssetLoader>(Reuse.Singleton);
|
||||
|
||||
container.RegisterMany(thisAssembly, type => type.IsAssignableTo<ViewModelBase>());
|
||||
container.RegisterMany(thisAssembly, type => type.IsAssignableTo<MainScreenViewModel>(), ifAlreadyRegistered: IfAlreadyRegistered.Replace);
|
||||
container.RegisterMany(thisAssembly, type => type.IsAssignableTo<IToolViewModel>() && type.IsInterface);
|
||||
container.RegisterMany(thisAssembly, type => type.IsAssignableTo<IVmFactory>() && type != typeof(PropertyVmFactory));
|
||||
|
||||
container.Register<NodeScriptWindowViewModelBase, NodeScriptWindowViewModel>(Reuse.Singleton);
|
||||
container.Register<IPropertyVmFactory, PropertyVmFactory>(Reuse.Singleton);
|
||||
|
||||
container.RegisterMany(thisAssembly, type => type.IsAssignableTo<IArtemisUIService>(), Reuse.Singleton);
|
||||
}
|
||||
}
|
||||
@ -1,36 +0,0 @@
|
||||
using System.Reflection;
|
||||
using Artemis.Core.DryIoc;
|
||||
using Artemis.UI.DryIoc.Factories;
|
||||
using Artemis.UI.DryIoc.InstanceProviders;
|
||||
using Artemis.UI.Screens;
|
||||
using Artemis.UI.Screens.VisualScripting;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services.NodeEditor;
|
||||
using Artemis.UI.Shared.Services.ProfileEditor;
|
||||
using Avalonia.Platform;
|
||||
using Avalonia.Shared.PlatformSupport;
|
||||
using DryIoc;
|
||||
|
||||
namespace Artemis.UI.DryIoc;
|
||||
|
||||
public class UIModule : IModule
|
||||
{
|
||||
public void Load(IRegistrator builder)
|
||||
{
|
||||
Assembly thisAssembly = typeof(UIModule).Assembly;
|
||||
|
||||
builder.RegisterInstance(new AssetLoader(), IfAlreadyRegistered.Throw);
|
||||
builder.Register<IAssetLoader, AssetLoader>(Reuse.Singleton);
|
||||
|
||||
builder.RegisterMany(new[] { thisAssembly }, type => type.IsAssignableTo<ViewModelBase>());
|
||||
builder.RegisterMany(new[] { thisAssembly }, type => type.IsAssignableTo<MainScreenViewModel>(), ifAlreadyRegistered: IfAlreadyRegistered.Replace);
|
||||
builder.RegisterMany(new[] { thisAssembly }, type => type.IsAssignableTo<IToolViewModel>() && type.IsInterface);
|
||||
builder.RegisterMany(new[] { thisAssembly }, type => type.IsAssignableTo<IVmFactory>() && type != typeof(PropertyVmFactory));
|
||||
|
||||
builder.Register<NodeScriptWindowViewModelBase, NodeScriptWindowViewModel>(Reuse.Singleton);
|
||||
builder.Register<IPropertyVmFactory, PropertyVmFactory>(Reuse.Singleton);
|
||||
|
||||
builder.RegisterMany(new[] { thisAssembly }, type => type.IsAssignableTo<IArtemisUIService>(), Reuse.Singleton);
|
||||
}
|
||||
}
|
||||
40
src/Artemis.VisualScripting/DryIoc/ContainerExtensions.cs
Normal file
40
src/Artemis.VisualScripting/DryIoc/ContainerExtensions.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using DryIoc;
|
||||
using Microsoft.Extensions.ObjectPool;
|
||||
using NoStringEvaluating;
|
||||
using NoStringEvaluating.Contract;
|
||||
using NoStringEvaluating.Models.Values;
|
||||
using NoStringEvaluating.Services.Cache;
|
||||
using NoStringEvaluating.Services.Checking;
|
||||
using NoStringEvaluating.Services.Parsing;
|
||||
using NoStringEvaluating.Services.Parsing.NodeReaders;
|
||||
|
||||
namespace Artemis.VisualScripting.DryIoc;
|
||||
|
||||
/// <summary>
|
||||
/// Provides an extension method to register services onto a DryIoc <see cref="IContainer"/>.
|
||||
/// </summary>
|
||||
public static class ContainerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers NoStringEvaluating services into the container.
|
||||
/// </summary>
|
||||
/// <param name="container">The builder building the current container</param>
|
||||
public static void RegisterNoStringEvaluating(this IContainer container)
|
||||
{
|
||||
// Pooling
|
||||
container.RegisterInstance(ObjectPool.Create<Stack<InternalEvaluatorValue>>());
|
||||
container.RegisterInstance(ObjectPool.Create<List<InternalEvaluatorValue>>());
|
||||
container.RegisterInstance(ObjectPool.Create<ExtraTypeIdContainer>());
|
||||
|
||||
// Parser
|
||||
container.Register<IFormulaCache, FormulaCache>(Reuse.Singleton);
|
||||
container.Register<IFunctionReader, FunctionReader>(Reuse.Singleton);
|
||||
container.Register<IFormulaParser, FormulaParser>(Reuse.Singleton);
|
||||
|
||||
// Checker
|
||||
container.Register<IFormulaChecker, FormulaChecker>(Reuse.Singleton);
|
||||
|
||||
// Evaluator
|
||||
container.Register<INoStringEvaluator, NoStringEvaluator>(Reuse.Singleton);
|
||||
}
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
using Artemis.Core.DryIoc;
|
||||
using DryIoc;
|
||||
using Microsoft.Extensions.ObjectPool;
|
||||
using NoStringEvaluating;
|
||||
using NoStringEvaluating.Contract;
|
||||
using NoStringEvaluating.Models.Values;
|
||||
using NoStringEvaluating.Services.Cache;
|
||||
using NoStringEvaluating.Services.Checking;
|
||||
using NoStringEvaluating.Services.Parsing;
|
||||
using NoStringEvaluating.Services.Parsing.NodeReaders;
|
||||
|
||||
namespace Artemis.VisualScripting.DryIoc;
|
||||
|
||||
public class NoStringDryIocModule : IModule
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public void Load(IRegistrator builder)
|
||||
{
|
||||
// Pooling
|
||||
builder.RegisterInstance(ObjectPool.Create<Stack<InternalEvaluatorValue>>());
|
||||
builder.RegisterInstance(ObjectPool.Create<List<InternalEvaluatorValue>>());
|
||||
builder.RegisterInstance(ObjectPool.Create<ExtraTypeIdContainer>());
|
||||
|
||||
// Parser
|
||||
builder.Register<IFormulaCache, FormulaCache>(Reuse.Singleton);
|
||||
builder.Register<IFunctionReader, FunctionReader>(Reuse.Singleton);
|
||||
builder.Register<IFormulaParser, FormulaParser>(Reuse.Singleton);
|
||||
|
||||
// Checker
|
||||
builder.Register<IFormulaChecker, FormulaChecker>(Reuse.Singleton);
|
||||
|
||||
// Evaluator
|
||||
builder.Register<INoStringEvaluator, NoStringEvaluator>(Reuse.Singleton);
|
||||
}
|
||||
}
|
||||
@ -3,7 +3,7 @@ using SkiaSharp;
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes.Color;
|
||||
|
||||
[Node("HSL Color", "Creates a color from hue, saturation and lightness values", "Color", InputType = typeof(Numeric), OutputType = typeof(SKColor))]
|
||||
[Node("HSL Color", "Creates a color from hue, saturation and lightness numbers", "Color", InputType = typeof(Numeric), OutputType = typeof(SKColor))]
|
||||
public class HslSKColorNode : Node
|
||||
{
|
||||
public HslSKColorNode()
|
||||
|
||||
31
src/Artemis.VisualScripting/Nodes/Color/HsvSKColorNode.cs
Normal file
31
src/Artemis.VisualScripting/Nodes/Color/HsvSKColorNode.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using Artemis.Core;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes.Color;
|
||||
|
||||
[Node("HSV Color", "Creates a color from hue, saturation and value numbers", "Color", InputType = typeof(Numeric), OutputType = typeof(SKColor))]
|
||||
public class HsvSKColorNode : Node
|
||||
{
|
||||
public HsvSKColorNode()
|
||||
{
|
||||
H = CreateInputPin<Numeric>("H");
|
||||
S = CreateInputPin<Numeric>("S");
|
||||
V = CreateInputPin<Numeric>("V");
|
||||
Output = CreateOutputPin<SKColor>();
|
||||
}
|
||||
|
||||
public InputPin<Numeric> H { get; set; }
|
||||
public InputPin<Numeric> S { get; set; }
|
||||
public InputPin<Numeric> V { get; set; }
|
||||
public OutputPin<SKColor> Output { get; }
|
||||
|
||||
#region Overrides of Node
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Evaluate()
|
||||
{
|
||||
Output.Value = SKColor.FromHsv(H.Value, S.Value, V.Value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
36
src/Artemis.VisualScripting/Nodes/Color/SkColorHsl.cs
Normal file
36
src/Artemis.VisualScripting/Nodes/Color/SkColorHsl.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using Artemis.Core;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes.Color;
|
||||
|
||||
[Node("Color to HSL", "Outputs H, S and L values from a color", "Color", InputType = typeof(SKColor), OutputType = typeof(Numeric))]
|
||||
public class SkColorHsl : Node
|
||||
{
|
||||
|
||||
public SkColorHsl()
|
||||
{
|
||||
Input = CreateInputPin<SKColor>();
|
||||
H = CreateOutputPin<Numeric>("H");
|
||||
S = CreateOutputPin<Numeric>("S");
|
||||
L = CreateOutputPin<Numeric>("L");
|
||||
}
|
||||
|
||||
public InputPin<SKColor> Input { get; }
|
||||
public OutputPin<Numeric> H { get; }
|
||||
public OutputPin<Numeric> S { get; }
|
||||
public OutputPin<Numeric> L { get; }
|
||||
|
||||
#region Overrides of Node
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Evaluate()
|
||||
{
|
||||
Input.Value.ToHsl(out float h, out float s, out float l);
|
||||
|
||||
H.Value = h;
|
||||
S.Value = s;
|
||||
L.Value = l;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
36
src/Artemis.VisualScripting/Nodes/Color/SkColorHsv.cs
Normal file
36
src/Artemis.VisualScripting/Nodes/Color/SkColorHsv.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using Artemis.Core;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes.Color;
|
||||
|
||||
[Node("Color to HSV", "Outputs H, S and L values from a color", "Color", InputType = typeof(SKColor), OutputType = typeof(Numeric))]
|
||||
public class SkColorHsv : Node
|
||||
{
|
||||
|
||||
public SkColorHsv()
|
||||
{
|
||||
Input = CreateInputPin<SKColor>();
|
||||
H = CreateOutputPin<Numeric>("H");
|
||||
S = CreateOutputPin<Numeric>("S");
|
||||
V = CreateOutputPin<Numeric>("V");
|
||||
}
|
||||
|
||||
public InputPin<SKColor> Input { get; }
|
||||
public OutputPin<Numeric> H { get; }
|
||||
public OutputPin<Numeric> S { get; }
|
||||
public OutputPin<Numeric> V { get; }
|
||||
|
||||
#region Overrides of Node
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Evaluate()
|
||||
{
|
||||
Input.Value.ToHsv(out float h, out float s, out float v);
|
||||
|
||||
H.Value = h;
|
||||
S.Value = s;
|
||||
V.Value = v;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user