mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
LUA loading/unloading
This commit is contained in:
parent
8e7f327200
commit
53e8e9c44e
@ -51,7 +51,7 @@ namespace Artemis.DAL
|
||||
public static bool IsProfileUnique(ProfileModel profileModel)
|
||||
{
|
||||
var existing = ReadProfiles(profileModel.KeyboardSlug + "/" + profileModel.GameName);
|
||||
return existing.Contains(profileModel);
|
||||
return !existing.Contains(profileModel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -38,7 +38,11 @@ namespace Artemis.Models
|
||||
public IDataModel DataModel { get; set; }
|
||||
public ProfileModel Profile { get; set; }
|
||||
|
||||
public abstract void Dispose();
|
||||
public virtual void Dispose()
|
||||
{
|
||||
if (Profile != null)
|
||||
Profile.LuaWrapper = null;
|
||||
}
|
||||
|
||||
// Called on creation
|
||||
public abstract void Enable();
|
||||
|
||||
@ -25,6 +25,7 @@ namespace Artemis.Modules.Effects.ProfilePreview
|
||||
public override void Dispose()
|
||||
{
|
||||
Initialized = false;
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public override void Enable()
|
||||
|
||||
@ -34,6 +34,7 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
||||
public override void Dispose()
|
||||
{
|
||||
Initialized = false;
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public override void Enable()
|
||||
@ -195,8 +196,12 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
||||
SetupSpotify();
|
||||
|
||||
var status = _spotify.GetStatus();
|
||||
if (status == null)
|
||||
return;
|
||||
|
||||
dataModel.Spotify.Playing = status.Playing;
|
||||
dataModel.Spotify.Running = SpotifyLocalAPI.IsSpotifyRunning();
|
||||
|
||||
if (status.Track != null)
|
||||
{
|
||||
dataModel.Spotify.Artist = status.Track.ArtistResource?.Name;
|
||||
@ -206,8 +211,10 @@ namespace Artemis.Modules.Effects.WindowsProfile
|
||||
}
|
||||
|
||||
if (dataModel.Spotify.SongLength > 0)
|
||||
{
|
||||
dataModel.Spotify.SongPercentCompleted =
|
||||
(int) (status.PlayingPosition/dataModel.Spotify.SongLength*100.0);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -34,6 +34,7 @@ namespace Artemis.Modules.Games.CounterStrike
|
||||
{
|
||||
Initialized = false;
|
||||
MainManager.GameStateWebServer.GameDataReceived -= HandleGameData;
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public override void Enable()
|
||||
|
||||
@ -26,12 +26,11 @@ namespace Artemis.Modules.Games.Dota2
|
||||
{
|
||||
Initialized = false;
|
||||
MainManager.GameStateWebServer.GameDataReceived -= HandleGameData;
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public override void Enable()
|
||||
{
|
||||
Initialized = false;
|
||||
|
||||
MainManager.GameStateWebServer.GameDataReceived += HandleGameData;
|
||||
Initialized = true;
|
||||
}
|
||||
|
||||
@ -27,6 +27,7 @@ namespace Artemis.Modules.Games.EurotruckSimulator2
|
||||
public override void Dispose()
|
||||
{
|
||||
Initialized = false;
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public override void Enable()
|
||||
|
||||
@ -91,6 +91,7 @@ namespace Artemis.Modules.Games.Overwatch
|
||||
_stickyUltimateUsed.Dispose();
|
||||
|
||||
MainManager.PipeServer.PipeMessage -= PipeServerOnPipeMessage;
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
private void PipeServerOnPipeMessage(string message)
|
||||
|
||||
@ -50,6 +50,7 @@ namespace Artemis.Modules.Games.RocketLeague
|
||||
{
|
||||
Initialized = false;
|
||||
_memory = null;
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public override void Enable()
|
||||
|
||||
@ -42,6 +42,7 @@ namespace Artemis.Modules.Games.TheDivision
|
||||
_stickyHp.Dispose();
|
||||
|
||||
MainManager.PipeServer.PipeMessage -= PipeServerOnPipeMessage;
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public override void Enable()
|
||||
|
||||
@ -35,6 +35,7 @@ namespace Artemis.Modules.Games.UnrealTournament
|
||||
|
||||
_killTimer.Stop();
|
||||
MainManager.PipeServer.PipeMessage -= PipeServerOnPipeMessage;
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public override void Enable()
|
||||
|
||||
@ -38,6 +38,7 @@ namespace Artemis.Modules.Games.Witcher3
|
||||
_witcherSettings = null;
|
||||
|
||||
_updateSw.Reset();
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public override void Enable()
|
||||
|
||||
@ -73,6 +73,7 @@ namespace Artemis.Modules.Games.WoW
|
||||
|
||||
_process.Dispose();
|
||||
_process = null;
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public override void Enable()
|
||||
|
||||
@ -19,6 +19,11 @@ namespace Artemis.Profiles.Lua
|
||||
|
||||
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);
|
||||
_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,
|
||||
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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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);
|
||||
if (font == null)
|
||||
throw new ScriptRuntimeException($"Font '{fontName}' not found");
|
||||
|
||||
@ -11,6 +11,7 @@ using Artemis.Profiles.Layers.Models;
|
||||
using Artemis.Profiles.Lua;
|
||||
using Artemis.Utilities;
|
||||
using Artemis.Utilities.ParentChild;
|
||||
using Castle.Core.Internal;
|
||||
using Newtonsoft.Json;
|
||||
using Color = System.Windows.Media.Color;
|
||||
using Point = System.Windows.Point;
|
||||
@ -23,7 +24,6 @@ namespace Artemis.Profiles
|
||||
public ProfileModel()
|
||||
{
|
||||
Layers = new ChildItemCollection<ProfileModel, LayerModel>(this);
|
||||
LuaWrapper = new LuaWrapper(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -106,6 +106,9 @@ namespace Artemis.Profiles
|
||||
internal void DrawLayers(Graphics g, IEnumerable<LayerModel> renderLayers, IDataModel dataModel, Rect rect,
|
||||
bool preview, bool updateAnimations)
|
||||
{
|
||||
if (LuaWrapper == null && !LuaScript.IsNullOrEmpty())
|
||||
LuaWrapper = new LuaWrapper(this);
|
||||
|
||||
var visual = new DrawingVisual();
|
||||
var layerModels = renderLayers.ToList();
|
||||
using (var c = visual.RenderOpen())
|
||||
|
||||
@ -17,6 +17,7 @@ using Artemis.Models;
|
||||
using Artemis.Profiles;
|
||||
using Artemis.Profiles.Layers.Models;
|
||||
using Artemis.Profiles.Layers.Types.Folder;
|
||||
using Artemis.Profiles.Lua;
|
||||
using Artemis.Services;
|
||||
using Artemis.Styles.DropTargetAdorners;
|
||||
using Artemis.Utilities;
|
||||
@ -231,6 +232,8 @@ namespace Artemis.ViewModels.Profiles
|
||||
public void Deactivate()
|
||||
{
|
||||
ProfileViewModel.Deactivate();
|
||||
if (SelectedProfile != null)
|
||||
SelectedProfile.LuaWrapper = null;
|
||||
_saveTimer.Stop();
|
||||
}
|
||||
|
||||
@ -699,9 +702,14 @@ namespace Artemis.ViewModels.Profiles
|
||||
|
||||
public void EditLua()
|
||||
{
|
||||
if (SelectedProfile == null)
|
||||
return;
|
||||
try
|
||||
{
|
||||
SelectedProfile?.LuaWrapper.OpenEditor();
|
||||
if (SelectedProfile.LuaWrapper == null)
|
||||
SelectedProfile.LuaWrapper = new LuaWrapper(SelectedProfile);
|
||||
|
||||
SelectedProfile.LuaWrapper.OpenEditor();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@ -146,7 +146,8 @@
|
||||
</Button.Content>
|
||||
</Button>
|
||||
<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>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Rectangle
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user