1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00
Artemis/src/Artemis.Core/Utilities/IntroAnimation.cs
2020-08-21 22:32:46 +02:00

92 lines
2.9 KiB
C#

using System;
using System.IO;
using System.Linq;
using Artemis.Core.Extensions;
using Artemis.Core.Models.Profile;
using Artemis.Core.Plugins.Modules;
using Artemis.Core.Services.Storage.Interfaces;
using Artemis.Storage.Entities.Profile;
using Newtonsoft.Json;
using Serilog;
using SkiaSharp;
namespace Artemis.Core.Utilities
{
internal class IntroAnimation
{
private readonly ILogger _logger;
private readonly IProfileService _profileService;
private readonly ISurfaceService _surfaceService;
public IntroAnimation(ILogger logger, IProfileService profileService, ISurfaceService surfaceService)
{
_logger = logger;
_profileService = profileService;
_surfaceService = surfaceService;
CreateIntroProfile();
}
public Profile AnimationProfile { get; set; }
public void Render(double deltaTime, SKCanvas canvas, SKImageInfo bitmapInfo)
{
if (AnimationProfile == null)
return;
AnimationProfile.Update(deltaTime);
AnimationProfile.Render(deltaTime, canvas, bitmapInfo);
}
private void CreateIntroProfile()
{
try
{
// Load the intro profile from JSON into a ProfileEntity
var json = File.ReadAllText(Path.Combine(Constants.ApplicationFolder, "Resources", "intro-profile.json"));
var profileEntity = JsonConvert.DeserializeObject<ProfileEntity>(json);
// Inject every LED on the surface into each layer
foreach (var profileEntityLayer in profileEntity.Layers)
{
profileEntityLayer.Leds.AddRange(_surfaceService.ActiveSurface.Devices.SelectMany(d => d.Leds).Select(l => new LedEntity
{
DeviceIdentifier = l.Device.RgbDevice.GetDeviceIdentifier(),
LedName = l.RgbLed.Id.ToString()
}));
}
var profile = new Profile(new DummyModule(), profileEntity);
profile.Activate(_surfaceService.ActiveSurface);
_profileService.InstantiateProfile(profile);
AnimationProfile = profile;
}
catch (Exception e)
{
_logger.Warning(e, "Failed to load intro profile");
}
}
}
internal class DummyModule : ProfileModule
{
public override void EnablePlugin()
{
throw new NotImplementedException();
}
public override void DisablePlugin()
{
throw new NotImplementedException();
}
public override void ModuleActivated()
{
throw new NotImplementedException();
}
public override void ModuleDeactivated()
{
throw new NotImplementedException();
}
}
}