mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Implemented basic LUA drawing
Implemented LUA access to datamodels
This commit is contained in:
parent
7a0d0543cc
commit
c7c3614f3b
@ -414,9 +414,15 @@
|
||||
</Compile>
|
||||
<Compile Include="Profiles\Layers\Types\Mousemat\MousematPropertiesViewModel.cs" />
|
||||
<Compile Include="Profiles\Layers\Types\Mousemat\MousematType.cs" />
|
||||
<Compile Include="Profiles\Lua\Brushes\ILuaBrush.cs" />
|
||||
<Compile Include="Profiles\Lua\Brushes\LuaLinearGradientBrush.cs" />
|
||||
<Compile Include="Profiles\Lua\Brushes\LuaRadialGradientBrush.cs" />
|
||||
<Compile Include="Profiles\Lua\LuaBrushWrapper.cs" />
|
||||
<Compile Include="Profiles\Lua\LuaDrawWrapper.cs" />
|
||||
<Compile Include="Profiles\Lua\LuaEventsWrapper.cs" />
|
||||
<Compile Include="Profiles\Lua\LuaLayerWrapper.cs" />
|
||||
<Compile Include="Profiles\Lua\LuaProfileWrapper.cs" />
|
||||
<Compile Include="Profiles\Lua\Brushes\LuaSolidColorBrush.cs" />
|
||||
<Compile Include="Profiles\Lua\LuaWrapper.cs" />
|
||||
<Compile Include="Profiles\ProfileModel.cs" />
|
||||
<Compile Include="Profiles\Layers\Models\SimplePropertiesModel.cs" />
|
||||
@ -641,7 +647,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<None Include="Resources\lua-placeholder.txt" />
|
||||
<None Include="Resources\lua-placeholder.lua" />
|
||||
<None Include="NLog.xsd">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
|
||||
@ -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
|
||||
{
|
||||
}
|
||||
|
||||
@ -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; }
|
||||
|
||||
@ -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; }
|
||||
|
||||
@ -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; }
|
||||
|
||||
@ -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; }
|
||||
}
|
||||
}
|
||||
@ -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; }
|
||||
|
||||
@ -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; }
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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; }
|
||||
|
||||
@ -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; }
|
||||
|
||||
9
Artemis/Artemis/Profiles/Lua/Brushes/ILuaBrush.cs
Normal file
9
Artemis/Artemis/Profiles/Lua/Brushes/ILuaBrush.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Artemis.Profiles.Lua.Brushes
|
||||
{
|
||||
public interface ILuaBrush
|
||||
{
|
||||
Brush Brush { get; set; }
|
||||
}
|
||||
}
|
||||
@ -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; }
|
||||
}
|
||||
}
|
||||
@ -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; }
|
||||
}
|
||||
}
|
||||
49
Artemis/Artemis/Profiles/Lua/Brushes/LuaSolidColorBrush.cs
Normal file
49
Artemis/Artemis/Profiles/Lua/Brushes/LuaSolidColorBrush.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
24
Artemis/Artemis/Profiles/Lua/LuaBrushWrapper.cs
Normal file
24
Artemis/Artemis/Profiles/Lua/LuaBrushWrapper.cs
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
26
Artemis/Artemis/Profiles/Lua/LuaDrawWrapper.cs
Normal file
26
Artemis/Artemis/Profiles/Lua/LuaDrawWrapper.cs
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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<LuaProfileUpdatingEventArgs> LuaProfileUpdating;
|
||||
public event EventHandler<LuaProfileDrawingEventArgs> 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; }
|
||||
}
|
||||
}
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ namespace Artemis.Profiles
|
||||
LuaWrapper = new LuaWrapper(this);
|
||||
DrawingVisual = new DrawingVisual();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the profile is actively being rendered
|
||||
/// </summary>
|
||||
@ -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();
|
||||
|
||||
7
Artemis/Artemis/Properties/Resources.Designer.cs
generated
7
Artemis/Artemis/Properties/Resources.Designer.cs
generated
@ -309,11 +309,12 @@ namespace Artemis.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to .
|
||||
/// Looks up a localized resource of type System.Byte[].
|
||||
/// </summary>
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -208,7 +208,7 @@
|
||||
<data name="audio" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\audio.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="lua-placeholder" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\lua-placeholder.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
|
||||
<data name="lua_placeholder" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\lua-placeholder.lua;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
</root>
|
||||
40
Artemis/Artemis/Resources/lua-placeholder.lua
Normal file
40
Artemis/Artemis/Resources/lua-placeholder.lua
Normal file
@ -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);
|
||||
@ -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.
|
||||
Loading…
x
Reference in New Issue
Block a user