mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Data model - Added data model visualization view model
Debugger - Split debugger into different tabs Debugger - Added data model debugger
This commit is contained in:
parent
291a343428
commit
796c0dc671
@ -12,13 +12,13 @@ namespace Artemis.Core.Extensions
|
||||
file.CopyTo(Path.Combine(target.FullName, file.Name));
|
||||
}
|
||||
|
||||
public static void RecursiveDelete(this DirectoryInfo baseDir)
|
||||
public static void DeleteRecursively(this DirectoryInfo baseDir)
|
||||
{
|
||||
if (!baseDir.Exists)
|
||||
return;
|
||||
|
||||
foreach (var dir in baseDir.EnumerateDirectories())
|
||||
RecursiveDelete(dir);
|
||||
DeleteRecursively(dir);
|
||||
var files = baseDir.GetFiles();
|
||||
foreach (var file in files)
|
||||
{
|
||||
|
||||
@ -12,6 +12,11 @@ namespace Artemis.Core.Extensions
|
||||
return type.BaseType?.GetGenericTypeDefinition() == genericType;
|
||||
}
|
||||
|
||||
public static bool IsStruct(this Type source)
|
||||
{
|
||||
return source.IsValueType && !source.IsPrimitive && !source.IsEnum;
|
||||
}
|
||||
|
||||
public static bool IsNumber(this object value)
|
||||
{
|
||||
return value is sbyte
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Artemis.Core.Plugins.Abstract.DataModels;
|
||||
using System;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
|
||||
|
||||
namespace Artemis.Core.Plugins.Abstract
|
||||
@ -16,6 +17,20 @@ namespace Artemis.Core.Plugins.Abstract
|
||||
get => (T) InternalDataModel;
|
||||
internal set => InternalDataModel = value;
|
||||
}
|
||||
|
||||
internal override void InternalEnablePlugin()
|
||||
{
|
||||
DataModel = Activator.CreateInstance<T>();
|
||||
DataModel.PluginInfo = PluginInfo;
|
||||
DataModel.DataModelDescription = GetDataModelDescription();
|
||||
base.InternalEnablePlugin();
|
||||
}
|
||||
|
||||
internal override void InternalDisablePlugin()
|
||||
{
|
||||
DataModel = null;
|
||||
base.InternalDisablePlugin();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -8,11 +8,13 @@ namespace Artemis.Core.Plugins.Abstract.DataModels
|
||||
/// <summary>
|
||||
/// Gets the plugin info this data model belongs to
|
||||
/// </summary>
|
||||
[DataModelIgnore]
|
||||
public PluginInfo PluginInfo { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="DataModelPropertyAttribute" /> describing this data model
|
||||
/// </summary>
|
||||
[DataModelIgnore]
|
||||
public DataModelPropertyAttribute DataModelDescription { get; internal set; }
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
|
||||
@ -44,9 +45,18 @@ namespace Artemis.Core.Plugins.Abstract
|
||||
return new DataModelPropertyAttribute {Name = PluginInfo.Name, Description = PluginInfo.Description};
|
||||
}
|
||||
|
||||
internal override DataModelPropertyAttribute InternalGetDataModelDescription()
|
||||
internal override void InternalEnablePlugin()
|
||||
{
|
||||
return GetDataModelDescription();
|
||||
DataModel = Activator.CreateInstance<T>();
|
||||
DataModel.PluginInfo = PluginInfo;
|
||||
DataModel.DataModelDescription = GetDataModelDescription();
|
||||
base.InternalEnablePlugin();
|
||||
}
|
||||
|
||||
internal override void InternalDisablePlugin()
|
||||
{
|
||||
DataModel = null;
|
||||
base.InternalDisablePlugin();
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,10 +101,5 @@ namespace Artemis.Core.Plugins.Abstract
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public abstract IEnumerable<ModuleViewModel> GetViewModels();
|
||||
|
||||
internal virtual DataModelPropertyAttribute InternalGetDataModelDescription()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using Artemis.Core.Plugins.Abstract.ViewModels;
|
||||
using Artemis.Core.Plugins.Exceptions;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Castle.Core.Internal;
|
||||
|
||||
namespace Artemis.Core.Plugins.Abstract
|
||||
{
|
||||
@ -9,7 +11,7 @@ namespace Artemis.Core.Plugins.Abstract
|
||||
/// </summary>
|
||||
public abstract class Plugin : IDisposable
|
||||
{
|
||||
public PluginInfo PluginInfo { get; internal set; }
|
||||
public PluginInfo PluginInfo { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the plugin is enabled
|
||||
@ -47,26 +49,39 @@ namespace Artemis.Core.Plugins.Abstract
|
||||
return null;
|
||||
}
|
||||
|
||||
internal void SetEnabled(bool enable)
|
||||
internal void SetEnabled(bool enable, bool isAutoEnable = false)
|
||||
{
|
||||
if (enable && !Enabled)
|
||||
{
|
||||
Enabled = true;
|
||||
PluginInfo.Enabled = true;
|
||||
|
||||
// If enable failed, put it back in a disabled state
|
||||
try
|
||||
{
|
||||
EnablePlugin();
|
||||
if (isAutoEnable && PluginInfo.GetLockFileCreated())
|
||||
{
|
||||
// Don't wrap existing lock exceptions, simply rethrow them
|
||||
if (PluginInfo.LoadException is ArtemisPluginLockException)
|
||||
throw PluginInfo.LoadException;
|
||||
|
||||
throw new ArtemisPluginLockException(PluginInfo.LoadException);
|
||||
}
|
||||
|
||||
Enabled = true;
|
||||
PluginInfo.Enabled = true;
|
||||
PluginInfo.CreateLockFile();
|
||||
|
||||
InternalEnablePlugin();
|
||||
OnPluginEnabled();
|
||||
PluginInfo.LoadException = null;
|
||||
}
|
||||
catch
|
||||
// If enable failed, put it back in a disabled state
|
||||
catch (Exception e)
|
||||
{
|
||||
Enabled = false;
|
||||
PluginInfo.Enabled = false;
|
||||
PluginInfo.LoadException = e;
|
||||
throw;
|
||||
}
|
||||
|
||||
OnPluginEnabled();
|
||||
PluginInfo.DeleteLockFile();
|
||||
}
|
||||
else if (!enable && Enabled)
|
||||
{
|
||||
@ -74,12 +89,21 @@ namespace Artemis.Core.Plugins.Abstract
|
||||
PluginInfo.Enabled = false;
|
||||
|
||||
// Even if disable failed, still leave it in a disabled state to avoid more issues
|
||||
DisablePlugin();
|
||||
|
||||
InternalDisablePlugin();
|
||||
OnPluginDisabled();
|
||||
}
|
||||
}
|
||||
|
||||
internal virtual void InternalEnablePlugin()
|
||||
{
|
||||
EnablePlugin();
|
||||
}
|
||||
|
||||
internal virtual void InternalDisablePlugin()
|
||||
{
|
||||
DisablePlugin();
|
||||
}
|
||||
|
||||
#region Events
|
||||
|
||||
public event EventHandler PluginEnabled;
|
||||
|
||||
@ -4,6 +4,7 @@ using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.Plugins.Abstract
|
||||
@ -18,7 +19,7 @@ namespace Artemis.Core.Plugins.Abstract
|
||||
/// </summary>
|
||||
public T DataModel
|
||||
{
|
||||
get => (T)InternalDataModel;
|
||||
get => (T) InternalDataModel;
|
||||
internal set => InternalDataModel = value;
|
||||
}
|
||||
|
||||
@ -42,12 +43,21 @@ namespace Artemis.Core.Plugins.Abstract
|
||||
/// <returns></returns>
|
||||
public virtual DataModelPropertyAttribute GetDataModelDescription()
|
||||
{
|
||||
return new DataModelPropertyAttribute { Name = PluginInfo.Name, Description = PluginInfo.Description };
|
||||
return new DataModelPropertyAttribute {Name = PluginInfo.Name, Description = PluginInfo.Description};
|
||||
}
|
||||
|
||||
internal override void InternalEnablePlugin()
|
||||
{
|
||||
DataModel = Activator.CreateInstance<T>();
|
||||
DataModel.PluginInfo = PluginInfo;
|
||||
DataModel.DataModelDescription = GetDataModelDescription();
|
||||
base.InternalEnablePlugin();
|
||||
}
|
||||
|
||||
internal override DataModelPropertyAttribute InternalGetDataModelDescription()
|
||||
internal override void InternalDisablePlugin()
|
||||
{
|
||||
return GetDataModelDescription();
|
||||
DataModel = null;
|
||||
base.InternalDisablePlugin();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace Artemis.Core.Plugins.Exceptions
|
||||
{
|
||||
public class ArtemisPluginLockException : Exception
|
||||
{
|
||||
public ArtemisPluginLockException(Exception innerException) : base(CreateExceptionMessage(innerException), innerException)
|
||||
{
|
||||
}
|
||||
|
||||
private static string CreateExceptionMessage(Exception innerException)
|
||||
{
|
||||
return innerException != null
|
||||
? "Found a lock file, skipping load, see inner exception for last known exception."
|
||||
: "Found a lock file, skipping load.";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -12,16 +12,17 @@ namespace Artemis.Core.Plugins.Models
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class PluginInfo : PropertyChangedBase
|
||||
{
|
||||
private Guid _guid;
|
||||
private string _name;
|
||||
private string _description;
|
||||
private string _icon;
|
||||
private Version _version;
|
||||
private string _main;
|
||||
private DirectoryInfo _directory;
|
||||
private Plugin _instance;
|
||||
private bool _enabled;
|
||||
private Guid _guid;
|
||||
private string _icon;
|
||||
private Plugin _instance;
|
||||
private bool _lastEnableSuccessful;
|
||||
private Exception _loadException;
|
||||
private string _main;
|
||||
private string _name;
|
||||
private Version _version;
|
||||
|
||||
internal PluginInfo()
|
||||
{
|
||||
@ -117,12 +118,12 @@ namespace Artemis.Core.Plugins.Models
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the last time the plugin loaded, it loaded correctly
|
||||
/// Gets the exception thrown while loading
|
||||
/// </summary>
|
||||
public bool LastEnableSuccessful
|
||||
public Exception LoadException
|
||||
{
|
||||
get => _lastEnableSuccessful;
|
||||
internal set => SetAndNotify(ref _lastEnableSuccessful, value);
|
||||
get => _loadException;
|
||||
internal set => SetAndNotify(ref _loadException, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -149,7 +150,22 @@ namespace Artemis.Core.Plugins.Models
|
||||
{
|
||||
PluginEntity.Id = Guid;
|
||||
PluginEntity.IsEnabled = Enabled;
|
||||
PluginEntity.LastEnableSuccessful = LastEnableSuccessful;
|
||||
}
|
||||
|
||||
internal void CreateLockFile()
|
||||
{
|
||||
File.Create(Path.Combine(Directory.FullName, "artemis.lock")).Close();
|
||||
}
|
||||
|
||||
internal void DeleteLockFile()
|
||||
{
|
||||
if (GetLockFileCreated())
|
||||
File.Delete(Path.Combine(Directory.FullName, "artemis.lock"));
|
||||
}
|
||||
|
||||
internal bool GetLockFileCreated()
|
||||
{
|
||||
return File.Exists(Path.Combine(Directory.FullName, "artemis.lock"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Exceptions;
|
||||
@ -107,8 +108,8 @@ namespace Artemis.Core.Services
|
||||
|
||||
private void UpdatePluginCache()
|
||||
{
|
||||
_modules = _pluginService.GetPluginsOfType<Module>();
|
||||
_dataModelExpansions = _pluginService.GetPluginsOfType<BaseDataModelExpansion>();
|
||||
_modules = _pluginService.GetPluginsOfType<Module>().Where(p => p.Enabled).ToList();
|
||||
_dataModelExpansions = _pluginService.GetPluginsOfType<BaseDataModelExpansion>().Where(p => p.Enabled).ToList();
|
||||
}
|
||||
|
||||
private void ConfigureJsonConvert()
|
||||
|
||||
@ -3,10 +3,8 @@ using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Models;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
|
||||
using Artemis.Core.Plugins.Exceptions;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
|
||||
@ -17,8 +15,8 @@ namespace Artemis.Core.Services
|
||||
/// </summary>
|
||||
public class DataModelService : IDataModelService
|
||||
{
|
||||
private readonly IPluginService _pluginService;
|
||||
private readonly List<DataModel> _dataModelExpansions;
|
||||
private readonly IPluginService _pluginService;
|
||||
|
||||
internal DataModelService(IPluginService pluginService)
|
||||
{
|
||||
@ -27,6 +25,11 @@ namespace Artemis.Core.Services
|
||||
|
||||
_pluginService.PluginEnabled += PluginServiceOnPluginEnabled;
|
||||
_pluginService.PluginDisabled += PluginServiceOnPluginDisabled;
|
||||
|
||||
foreach (var module in _pluginService.GetPluginsOfType<Module>().Where(m => m.InternalExpandsMainDataModel))
|
||||
AddModuleDataModel(module);
|
||||
foreach (var dataModelExpansion in _pluginService.GetPluginsOfType<BaseDataModelExpansion>())
|
||||
AddDataModelExpansionDataModel(dataModelExpansion);
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<DataModel> DataModelExpansions
|
||||
@ -64,27 +67,25 @@ namespace Artemis.Core.Services
|
||||
private void PluginServiceOnPluginEnabled(object sender, PluginEventArgs e)
|
||||
{
|
||||
if (e.PluginInfo.Instance is Module module && module.InternalExpandsMainDataModel)
|
||||
{
|
||||
if (module.InternalDataModel.DataModelDescription == null)
|
||||
{
|
||||
module.InternalDataModel.DataModelDescription = module.InternalGetDataModelDescription();
|
||||
if (module.InternalDataModel.DataModelDescription == null)
|
||||
throw new ArtemisPluginException(module.PluginInfo, "Module overrides GetDataModelDescription but returned null");
|
||||
}
|
||||
|
||||
_dataModelExpansions.Add(module.InternalDataModel);
|
||||
}
|
||||
AddModuleDataModel(module);
|
||||
else if (e.PluginInfo.Instance is BaseDataModelExpansion dataModelExpansion)
|
||||
{
|
||||
if (dataModelExpansion.InternalDataModel.DataModelDescription == null)
|
||||
{
|
||||
dataModelExpansion.InternalDataModel.DataModelDescription = dataModelExpansion.GetDataModelDescription();
|
||||
if (dataModelExpansion.InternalDataModel.DataModelDescription == null)
|
||||
throw new ArtemisPluginException(dataModelExpansion.PluginInfo, "Data model expansion overrides GetDataModelDescription but returned null");
|
||||
}
|
||||
AddDataModelExpansionDataModel(dataModelExpansion);
|
||||
}
|
||||
|
||||
_dataModelExpansions.Add(dataModelExpansion.InternalDataModel);
|
||||
}
|
||||
private void AddDataModelExpansionDataModel(BaseDataModelExpansion dataModelExpansion)
|
||||
{
|
||||
if (dataModelExpansion.InternalDataModel.DataModelDescription == null)
|
||||
throw new ArtemisPluginException(dataModelExpansion.PluginInfo, "Data model expansion overrides GetDataModelDescription but returned null");
|
||||
|
||||
AddExpansion(dataModelExpansion.InternalDataModel);
|
||||
}
|
||||
|
||||
private void AddModuleDataModel(Module module)
|
||||
{
|
||||
if (module.InternalDataModel.DataModelDescription == null)
|
||||
throw new ArtemisPluginException(module.PluginInfo, "Module overrides GetDataModelDescription but returned null");
|
||||
|
||||
AddExpansion(module.InternalDataModel);
|
||||
}
|
||||
|
||||
private void PluginServiceOnPluginDisabled(object sender, PluginEventArgs e)
|
||||
|
||||
@ -46,7 +46,8 @@ namespace Artemis.Core.Services.Interfaces
|
||||
/// Enables the provided plugin
|
||||
/// </summary>
|
||||
/// <param name="plugin"></param>
|
||||
void EnablePlugin(Plugin plugin);
|
||||
/// <param name="isAutoEnable">If true, fails if there is a lock file present</param>
|
||||
void EnablePlugin(Plugin plugin, bool isAutoEnable = false);
|
||||
|
||||
/// <summary>
|
||||
/// Disables the provided plugin
|
||||
|
||||
@ -148,22 +148,14 @@ namespace Artemis.Core.Services
|
||||
// Activate plugins after they are all loaded
|
||||
foreach (var pluginInfo in _plugins.Where(p => p.Enabled))
|
||||
{
|
||||
if (!pluginInfo.LastEnableSuccessful)
|
||||
{
|
||||
pluginInfo.Enabled = false;
|
||||
_logger.Warning("Plugin failed to load last time, disabling it now to avoid instability. Plugin info: {pluginInfo}", pluginInfo);
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
EnablePlugin(pluginInfo.Instance);
|
||||
EnablePlugin(pluginInfo.Instance, true);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// ignored, logged in EnablePlugin
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
LoadingPlugins = false;
|
||||
@ -204,11 +196,10 @@ namespace Artemis.Core.Services
|
||||
|
||||
var pluginEntity = _pluginRepository.GetPluginByGuid(pluginInfo.Guid);
|
||||
if (pluginEntity == null)
|
||||
pluginEntity = new PluginEntity {Id = pluginInfo.Guid, IsEnabled = true, LastEnableSuccessful = true};
|
||||
pluginEntity = new PluginEntity {Id = pluginInfo.Guid, IsEnabled = true};
|
||||
|
||||
pluginInfo.PluginEntity = pluginEntity;
|
||||
pluginInfo.Enabled = pluginEntity.IsEnabled;
|
||||
pluginInfo.LastEnableSuccessful = pluginEntity.LastEnableSuccessful;
|
||||
|
||||
var mainFile = Path.Combine(pluginInfo.Directory.FullName, pluginInfo.Main);
|
||||
if (!File.Exists(mainFile))
|
||||
@ -294,20 +285,15 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
public void EnablePlugin(Plugin plugin)
|
||||
public void EnablePlugin(Plugin plugin, bool isAutoEnable = false)
|
||||
{
|
||||
lock (_plugins)
|
||||
{
|
||||
_logger.Debug("Enabling plugin {pluginInfo}", plugin.PluginInfo);
|
||||
|
||||
plugin.PluginInfo.LastEnableSuccessful = false;
|
||||
plugin.PluginInfo.ApplyToEntity();
|
||||
|
||||
_pluginRepository.SavePlugin(plugin.PluginInfo.PluginEntity);
|
||||
|
||||
try
|
||||
{
|
||||
plugin.SetEnabled(true);
|
||||
plugin.SetEnabled(true, isAutoEnable);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -316,16 +302,16 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
finally
|
||||
{
|
||||
// We got this far so the plugin enabled and we didn't crash horribly, yay
|
||||
if (plugin.PluginInfo.Enabled)
|
||||
{
|
||||
plugin.PluginInfo.LastEnableSuccessful = true;
|
||||
plugin.PluginInfo.ApplyToEntity();
|
||||
// On an auto-enable, ensure PluginInfo.Enabled is true even if enable failed, that way a failure on auto-enable does
|
||||
// not affect the user's settings
|
||||
if (isAutoEnable)
|
||||
plugin.PluginInfo.Enabled = true;
|
||||
|
||||
_pluginRepository.SavePlugin(plugin.PluginInfo.PluginEntity);
|
||||
plugin.PluginInfo.ApplyToEntity();
|
||||
_pluginRepository.SavePlugin(plugin.PluginInfo.PluginEntity);
|
||||
|
||||
if (plugin.PluginInfo.Enabled)
|
||||
_logger.Debug("Successfully enabled plugin {pluginInfo}", plugin.PluginInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -398,13 +384,16 @@ namespace Artemis.Core.Services
|
||||
private static void CopyBuiltInPlugin(DirectoryInfo builtInPluginDirectory)
|
||||
{
|
||||
var pluginDirectory = new DirectoryInfo(Path.Combine(Constants.DataFolder, "plugins", builtInPluginDirectory.Name));
|
||||
var createLockFile = File.Exists(Path.Combine(pluginDirectory.FullName, "artemis.lock"));
|
||||
|
||||
// Remove the old directory if it exists
|
||||
if (Directory.Exists(pluginDirectory.FullName))
|
||||
pluginDirectory.RecursiveDelete();
|
||||
pluginDirectory.DeleteRecursively();
|
||||
Directory.CreateDirectory(pluginDirectory.FullName);
|
||||
|
||||
builtInPluginDirectory.CopyFilesRecursively(pluginDirectory);
|
||||
if (createLockFile)
|
||||
File.Create(Path.Combine(pluginDirectory.FullName, "artemis.lock")).Close();
|
||||
}
|
||||
|
||||
#region Events
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LiteDB" Version="5.0.8" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="Serilog" Version="2.9.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using LiteDB;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.Storage.Entities.Plugins
|
||||
{
|
||||
@ -8,8 +10,6 @@ namespace Artemis.Storage.Entities.Plugins
|
||||
public class PluginEntity
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public bool IsEnabled { get; set; }
|
||||
public bool LastEnableSuccessful { get; set; }
|
||||
}
|
||||
}
|
||||
@ -20,8 +20,11 @@
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel>
|
||||
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" Text="Stack trace"
|
||||
TextWrapping="Wrap" FontWeight="Bold" />
|
||||
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}"
|
||||
Text="Stack trace"
|
||||
TextWrapping="Wrap"
|
||||
FontWeight="Bold"
|
||||
MaxWidth="1000"/>
|
||||
|
||||
<avalonedit:TextEditor SyntaxHighlighting="C#"
|
||||
FontFamily="pack://application:,,,/Resources/Fonts/#Roboto Mono"
|
||||
|
||||
@ -1,11 +1,15 @@
|
||||
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
|
||||
using System.Reflection;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.DataModelVisualization
|
||||
{
|
||||
public abstract class DataModelVisualizationViewModel : PropertyChangedBase
|
||||
{
|
||||
public PropertyInfo PropertyInfo { get; protected set; }
|
||||
public DataModelPropertyAttribute PropertyDescription { get; protected set; }
|
||||
public DataModelViewModel Parent { get; protected set; }
|
||||
|
||||
public abstract void Update();
|
||||
}
|
||||
}
|
||||
@ -1,23 +1,39 @@
|
||||
using System.Reflection;
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
|
||||
using FastMember;
|
||||
|
||||
namespace Artemis.UI.DataModelVisualization
|
||||
{
|
||||
public class DataModelPropertyViewModel : DataModelVisualizationViewModel
|
||||
public class DataModelPropertyViewModel<T, TP> : DataModelPropertyViewModel
|
||||
{
|
||||
private readonly ObjectAccessor _accessor;
|
||||
private readonly Func<T, TP> _expression;
|
||||
|
||||
public DataModelPropertyViewModel(PropertyInfo propertyInfo, DataModelPropertyAttribute propertyDescription, DataModelViewModel parent)
|
||||
{
|
||||
_accessor = ObjectAccessor.Create(parent.Model);
|
||||
|
||||
PropertyInfo = propertyInfo;
|
||||
Parent = parent;
|
||||
PropertyDescription = propertyDescription;
|
||||
|
||||
var instance = Expression.Parameter(typeof(T), "instance");
|
||||
var body = Expression.Property(instance, propertyInfo);
|
||||
_expression = Expression.Lambda<Func<T, TP>>(body, instance).Compile();
|
||||
}
|
||||
|
||||
public PropertyInfo PropertyInfo { get; }
|
||||
public object Value => _accessor[PropertyInfo.Name];
|
||||
public TP Value
|
||||
{
|
||||
get => BaseValue is TP value ? value : default;
|
||||
set => BaseValue = value;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
Value = _expression((T) Parent.Model);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class DataModelPropertyViewModel : DataModelVisualizationViewModel
|
||||
{
|
||||
public object BaseValue { get; protected set; }
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Artemis.Core.Extensions;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
|
||||
using Humanizer;
|
||||
using Stylet;
|
||||
@ -12,8 +14,9 @@ namespace Artemis.UI.DataModelVisualization
|
||||
Children = new BindableCollection<DataModelVisualizationViewModel>();
|
||||
}
|
||||
|
||||
public DataModelViewModel(object model, DataModelPropertyAttribute propertyDescription, DataModelViewModel parent)
|
||||
public DataModelViewModel(PropertyInfo propertyInfo, object model, DataModelPropertyAttribute propertyDescription, DataModelViewModel parent)
|
||||
{
|
||||
PropertyInfo = propertyInfo;
|
||||
Model = model;
|
||||
PropertyDescription = propertyDescription;
|
||||
Parent = parent;
|
||||
@ -22,7 +25,7 @@ namespace Artemis.UI.DataModelVisualization
|
||||
PopulateProperties();
|
||||
}
|
||||
|
||||
public object Model { get; }
|
||||
public object Model { get; private set; }
|
||||
public BindableCollection<DataModelVisualizationViewModel> Children { get; set; }
|
||||
|
||||
public void PopulateProperties()
|
||||
@ -39,21 +42,34 @@ namespace Artemis.UI.DataModelVisualization
|
||||
if (dataModelPropertyAttribute == null)
|
||||
dataModelPropertyAttribute = new DataModelPropertyAttribute {Name = propertyInfo.Name.Humanize()};
|
||||
|
||||
// For value types create a child view model if the value type is not null
|
||||
if (propertyInfo.PropertyType.IsValueType)
|
||||
// For primitives, create a property view model, it may be null that is fine
|
||||
if (propertyInfo.PropertyType.IsPrimitive || propertyInfo.PropertyType == typeof(string))
|
||||
{
|
||||
// This may be slower than avoiding generics and Activator.CreateInstance but it allows for expression trees inside the VM we're creating
|
||||
// here, this means slow creation but fast updates after that
|
||||
var viewModelType = typeof(DataModelPropertyViewModel<,>).MakeGenericType(Model.GetType(), propertyInfo.PropertyType);
|
||||
var viewModel = (DataModelVisualizationViewModel) Activator.CreateInstance(viewModelType, propertyInfo, dataModelPropertyAttribute, this);
|
||||
Children.Add(viewModel);
|
||||
}
|
||||
// For other value types create a child view model if the value type is not null
|
||||
else if (propertyInfo.PropertyType.IsClass || propertyInfo.PropertyType.IsStruct())
|
||||
{
|
||||
var value = propertyInfo.GetValue(Model);
|
||||
if (value == null)
|
||||
continue;
|
||||
|
||||
Children.Add(new DataModelViewModel(value, dataModelPropertyAttribute, this));
|
||||
}
|
||||
// For primitives, create a property view model, it may be null that is fine
|
||||
else if (propertyInfo.PropertyType.IsPrimitive)
|
||||
{
|
||||
Children.Add(new DataModelPropertyViewModel(propertyInfo, dataModelPropertyAttribute, this));
|
||||
Children.Add(new DataModelViewModel(propertyInfo, value, dataModelPropertyAttribute, this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
if (PropertyInfo != null && PropertyInfo.PropertyType.IsStruct())
|
||||
Model = PropertyInfo.GetValue(Parent.Model);
|
||||
|
||||
foreach (var dataModelVisualizationViewModel in Children)
|
||||
dataModelVisualizationViewModel.Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -27,39 +27,26 @@
|
||||
<mde:AppBar.AppIcon>
|
||||
<materialDesign:PackIcon Kind="Matrix" Width="20" Height="28" />
|
||||
</mde:AppBar.AppIcon>
|
||||
|
||||
|
||||
<materialDesign:PopupBox DockPanel.Dock="Right" PlacementMode="BottomAndAlignRightEdges" StaysOpen="False">
|
||||
<StackPanel>
|
||||
<Button Content="Force garbage collection" Command="{s:Action ForceGarbageCollection}"/>
|
||||
<Button Content="Force garbage collection" Command="{s:Action ForceGarbageCollection}" />
|
||||
</StackPanel>
|
||||
</materialDesign:PopupBox>
|
||||
</mde:AppBar>
|
||||
|
||||
<StackPanel Margin="10, 10, 10, 10">
|
||||
<TextBlock TextWrapping="Wrap">
|
||||
In this window you can view the inner workings of Artemis.
|
||||
Please note that having this window open can have a performance impact on your system.
|
||||
</TextBlock>
|
||||
|
||||
<Grid Margin="0,10,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0">
|
||||
This image shows what is being rendered and dispatched to RGB.NET
|
||||
</TextBlock>
|
||||
<TextBlock Grid.Column="1" HorizontalAlignment="Right" Margin="0,0,5,0" FontWeight="Bold">
|
||||
FPS:
|
||||
</TextBlock>
|
||||
<TextBlock Grid.Column="2" HorizontalAlignment="Right" Text="{Binding CurrentFps}" />
|
||||
</Grid>
|
||||
|
||||
<materialDesign:Card VerticalAlignment="Stretch" Margin="0, 5,0,0">
|
||||
<Image Source="{Binding CurrentFrame}" />
|
||||
</materialDesign:Card>
|
||||
</StackPanel>
|
||||
<TabControl ItemsSource="{Binding Items}"
|
||||
SelectedItem="{Binding ActiveItem}"
|
||||
DisplayMemberPath="DisplayName"
|
||||
Style="{StaticResource MaterialDesignTabControl}">
|
||||
<TabControl.ContentTemplate>
|
||||
<DataTemplate>
|
||||
<materialDesign:TransitioningContent OpeningEffect="{materialDesign:TransitionEffect FadeIn}">
|
||||
<ContentControl s:View.Model="{Binding}" TextElement.Foreground="{DynamicResource MaterialDesignBody}" Margin="10" />
|
||||
</materialDesign:TransitioningContent>
|
||||
</DataTemplate>
|
||||
</TabControl.ContentTemplate>
|
||||
</TabControl>
|
||||
</DockPanel>
|
||||
|
||||
</mde:MaterialWindow>
|
||||
@ -1,33 +1,19 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Core.Services.Storage.Interfaces;
|
||||
using SkiaSharp;
|
||||
using SkiaSharp.Views.WPF;
|
||||
using Artemis.UI.Screens.Settings.Debug.Tabs;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Settings.Debug
|
||||
{
|
||||
public class DebugViewModel : Screen
|
||||
public class DebugViewModel : Conductor<Screen>.Collection.OneActive
|
||||
{
|
||||
private readonly ICoreService _coreService;
|
||||
private readonly IRgbService _rgbService;
|
||||
|
||||
public DebugViewModel(ICoreService coreService, IRgbService rgbService, ISurfaceService surfaceService)
|
||||
public DebugViewModel(RenderDebugViewModel renderDebugViewModel, DataModelDebugViewModel dataModelDebugViewModel, LogsDebugViewModel logsDebugViewModel)
|
||||
{
|
||||
_coreService = coreService;
|
||||
_rgbService = rgbService;
|
||||
|
||||
surfaceService.SurfaceConfigurationUpdated += (sender, args) => Execute.PostToUIThread(() => CurrentFrame = null);
|
||||
surfaceService.ActiveSurfaceConfigurationSelected += (sender, args) => Execute.PostToUIThread(() => CurrentFrame = null);
|
||||
Items.Add(renderDebugViewModel);
|
||||
Items.Add(dataModelDebugViewModel);
|
||||
Items.Add(logsDebugViewModel);
|
||||
ActiveItem = renderDebugViewModel;
|
||||
}
|
||||
|
||||
public ImageSource CurrentFrame { get; set; }
|
||||
public double CurrentFps { get; set; }
|
||||
|
||||
public string Title => "Debugger";
|
||||
|
||||
public void ForceGarbageCollection()
|
||||
@ -36,59 +22,5 @@ namespace Artemis.UI.Screens.Settings.Debug
|
||||
GC.WaitForPendingFinalizers();
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
protected override void OnInitialActivate()
|
||||
{
|
||||
_coreService.FrameRendered += CoreServiceOnFrameRendered;
|
||||
_coreService.FrameRendering += CoreServiceOnFrameRendering;
|
||||
base.OnInitialActivate();
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
_coreService.FrameRendered -= CoreServiceOnFrameRendered;
|
||||
_coreService.FrameRendering -= CoreServiceOnFrameRendering;
|
||||
base.OnClose();
|
||||
}
|
||||
|
||||
private void CoreServiceOnFrameRendered(object sender, FrameRenderedEventArgs e)
|
||||
{
|
||||
Execute.PostToUIThread(() =>
|
||||
{
|
||||
if (e.BitmapBrush?.Bitmap == null)
|
||||
return;
|
||||
|
||||
if (!(CurrentFrame is WriteableBitmap writeableBitmap))
|
||||
{
|
||||
CurrentFrame = e.BitmapBrush.Bitmap.ToWriteableBitmap();
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (var skiaImage = SKImage.FromPixels(e.BitmapBrush.Bitmap.PeekPixels()))
|
||||
{
|
||||
var info = new SKImageInfo(skiaImage.Width, skiaImage.Height);
|
||||
writeableBitmap.Lock();
|
||||
using (var pixmap = new SKPixmap(info, writeableBitmap.BackBuffer, writeableBitmap.BackBufferStride))
|
||||
{
|
||||
skiaImage.ReadPixels(pixmap, 0, 0);
|
||||
}
|
||||
|
||||
writeableBitmap.AddDirtyRect(new Int32Rect(0, 0, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight));
|
||||
writeableBitmap.Unlock();
|
||||
}
|
||||
}
|
||||
catch (AccessViolationException)
|
||||
{
|
||||
// oops
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void CoreServiceOnFrameRendering(object sender, FrameRenderingEventArgs e)
|
||||
{
|
||||
CurrentFps = Math.Round(1.0 / e.DeltaTime, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.Settings.Debug.Tabs.DataModelDebugView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Artemis.UI.Screens.Settings.Debug.Tabs"
|
||||
xmlns:dataModel="clr-namespace:Artemis.UI.DataModelVisualization"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:converters="clr-namespace:Artemis.UI.Converters"
|
||||
xmlns:wpf="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance local:DataModelDebugViewModel}">
|
||||
<UserControl.Resources>
|
||||
<converters:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<TreeView ItemsSource="{Binding MainDataModel.Children}" HorizontalContentAlignment="Stretch">
|
||||
<TreeView.Resources>
|
||||
<HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelViewModel}" ItemsSource="{Binding Children}">
|
||||
<TextBlock Text="{Binding PropertyDescription.Name}" ToolTip="{Binding PropertyDescription.Description}" />
|
||||
</HierarchicalDataTemplate>
|
||||
<HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelPropertyViewModel}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" Margin="0 0 5 0" FontWeight="Bold">
|
||||
<Run>[</Run><Run Text="{Binding PropertyInfo.PropertyType.Name, Mode=OneWay}" /><Run>]</Run>
|
||||
</TextBlock>
|
||||
<TextBlock Grid.Column="1" Text="{Binding PropertyDescription.Name}" ToolTip="{Binding PropertyDescription.Description}" />
|
||||
<TextBlock Grid.Column="2"
|
||||
Text="{Binding Value, Mode=OneWay}"
|
||||
FontFamily="Consolas"
|
||||
HorizontalAlignment="Right"
|
||||
Visibility="{Binding Value, Converter={StaticResource NullToVisibilityConverter}}"/>
|
||||
<TextBlock Grid.Column="2"
|
||||
Text="null"
|
||||
FontFamily="Consolas"
|
||||
HorizontalAlignment="Right"
|
||||
Foreground="{DynamicResource MaterialDesignCheckBoxDisabled}"
|
||||
Visibility="{Binding Value, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}"/>
|
||||
</Grid>
|
||||
</HierarchicalDataTemplate>
|
||||
</TreeView.Resources>
|
||||
</TreeView>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@ -0,0 +1,35 @@
|
||||
using System.Timers;
|
||||
using Artemis.UI.DataModelVisualization;
|
||||
using Artemis.UI.Services;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Settings.Debug.Tabs
|
||||
{
|
||||
public class DataModelDebugViewModel : Screen
|
||||
{
|
||||
private readonly IDataModelVisualizationService _dataModelVisualizationService;
|
||||
private readonly Timer _updateTimer;
|
||||
|
||||
public DataModelDebugViewModel(IDataModelVisualizationService dataModelVisualizationService)
|
||||
{
|
||||
_dataModelVisualizationService = dataModelVisualizationService;
|
||||
_updateTimer = new Timer(500);
|
||||
_updateTimer.Elapsed += (sender, args) => MainDataModel.Update();
|
||||
|
||||
DisplayName = "Data model";
|
||||
}
|
||||
|
||||
public DataModelViewModel MainDataModel { get; set; }
|
||||
|
||||
protected override void OnActivate()
|
||||
{
|
||||
MainDataModel = _dataModelVisualizationService.GetMainDataModelVisualization();
|
||||
_updateTimer.Start();
|
||||
}
|
||||
|
||||
protected override void OnDeactivate()
|
||||
{
|
||||
_updateTimer.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.Settings.Debug.Tabs.LogsDebugView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Artemis.UI.Screens.Settings.Debug.Tabs"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance local:LogsDebugViewModel}">
|
||||
<Grid>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Artemis.UI.Screens.Settings.Debug.Tabs
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for LogsDebugView.xaml
|
||||
/// </summary>
|
||||
public partial class LogsDebugView : UserControl
|
||||
{
|
||||
public LogsDebugView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Settings.Debug.Tabs
|
||||
{
|
||||
public class LogsDebugViewModel : Screen
|
||||
{
|
||||
public LogsDebugViewModel()
|
||||
{
|
||||
DisplayName = "Logs";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.Settings.Debug.Tabs.RenderDebugView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Artemis.UI.Screens.Settings.Debug.Tabs"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance local:RenderDebugViewModel}">
|
||||
<StackPanel>
|
||||
<TextBlock TextWrapping="Wrap">
|
||||
In this window you can view the inner workings of Artemis.
|
||||
Please note that having this window open can have a performance impact on your system.
|
||||
</TextBlock>
|
||||
|
||||
<Grid Margin="0,10,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0">
|
||||
This image shows what is being rendered and dispatched to RGB.NET
|
||||
</TextBlock>
|
||||
<TextBlock Grid.Column="1" HorizontalAlignment="Right" Margin="0,0,5,0" FontWeight="Bold">
|
||||
FPS:
|
||||
</TextBlock>
|
||||
<TextBlock Grid.Column="2" HorizontalAlignment="Right" Text="{Binding CurrentFps}" />
|
||||
</Grid>
|
||||
|
||||
<materialDesign:Card VerticalAlignment="Stretch" Margin="0, 5,0,0">
|
||||
<Image Source="{Binding CurrentFrame}" />
|
||||
</materialDesign:Card>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Core.Services.Storage.Interfaces;
|
||||
using SkiaSharp;
|
||||
using SkiaSharp.Views.WPF;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.Settings.Debug.Tabs
|
||||
{
|
||||
public class RenderDebugViewModel : Screen
|
||||
{
|
||||
private readonly ICoreService _coreService;
|
||||
private readonly IRgbService _rgbService;
|
||||
private readonly ISurfaceService _surfaceService;
|
||||
|
||||
public RenderDebugViewModel(ICoreService coreService, IRgbService rgbService, ISurfaceService surfaceService)
|
||||
{
|
||||
_coreService = coreService;
|
||||
_rgbService = rgbService;
|
||||
_surfaceService = surfaceService;
|
||||
|
||||
DisplayName = "Rendering";
|
||||
}
|
||||
|
||||
public ImageSource CurrentFrame { get; set; }
|
||||
public double CurrentFps { get; set; }
|
||||
|
||||
protected override void OnActivate()
|
||||
{
|
||||
_coreService.FrameRendered += CoreServiceOnFrameRendered;
|
||||
_coreService.FrameRendering += CoreServiceOnFrameRendering;
|
||||
base.OnActivate();
|
||||
}
|
||||
|
||||
protected override void OnDeactivate()
|
||||
{
|
||||
_coreService.FrameRendered -= CoreServiceOnFrameRendered;
|
||||
_coreService.FrameRendering -= CoreServiceOnFrameRendering;
|
||||
base.OnDeactivate();
|
||||
}
|
||||
|
||||
private void CoreServiceOnFrameRendered(object sender, FrameRenderedEventArgs e)
|
||||
{
|
||||
Execute.PostToUIThread(() =>
|
||||
{
|
||||
if (e.BitmapBrush?.Bitmap == null)
|
||||
return;
|
||||
|
||||
if (!(CurrentFrame is WriteableBitmap writeableBitmap))
|
||||
{
|
||||
CurrentFrame = e.BitmapBrush.Bitmap.ToWriteableBitmap();
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (var skiaImage = SKImage.FromPixels(e.BitmapBrush.Bitmap.PeekPixels()))
|
||||
{
|
||||
var info = new SKImageInfo(skiaImage.Width, skiaImage.Height);
|
||||
writeableBitmap.Lock();
|
||||
using (var pixmap = new SKPixmap(info, writeableBitmap.BackBuffer, writeableBitmap.BackBufferStride))
|
||||
{
|
||||
skiaImage.ReadPixels(pixmap, 0, 0);
|
||||
}
|
||||
|
||||
writeableBitmap.AddDirtyRect(new Int32Rect(0, 0, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight));
|
||||
writeableBitmap.Unlock();
|
||||
}
|
||||
}
|
||||
catch (AccessViolationException)
|
||||
{
|
||||
// oops
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void CoreServiceOnFrameRendering(object sender, FrameRenderingEventArgs e)
|
||||
{
|
||||
CurrentFps = Math.Round(1.0 / e.DeltaTime, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -46,15 +46,19 @@
|
||||
<materialDesign:PackIcon Kind="{Binding Icon}" Width="48" Height="48" Grid.Row="0" Grid.RowSpan="2" HorizontalAlignment="Center" />
|
||||
|
||||
<TextBlock Grid.Column="1" Grid.Row="0" Style="{StaticResource MaterialDesignTextBlock}" Text="{Binding PluginInfo.Name}" />
|
||||
<materialDesign:Card Grid.Column="2" Grid.Row="0"
|
||||
Background="#FF4343"
|
||||
Foreground="White"
|
||||
Height="22"
|
||||
Padding="4"
|
||||
Margin="0 -18 0 0"
|
||||
Visibility="{Binding DisplayLoadFailed, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}">
|
||||
LOAD FAILED
|
||||
</materialDesign:Card>
|
||||
<Button Grid.Column="2" Grid.Row="0"
|
||||
Background="#FF4343"
|
||||
BorderBrush="#FF7474"
|
||||
Foreground="White"
|
||||
Height="22"
|
||||
Padding="4"
|
||||
Margin="0 -18 0 0"
|
||||
Visibility="{Binding DisplayLoadFailed, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}"
|
||||
Style="{StaticResource MaterialDesignRaisedButton}"
|
||||
ToolTip="Click to see the full error that occured"
|
||||
Command="{s:Action ShowLoadException}">
|
||||
<TextBlock FontSize="11">LOAD FAILED</TextBlock>
|
||||
</Button>
|
||||
|
||||
<TextBlock Grid.Column="1"
|
||||
Grid.Row="1"
|
||||
@ -66,7 +70,7 @@
|
||||
</Grid>
|
||||
|
||||
<StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal">
|
||||
<Button Style="{StaticResource MaterialDesignOutlinedButton}" ToolTip="MaterialDesignOutlinedButton" Margin="4" s:View.ActionTarget="{Binding}" Command="{s:Action OpenSettings}">
|
||||
<Button Style="{StaticResource MaterialDesignOutlinedButton}" ToolTip="MaterialDesignOutlinedButton" Margin="4" Command="{s:Action OpenSettings}">
|
||||
SETTINGS
|
||||
</Button>
|
||||
</StackPanel>
|
||||
|
||||
@ -32,23 +32,18 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
|
||||
public Plugin Plugin { get; set; }
|
||||
public PluginInfo PluginInfo { get; set; }
|
||||
|
||||
public string Type => Plugin.GetType().BaseType?.Name ?? Plugin.GetType().Name;
|
||||
|
||||
public bool Enabling { get; set; }
|
||||
public PackIconKind Icon => GetIconKind();
|
||||
public string Type => Plugin.GetType().BaseType?.Name ?? Plugin.GetType().Name;
|
||||
public bool CanOpenSettings => IsEnabled && Plugin.HasConfigurationViewModel;
|
||||
public bool DisplayLoadFailed => !Enabling && PluginInfo.LoadException != null;
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get => PluginInfo.Enabled;
|
||||
get => Plugin.Enabled;
|
||||
set => Task.Run(() => UpdateEnabled(value));
|
||||
}
|
||||
|
||||
public bool CanOpenSettings => IsEnabled && Plugin.HasConfigurationViewModel;
|
||||
|
||||
public bool Enabling { get; set; }
|
||||
|
||||
public bool DisplayLoadFailed => !Enabling && !PluginInfo.LastEnableSuccessful;
|
||||
|
||||
public async Task OpenSettings()
|
||||
{
|
||||
try
|
||||
@ -76,6 +71,14 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
}
|
||||
}
|
||||
|
||||
public async Task ShowLoadException()
|
||||
{
|
||||
if (PluginInfo.LoadException == null)
|
||||
return;
|
||||
|
||||
await _dialogService.ShowExceptionDialog("The plugin failed to load: " + PluginInfo.LoadException.Message, PluginInfo.LoadException);
|
||||
}
|
||||
|
||||
private PackIconKind GetIconKind()
|
||||
{
|
||||
if (PluginInfo.Icon != null)
|
||||
@ -106,7 +109,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
|
||||
private async Task UpdateEnabled(bool enable)
|
||||
{
|
||||
if (PluginInfo.Enabled == enable)
|
||||
if (Plugin.Enabled == enable)
|
||||
{
|
||||
NotifyOfPropertyChange(nameof(IsEnabled));
|
||||
return;
|
||||
@ -133,7 +136,6 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
||||
try
|
||||
{
|
||||
_pluginService.EnablePlugin(Plugin);
|
||||
_snackbarMessageQueue.Enqueue($"Enabled plugin {PluginInfo.Name}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@ -17,7 +17,7 @@ namespace Artemis.UI.Services
|
||||
{
|
||||
var viewModel = new DataModelViewModel();
|
||||
foreach (var dataModelExpansion in _dataModelService.DataModelExpansions)
|
||||
viewModel.Children.Add(new DataModelViewModel(dataModelExpansion, dataModelExpansion.DataModelDescription, viewModel));
|
||||
viewModel.Children.Add(new DataModelViewModel(null,dataModelExpansion, dataModelExpansion.DataModelDescription, viewModel));
|
||||
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
@ -1,10 +1,16 @@
|
||||
using Artemis.Core.Plugins.Abstract.DataModels;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Plugins.Modules.General
|
||||
{
|
||||
public class GeneralDataModel : DataModel
|
||||
{
|
||||
public GeneralDataModel()
|
||||
{
|
||||
PlayerInfo = new PlayerInfo();
|
||||
}
|
||||
|
||||
[DataModelProperty(Name = "A test string", Description = "This is a test string that's not of any use outside testing!")]
|
||||
public string TestString { get; set; }
|
||||
|
||||
@ -13,6 +19,8 @@ namespace Artemis.Plugins.Modules.General
|
||||
|
||||
[DataModelProperty(Name = "Player info", Description = "[TEST] Contains information about the player")]
|
||||
public PlayerInfo PlayerInfo { get; set; }
|
||||
|
||||
public double UpdatesDividedByFour { get; set; }
|
||||
}
|
||||
|
||||
public class PlayerInfo : DataModel
|
||||
@ -22,5 +30,7 @@ namespace Artemis.Plugins.Modules.General
|
||||
|
||||
[DataModelProperty(Name = "A test boolean", Description = "This is a test boolean that's not of any use outside testing!")]
|
||||
public bool TestBoolean { get; set; }
|
||||
|
||||
public SKPoint Position { get; set; }
|
||||
}
|
||||
}
|
||||
@ -5,16 +5,19 @@ using Artemis.Core.Plugins.Abstract.DataModels;
|
||||
using Artemis.Core.Plugins.Abstract.ViewModels;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Plugins.Modules.General.ViewModels;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Plugins.Modules.General
|
||||
{
|
||||
public class GeneralModule : ProfileModule<GeneralDataModel>
|
||||
{
|
||||
private readonly PluginSettings _settings;
|
||||
private Random _rand;
|
||||
|
||||
public GeneralModule(PluginSettings settings)
|
||||
{
|
||||
_settings = settings;
|
||||
_rand = new Random();
|
||||
}
|
||||
|
||||
public override IEnumerable<ModuleViewModel> GetViewModels()
|
||||
@ -22,6 +25,12 @@ namespace Artemis.Plugins.Modules.General
|
||||
return new List<ModuleViewModel> {new GeneralViewModel(this)};
|
||||
}
|
||||
|
||||
public override void Update(double deltaTime)
|
||||
{
|
||||
DataModel.UpdatesDividedByFour += 0.25;
|
||||
DataModel.PlayerInfo.Position = new SKPoint(_rand.Next(100), _rand.Next(100));
|
||||
}
|
||||
|
||||
public override void EnablePlugin()
|
||||
{
|
||||
DisplayName = "General";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user