From 2106b44f85a608feb249debd811c007b8d82826c Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Thu, 22 Dec 2016 17:54:52 +0100 Subject: [PATCH] Using my repo as if it's dropbox heh --- Artemis/Artemis/Artemis.csproj | 17 ++-- .../Profiles/Lua/LuaKeyboardWrapper.cs | 51 ------------ Artemis/Artemis/Profiles/Lua/LuaWrapper.cs | 78 ++++++++++--------- .../Events/LuaDeviceDrawingEventArgs.cs | 8 +- .../Events/LuaDeviceUpdatingEventArgs.cs | 2 +- .../Events/LuaEventsModule.cs} | 27 +++++-- .../Events/LuaKeyPressEventArgs.cs | 2 +- .../Profiles/Lua/Modules/ILuaModule.cs | 10 --- .../Profiles/Lua/Modules/LuaKeyboardModule.cs | 42 +++++----- .../LuaLayerModule.cs} | 25 +++--- .../Artemis/Profiles/Lua/Modules/LuaModule.cs | 30 +++++++ .../LuaProfileModule.cs} | 23 +++--- .../LuaDrawWrapper.cs} | 20 ++--- 13 files changed, 166 insertions(+), 169 deletions(-) delete mode 100644 Artemis/Artemis/Profiles/Lua/LuaKeyboardWrapper.cs rename Artemis/Artemis/Profiles/Lua/{ => Modules}/Events/LuaDeviceDrawingEventArgs.cs (72%) rename Artemis/Artemis/Profiles/Lua/{ => Modules}/Events/LuaDeviceUpdatingEventArgs.cs (91%) rename Artemis/Artemis/Profiles/Lua/{Events/LuaEventsWrapper.cs => Modules/Events/LuaEventsModule.cs} (85%) rename Artemis/Artemis/Profiles/Lua/{ => Modules}/Events/LuaKeyPressEventArgs.cs (90%) delete mode 100644 Artemis/Artemis/Profiles/Lua/Modules/ILuaModule.cs rename Artemis/Artemis/Profiles/Lua/{LuaLayerWrapper.cs => Modules/LuaLayerModule.cs} (90%) create mode 100644 Artemis/Artemis/Profiles/Lua/Modules/LuaModule.cs rename Artemis/Artemis/Profiles/Lua/{LuaProfileWrapper.cs => Modules/LuaProfileModule.cs} (64%) rename Artemis/Artemis/Profiles/Lua/{Modules/LuaDrawModule.cs => Wrappers/LuaDrawWrapper.cs} (83%) diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 756557d09..cc1b55ec7 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -508,19 +508,18 @@ - - - + + + - - - - - + + - + + + diff --git a/Artemis/Artemis/Profiles/Lua/LuaKeyboardWrapper.cs b/Artemis/Artemis/Profiles/Lua/LuaKeyboardWrapper.cs deleted file mode 100644 index 136370d2d..000000000 --- a/Artemis/Artemis/Profiles/Lua/LuaKeyboardWrapper.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Windows.Forms; -using Artemis.DeviceProviders; -using Artemis.Utilities.Keyboard; -using MoonSharp.Interpreter; -using MoonSharp.Interpreter.Interop; - -namespace Artemis.Profiles.Lua -{ - [MoonSharpUserData] - public class LuaKeyboardWrapper : IDisposable - { - private readonly KeyboardProvider _keyboardProvider; - - public LuaKeyboardWrapper(KeyboardProvider keyboardProvider) - { - _keyboardProvider = keyboardProvider; - - KeyboardHook.KeyDownCallback += KeyboardHookOnKeyDownCallback; - } - - public string Name => _keyboardProvider.Name; - public string Slug => _keyboardProvider.Slug; - public int Width => _keyboardProvider.Width; - public int Height => _keyboardProvider.Height; - - [MoonSharpVisible(false)] - public void Dispose() - { - KeyboardHook.KeyDownCallback -= KeyboardHookOnKeyDownCallback; - } - - private void KeyboardHookOnKeyDownCallback(KeyEventArgs e) - { - var keyMatch = _keyboardProvider.GetKeyPosition(e.KeyCode); - if (keyMatch != null) - LuaWrapper.LuaEventsWrapper.InvokeKeyPressed(LuaWrapper.ProfileModel, this, keyMatch.Value.KeyCode, - keyMatch.Value.X, keyMatch.Value.Y); - } - - public void PressKeys(string keys) - { - SendKeys.SendWait(keys); - } - - public void GetKeyPosition(Keys key) - { - _keyboardProvider.GetKeyPosition(key); - } - } -} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Lua/LuaWrapper.cs b/Artemis/Artemis/Profiles/Lua/LuaWrapper.cs index 5b221e6cf..0f9a94e3c 100644 --- a/Artemis/Artemis/Profiles/Lua/LuaWrapper.cs +++ b/Artemis/Artemis/Profiles/Lua/LuaWrapper.cs @@ -3,28 +3,36 @@ using System.IO; using System.Text; using Artemis.DAL; using Artemis.DeviceProviders; +using Artemis.Profiles.Layers.Models; using Artemis.Profiles.Lua.Brushes; -using Artemis.Profiles.Lua.Events; +using Artemis.Profiles.Lua.Modules.Events; using Artemis.Properties; using Castle.Core.Internal; using MoonSharp.Interpreter; +using Ninject; using NLog; namespace Artemis.Profiles.Lua { - public static class LuaWrapper + /// + /// This class is a singleton due to the fact that the LuaScript isn't very memory + /// friendly when creating new ones over and over. + /// + public class LuaWrapper { - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - private static readonly Script LuaScript = new Script(CoreModules.Preset_SoftSandbox); - private static FileSystemWatcher _watcher; + private readonly IKernel _kernel; + private readonly Logger _logger = LogManager.GetCurrentClassLogger(); + private readonly Script _luaScript = new Script(CoreModules.Preset_SoftSandbox); + private FileSystemWatcher _watcher; - public static ProfileModel ProfileModel { get; private set; } - public static KeyboardProvider KeyboardProvider { get; private set; } - public static LuaProfileWrapper LuaProfileWrapper { get; private set; } - public static LuaBrushWrapper LuaBrushWrapper { get; private set; } - public static LuaKeyboardWrapper LuaKeyboardWrapper { get; private set; } - public static LuaMouseWrapper LuaMouseWrapper { get; set; } - public static LuaEventsWrapper LuaEventsWrapper { get; private set; } + public ProfileModel ProfileModel { get; private set; } + public KeyboardProvider KeyboardProvider { get; private set; } + public LayerModel LayerModel { get; set; } + + public LuaWrapper(IKernel kernel) + { + _kernel = kernel; + } public static void SetupLua(ProfileModel profileModel, KeyboardProvider keyboardProvider) { @@ -42,12 +50,12 @@ namespace Artemis.Profiles.Lua LuaMouseWrapper = new LuaMouseWrapper(); LuaEventsWrapper = new LuaEventsWrapper(); - LuaScript.Options.DebugPrint = LuaPrint; - LuaScript.Globals["Profile"] = LuaProfileWrapper; - LuaScript.Globals["Events"] = LuaEventsWrapper; - LuaScript.Globals["Brushes"] = LuaBrushWrapper; - LuaScript.Globals["Keyboard"] = LuaKeyboardWrapper; - LuaScript.Globals["Mouse"] = LuaMouseWrapper; + _luaScript.Options.DebugPrint = LuaPrint; + _luaScript.Globals["Profile"] = LuaProfileWrapper; + _luaScript.Globals["Events"] = LuaEventsWrapper; + _luaScript.Globals["Brushes"] = LuaBrushWrapper; + _luaScript.Globals["Keyboard"] = LuaKeyboardWrapper; + _luaScript.Globals["Mouse"] = LuaMouseWrapper; if (ProfileModel == null) return; @@ -58,29 +66,29 @@ namespace Artemis.Profiles.Lua { lock (LuaEventsWrapper.InvokeLock) { - lock (LuaScript) + lock (_luaScript) { - LuaScript.DoString(ProfileModel.LuaScript); + _luaScript.DoString(ProfileModel.LuaScript); } } } catch (InternalErrorException e) { - Logger.Error(e, "[{0}-LUA]: Error: {1}", ProfileModel.Name, e.DecoratedMessage); + _logger.Error(e, "[{0}-LUA]: Error: {1}", ProfileModel.Name, e.DecoratedMessage); } catch (SyntaxErrorException e) { - Logger.Error(e, "[{0}-LUA]: Error: {1}", ProfileModel.Name, e.DecoratedMessage); + _logger.Error(e, "[{0}-LUA]: Error: {1}", ProfileModel.Name, e.DecoratedMessage); } catch (ScriptRuntimeException e) { - Logger.Error(e, "[{0}-LUA]: Error: {1}", ProfileModel.Name, e.DecoratedMessage); + _logger.Error(e, "[{0}-LUA]: Error: {1}", ProfileModel.Name, e.DecoratedMessage); } } public static void Clear() { - lock (LuaScript) + lock (_luaScript) { // Clear old fields/properties KeyboardProvider = null; @@ -93,12 +101,12 @@ namespace Artemis.Profiles.Lua try { - LuaScript.Globals.Clear(); - LuaScript.Registry.Clear(); - LuaScript.Registry.RegisterConstants(); - LuaScript.Registry.RegisterCoreModules(CoreModules.Preset_SoftSandbox); - LuaScript.Globals.RegisterConstants(); - LuaScript.Globals.RegisterCoreModules(CoreModules.Preset_SoftSandbox); + _luaScript.Globals.Clear(); + _luaScript.Registry.Clear(); + _luaScript.Registry.RegisterConstants(); + _luaScript.Registry.RegisterCoreModules(CoreModules.Preset_SoftSandbox); + _luaScript.Globals.RegisterConstants(); + _luaScript.Globals.RegisterCoreModules(CoreModules.Preset_SoftSandbox); } catch (NullReferenceException) { @@ -109,17 +117,17 @@ namespace Artemis.Profiles.Lua { lock (LuaEventsWrapper.InvokeLock) { - lock (LuaScript) + lock (_luaScript) { - LuaScript.DoString(""); + _luaScript.DoString(""); } } } else { - lock (LuaScript) + lock (_luaScript) { - LuaScript.DoString(""); + _luaScript.DoString(""); } } @@ -132,7 +140,7 @@ namespace Artemis.Profiles.Lua private static void LuaPrint(string s) { - Logger.Debug("[{0}-LUA]: {1}", ProfileModel?.Name, s); + _logger.Debug("[{0}-LUA]: {1}", ProfileModel?.Name, s); } #endregion diff --git a/Artemis/Artemis/Profiles/Lua/Events/LuaDeviceDrawingEventArgs.cs b/Artemis/Artemis/Profiles/Lua/Modules/Events/LuaDeviceDrawingEventArgs.cs similarity index 72% rename from Artemis/Artemis/Profiles/Lua/Events/LuaDeviceDrawingEventArgs.cs rename to Artemis/Artemis/Profiles/Lua/Modules/Events/LuaDeviceDrawingEventArgs.cs index 8b07b3f07..7f12c88b5 100644 --- a/Artemis/Artemis/Profiles/Lua/Events/LuaDeviceDrawingEventArgs.cs +++ b/Artemis/Artemis/Profiles/Lua/Modules/Events/LuaDeviceDrawingEventArgs.cs @@ -1,14 +1,14 @@ using System; using Artemis.Models.Interfaces; -using Artemis.Profiles.Lua.Modules; +using Artemis.Profiles.Lua.Wrappers; using MoonSharp.Interpreter; -namespace Artemis.Profiles.Lua.Events +namespace Artemis.Profiles.Lua.Modules.Events { [MoonSharpUserData] public class LuaDeviceDrawingEventArgs : EventArgs { - public LuaDeviceDrawingEventArgs(string deviceType, IDataModel dataModel, bool preview, LuaDrawModule luaDrawWrapper) + public LuaDeviceDrawingEventArgs(string deviceType, IDataModel dataModel, bool preview, LuaDrawWrapper luaDrawWrapper) { DeviceType = deviceType; DataModel = dataModel; @@ -19,6 +19,6 @@ namespace Artemis.Profiles.Lua.Events public string DeviceType { get; set; } public IDataModel DataModel { get; } public bool Preview { get; } - public LuaDrawModule Drawing { get; set; } + public LuaDrawWrapper Drawing { get; set; } } } \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Lua/Events/LuaDeviceUpdatingEventArgs.cs b/Artemis/Artemis/Profiles/Lua/Modules/Events/LuaDeviceUpdatingEventArgs.cs similarity index 91% rename from Artemis/Artemis/Profiles/Lua/Events/LuaDeviceUpdatingEventArgs.cs rename to Artemis/Artemis/Profiles/Lua/Modules/Events/LuaDeviceUpdatingEventArgs.cs index 1b9c3b256..58945694f 100644 --- a/Artemis/Artemis/Profiles/Lua/Events/LuaDeviceUpdatingEventArgs.cs +++ b/Artemis/Artemis/Profiles/Lua/Modules/Events/LuaDeviceUpdatingEventArgs.cs @@ -2,7 +2,7 @@ using Artemis.Models.Interfaces; using MoonSharp.Interpreter; -namespace Artemis.Profiles.Lua.Events +namespace Artemis.Profiles.Lua.Modules.Events { [MoonSharpUserData] public class LuaDeviceUpdatingEventArgs : EventArgs diff --git a/Artemis/Artemis/Profiles/Lua/Events/LuaEventsWrapper.cs b/Artemis/Artemis/Profiles/Lua/Modules/Events/LuaEventsModule.cs similarity index 85% rename from Artemis/Artemis/Profiles/Lua/Events/LuaEventsWrapper.cs rename to Artemis/Artemis/Profiles/Lua/Modules/Events/LuaEventsModule.cs index c46d16205..8f25d2c46 100644 --- a/Artemis/Artemis/Profiles/Lua/Events/LuaEventsWrapper.cs +++ b/Artemis/Artemis/Profiles/Lua/Modules/Events/LuaEventsModule.cs @@ -2,17 +2,22 @@ using System.Windows.Forms; using System.Windows.Media; using Artemis.Models.Interfaces; -using Artemis.Profiles.Lua.Modules; +using Artemis.Profiles.Lua.Wrappers; using MoonSharp.Interpreter; using NLog; -namespace Artemis.Profiles.Lua.Events +namespace Artemis.Profiles.Lua.Modules.Events { - [MoonSharpUserData] - public class LuaEventsWrapper + public class LuaEventsModule : LuaModule { private readonly Logger _logger = LogManager.GetCurrentClassLogger(); public readonly string InvokeLock = string.Empty; + + public LuaEventsModule(LuaWrapper luaWrapper) : base(luaWrapper) + { + } + + public override string ModuleName => "Events"; public event EventHandler DeviceUpdating; public event EventHandler DeviceDrawing; public event EventHandler KeyboardKeyPressed; @@ -37,7 +42,7 @@ namespace Artemis.Profiles.Lua.Events try { LuaInvoke(profileModel, () => OnDeviceDrawing(new LuaProfileWrapper(profileModel), - new LuaDeviceDrawingEventArgs(deviceType, dataModel, preview, new LuaDrawModule(c)))); + new LuaDeviceDrawingEventArgs(deviceType, dataModel, preview, new LuaDrawWrapper(c)))); } catch (Exception) { @@ -45,7 +50,7 @@ namespace Artemis.Profiles.Lua.Events } } - internal void InvokeKeyPressed(ProfileModel profileModel, LuaKeyboardWrapper keyboard, Keys key, int x, int y) + internal void InvokeKeyPressed(ProfileModel profileModel, LuaKeyboardModule keyboard, Keys key, int x, int y) { try { @@ -91,10 +96,18 @@ namespace Artemis.Profiles.Lua.Events DeviceDrawing?.Invoke(profileModel, e); } - protected virtual void OnKeyboardKeyPressed(LuaProfileWrapper profileModel, LuaKeyboardWrapper keyboard, + protected virtual void OnKeyboardKeyPressed(LuaProfileWrapper profileModel, LuaKeyboardModule keyboard, LuaKeyPressEventArgs e) { KeyboardKeyPressed?.Invoke(profileModel, e); } + + #region Overriding members + + public override void Dispose() + { + } + + #endregion } } \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Lua/Events/LuaKeyPressEventArgs.cs b/Artemis/Artemis/Profiles/Lua/Modules/Events/LuaKeyPressEventArgs.cs similarity index 90% rename from Artemis/Artemis/Profiles/Lua/Events/LuaKeyPressEventArgs.cs rename to Artemis/Artemis/Profiles/Lua/Modules/Events/LuaKeyPressEventArgs.cs index 9b595fb3b..a932b5180 100644 --- a/Artemis/Artemis/Profiles/Lua/Events/LuaKeyPressEventArgs.cs +++ b/Artemis/Artemis/Profiles/Lua/Modules/Events/LuaKeyPressEventArgs.cs @@ -2,7 +2,7 @@ using System.Windows.Forms; using MoonSharp.Interpreter; -namespace Artemis.Profiles.Lua.Events +namespace Artemis.Profiles.Lua.Modules.Events { [MoonSharpUserData] public class LuaKeyPressEventArgs : EventArgs diff --git a/Artemis/Artemis/Profiles/Lua/Modules/ILuaModule.cs b/Artemis/Artemis/Profiles/Lua/Modules/ILuaModule.cs deleted file mode 100644 index ae57bc35d..000000000 --- a/Artemis/Artemis/Profiles/Lua/Modules/ILuaModule.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; - -namespace Artemis.Profiles.Lua.Modules -{ - public interface ILuaModule : IDisposable - { - bool AlwaysPresent { get; } - string ModuleName { get; } - } -} diff --git a/Artemis/Artemis/Profiles/Lua/Modules/LuaKeyboardModule.cs b/Artemis/Artemis/Profiles/Lua/Modules/LuaKeyboardModule.cs index 59e834c04..7a2f29b7c 100644 --- a/Artemis/Artemis/Profiles/Lua/Modules/LuaKeyboardModule.cs +++ b/Artemis/Artemis/Profiles/Lua/Modules/LuaKeyboardModule.cs @@ -1,45 +1,45 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; +using System.Windows.Forms; using Artemis.DeviceProviders; -using MoonSharp.Interpreter.Interop; +using Artemis.Utilities.Keyboard; +using MoonSharp.Interpreter; namespace Artemis.Profiles.Lua.Modules { - public class LuaKeyboardModule : ILuaModule + [MoonSharpUserData] + public class LuaKeyboardModule : LuaModule { - public bool AlwaysPresent => true; - public string ModuleName => "Keyboard"; - private readonly KeyboardProvider _keyboardProvider; - public LuaKeyboardModule(KeyboardProvider keyboardProvider) + public LuaKeyboardModule(LuaWrapper luaWrapper) : base(luaWrapper) { - _keyboardProvider = keyboardProvider; - + _keyboardProvider = luaWrapper.KeyboardProvider; KeyboardHook.KeyDownCallback += KeyboardHookOnKeyDownCallback; } + // TODO: Visible in LUA? Decladed as invisile in base class + public override string ModuleName => "Keyboard"; + public string Name => _keyboardProvider.Name; public string Slug => _keyboardProvider.Slug; public int Width => _keyboardProvider.Width; public int Height => _keyboardProvider.Height; - [MoonSharpVisible(false)] - public void Dispose() + #region Overriding members + + public override void Dispose() { KeyboardHook.KeyDownCallback -= KeyboardHookOnKeyDownCallback; } + #endregion + private void KeyboardHookOnKeyDownCallback(KeyEventArgs e) { - var keyMatch = _keyboardProvider.GetKeyPosition(e.KeyCode); - if (keyMatch != null) - LuaWrapper.LuaEventsWrapper.InvokeKeyPressed(LuaWrapper.ProfileModel, this, keyMatch.Value.KeyCode, - keyMatch.Value.X, keyMatch.Value.Y); + // TODO + //var keyMatch = _keyboardProvider.GetKeyPosition(e.KeyCode); + //if (keyMatch != null) + // LuaWrapper.LuaEventsWrapper.InvokeKeyPressed(LuaWrapper.ProfileModel, this, keyMatch.Value.KeyCode, + // keyMatch.Value.X, keyMatch.Value.Y); } public void PressKeys(string keys) @@ -52,4 +52,4 @@ namespace Artemis.Profiles.Lua.Modules _keyboardProvider.GetKeyPosition(key); } } -} +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Lua/LuaLayerWrapper.cs b/Artemis/Artemis/Profiles/Lua/Modules/LuaLayerModule.cs similarity index 90% rename from Artemis/Artemis/Profiles/Lua/LuaLayerWrapper.cs rename to Artemis/Artemis/Profiles/Lua/Modules/LuaLayerModule.cs index f9d9dffc5..d95c2a615 100644 --- a/Artemis/Artemis/Profiles/Lua/LuaLayerWrapper.cs +++ b/Artemis/Artemis/Profiles/Lua/Modules/LuaLayerModule.cs @@ -6,25 +6,32 @@ using Artemis.Profiles.Layers.Models; using Artemis.Profiles.Lua.Brushes; using MoonSharp.Interpreter; -namespace Artemis.Profiles.Lua +namespace Artemis.Profiles.Lua.Modules { - /// - /// Serves as a sandboxed wrapper around the LayerModel - /// [MoonSharpUserData] - public class LuaLayerWrapper + public class LuaLayerModule : LuaModule { private readonly LayerModel _layerModel; - public LuaLayerWrapper(LayerModel layerModel) + public LuaLayerModule(LuaWrapper luaWrapper) : base(luaWrapper) { - _layerModel = layerModel; - SavedProperties = new LuaLayerProperties(layerModel); + _layerModel = luaWrapper.LayerModel; + SavedProperties = new Lua.LuaLayerProperties(_layerModel); // Triger an update to fill up the Properties _layerModel.Update(new ProfilePreviewDataModel(), true, false); } + public override string ModuleName => "Layer"; + + #region Overriding members + + public override void Dispose() + { + } + + #endregion + #region Child methods public List GetChildren() @@ -106,7 +113,7 @@ namespace Artemis.Profiles.Lua #region Advanced layer properties - public LuaLayerProperties SavedProperties { get; set; } + public Lua.LuaLayerProperties SavedProperties { get; set; } public string BrushType => _layerModel.Properties.Brush?.GetType().Name; diff --git a/Artemis/Artemis/Profiles/Lua/Modules/LuaModule.cs b/Artemis/Artemis/Profiles/Lua/Modules/LuaModule.cs new file mode 100644 index 000000000..68841aa77 --- /dev/null +++ b/Artemis/Artemis/Profiles/Lua/Modules/LuaModule.cs @@ -0,0 +1,30 @@ +using System; +using MoonSharp.Interpreter; +using MoonSharp.Interpreter.Interop; + +namespace Artemis.Profiles.Lua.Modules +{ + /// + /// Defines a module which will be accessable in all LUA scripts. + /// + [MoonSharpUserData] + public abstract class LuaModule : IDisposable + { + public LuaModule(LuaWrapper luaWrapper) + { + LuaWrapper = luaWrapper; + } + + /// + /// The name under which this module will be accessable in LUA + /// + [MoonSharpVisible(false)] + public abstract string ModuleName { get; } + + [MoonSharpVisible(false)] + public LuaWrapper LuaWrapper { get; set; } + + [MoonSharpVisible(false)] + public abstract void Dispose(); + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Profiles/Lua/LuaProfileWrapper.cs b/Artemis/Artemis/Profiles/Lua/Modules/LuaProfileModule.cs similarity index 64% rename from Artemis/Artemis/Profiles/Lua/LuaProfileWrapper.cs rename to Artemis/Artemis/Profiles/Lua/Modules/LuaProfileModule.cs index 512cd49ea..f3a1b5617 100644 --- a/Artemis/Artemis/Profiles/Lua/LuaProfileWrapper.cs +++ b/Artemis/Artemis/Profiles/Lua/Modules/LuaProfileModule.cs @@ -1,28 +1,33 @@ using System.Collections.Generic; using System.Linq; -using MoonSharp.Interpreter; -namespace Artemis.Profiles.Lua +namespace Artemis.Profiles.Lua.Modules { - /// - /// Serves as a sandboxed wrapper around the ProfileModel - /// - [MoonSharpUserData] - public class LuaProfileWrapper + public class LuaProfileModule : LuaModule { private readonly ProfileModel _profileModel; - public LuaProfileWrapper(ProfileModel profileModel) + public LuaProfileModule(LuaWrapper luaWrapper) : base(luaWrapper) { - _profileModel = profileModel; + _profileModel = luaWrapper.ProfileModel; } + public override string ModuleName => "Profile"; + #region General profile properties public string Name => _profileModel.Name; #endregion + #region Overriding members + + public override void Dispose() + { + } + + #endregion + #region Layer methods public List GetLayers() diff --git a/Artemis/Artemis/Profiles/Lua/Modules/LuaDrawModule.cs b/Artemis/Artemis/Profiles/Lua/Wrappers/LuaDrawWrapper.cs similarity index 83% rename from Artemis/Artemis/Profiles/Lua/Modules/LuaDrawModule.cs rename to Artemis/Artemis/Profiles/Lua/Wrappers/LuaDrawWrapper.cs index cf6a48bde..7fefa6300 100644 --- a/Artemis/Artemis/Profiles/Lua/Modules/LuaDrawModule.cs +++ b/Artemis/Artemis/Profiles/Lua/Wrappers/LuaDrawWrapper.cs @@ -5,27 +5,23 @@ using System.Windows.Media; using Artemis.Profiles.Lua.Brushes; using MoonSharp.Interpreter; -namespace Artemis.Profiles.Lua.Modules +namespace Artemis.Profiles.Lua.Wrappers { + /// + /// A wrapper that is provided to each OnDraw event to allow drawing in LUA + /// [MoonSharpUserData] - public class LuaDrawModule : ILuaModule + public class LuaDrawWrapper { private readonly DrawingContext _ctx; private readonly FontFamily _font; - public LuaDrawModule(DrawingContext ctx) + public LuaDrawWrapper(DrawingContext ctx) { _ctx = ctx; _font = new FontFamily(new Uri("pack://application:,,,/"), "./resources/#Silkscreen"); } - public bool AlwaysPresent => false; - public string ModuleName => null; - - public void Dispose() - { - } - public void DrawEllipse(LuaBrush luaBrush, double x, double y, double height, double width) { x *= 4; @@ -33,7 +29,7 @@ namespace Artemis.Profiles.Lua.Modules height *= 4; width *= 4; - var center = new Point(x + width/2, y + height/2); + var center = new Point(x + width / 2, y + height / 2); _ctx.DrawEllipse(luaBrush.Brush, new Pen(), center, width, height); } @@ -70,7 +66,7 @@ namespace Artemis.Profiles.Lua.Modules fontSize, luaBrush.Brush); _ctx.DrawText(formatted, new Point(x, y)); - return formatted.Width/4; + return formatted.Width / 4; } } } \ No newline at end of file