1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-31 09:43:46 +00:00

LUA loading/unloading

This commit is contained in:
SpoinkyNL 2016-10-30 19:36:35 +01:00
parent 8e7f327200
commit 53e8e9c44e
17 changed files with 57 additions and 7 deletions

View File

@ -51,7 +51,7 @@ namespace Artemis.DAL
public static bool IsProfileUnique(ProfileModel profileModel) public static bool IsProfileUnique(ProfileModel profileModel)
{ {
var existing = ReadProfiles(profileModel.KeyboardSlug + "/" + profileModel.GameName); var existing = ReadProfiles(profileModel.KeyboardSlug + "/" + profileModel.GameName);
return existing.Contains(profileModel); return !existing.Contains(profileModel);
} }
/// <summary> /// <summary>

View File

@ -38,7 +38,11 @@ namespace Artemis.Models
public IDataModel DataModel { get; set; } public IDataModel DataModel { get; set; }
public ProfileModel Profile { get; set; } public ProfileModel Profile { get; set; }
public abstract void Dispose(); public virtual void Dispose()
{
if (Profile != null)
Profile.LuaWrapper = null;
}
// Called on creation // Called on creation
public abstract void Enable(); public abstract void Enable();

View File

@ -25,6 +25,7 @@ namespace Artemis.Modules.Effects.ProfilePreview
public override void Dispose() public override void Dispose()
{ {
Initialized = false; Initialized = false;
base.Dispose();
} }
public override void Enable() public override void Enable()

View File

@ -34,6 +34,7 @@ namespace Artemis.Modules.Effects.WindowsProfile
public override void Dispose() public override void Dispose()
{ {
Initialized = false; Initialized = false;
base.Dispose();
} }
public override void Enable() public override void Enable()
@ -195,8 +196,12 @@ namespace Artemis.Modules.Effects.WindowsProfile
SetupSpotify(); SetupSpotify();
var status = _spotify.GetStatus(); var status = _spotify.GetStatus();
if (status == null)
return;
dataModel.Spotify.Playing = status.Playing; dataModel.Spotify.Playing = status.Playing;
dataModel.Spotify.Running = SpotifyLocalAPI.IsSpotifyRunning(); dataModel.Spotify.Running = SpotifyLocalAPI.IsSpotifyRunning();
if (status.Track != null) if (status.Track != null)
{ {
dataModel.Spotify.Artist = status.Track.ArtistResource?.Name; dataModel.Spotify.Artist = status.Track.ArtistResource?.Name;
@ -206,8 +211,10 @@ namespace Artemis.Modules.Effects.WindowsProfile
} }
if (dataModel.Spotify.SongLength > 0) if (dataModel.Spotify.SongLength > 0)
{
dataModel.Spotify.SongPercentCompleted = dataModel.Spotify.SongPercentCompleted =
(int) (status.PlayingPosition/dataModel.Spotify.SongLength*100.0); (int) (status.PlayingPosition/dataModel.Spotify.SongLength*100.0);
}
} }
#endregion #endregion

View File

@ -34,6 +34,7 @@ namespace Artemis.Modules.Games.CounterStrike
{ {
Initialized = false; Initialized = false;
MainManager.GameStateWebServer.GameDataReceived -= HandleGameData; MainManager.GameStateWebServer.GameDataReceived -= HandleGameData;
base.Dispose();
} }
public override void Enable() public override void Enable()

View File

@ -26,12 +26,11 @@ namespace Artemis.Modules.Games.Dota2
{ {
Initialized = false; Initialized = false;
MainManager.GameStateWebServer.GameDataReceived -= HandleGameData; MainManager.GameStateWebServer.GameDataReceived -= HandleGameData;
base.Dispose();
} }
public override void Enable() public override void Enable()
{ {
Initialized = false;
MainManager.GameStateWebServer.GameDataReceived += HandleGameData; MainManager.GameStateWebServer.GameDataReceived += HandleGameData;
Initialized = true; Initialized = true;
} }

View File

@ -27,6 +27,7 @@ namespace Artemis.Modules.Games.EurotruckSimulator2
public override void Dispose() public override void Dispose()
{ {
Initialized = false; Initialized = false;
base.Dispose();
} }
public override void Enable() public override void Enable()

View File

@ -91,6 +91,7 @@ namespace Artemis.Modules.Games.Overwatch
_stickyUltimateUsed.Dispose(); _stickyUltimateUsed.Dispose();
MainManager.PipeServer.PipeMessage -= PipeServerOnPipeMessage; MainManager.PipeServer.PipeMessage -= PipeServerOnPipeMessage;
base.Dispose();
} }
private void PipeServerOnPipeMessage(string message) private void PipeServerOnPipeMessage(string message)

View File

@ -50,6 +50,7 @@ namespace Artemis.Modules.Games.RocketLeague
{ {
Initialized = false; Initialized = false;
_memory = null; _memory = null;
base.Dispose();
} }
public override void Enable() public override void Enable()

View File

@ -42,6 +42,7 @@ namespace Artemis.Modules.Games.TheDivision
_stickyHp.Dispose(); _stickyHp.Dispose();
MainManager.PipeServer.PipeMessage -= PipeServerOnPipeMessage; MainManager.PipeServer.PipeMessage -= PipeServerOnPipeMessage;
base.Dispose();
} }
public override void Enable() public override void Enable()

View File

@ -35,6 +35,7 @@ namespace Artemis.Modules.Games.UnrealTournament
_killTimer.Stop(); _killTimer.Stop();
MainManager.PipeServer.PipeMessage -= PipeServerOnPipeMessage; MainManager.PipeServer.PipeMessage -= PipeServerOnPipeMessage;
base.Dispose();
} }
public override void Enable() public override void Enable()

View File

@ -38,6 +38,7 @@ namespace Artemis.Modules.Games.Witcher3
_witcherSettings = null; _witcherSettings = null;
_updateSw.Reset(); _updateSw.Reset();
base.Dispose();
} }
public override void Enable() public override void Enable()

View File

@ -73,6 +73,7 @@ namespace Artemis.Modules.Games.WoW
_process.Dispose(); _process.Dispose();
_process = null; _process = null;
base.Dispose();
} }
public override void Enable() public override void Enable()

View File

@ -19,6 +19,11 @@ namespace Artemis.Profiles.Lua
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;
y *= 4;
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); _ctx.DrawEllipse(luaBrush.Brush, new Pen(), center, width, height);
} }
@ -26,16 +31,30 @@ namespace Artemis.Profiles.Lua
public void DrawLine(LuaBrush luaBrush, double startX, double startY, double endX, double endY, public void DrawLine(LuaBrush luaBrush, double startX, double startY, double endX, double endY,
double thickness) double thickness)
{ {
startX *= 4;
startY *= 4;
endX *= 4;
endY *= 4;
thickness *= 4;
_ctx.DrawLine(new Pen(luaBrush.Brush, thickness), new Point(startX, startY), new Point(endX, endY)); _ctx.DrawLine(new Pen(luaBrush.Brush, thickness), new Point(startX, startY), new Point(endX, endY));
} }
public void DrawRectangle(LuaBrush luaBrush, double x, double y, double height, double width) public void DrawRectangle(LuaBrush luaBrush, double x, double y, double height, double width)
{ {
x *= 4;
y *= 4;
height *= 4;
width *= 4;
_ctx.DrawRectangle(luaBrush.Brush, new Pen(), new Rect(x, y, width, height)); _ctx.DrawRectangle(luaBrush.Brush, new Pen(), new Rect(x, y, width, height));
} }
public void DrawText(string text, string fontName, int fontSize, LuaBrush luaBrush, double x, double y) public void DrawText(string text, string fontName, int fontSize, LuaBrush luaBrush, double x, double y)
{ {
x *= 4;
y *= 4;
var font = Fonts.SystemTypefaces.FirstOrDefault(f => f.FontFamily.ToString() == fontName); var font = Fonts.SystemTypefaces.FirstOrDefault(f => f.FontFamily.ToString() == fontName);
if (font == null) if (font == null)
throw new ScriptRuntimeException($"Font '{fontName}' not found"); throw new ScriptRuntimeException($"Font '{fontName}' not found");

View File

@ -11,6 +11,7 @@ using Artemis.Profiles.Layers.Models;
using Artemis.Profiles.Lua; using Artemis.Profiles.Lua;
using Artemis.Utilities; using Artemis.Utilities;
using Artemis.Utilities.ParentChild; using Artemis.Utilities.ParentChild;
using Castle.Core.Internal;
using Newtonsoft.Json; using Newtonsoft.Json;
using Color = System.Windows.Media.Color; using Color = System.Windows.Media.Color;
using Point = System.Windows.Point; using Point = System.Windows.Point;
@ -23,7 +24,6 @@ namespace Artemis.Profiles
public ProfileModel() public ProfileModel()
{ {
Layers = new ChildItemCollection<ProfileModel, LayerModel>(this); Layers = new ChildItemCollection<ProfileModel, LayerModel>(this);
LuaWrapper = new LuaWrapper(this);
} }
/// <summary> /// <summary>
@ -106,6 +106,9 @@ namespace Artemis.Profiles
internal void DrawLayers(Graphics g, IEnumerable<LayerModel> renderLayers, IDataModel dataModel, Rect rect, internal void DrawLayers(Graphics g, IEnumerable<LayerModel> renderLayers, IDataModel dataModel, Rect rect,
bool preview, bool updateAnimations) bool preview, bool updateAnimations)
{ {
if (LuaWrapper == null && !LuaScript.IsNullOrEmpty())
LuaWrapper = new LuaWrapper(this);
var visual = new DrawingVisual(); var visual = new DrawingVisual();
var layerModels = renderLayers.ToList(); var layerModels = renderLayers.ToList();
using (var c = visual.RenderOpen()) using (var c = visual.RenderOpen())

View File

@ -17,6 +17,7 @@ using Artemis.Models;
using Artemis.Profiles; using Artemis.Profiles;
using Artemis.Profiles.Layers.Models; using Artemis.Profiles.Layers.Models;
using Artemis.Profiles.Layers.Types.Folder; using Artemis.Profiles.Layers.Types.Folder;
using Artemis.Profiles.Lua;
using Artemis.Services; using Artemis.Services;
using Artemis.Styles.DropTargetAdorners; using Artemis.Styles.DropTargetAdorners;
using Artemis.Utilities; using Artemis.Utilities;
@ -231,6 +232,8 @@ namespace Artemis.ViewModels.Profiles
public void Deactivate() public void Deactivate()
{ {
ProfileViewModel.Deactivate(); ProfileViewModel.Deactivate();
if (SelectedProfile != null)
SelectedProfile.LuaWrapper = null;
_saveTimer.Stop(); _saveTimer.Stop();
} }
@ -699,9 +702,14 @@ namespace Artemis.ViewModels.Profiles
public void EditLua() public void EditLua()
{ {
if (SelectedProfile == null)
return;
try try
{ {
SelectedProfile?.LuaWrapper.OpenEditor(); if (SelectedProfile.LuaWrapper == null)
SelectedProfile.LuaWrapper = new LuaWrapper(SelectedProfile);
SelectedProfile.LuaWrapper.OpenEditor();
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -146,7 +146,8 @@
</Button.Content> </Button.Content>
</Button> </Button>
<Button x:Name="EditLua" VerticalAlignment="Top" Style="{DynamicResource SquareButtonStyle}" <Button x:Name="EditLua" VerticalAlignment="Top" Style="{DynamicResource SquareButtonStyle}"
Height="26" HorizontalAlignment="Right" Margin="10,0,0,0" ToolTip="Import profile"> Height="26" HorizontalAlignment="Right" Margin="10,0,0,0" ToolTip="Import profile"
IsEnabled="{Binding Path=EditorEnabled, Mode=OneWay}">
<Button.Content> <Button.Content>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<Rectangle <Rectangle