diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj
index 1a0103842..68945023b 100644
--- a/Artemis/Artemis/Artemis.csproj
+++ b/Artemis/Artemis/Artemis.csproj
@@ -414,9 +414,15 @@
+
+
+
+
+
+
@@ -641,7 +647,7 @@
Code
-
+
Designer
diff --git a/Artemis/Artemis/Modules/Effects/ProfilePreview/ProfilePreviewModel.cs b/Artemis/Artemis/Modules/Effects/ProfilePreview/ProfilePreviewModel.cs
index 90d53c22c..31f38bf92 100644
--- a/Artemis/Artemis/Modules/Effects/ProfilePreview/ProfilePreviewModel.cs
+++ b/Artemis/Artemis/Modules/Effects/ProfilePreview/ProfilePreviewModel.cs
@@ -9,6 +9,7 @@ using Artemis.Profiles.Layers.Interfaces;
using Artemis.Profiles.Layers.Models;
using Artemis.ViewModels.Profiles;
using Castle.Components.DictionaryAdapter;
+using MoonSharp.Interpreter;
namespace Artemis.Modules.Effects.ProfilePreview
{
@@ -90,6 +91,7 @@ namespace Artemis.Modules.Effects.ProfilePreview
}
}
+ [MoonSharpUserData]
public class ProfilePreviewDataModel : IDataModel
{
}
diff --git a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileDataModel.cs b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileDataModel.cs
index e8ae34117..2636e797a 100644
--- a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileDataModel.cs
+++ b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileDataModel.cs
@@ -1,7 +1,9 @@
using Artemis.Models.Interfaces;
+using MoonSharp.Interpreter;
namespace Artemis.Modules.Effects.WindowsProfile
{
+ [MoonSharpUserData]
public class WindowsProfileDataModel : IDataModel
{
public WindowsProfileDataModel()
@@ -18,6 +20,7 @@ namespace Artemis.Modules.Effects.WindowsProfile
public CurrentTime CurrentTime { get; set; }
}
+ [MoonSharpUserData]
public class CurrentTime
{
public int Hours24 { get; set; }
@@ -26,6 +29,7 @@ namespace Artemis.Modules.Effects.WindowsProfile
public int Seconds { get; set; }
}
+ [MoonSharpUserData]
public class CpuDataModel
{
public int TotalUsage { get; set; }
@@ -39,11 +43,13 @@ namespace Artemis.Modules.Effects.WindowsProfile
public int Core8Usage { get; set; }
}
+ [MoonSharpUserData]
public class PerformanceDataModel
{
public int RAMUsage { get; set; }
}
+ [MoonSharpUserData]
public class Spotify
{
public bool Running { get; set; }
diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeDataModel.cs b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeDataModel.cs
index 6e76b2e87..546937029 100644
--- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeDataModel.cs
+++ b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeDataModel.cs
@@ -1,8 +1,10 @@
using Artemis.Models.Interfaces;
+using MoonSharp.Interpreter;
using Newtonsoft.Json;
namespace Artemis.Modules.Games.CounterStrike
{
+ [MoonSharpUserData]
public class CounterStrikeDataModel : IDataModel
{
public Provider provider { get; set; }
@@ -12,6 +14,7 @@ namespace Artemis.Modules.Games.CounterStrike
public Previously previously { get; set; }
}
+ [MoonSharpUserData]
public class Provider
{
public string name { get; set; }
@@ -21,16 +24,19 @@ namespace Artemis.Modules.Games.CounterStrike
public int timestamp { get; set; }
}
+ [MoonSharpUserData]
public class TeamCt
{
public int score { get; set; }
}
+ [MoonSharpUserData]
public class TeamT
{
public int score { get; set; }
}
+ [MoonSharpUserData]
public class Map
{
public string mode { get; set; }
@@ -41,11 +47,13 @@ namespace Artemis.Modules.Games.CounterStrike
public TeamT team_t { get; set; }
}
+ [MoonSharpUserData]
public class Round
{
public string phase { get; set; }
}
+ [MoonSharpUserData]
public class State
{
[JsonIgnore]
@@ -63,7 +71,7 @@ namespace Artemis.Modules.Games.CounterStrike
public int round_killhs { get; set; }
}
-
+ [MoonSharpUserData]
public class Weapon
{
public string name { get; set; }
@@ -75,6 +83,7 @@ namespace Artemis.Modules.Games.CounterStrike
public string state { get; set; }
}
+ [MoonSharpUserData]
public class Weapons
{
public Weapon active_weapon { get; set; }
@@ -83,6 +92,7 @@ namespace Artemis.Modules.Games.CounterStrike
public Weapon weapon_2 { get; set; }
}
+ [MoonSharpUserData]
public class MatchStats
{
public int kills { get; set; }
@@ -92,6 +102,7 @@ namespace Artemis.Modules.Games.CounterStrike
public int score { get; set; }
}
+ [MoonSharpUserData]
public class Player
{
public string steamid { get; set; }
@@ -103,11 +114,13 @@ namespace Artemis.Modules.Games.CounterStrike
public MatchStats match_stats { get; set; }
}
+ [MoonSharpUserData]
public class Round2
{
public string phase { get; set; }
}
+ [MoonSharpUserData]
public class Previously
{
public Round2 round { get; set; }
diff --git a/Artemis/Artemis/Modules/Games/Dota2/Dota2DataModel.cs b/Artemis/Artemis/Modules/Games/Dota2/Dota2DataModel.cs
index 184d45f9e..9d98ca997 100644
--- a/Artemis/Artemis/Modules/Games/Dota2/Dota2DataModel.cs
+++ b/Artemis/Artemis/Modules/Games/Dota2/Dota2DataModel.cs
@@ -1,7 +1,9 @@
using Artemis.Models.Interfaces;
+using MoonSharp.Interpreter;
namespace Artemis.Modules.Games.Dota2
{
+ [MoonSharpUserData]
public class Dota2DataModel : IDataModel
{
public Provider provider { get; set; }
@@ -13,6 +15,7 @@ namespace Artemis.Modules.Games.Dota2
public Previously previously { get; set; }
}
+ [MoonSharpUserData]
public class Provider
{
public string name { get; set; }
@@ -21,6 +24,7 @@ namespace Artemis.Modules.Games.Dota2
public int timestamp { get; set; }
}
+ [MoonSharpUserData]
public class Map
{
public int dayCyclePercentage;
@@ -36,6 +40,7 @@ namespace Artemis.Modules.Games.Dota2
public int ward_purchase_cooldown { get; set; }
}
+ [MoonSharpUserData]
public class Player
{
public string steamid { get; set; }
@@ -55,6 +60,7 @@ namespace Artemis.Modules.Games.Dota2
public int xpm { get; set; }
}
+ [MoonSharpUserData]
public class Hero
{
public int id { get; set; }
@@ -80,6 +86,7 @@ namespace Artemis.Modules.Games.Dota2
public bool has_debuff { get; set; }
}
+ [MoonSharpUserData]
public class Abilities
{
public Ability0 ability0 { get; set; }
@@ -90,6 +97,7 @@ namespace Artemis.Modules.Games.Dota2
public Attributes attributes { get; set; }
}
+ [MoonSharpUserData]
public class Ability0
{
public string name { get; set; }
@@ -101,6 +109,7 @@ namespace Artemis.Modules.Games.Dota2
public bool ultimate { get; set; }
}
+ [MoonSharpUserData]
public class Ability1
{
public string name { get; set; }
@@ -112,6 +121,7 @@ namespace Artemis.Modules.Games.Dota2
public bool ultimate { get; set; }
}
+ [MoonSharpUserData]
public class Ability2
{
public string name { get; set; }
@@ -123,6 +133,7 @@ namespace Artemis.Modules.Games.Dota2
public bool ultimate { get; set; }
}
+ [MoonSharpUserData]
public class Ability3
{
public string name { get; set; }
@@ -134,11 +145,13 @@ namespace Artemis.Modules.Games.Dota2
public bool ultimate { get; set; }
}
+ [MoonSharpUserData]
public class Attributes
{
public int level { get; set; }
}
+ [MoonSharpUserData]
public class Items
{
public Slot0 slot0 { get; set; }
@@ -155,71 +168,85 @@ namespace Artemis.Modules.Games.Dota2
public Stash5 stash5 { get; set; }
}
+ [MoonSharpUserData]
public class Slot0
{
public string name { get; set; }
}
+ [MoonSharpUserData]
public class Slot1
{
public string name { get; set; }
}
+ [MoonSharpUserData]
public class Slot2
{
public string name { get; set; }
}
+ [MoonSharpUserData]
public class Slot3
{
public string name { get; set; }
}
+ [MoonSharpUserData]
public class Slot4
{
public string name { get; set; }
}
+ [MoonSharpUserData]
public class Slot5
{
public string name { get; set; }
}
+ [MoonSharpUserData]
public class Stash0
{
public string name { get; set; }
}
+ [MoonSharpUserData]
public class Stash1
{
public string name { get; set; }
}
+ [MoonSharpUserData]
public class Stash2
{
public string name { get; set; }
}
+ [MoonSharpUserData]
public class Stash3
{
public string name { get; set; }
}
+ [MoonSharpUserData]
public class Stash4
{
public string name { get; set; }
}
+ [MoonSharpUserData]
public class Stash5
{
public string name { get; set; }
}
+ [MoonSharpUserData]
public class Previously
{
public Player1 player { get; set; }
}
+ [MoonSharpUserData]
public class Player1
{
public int gold { get; set; }
diff --git a/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2DataModel.cs b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2DataModel.cs
index 44493b246..e1c9cd275 100644
--- a/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2DataModel.cs
+++ b/Artemis/Artemis/Modules/Games/EurotruckSimulator2/EurotruckSimulator2DataModel.cs
@@ -1,14 +1,23 @@
using Artemis.Models.Interfaces;
using Artemis.Modules.Games.EurotruckSimulator2.Data;
+using MoonSharp.Interpreter;
+using MoonSharp.Interpreter.Interop;
namespace Artemis.Modules.Games.EurotruckSimulator2
{
+ [MoonSharpUserData]
public class EurotruckSimulator2DataModel : IDataModel
{
+ // TODO: Test LUA functionality
+ [MoonSharpVisible(true)]
public IEts2Game Game { get; set; }
+ [MoonSharpVisible(true)]
public IEts2Job Job { get; set; }
+ [MoonSharpVisible(true)]
public IEts2Navigation Navigation { get; set; }
+ [MoonSharpVisible(true)]
public IEts2Trailer Trailer { get; set; }
+ [MoonSharpVisible(true)]
public IEts2Truck Truck { get; set; }
}
}
\ No newline at end of file
diff --git a/Artemis/Artemis/Modules/Games/Overwatch/OverwatchDataModel.cs b/Artemis/Artemis/Modules/Games/Overwatch/OverwatchDataModel.cs
index f7e3ece14..5d0353154 100644
--- a/Artemis/Artemis/Modules/Games/Overwatch/OverwatchDataModel.cs
+++ b/Artemis/Artemis/Modules/Games/Overwatch/OverwatchDataModel.cs
@@ -1,7 +1,9 @@
using Artemis.Models.Interfaces;
+using MoonSharp.Interpreter;
namespace Artemis.Modules.Games.Overwatch
{
+ [MoonSharpUserData]
public class OverwatchDataModel : IDataModel
{
public OverwatchStatus Status { get; set; }
diff --git a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueDataModel.cs b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueDataModel.cs
index d0196e16d..287f87fe2 100644
--- a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueDataModel.cs
+++ b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueDataModel.cs
@@ -1,7 +1,9 @@
using Artemis.Models.Interfaces;
+using MoonSharp.Interpreter;
namespace Artemis.Modules.Games.RocketLeague
{
+ [MoonSharpUserData]
public class RocketLeagueDataModel : IDataModel
{
public int Boost { get; set; }
diff --git a/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionDataModel.cs b/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionDataModel.cs
index f5a372e85..8411289d1 100644
--- a/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionDataModel.cs
+++ b/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionDataModel.cs
@@ -1,14 +1,11 @@
using Artemis.Models.Interfaces;
+using MoonSharp.Interpreter;
namespace Artemis.Modules.Games.TheDivision
{
+ [MoonSharpUserData]
public class TheDivisionDataModel : IDataModel
{
- public TheDivisionDataModel()
- {
- TestyTest = new TestTest();
- }
-
public PlayerState PartyMember1 { get; set; }
public PlayerState PartyMember2 { get; set; }
public PlayerState PartyMember3 { get; set; }
@@ -16,17 +13,8 @@ namespace Artemis.Modules.Games.TheDivision
public bool LowAmmo { get; set; }
public bool LowHp { get; set; }
public GrenadeState GrenadeState { get; set; }
-
- public TestTest TestyTest { get; set; }
}
-
-
- public class TestTest
- {
- public string TestS { get; set; }
- public int TestI { get; set; }
- }
-
+
public enum GrenadeState
{
HasGrenade,
diff --git a/Artemis/Artemis/Modules/Games/UnrealTournament/UnrealTournamentDataModel.cs b/Artemis/Artemis/Modules/Games/UnrealTournament/UnrealTournamentDataModel.cs
index f1971d73f..d11a0f530 100644
--- a/Artemis/Artemis/Modules/Games/UnrealTournament/UnrealTournamentDataModel.cs
+++ b/Artemis/Artemis/Modules/Games/UnrealTournament/UnrealTournamentDataModel.cs
@@ -1,9 +1,11 @@
using System.ComponentModel;
using Artemis.Models.Interfaces;
+using MoonSharp.Interpreter;
using Newtonsoft.Json;
namespace Artemis.Modules.Games.UnrealTournament
{
+ [MoonSharpUserData]
public class UnrealTournamentDataModel : IDataModel
{
public State State { get; set; }
@@ -19,6 +21,7 @@ namespace Artemis.Modules.Games.UnrealTournament
Dead
}
+ [MoonSharpUserData]
public class Player
{
public int Health { get; set; }
@@ -41,6 +44,7 @@ namespace Artemis.Modules.Games.UnrealTournament
MonsterKill = 5
}
+ [MoonSharpUserData]
public class PlayerState
{
public string PlayerName { get; set; }
@@ -72,6 +76,7 @@ namespace Artemis.Modules.Games.UnrealTournament
public int No_Showdowns { get; set; }
}
+ [MoonSharpUserData]
public class Inventory
{
public bool HasJumpBoots { get; set; }
@@ -84,6 +89,7 @@ namespace Artemis.Modules.Games.UnrealTournament
public bool HasHelmet { get; set; }
}
+ [MoonSharpUserData]
public class Weapon
{
public string Name { get; set; }
@@ -102,6 +108,7 @@ namespace Artemis.Modules.Games.UnrealTournament
ZoomingOut = 2
}
+ [MoonSharpUserData]
public class Environment
{
public string GameMode { get; set; }
diff --git a/Artemis/Artemis/Modules/Games/Witcher3/Witcher3DataModel.cs b/Artemis/Artemis/Modules/Games/Witcher3/Witcher3DataModel.cs
index e153ad6bd..35c1c9e8f 100644
--- a/Artemis/Artemis/Modules/Games/Witcher3/Witcher3DataModel.cs
+++ b/Artemis/Artemis/Modules/Games/Witcher3/Witcher3DataModel.cs
@@ -1,7 +1,9 @@
using Artemis.Models.Interfaces;
+using MoonSharp.Interpreter;
namespace Artemis.Modules.Games.Witcher3
{
+ [MoonSharpUserData]
public class Witcher3DataModel : IDataModel
{
public WitcherSign WitcherSign { get; set; }
diff --git a/Artemis/Artemis/Profiles/Lua/Brushes/ILuaBrush.cs b/Artemis/Artemis/Profiles/Lua/Brushes/ILuaBrush.cs
new file mode 100644
index 000000000..58b78b300
--- /dev/null
+++ b/Artemis/Artemis/Profiles/Lua/Brushes/ILuaBrush.cs
@@ -0,0 +1,9 @@
+using System.Windows.Media;
+
+namespace Artemis.Profiles.Lua.Brushes
+{
+ public interface ILuaBrush
+ {
+ Brush Brush { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Artemis/Artemis/Profiles/Lua/Brushes/LuaLinearGradientBrush.cs b/Artemis/Artemis/Profiles/Lua/Brushes/LuaLinearGradientBrush.cs
new file mode 100644
index 000000000..01c9819e3
--- /dev/null
+++ b/Artemis/Artemis/Profiles/Lua/Brushes/LuaLinearGradientBrush.cs
@@ -0,0 +1,25 @@
+using System.Windows.Media;
+using MoonSharp.Interpreter;
+
+namespace Artemis.Profiles.Lua.Brushes
+{
+ [MoonSharpUserData]
+ public class LuaLinearGradientBrush : ILuaBrush
+ {
+ // ReSharper disable once SuggestBaseTypeForParameter
+ public LuaLinearGradientBrush(LinearGradientBrush linearGradientBrush)
+ {
+ Brush = linearGradientBrush;
+ }
+
+ private void SetupBrush()
+ {
+ // TODO: Convert array of hex code and offset to gradient stop collection
+ var gradientStop = new GradientStop();
+ var collection = new GradientStopCollection();
+ Brush = new LinearGradientBrush();
+ }
+
+ public Brush Brush { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Artemis/Artemis/Profiles/Lua/Brushes/LuaRadialGradientBrush.cs b/Artemis/Artemis/Profiles/Lua/Brushes/LuaRadialGradientBrush.cs
new file mode 100644
index 000000000..4850362f5
--- /dev/null
+++ b/Artemis/Artemis/Profiles/Lua/Brushes/LuaRadialGradientBrush.cs
@@ -0,0 +1,17 @@
+using System.Windows.Media;
+using MoonSharp.Interpreter;
+
+namespace Artemis.Profiles.Lua.Brushes
+{
+ [MoonSharpUserData]
+ public class LuaRadialGradientBrush : ILuaBrush
+ {
+ // ReSharper disable once SuggestBaseTypeForParameter
+ public LuaRadialGradientBrush(RadialGradientBrush radialGradientBrush)
+ {
+ Brush = radialGradientBrush;
+ }
+
+ public Brush Brush { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Artemis/Artemis/Profiles/Lua/Brushes/LuaSolidColorBrush.cs b/Artemis/Artemis/Profiles/Lua/Brushes/LuaSolidColorBrush.cs
new file mode 100644
index 000000000..c9179fcc9
--- /dev/null
+++ b/Artemis/Artemis/Profiles/Lua/Brushes/LuaSolidColorBrush.cs
@@ -0,0 +1,49 @@
+using System.Windows.Media;
+using MoonSharp.Interpreter;
+using MoonSharp.Interpreter.Interop;
+
+namespace Artemis.Profiles.Lua.Brushes
+{
+ [MoonSharpUserData]
+ public class LuaSolidColorBrush : ILuaBrush
+ {
+ // ReSharper disable once SuggestBaseTypeForParameter
+ public LuaSolidColorBrush(SolidColorBrush solidColorBrush)
+ {
+ Brush = solidColorBrush;
+ }
+
+ public LuaSolidColorBrush(string hexCode)
+ {
+ SetupBrush(hexCode);
+ }
+
+ public string HexCode
+ {
+ get
+ {
+ var c = ((SolidColorBrush) Brush).Color;
+ return "#" + c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");
+ }
+ set { SetupBrush(value); }
+ }
+
+ [MoonSharpVisible(false)]
+ public Brush Brush { get; set; }
+
+ private void SetupBrush(string hexCode)
+ {
+ var convertFromString = ColorConverter.ConvertFromString(hexCode);
+ if (convertFromString != null)
+ {
+ var col = (Color) convertFromString;
+ Brush = new SolidColorBrush(col);
+ Brush.Freeze();
+ }
+ else
+ {
+ Brush = null;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Artemis/Artemis/Profiles/Lua/LuaBrushWrapper.cs b/Artemis/Artemis/Profiles/Lua/LuaBrushWrapper.cs
new file mode 100644
index 000000000..032da035b
--- /dev/null
+++ b/Artemis/Artemis/Profiles/Lua/LuaBrushWrapper.cs
@@ -0,0 +1,24 @@
+using Artemis.Profiles.Lua.Brushes;
+using MoonSharp.Interpreter;
+
+namespace Artemis.Profiles.Lua
+{
+ [MoonSharpUserData]
+ public class LuaBrushWrapper
+ {
+ public static LuaSolidColorBrush GetSolidColorBrush(string hexCode)
+ {
+ return new LuaSolidColorBrush(hexCode);
+ }
+
+ public static LuaSolidColorBrush GetLinearGradientBrush(string hexCode)
+ {
+ return new LuaSolidColorBrush(hexCode);
+ }
+
+ public static LuaSolidColorBrush GetRadialGradientBrush(string hexCode)
+ {
+ return new LuaSolidColorBrush(hexCode);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Artemis/Artemis/Profiles/Lua/LuaDrawWrapper.cs b/Artemis/Artemis/Profiles/Lua/LuaDrawWrapper.cs
new file mode 100644
index 000000000..a49d6c6c1
--- /dev/null
+++ b/Artemis/Artemis/Profiles/Lua/LuaDrawWrapper.cs
@@ -0,0 +1,26 @@
+using System.Runtime.InteropServices;
+using System.Windows;
+using System.Windows.Media;
+using Artemis.Profiles.Lua.Brushes;
+using MoonSharp.Interpreter;
+using Pen = System.Windows.Media.Pen;
+
+namespace Artemis.Profiles.Lua
+{
+ [MoonSharpUserData]
+ public class LuaDrawWrapper
+ {
+ private readonly DrawingContext _ctx;
+
+ public LuaDrawWrapper(DrawingContext ctx)
+ {
+ _ctx = ctx;
+ }
+
+ public void DrawCircle(ILuaBrush luaBrush, double x, double y, double height, double width)
+ {
+ var center = new Point(x + width/2, y + height/2);
+ _ctx.DrawEllipse(luaBrush.Brush, new Pen(), center, width, height);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Artemis/Artemis/Profiles/Lua/LuaEventsWrapper.cs b/Artemis/Artemis/Profiles/Lua/LuaEventsWrapper.cs
index 68d740b85..aa6ebcb0a 100644
--- a/Artemis/Artemis/Profiles/Lua/LuaEventsWrapper.cs
+++ b/Artemis/Artemis/Profiles/Lua/LuaEventsWrapper.cs
@@ -1,9 +1,97 @@
-using MoonSharp.Interpreter;
+using System;
+using System.Windows.Media;
+using Artemis.Models.Interfaces;
+using MoonSharp.Interpreter;
+using NLog;
namespace Artemis.Profiles.Lua
{
[MoonSharpUserData]
public class LuaEventsWrapper
{
+ private readonly Logger _logger = LogManager.GetCurrentClassLogger();
+ public event EventHandler LuaProfileUpdating;
+ public event EventHandler LuaProfileDrawing;
+
+ internal void InvokeProfileUpdate(ProfileModel profileModel, IDataModel dataModel, bool preview)
+ {
+ OnLuaProfileUpdating(new LuaProfileWrapper(profileModel),
+ new LuaProfileUpdatingEventArgs(dataModel, preview));
+ }
+
+ internal void InvokeProfileDraw(ProfileModel profileModel, IDataModel dataModel, bool preview, DrawingContext c)
+ {
+ OnLuaProfileDrawing(new LuaProfileWrapper(profileModel),
+ new LuaProfileDrawingEventArgs(dataModel, preview, new LuaDrawWrapper(c)));
+ }
+
+
+ protected virtual void OnLuaProfileUpdating(LuaProfileWrapper profileModel, LuaProfileUpdatingEventArgs e)
+ {
+ try
+ {
+ LuaProfileUpdating?.Invoke(profileModel, e);
+ }
+ catch (InternalErrorException ex)
+ {
+ _logger.Error(ex, "[{0}-LUA]: Error: {1}", profileModel.Name, ex.DecoratedMessage);
+ }
+ catch (SyntaxErrorException ex)
+ {
+ _logger.Error(ex, "[{0}-LUA]: Error: {1}", profileModel.Name, ex.DecoratedMessage);
+ }
+ catch (ScriptRuntimeException ex)
+ {
+ _logger.Error(ex, "[{0}-LUA]: Error: {1}", profileModel.Name, ex.DecoratedMessage);
+ }
+ }
+
+ protected virtual void OnLuaProfileDrawing(LuaProfileWrapper profileModel, LuaProfileDrawingEventArgs e)
+ {
+ try
+ {
+ LuaProfileDrawing?.Invoke(profileModel, e);
+ }
+ catch (InternalErrorException ex)
+ {
+ _logger.Error(ex, "[{0}-LUA]: Error: {1}", profileModel.Name, ex.DecoratedMessage);
+ }
+ catch (SyntaxErrorException ex)
+ {
+ _logger.Error(ex, "[{0}-LUA]: Error: {1}", profileModel.Name, ex.DecoratedMessage);
+ }
+ catch (ScriptRuntimeException ex)
+ {
+ _logger.Error(ex, "[{0}-LUA]: Error: {1}", profileModel.Name, ex.DecoratedMessage);
+ }
+ }
+ }
+
+ [MoonSharpUserData]
+ public class LuaProfileUpdatingEventArgs : EventArgs
+ {
+ public LuaProfileUpdatingEventArgs(IDataModel dataModel, bool preview)
+ {
+ DataModel = dataModel;
+ Preview = preview;
+ }
+
+ public IDataModel DataModel { get; }
+ public bool Preview { get; }
+ }
+
+ [MoonSharpUserData]
+ public class LuaProfileDrawingEventArgs : EventArgs
+ {
+ public LuaProfileDrawingEventArgs(IDataModel dataModel, bool preview, LuaDrawWrapper luaDrawWrapper)
+ {
+ DataModel = dataModel;
+ Preview = preview;
+ Drawing = luaDrawWrapper;
+ }
+
+ public IDataModel DataModel { get; }
+ public bool Preview { get; }
+ public LuaDrawWrapper Drawing { get; set; }
}
}
\ No newline at end of file
diff --git a/Artemis/Artemis/Profiles/Lua/LuaWrapper.cs b/Artemis/Artemis/Profiles/Lua/LuaWrapper.cs
index 634db40b0..a7a09aa4a 100644
--- a/Artemis/Artemis/Profiles/Lua/LuaWrapper.cs
+++ b/Artemis/Artemis/Profiles/Lua/LuaWrapper.cs
@@ -1,10 +1,11 @@
using System;
using System.IO;
+using System.Text;
+using Artemis.DAL;
using Artemis.Properties;
using Castle.Core.Internal;
using MoonSharp.Interpreter;
using NLog;
-using NuGet;
namespace Artemis.Profiles.Lua
{
@@ -16,25 +17,25 @@ namespace Artemis.Profiles.Lua
{
ProfileModel = profileModel;
LuaProfileWrapper = new LuaProfileWrapper(ProfileModel);
- LuaEventsWrapper = new LuaEventsWrapper();
-
+ LuaBrushWrapper = new LuaBrushWrapper();
SetupLuaScript();
}
-
+
public ProfileModel ProfileModel { get; set; }
-
public LuaEventsWrapper LuaEventsWrapper { get; set; }
-
+ public LuaBrushWrapper LuaBrushWrapper { get; set; }
public LuaProfileWrapper LuaProfileWrapper { get; set; }
-
public Script LuaScript { get; set; }
private void SetupLuaScript()
{
+ LuaEventsWrapper = new LuaEventsWrapper();
LuaScript = new Script(CoreModules.Preset_SoftSandbox);
+
LuaScript.Options.DebugPrint = LuaPrint;
LuaScript.Globals["Profile"] = LuaProfileWrapper;
LuaScript.Globals["Events"] = LuaEventsWrapper;
+ LuaScript.Globals["Brushes"] = LuaBrushWrapper;
if (ProfileModel.LuaScript.IsNullOrEmpty())
return;
@@ -43,6 +44,14 @@ namespace Artemis.Profiles.Lua
{
LuaScript.DoString(ProfileModel.LuaScript);
}
+ catch (InternalErrorException e)
+ {
+ 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);
+ }
catch (ScriptRuntimeException e)
{
Logger.Error(e, "[{0}-LUA]: Error: {1}", ProfileModel.Name, e.DecoratedMessage);
@@ -69,7 +78,7 @@ namespace Artemis.Profiles.Lua
// Add instructions to LUA script if it's a new file
if (ProfileModel.LuaScript.IsNullOrEmpty())
- ProfileModel.LuaScript = Resources.lua_placeholder;
+ ProfileModel.LuaScript = Encoding.UTF8.GetString(Resources.lua_placeholder);
File.WriteAllText(Path.GetTempPath() + fileName, ProfileModel.LuaScript);
// Watch the file for changes
@@ -95,7 +104,7 @@ namespace Artemis.Profiles.Lua
}
}
- DAL.ProfileProvider.AddOrUpdate(ProfileModel);
+ ProfileProvider.AddOrUpdate(ProfileModel);
SetupLuaScript();
}
diff --git a/Artemis/Artemis/Profiles/ProfileModel.cs b/Artemis/Artemis/Profiles/ProfileModel.cs
index 3b0e01f68..f77741a12 100644
--- a/Artemis/Artemis/Profiles/ProfileModel.cs
+++ b/Artemis/Artemis/Profiles/ProfileModel.cs
@@ -26,7 +26,7 @@ namespace Artemis.Profiles
LuaWrapper = new LuaWrapper(this);
DrawingVisual = new DrawingVisual();
}
-
+
///
/// Indicates whether the profile is actively being rendered
///
@@ -111,18 +111,22 @@ namespace Artemis.Profiles
bool preview, bool updateAnimations)
{
var visual = new DrawingVisual();
+ var layerModels = renderLayers.ToList();
using (var c = visual.RenderOpen())
{
// Setup the DrawingVisual's size
c.PushClip(new RectangleGeometry(rect));
c.DrawRectangle(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)), null, rect);
- // Draw the layers
- foreach (var layerModel in renderLayers)
- {
+ // Update the layers
+ foreach (var layerModel in layerModels)
layerModel.Update(dataModel, preview, updateAnimations);
+ LuaWrapper?.LuaEventsWrapper?.InvokeProfileUpdate(this, dataModel, preview);
+
+ // Draw the layers
+ foreach (var layerModel in layerModels)
layerModel.Draw(dataModel, c, preview, updateAnimations);
- }
+ LuaWrapper?.LuaEventsWrapper?.InvokeProfileDraw(this, dataModel, preview, c);
// Remove the clip
c.Pop();
diff --git a/Artemis/Artemis/Properties/Resources.Designer.cs b/Artemis/Artemis/Properties/Resources.Designer.cs
index 39ed3e2b9..f9f421337 100644
--- a/Artemis/Artemis/Properties/Resources.Designer.cs
+++ b/Artemis/Artemis/Properties/Resources.Designer.cs
@@ -309,11 +309,12 @@ namespace Artemis.Properties {
}
///
- /// Looks up a localized string similar to .
+ /// Looks up a localized resource of type System.Byte[].
///
- internal static string lua_placeholder {
+ internal static byte[] lua_placeholder {
get {
- return ResourceManager.GetString("lua-placeholder", resourceCulture);
+ object obj = ResourceManager.GetObject("lua_placeholder", resourceCulture);
+ return ((byte[])(obj));
}
}
diff --git a/Artemis/Artemis/Properties/Resources.resx b/Artemis/Artemis/Properties/Resources.resx
index 555a4ee25..537017134 100644
--- a/Artemis/Artemis/Properties/Resources.resx
+++ b/Artemis/Artemis/Properties/Resources.resx
@@ -208,7 +208,7 @@
..\Resources\audio.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
-
- ..\Resources\lua-placeholder.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252
+
+ ..\Resources\lua-placeholder.lua;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
\ No newline at end of file
diff --git a/Artemis/Artemis/Resources/lua-placeholder.lua b/Artemis/Artemis/Resources/lua-placeholder.lua
new file mode 100644
index 000000000..15bbabfa5
--- /dev/null
+++ b/Artemis/Artemis/Resources/lua-placeholder.lua
@@ -0,0 +1,40 @@
+----------------------------------------------------------------------------------
+-------------------------------- Artemis LUA file --------------------------------
+----------------------------------------------------------------------------------
+
+-- This is a default script to be executed by Artemis.
+-- You do not need to use this if you don't want to script. The default profiles
+-- should provide you with a lot of functionality out of the box.
+-- However, if you wan't to change the way profiles work, this is the ideal way
+-- go about it.
+
+-- For docs and examples, see wiki: https://github.com/SpoinkyNL/Artemis/wiki/LUA
+
+-- Note: You are editing a temporary file. Whenever you save this file the
+-- changes are applied to the profile and the script restarted.
+
+-- This event is raised after every profile update, before drawing.
+function updateHandler(profile, eventArgs)
+ -- Don't do anything when previewing. You can ofcourse remove this if you want
+ if eventArgs.Preview == true then
+ return
+ end
+
+ -- Custom update code here
+end
+
+-- This event is raised after every profile draw, after updating.
+function drawHandler(profile, eventArgs)
+ -- Don't do anything when previewing. You can ofcourse remove this if you want
+ if eventArgs.Preview == true then
+ return
+ end
+
+ -- Custom draw code here
+end
+
+
+-- Register the default events, you can rename/remove these if you so desire.
+-- These events are raised every 40 ms (25 times a second).
+Events.LuaProfileUpdating.add(updateHandler);
+Events.LuaProfileDrawing.add(drawHandler);
\ No newline at end of file
diff --git a/Artemis/Artemis/Resources/lua-placeholder.txt b/Artemis/Artemis/Resources/lua-placeholder.txt
deleted file mode 100644
index 7641d7eff..000000000
--- a/Artemis/Artemis/Resources/lua-placeholder.txt
+++ /dev/null
@@ -1,12 +0,0 @@
---------------------------------------------------------------------------------
-------------------------------- Artemis LUA file -------------------------------
---------------------------------------------------------------------------------
-
--- This is a default script to be executed by Artemis.
--- You do not need to use this if you don't want to script. The default profiles
--- should provide you with a lot of functionality out of the box.
--- However, if you wan't to change the way profiles work, this is the ideal way
--- go about it.
-
--- Note: You are editing a temporary file. Whenever you save this file the
--- changes are applied to the profile and the script restarted.
\ No newline at end of file