mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Updated for RGB.NET's changes regarding rotation
This commit is contained in:
1 parent
97907c97eb
commit
086f2fc1f9
19 files changed
+175
-88
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Exceptions;
|
||||
@@ -21,6 +22,7 @@ namespace Artemis.Core.Services
|
||||
private readonly IPluginService _pluginService;
|
||||
private readonly IRgbService _rgbService;
|
||||
private readonly ISurfaceService _surfaceService;
|
||||
private List<Module> _modules;
|
||||
|
||||
internal CoreService(ILogger logger, IPluginService pluginService, IRgbService rgbService, ISurfaceService surfaceService)
|
||||
{
|
||||
@@ -31,6 +33,10 @@ namespace Artemis.Core.Services
|
||||
_rgbService.Surface.Updating += SurfaceOnUpdating;
|
||||
_rgbService.Surface.Updated += SurfaceOnUpdated;
|
||||
|
||||
_modules = _pluginService.GetPluginsOfType<Module>();
|
||||
_pluginService.PluginEnabled += (sender, args) => _modules = _pluginService.GetPluginsOfType<Module>();
|
||||
_pluginService.PluginDisabled += (sender, args) => _modules = _pluginService.GetPluginsOfType<Module>();
|
||||
|
||||
Task.Run(Initialize);
|
||||
}
|
||||
|
||||
@@ -66,11 +72,12 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
try
|
||||
{
|
||||
var modules = _pluginService.GetPluginsOfType<Module>();
|
||||
|
||||
// Update all active modules
|
||||
foreach (var module in modules)
|
||||
module.Update(args.DeltaTime);
|
||||
lock (_modules)
|
||||
{
|
||||
// Update all active modules
|
||||
foreach (var module in _modules)
|
||||
module.Update(args.DeltaTime);
|
||||
}
|
||||
|
||||
// If there is no graphics decorator, skip the frame
|
||||
if (_rgbService.GraphicsDecorator == null)
|
||||
@@ -84,11 +91,14 @@ namespace Artemis.Core.Services
|
||||
return;
|
||||
|
||||
g.Clear(Color.Black);
|
||||
foreach (var module in modules)
|
||||
module.Render(args.DeltaTime, _surfaceService.ActiveSurface, g);
|
||||
lock (_modules)
|
||||
{
|
||||
foreach (var module in _modules)
|
||||
module.Render(args.DeltaTime, _surfaceService.ActiveSurface, g);
|
||||
}
|
||||
}
|
||||
|
||||
OnFrameRendering(new FrameRenderingEventArgs(modules, _rgbService.GraphicsDecorator.GetBitmap(), args.DeltaTime, _rgbService.Surface));
|
||||
OnFrameRendering(new FrameRenderingEventArgs(_modules, _rgbService.GraphicsDecorator.GetBitmap(), args.DeltaTime, _rgbService.Surface));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -48,5 +48,10 @@ namespace Artemis.Core.Services.Storage.Interfaces
|
||||
/// Occurs when the active device entity has been changed
|
||||
/// </summary>
|
||||
event EventHandler<SurfaceConfigurationEventArgs> ActiveSurfaceConfigurationChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a surface configuration has been updated
|
||||
/// </summary>
|
||||
event EventHandler<SurfaceConfigurationEventArgs> SurfaceConfigurationUpdated;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Core.Services.Storage.Interfaces;
|
||||
@@ -14,12 +16,36 @@ namespace Artemis.Core.Services.Storage
|
||||
public class ProfileService : IProfileService
|
||||
{
|
||||
private readonly IPluginService _pluginService;
|
||||
private readonly ISurfaceService _surfaceService;
|
||||
private readonly IProfileRepository _profileRepository;
|
||||
|
||||
internal ProfileService(IPluginService pluginService, IProfileRepository profileRepository)
|
||||
internal ProfileService(IPluginService pluginService, ISurfaceService surfaceService, IProfileRepository profileRepository)
|
||||
{
|
||||
_pluginService = pluginService;
|
||||
_surfaceService = surfaceService;
|
||||
_profileRepository = profileRepository;
|
||||
|
||||
_surfaceService.ActiveSurfaceConfigurationChanged += SurfaceServiceOnActiveSurfaceConfigurationChanged;
|
||||
_surfaceService.SurfaceConfigurationUpdated += SurfaceServiceOnSurfaceConfigurationUpdated;
|
||||
}
|
||||
|
||||
private void SurfaceServiceOnActiveSurfaceConfigurationChanged(object sender, SurfaceConfigurationEventArgs e)
|
||||
{
|
||||
ApplySurfaceToProfiles(e.Surface);
|
||||
}
|
||||
|
||||
private void SurfaceServiceOnSurfaceConfigurationUpdated(object sender, SurfaceConfigurationEventArgs e)
|
||||
{
|
||||
if (!e.Surface.IsActive)
|
||||
return;
|
||||
ApplySurfaceToProfiles(e.Surface);
|
||||
}
|
||||
|
||||
private void ApplySurfaceToProfiles(Surface surface)
|
||||
{
|
||||
var profileModules = _pluginService.GetPluginsOfType<ProfileModule>();
|
||||
foreach (var profileModule in profileModules.Where(p => p.ActiveProfile != null).ToList())
|
||||
profileModule.ActiveProfile.ApplySurface(surface);
|
||||
}
|
||||
|
||||
public List<Profile> GetProfiles(ProfileModule module)
|
||||
@@ -55,6 +81,8 @@ namespace Artemis.Core.Services.Storage
|
||||
var profile = new Profile(module.PluginInfo, name);
|
||||
_profileRepository.Add(profile.ProfileEntity);
|
||||
|
||||
if (_surfaceService.ActiveSurface != null)
|
||||
profile.ApplySurface(_surfaceService.ActiveSurface);
|
||||
return profile;
|
||||
}
|
||||
|
||||
@@ -70,6 +98,9 @@ namespace Artemis.Core.Services.Storage
|
||||
{
|
||||
foreach (var profileElement in profile.Children)
|
||||
profileElement.ApplyToEntity();
|
||||
|
||||
if (_surfaceService.ActiveSurface != null)
|
||||
profile.ApplySurface(_surfaceService.ActiveSurface);
|
||||
}
|
||||
|
||||
_profileRepository.Save(profile.ProfileEntity);
|
||||
|
||||
Reference in new issue
Block a user