mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-01-02 10:43:31 +00:00
Using my repo as if it's dropbox heh
This commit is contained in:
parent
f1714c1262
commit
2106b44f85
@ -508,19 +508,18 @@
|
|||||||
<Compile Include="Profiles\Lua\Brushes\LuaColor.cs" />
|
<Compile Include="Profiles\Lua\Brushes\LuaColor.cs" />
|
||||||
<Compile Include="Profiles\Lua\Brushes\LuaLinearGradientBrush.cs" />
|
<Compile Include="Profiles\Lua\Brushes\LuaLinearGradientBrush.cs" />
|
||||||
<Compile Include="Profiles\Lua\Brushes\LuaRadialGradientBrush.cs" />
|
<Compile Include="Profiles\Lua\Brushes\LuaRadialGradientBrush.cs" />
|
||||||
<Compile Include="Profiles\Lua\Events\LuaKeyPressEventArgs.cs" />
|
<Compile Include="Profiles\Lua\Modules\Events\LuaKeyPressEventArgs.cs" />
|
||||||
<Compile Include="Profiles\Lua\Events\LuaDeviceDrawingEventArgs.cs" />
|
<Compile Include="Profiles\Lua\Modules\Events\LuaDeviceDrawingEventArgs.cs" />
|
||||||
<Compile Include="Profiles\Lua\Events\LuaDeviceUpdatingEventArgs.cs" />
|
<Compile Include="Profiles\Lua\Modules\Events\LuaDeviceUpdatingEventArgs.cs" />
|
||||||
<Compile Include="Profiles\Lua\Brushes\LuaBrushWrapper.cs" />
|
<Compile Include="Profiles\Lua\Brushes\LuaBrushWrapper.cs" />
|
||||||
<Compile Include="Profiles\Lua\Modules\ILuaModule.cs" />
|
<Compile Include="Profiles\Lua\Modules\Events\LuaEventsModule.cs" />
|
||||||
<Compile Include="Profiles\Lua\Events\LuaEventsWrapper.cs" />
|
<Compile Include="Profiles\Lua\Modules\LuaModule.cs" />
|
||||||
<Compile Include="Profiles\Lua\LuaKeyboardWrapper.cs" />
|
|
||||||
<Compile Include="Profiles\Lua\LuaLayerWrapper.cs" />
|
|
||||||
<Compile Include="Profiles\Lua\LuaProfileWrapper.cs" />
|
|
||||||
<Compile Include="Profiles\Lua\Brushes\LuaSolidColorBrush.cs" />
|
<Compile Include="Profiles\Lua\Brushes\LuaSolidColorBrush.cs" />
|
||||||
<Compile Include="Profiles\Lua\LuaWrapper.cs" />
|
<Compile Include="Profiles\Lua\LuaWrapper.cs" />
|
||||||
<Compile Include="Profiles\Lua\Modules\LuaDrawModule.cs" />
|
|
||||||
<Compile Include="Profiles\Lua\Modules\LuaKeyboardModule.cs" />
|
<Compile Include="Profiles\Lua\Modules\LuaKeyboardModule.cs" />
|
||||||
|
<Compile Include="Profiles\Lua\Modules\LuaLayerModule.cs" />
|
||||||
|
<Compile Include="Profiles\Lua\Modules\LuaProfileModule.cs" />
|
||||||
|
<Compile Include="Profiles\Lua\Wrappers\LuaDrawWrapper.cs" />
|
||||||
<Compile Include="Profiles\ProfileModel.cs" />
|
<Compile Include="Profiles\ProfileModel.cs" />
|
||||||
<Compile Include="Profiles\Layers\Models\SimplePropertiesModel.cs" />
|
<Compile Include="Profiles\Layers\Models\SimplePropertiesModel.cs" />
|
||||||
<Compile Include="Profiles\Layers\Types\Keyboard\KeyboardPropertiesModel.cs" />
|
<Compile Include="Profiles\Layers\Types\Keyboard\KeyboardPropertiesModel.cs" />
|
||||||
|
|||||||
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -3,28 +3,36 @@ using System.IO;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Artemis.DAL;
|
using Artemis.DAL;
|
||||||
using Artemis.DeviceProviders;
|
using Artemis.DeviceProviders;
|
||||||
|
using Artemis.Profiles.Layers.Models;
|
||||||
using Artemis.Profiles.Lua.Brushes;
|
using Artemis.Profiles.Lua.Brushes;
|
||||||
using Artemis.Profiles.Lua.Events;
|
using Artemis.Profiles.Lua.Modules.Events;
|
||||||
using Artemis.Properties;
|
using Artemis.Properties;
|
||||||
using Castle.Core.Internal;
|
using Castle.Core.Internal;
|
||||||
using MoonSharp.Interpreter;
|
using MoonSharp.Interpreter;
|
||||||
|
using Ninject;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
namespace Artemis.Profiles.Lua
|
namespace Artemis.Profiles.Lua
|
||||||
{
|
{
|
||||||
public static class LuaWrapper
|
/// <summary>
|
||||||
|
/// This class is a singleton due to the fact that the LuaScript isn't very memory
|
||||||
|
/// friendly when creating new ones over and over.
|
||||||
|
/// </summary>
|
||||||
|
public class LuaWrapper
|
||||||
{
|
{
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
private readonly IKernel _kernel;
|
||||||
private static readonly Script LuaScript = new Script(CoreModules.Preset_SoftSandbox);
|
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||||
private static FileSystemWatcher _watcher;
|
private readonly Script _luaScript = new Script(CoreModules.Preset_SoftSandbox);
|
||||||
|
private FileSystemWatcher _watcher;
|
||||||
|
|
||||||
public static ProfileModel ProfileModel { get; private set; }
|
public ProfileModel ProfileModel { get; private set; }
|
||||||
public static KeyboardProvider KeyboardProvider { get; private set; }
|
public KeyboardProvider KeyboardProvider { get; private set; }
|
||||||
public static LuaProfileWrapper LuaProfileWrapper { get; private set; }
|
public LayerModel LayerModel { get; set; }
|
||||||
public static LuaBrushWrapper LuaBrushWrapper { get; private set; }
|
|
||||||
public static LuaKeyboardWrapper LuaKeyboardWrapper { get; private set; }
|
public LuaWrapper(IKernel kernel)
|
||||||
public static LuaMouseWrapper LuaMouseWrapper { get; set; }
|
{
|
||||||
public static LuaEventsWrapper LuaEventsWrapper { get; private set; }
|
_kernel = kernel;
|
||||||
|
}
|
||||||
|
|
||||||
public static void SetupLua(ProfileModel profileModel, KeyboardProvider keyboardProvider)
|
public static void SetupLua(ProfileModel profileModel, KeyboardProvider keyboardProvider)
|
||||||
{
|
{
|
||||||
@ -42,12 +50,12 @@ namespace Artemis.Profiles.Lua
|
|||||||
LuaMouseWrapper = new LuaMouseWrapper();
|
LuaMouseWrapper = new LuaMouseWrapper();
|
||||||
LuaEventsWrapper = new LuaEventsWrapper();
|
LuaEventsWrapper = new LuaEventsWrapper();
|
||||||
|
|
||||||
LuaScript.Options.DebugPrint = LuaPrint;
|
_luaScript.Options.DebugPrint = LuaPrint;
|
||||||
LuaScript.Globals["Profile"] = LuaProfileWrapper;
|
_luaScript.Globals["Profile"] = LuaProfileWrapper;
|
||||||
LuaScript.Globals["Events"] = LuaEventsWrapper;
|
_luaScript.Globals["Events"] = LuaEventsWrapper;
|
||||||
LuaScript.Globals["Brushes"] = LuaBrushWrapper;
|
_luaScript.Globals["Brushes"] = LuaBrushWrapper;
|
||||||
LuaScript.Globals["Keyboard"] = LuaKeyboardWrapper;
|
_luaScript.Globals["Keyboard"] = LuaKeyboardWrapper;
|
||||||
LuaScript.Globals["Mouse"] = LuaMouseWrapper;
|
_luaScript.Globals["Mouse"] = LuaMouseWrapper;
|
||||||
|
|
||||||
if (ProfileModel == null)
|
if (ProfileModel == null)
|
||||||
return;
|
return;
|
||||||
@ -58,29 +66,29 @@ namespace Artemis.Profiles.Lua
|
|||||||
{
|
{
|
||||||
lock (LuaEventsWrapper.InvokeLock)
|
lock (LuaEventsWrapper.InvokeLock)
|
||||||
{
|
{
|
||||||
lock (LuaScript)
|
lock (_luaScript)
|
||||||
{
|
{
|
||||||
LuaScript.DoString(ProfileModel.LuaScript);
|
_luaScript.DoString(ProfileModel.LuaScript);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (InternalErrorException e)
|
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)
|
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)
|
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()
|
public static void Clear()
|
||||||
{
|
{
|
||||||
lock (LuaScript)
|
lock (_luaScript)
|
||||||
{
|
{
|
||||||
// Clear old fields/properties
|
// Clear old fields/properties
|
||||||
KeyboardProvider = null;
|
KeyboardProvider = null;
|
||||||
@ -93,12 +101,12 @@ namespace Artemis.Profiles.Lua
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
LuaScript.Globals.Clear();
|
_luaScript.Globals.Clear();
|
||||||
LuaScript.Registry.Clear();
|
_luaScript.Registry.Clear();
|
||||||
LuaScript.Registry.RegisterConstants();
|
_luaScript.Registry.RegisterConstants();
|
||||||
LuaScript.Registry.RegisterCoreModules(CoreModules.Preset_SoftSandbox);
|
_luaScript.Registry.RegisterCoreModules(CoreModules.Preset_SoftSandbox);
|
||||||
LuaScript.Globals.RegisterConstants();
|
_luaScript.Globals.RegisterConstants();
|
||||||
LuaScript.Globals.RegisterCoreModules(CoreModules.Preset_SoftSandbox);
|
_luaScript.Globals.RegisterCoreModules(CoreModules.Preset_SoftSandbox);
|
||||||
}
|
}
|
||||||
catch (NullReferenceException)
|
catch (NullReferenceException)
|
||||||
{
|
{
|
||||||
@ -109,17 +117,17 @@ namespace Artemis.Profiles.Lua
|
|||||||
{
|
{
|
||||||
lock (LuaEventsWrapper.InvokeLock)
|
lock (LuaEventsWrapper.InvokeLock)
|
||||||
{
|
{
|
||||||
lock (LuaScript)
|
lock (_luaScript)
|
||||||
{
|
{
|
||||||
LuaScript.DoString("");
|
_luaScript.DoString("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lock (LuaScript)
|
lock (_luaScript)
|
||||||
{
|
{
|
||||||
LuaScript.DoString("");
|
_luaScript.DoString("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +140,7 @@ namespace Artemis.Profiles.Lua
|
|||||||
|
|
||||||
private static void LuaPrint(string s)
|
private static void LuaPrint(string s)
|
||||||
{
|
{
|
||||||
Logger.Debug("[{0}-LUA]: {1}", ProfileModel?.Name, s);
|
_logger.Debug("[{0}-LUA]: {1}", ProfileModel?.Name, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using Artemis.Models.Interfaces;
|
using Artemis.Models.Interfaces;
|
||||||
using Artemis.Profiles.Lua.Modules;
|
using Artemis.Profiles.Lua.Wrappers;
|
||||||
using MoonSharp.Interpreter;
|
using MoonSharp.Interpreter;
|
||||||
|
|
||||||
namespace Artemis.Profiles.Lua.Events
|
namespace Artemis.Profiles.Lua.Modules.Events
|
||||||
{
|
{
|
||||||
[MoonSharpUserData]
|
[MoonSharpUserData]
|
||||||
public class LuaDeviceDrawingEventArgs : EventArgs
|
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;
|
DeviceType = deviceType;
|
||||||
DataModel = dataModel;
|
DataModel = dataModel;
|
||||||
@ -19,6 +19,6 @@ namespace Artemis.Profiles.Lua.Events
|
|||||||
public string DeviceType { get; set; }
|
public string DeviceType { get; set; }
|
||||||
public IDataModel DataModel { get; }
|
public IDataModel DataModel { get; }
|
||||||
public bool Preview { get; }
|
public bool Preview { get; }
|
||||||
public LuaDrawModule Drawing { get; set; }
|
public LuaDrawWrapper Drawing { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2,7 +2,7 @@
|
|||||||
using Artemis.Models.Interfaces;
|
using Artemis.Models.Interfaces;
|
||||||
using MoonSharp.Interpreter;
|
using MoonSharp.Interpreter;
|
||||||
|
|
||||||
namespace Artemis.Profiles.Lua.Events
|
namespace Artemis.Profiles.Lua.Modules.Events
|
||||||
{
|
{
|
||||||
[MoonSharpUserData]
|
[MoonSharpUserData]
|
||||||
public class LuaDeviceUpdatingEventArgs : EventArgs
|
public class LuaDeviceUpdatingEventArgs : EventArgs
|
||||||
@ -2,17 +2,22 @@
|
|||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using Artemis.Models.Interfaces;
|
using Artemis.Models.Interfaces;
|
||||||
using Artemis.Profiles.Lua.Modules;
|
using Artemis.Profiles.Lua.Wrappers;
|
||||||
using MoonSharp.Interpreter;
|
using MoonSharp.Interpreter;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
namespace Artemis.Profiles.Lua.Events
|
namespace Artemis.Profiles.Lua.Modules.Events
|
||||||
{
|
{
|
||||||
[MoonSharpUserData]
|
public class LuaEventsModule : LuaModule
|
||||||
public class LuaEventsWrapper
|
|
||||||
{
|
{
|
||||||
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
private readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||||
public readonly string InvokeLock = string.Empty;
|
public readonly string InvokeLock = string.Empty;
|
||||||
|
|
||||||
|
public LuaEventsModule(LuaWrapper luaWrapper) : base(luaWrapper)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ModuleName => "Events";
|
||||||
public event EventHandler<LuaDeviceUpdatingEventArgs> DeviceUpdating;
|
public event EventHandler<LuaDeviceUpdatingEventArgs> DeviceUpdating;
|
||||||
public event EventHandler<LuaDeviceDrawingEventArgs> DeviceDrawing;
|
public event EventHandler<LuaDeviceDrawingEventArgs> DeviceDrawing;
|
||||||
public event EventHandler<LuaKeyPressEventArgs> KeyboardKeyPressed;
|
public event EventHandler<LuaKeyPressEventArgs> KeyboardKeyPressed;
|
||||||
@ -37,7 +42,7 @@ namespace Artemis.Profiles.Lua.Events
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
LuaInvoke(profileModel, () => OnDeviceDrawing(new LuaProfileWrapper(profileModel),
|
LuaInvoke(profileModel, () => OnDeviceDrawing(new LuaProfileWrapper(profileModel),
|
||||||
new LuaDeviceDrawingEventArgs(deviceType, dataModel, preview, new LuaDrawModule(c))));
|
new LuaDeviceDrawingEventArgs(deviceType, dataModel, preview, new LuaDrawWrapper(c))));
|
||||||
}
|
}
|
||||||
catch (Exception)
|
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
|
try
|
||||||
{
|
{
|
||||||
@ -91,10 +96,18 @@ namespace Artemis.Profiles.Lua.Events
|
|||||||
DeviceDrawing?.Invoke(profileModel, e);
|
DeviceDrawing?.Invoke(profileModel, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void OnKeyboardKeyPressed(LuaProfileWrapper profileModel, LuaKeyboardWrapper keyboard,
|
protected virtual void OnKeyboardKeyPressed(LuaProfileWrapper profileModel, LuaKeyboardModule keyboard,
|
||||||
LuaKeyPressEventArgs e)
|
LuaKeyPressEventArgs e)
|
||||||
{
|
{
|
||||||
KeyboardKeyPressed?.Invoke(profileModel, e);
|
KeyboardKeyPressed?.Invoke(profileModel, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Overriding members
|
||||||
|
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2,7 +2,7 @@
|
|||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using MoonSharp.Interpreter;
|
using MoonSharp.Interpreter;
|
||||||
|
|
||||||
namespace Artemis.Profiles.Lua.Events
|
namespace Artemis.Profiles.Lua.Modules.Events
|
||||||
{
|
{
|
||||||
[MoonSharpUserData]
|
[MoonSharpUserData]
|
||||||
public class LuaKeyPressEventArgs : EventArgs
|
public class LuaKeyPressEventArgs : EventArgs
|
||||||
@ -1,10 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace Artemis.Profiles.Lua.Modules
|
|
||||||
{
|
|
||||||
public interface ILuaModule : IDisposable
|
|
||||||
{
|
|
||||||
bool AlwaysPresent { get; }
|
|
||||||
string ModuleName { get; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,45 +1,45 @@
|
|||||||
using System;
|
using System.Windows.Forms;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using Artemis.DeviceProviders;
|
using Artemis.DeviceProviders;
|
||||||
using MoonSharp.Interpreter.Interop;
|
using Artemis.Utilities.Keyboard;
|
||||||
|
using MoonSharp.Interpreter;
|
||||||
|
|
||||||
namespace Artemis.Profiles.Lua.Modules
|
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;
|
private readonly KeyboardProvider _keyboardProvider;
|
||||||
|
|
||||||
public LuaKeyboardModule(KeyboardProvider keyboardProvider)
|
public LuaKeyboardModule(LuaWrapper luaWrapper) : base(luaWrapper)
|
||||||
{
|
{
|
||||||
_keyboardProvider = keyboardProvider;
|
_keyboardProvider = luaWrapper.KeyboardProvider;
|
||||||
|
|
||||||
KeyboardHook.KeyDownCallback += KeyboardHookOnKeyDownCallback;
|
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 Name => _keyboardProvider.Name;
|
||||||
public string Slug => _keyboardProvider.Slug;
|
public string Slug => _keyboardProvider.Slug;
|
||||||
public int Width => _keyboardProvider.Width;
|
public int Width => _keyboardProvider.Width;
|
||||||
public int Height => _keyboardProvider.Height;
|
public int Height => _keyboardProvider.Height;
|
||||||
|
|
||||||
[MoonSharpVisible(false)]
|
#region Overriding members
|
||||||
public void Dispose()
|
|
||||||
|
public override void Dispose()
|
||||||
{
|
{
|
||||||
KeyboardHook.KeyDownCallback -= KeyboardHookOnKeyDownCallback;
|
KeyboardHook.KeyDownCallback -= KeyboardHookOnKeyDownCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
private void KeyboardHookOnKeyDownCallback(KeyEventArgs e)
|
private void KeyboardHookOnKeyDownCallback(KeyEventArgs e)
|
||||||
{
|
{
|
||||||
var keyMatch = _keyboardProvider.GetKeyPosition(e.KeyCode);
|
// TODO
|
||||||
if (keyMatch != null)
|
//var keyMatch = _keyboardProvider.GetKeyPosition(e.KeyCode);
|
||||||
LuaWrapper.LuaEventsWrapper.InvokeKeyPressed(LuaWrapper.ProfileModel, this, keyMatch.Value.KeyCode,
|
//if (keyMatch != null)
|
||||||
keyMatch.Value.X, keyMatch.Value.Y);
|
// LuaWrapper.LuaEventsWrapper.InvokeKeyPressed(LuaWrapper.ProfileModel, this, keyMatch.Value.KeyCode,
|
||||||
|
// keyMatch.Value.X, keyMatch.Value.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PressKeys(string keys)
|
public void PressKeys(string keys)
|
||||||
|
|||||||
@ -6,25 +6,32 @@ using Artemis.Profiles.Layers.Models;
|
|||||||
using Artemis.Profiles.Lua.Brushes;
|
using Artemis.Profiles.Lua.Brushes;
|
||||||
using MoonSharp.Interpreter;
|
using MoonSharp.Interpreter;
|
||||||
|
|
||||||
namespace Artemis.Profiles.Lua
|
namespace Artemis.Profiles.Lua.Modules
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Serves as a sandboxed wrapper around the LayerModel
|
|
||||||
/// </summary>
|
|
||||||
[MoonSharpUserData]
|
[MoonSharpUserData]
|
||||||
public class LuaLayerWrapper
|
public class LuaLayerModule : LuaModule
|
||||||
{
|
{
|
||||||
private readonly LayerModel _layerModel;
|
private readonly LayerModel _layerModel;
|
||||||
|
|
||||||
public LuaLayerWrapper(LayerModel layerModel)
|
public LuaLayerModule(LuaWrapper luaWrapper) : base(luaWrapper)
|
||||||
{
|
{
|
||||||
_layerModel = layerModel;
|
_layerModel = luaWrapper.LayerModel;
|
||||||
SavedProperties = new LuaLayerProperties(layerModel);
|
SavedProperties = new Lua.LuaLayerProperties(_layerModel);
|
||||||
|
|
||||||
// Triger an update to fill up the Properties
|
// Triger an update to fill up the Properties
|
||||||
_layerModel.Update(new ProfilePreviewDataModel(), true, false);
|
_layerModel.Update(new ProfilePreviewDataModel(), true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ModuleName => "Layer";
|
||||||
|
|
||||||
|
#region Overriding members
|
||||||
|
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Child methods
|
#region Child methods
|
||||||
|
|
||||||
public List<LuaLayerWrapper> GetChildren()
|
public List<LuaLayerWrapper> GetChildren()
|
||||||
@ -106,7 +113,7 @@ namespace Artemis.Profiles.Lua
|
|||||||
|
|
||||||
#region Advanced layer properties
|
#region Advanced layer properties
|
||||||
|
|
||||||
public LuaLayerProperties SavedProperties { get; set; }
|
public Lua.LuaLayerProperties SavedProperties { get; set; }
|
||||||
|
|
||||||
public string BrushType => _layerModel.Properties.Brush?.GetType().Name;
|
public string BrushType => _layerModel.Properties.Brush?.GetType().Name;
|
||||||
|
|
||||||
30
Artemis/Artemis/Profiles/Lua/Modules/LuaModule.cs
Normal file
30
Artemis/Artemis/Profiles/Lua/Modules/LuaModule.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using MoonSharp.Interpreter;
|
||||||
|
using MoonSharp.Interpreter.Interop;
|
||||||
|
|
||||||
|
namespace Artemis.Profiles.Lua.Modules
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Defines a module which will be accessable in all LUA scripts.
|
||||||
|
/// </summary>
|
||||||
|
[MoonSharpUserData]
|
||||||
|
public abstract class LuaModule : IDisposable
|
||||||
|
{
|
||||||
|
public LuaModule(LuaWrapper luaWrapper)
|
||||||
|
{
|
||||||
|
LuaWrapper = luaWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The name under which this module will be accessable in LUA
|
||||||
|
/// </summary>
|
||||||
|
[MoonSharpVisible(false)]
|
||||||
|
public abstract string ModuleName { get; }
|
||||||
|
|
||||||
|
[MoonSharpVisible(false)]
|
||||||
|
public LuaWrapper LuaWrapper { get; set; }
|
||||||
|
|
||||||
|
[MoonSharpVisible(false)]
|
||||||
|
public abstract void Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,28 +1,33 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using MoonSharp.Interpreter;
|
|
||||||
|
|
||||||
namespace Artemis.Profiles.Lua
|
namespace Artemis.Profiles.Lua.Modules
|
||||||
{
|
{
|
||||||
/// <summary>
|
public class LuaProfileModule : LuaModule
|
||||||
/// Serves as a sandboxed wrapper around the ProfileModel
|
|
||||||
/// </summary>
|
|
||||||
[MoonSharpUserData]
|
|
||||||
public class LuaProfileWrapper
|
|
||||||
{
|
{
|
||||||
private readonly ProfileModel _profileModel;
|
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
|
#region General profile properties
|
||||||
|
|
||||||
public string Name => _profileModel.Name;
|
public string Name => _profileModel.Name;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Overriding members
|
||||||
|
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Layer methods
|
#region Layer methods
|
||||||
|
|
||||||
public List<LuaLayerWrapper> GetLayers()
|
public List<LuaLayerWrapper> GetLayers()
|
||||||
@ -5,27 +5,23 @@ using System.Windows.Media;
|
|||||||
using Artemis.Profiles.Lua.Brushes;
|
using Artemis.Profiles.Lua.Brushes;
|
||||||
using MoonSharp.Interpreter;
|
using MoonSharp.Interpreter;
|
||||||
|
|
||||||
namespace Artemis.Profiles.Lua.Modules
|
namespace Artemis.Profiles.Lua.Wrappers
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A wrapper that is provided to each OnDraw event to allow drawing in LUA
|
||||||
|
/// </summary>
|
||||||
[MoonSharpUserData]
|
[MoonSharpUserData]
|
||||||
public class LuaDrawModule : ILuaModule
|
public class LuaDrawWrapper
|
||||||
{
|
{
|
||||||
private readonly DrawingContext _ctx;
|
private readonly DrawingContext _ctx;
|
||||||
private readonly FontFamily _font;
|
private readonly FontFamily _font;
|
||||||
|
|
||||||
public LuaDrawModule(DrawingContext ctx)
|
public LuaDrawWrapper(DrawingContext ctx)
|
||||||
{
|
{
|
||||||
_ctx = ctx;
|
_ctx = ctx;
|
||||||
_font = new FontFamily(new Uri("pack://application:,,,/"), "./resources/#Silkscreen");
|
_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)
|
public void DrawEllipse(LuaBrush luaBrush, double x, double y, double height, double width)
|
||||||
{
|
{
|
||||||
x *= 4;
|
x *= 4;
|
||||||
Loading…
x
Reference in New Issue
Block a user