mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-01-01 02:03:32 +00:00
Updated default Rocket League profiles
Added GetRelativeColor to LUA API
This commit is contained in:
parent
c0918ebea6
commit
f26e60793c
@ -1,14 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using Artemis.DAL;
|
|
||||||
using Artemis.DeviceProviders;
|
using Artemis.DeviceProviders;
|
||||||
using Artemis.Profiles;
|
using Artemis.Profiles;
|
||||||
using Artemis.Profiles.Lua;
|
using Artemis.Profiles.Lua;
|
||||||
using Artemis.Profiles.Lua.Modules;
|
using Artemis.Profiles.Lua.Modules;
|
||||||
using Artemis.Properties;
|
|
||||||
using Castle.Core.Internal;
|
using Castle.Core.Internal;
|
||||||
using MoonSharp.Interpreter;
|
using MoonSharp.Interpreter;
|
||||||
using Ninject;
|
using Ninject;
|
||||||
@ -23,7 +19,6 @@ namespace Artemis.Managers
|
|||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly Script _luaScript;
|
private readonly Script _luaScript;
|
||||||
private List<LuaModule> _luaModules;
|
private List<LuaModule> _luaModules;
|
||||||
private FileSystemWatcher _watcher;
|
|
||||||
|
|
||||||
public LuaManager(IKernel kernel, ILogger logger, DeviceManager deviceManager)
|
public LuaManager(IKernel kernel, ILogger logger, DeviceManager deviceManager)
|
||||||
{
|
{
|
||||||
@ -178,67 +173,5 @@ namespace Artemis.Managers
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Editor
|
|
||||||
|
|
||||||
public void OpenEditor()
|
|
||||||
{
|
|
||||||
if (ProfileModel == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Create a temp file
|
|
||||||
var fileName = Guid.NewGuid() + ".lua";
|
|
||||||
var file = File.Create(Path.GetTempPath() + fileName);
|
|
||||||
file.Dispose();
|
|
||||||
|
|
||||||
// Add instructions to LUA script if it's a new file
|
|
||||||
if (ProfileModel.LuaScript.IsNullOrEmpty())
|
|
||||||
ProfileModel.LuaScript = Encoding.UTF8.GetString(Resources.lua_placeholder);
|
|
||||||
File.WriteAllText(Path.GetTempPath() + fileName, ProfileModel.LuaScript);
|
|
||||||
|
|
||||||
// Watch the file for changes
|
|
||||||
SetupWatcher(Path.GetTempPath(), fileName);
|
|
||||||
|
|
||||||
// Open the temp file with the default editor
|
|
||||||
System.Diagnostics.Process.Start(Path.GetTempPath() + fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetupWatcher(string path, string fileName)
|
|
||||||
{
|
|
||||||
if (_watcher == null)
|
|
||||||
{
|
|
||||||
_watcher = new FileSystemWatcher(Path.GetTempPath(), fileName);
|
|
||||||
_watcher.Changed += LuaFileChanged;
|
|
||||||
_watcher.EnableRaisingEvents = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
_watcher.Path = path;
|
|
||||||
_watcher.Filter = fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void LuaFileChanged(object sender, FileSystemEventArgs args)
|
|
||||||
{
|
|
||||||
if (args.ChangeType != WatcherChangeTypes.Changed)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (ProfileModel == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
lock (ProfileModel)
|
|
||||||
{
|
|
||||||
using (var fs = new FileStream(args.FullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
|
||||||
{
|
|
||||||
using (var sr = new StreamReader(fs))
|
|
||||||
{
|
|
||||||
ProfileModel.LuaScript = sr.ReadToEnd();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ProfileProvider.AddOrUpdate(ProfileModel);
|
|
||||||
SetupLua(ProfileModel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,10 +56,15 @@ namespace Artemis.Models
|
|||||||
|
|
||||||
private void DeviceManagerOnOnKeyboardChangedEvent(object sender, KeyboardChangedEventArgs args)
|
private void DeviceManagerOnOnKeyboardChangedEvent(object sender, KeyboardChangedEventArgs args)
|
||||||
{
|
{
|
||||||
|
if (!Initialized)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(Settings?.LastProfile))
|
if (!string.IsNullOrEmpty(Settings?.LastProfile))
|
||||||
Profile = ProfileProvider.GetProfile(DeviceManager.ActiveKeyboard, this, Settings.LastProfile);
|
Profile = ProfileProvider.GetProfile(DeviceManager.ActiveKeyboard, this, Settings.LastProfile);
|
||||||
else
|
else
|
||||||
Profile = ProfileProvider.GetProfile(DeviceManager.ActiveKeyboard, this, "Default");
|
Profile = ProfileProvider.GetProfile(DeviceManager.ActiveKeyboard, this, "Default");
|
||||||
|
|
||||||
|
Profile?.Activate(LuaManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called on creation
|
// Called on creation
|
||||||
@ -70,6 +75,8 @@ namespace Artemis.Models
|
|||||||
Profile = ProfileProvider.GetProfile(DeviceManager.ActiveKeyboard, this, Settings.LastProfile);
|
Profile = ProfileProvider.GetProfile(DeviceManager.ActiveKeyboard, this, Settings.LastProfile);
|
||||||
else
|
else
|
||||||
Profile = ProfileProvider.GetProfile(DeviceManager.ActiveKeyboard, this, "Default");
|
Profile = ProfileProvider.GetProfile(DeviceManager.ActiveKeyboard, this, "Default");
|
||||||
|
|
||||||
|
Profile?.Activate(LuaManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called every frame
|
// Called every frame
|
||||||
|
|||||||
@ -57,7 +57,7 @@ namespace Artemis.Profiles.Lua.Modules.Brushes
|
|||||||
{
|
{
|
||||||
var collection = new GradientStopCollection(gradientColors
|
var collection = new GradientStopCollection(gradientColors
|
||||||
.Select(gc => new GradientStop(gc.Key.Color, gc.Value)));
|
.Select(gc => new GradientStop(gc.Key.Color, gc.Value)));
|
||||||
|
|
||||||
Brush = new LinearGradientBrush(collection, new Point(startX, startY), new Point(endX, endY));
|
Brush = new LinearGradientBrush(collection, new Point(startX, startY), new Point(endX, endY));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Windows.Media;
|
||||||
using Artemis.Managers;
|
using Artemis.Managers;
|
||||||
using Artemis.Profiles.Lua.Modules.Brushes;
|
using Artemis.Profiles.Lua.Modules.Brushes;
|
||||||
using Artemis.Utilities;
|
using Artemis.Utilities;
|
||||||
@ -47,5 +50,35 @@ namespace Artemis.Profiles.Lua.Modules
|
|||||||
{
|
{
|
||||||
return new LuaRadialGradientBrush(gradientColors, centerX, centerY, originX, originY);
|
return new LuaRadialGradientBrush(gradientColors, centerX, centerY, originX, originY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LuaColor GetRelativeColor(Dictionary<LuaColor, double> gradientColors, double offset)
|
||||||
|
{
|
||||||
|
if (offset < 0)
|
||||||
|
offset = 0;
|
||||||
|
if (offset > 1)
|
||||||
|
offset = 1;
|
||||||
|
|
||||||
|
var gsc = new GradientStopCollection(gradientColors.Select(gc => new GradientStop(gc.Key.Color, gc.Value)));
|
||||||
|
var b = gsc.First(w => Math.Abs(w.Offset - gsc.Min(m => m.Offset)) < 0.01);
|
||||||
|
var a = gsc.First(w => Math.Abs(w.Offset - gsc.Max(m => m.Offset)) < 0.01);
|
||||||
|
|
||||||
|
foreach (var gs in gsc)
|
||||||
|
{
|
||||||
|
if (gs.Offset < offset && gs.Offset > b.Offset)
|
||||||
|
b = gs;
|
||||||
|
if (gs.Offset > offset && gs.Offset < a.Offset)
|
||||||
|
a = gs;
|
||||||
|
}
|
||||||
|
|
||||||
|
var color = new Color
|
||||||
|
{
|
||||||
|
ScA = (float) ((offset - b.Offset) * (a.Color.ScA - b.Color.ScA) / (a.Offset - b.Offset) + b.Color.ScA),
|
||||||
|
ScR = (float) ((offset - b.Offset) * (a.Color.ScR - b.Color.ScR) / (a.Offset - b.Offset) + b.Color.ScR),
|
||||||
|
ScG = (float) ((offset - b.Offset) * (a.Color.ScG - b.Color.ScG) / (a.Offset - b.Offset) + b.Color.ScG),
|
||||||
|
ScB = (float) ((offset - b.Offset) * (a.Color.ScB - b.Color.ScB) / (a.Offset - b.Offset) + b.Color.ScB)
|
||||||
|
};
|
||||||
|
|
||||||
|
return new LuaColor(color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -20,7 +20,7 @@ namespace Artemis.Profiles.Lua.Modules
|
|||||||
_layerModel = layerModel;
|
_layerModel = layerModel;
|
||||||
SavedProperties = new Wrappers.LuaLayerProperties(_layerModel);
|
SavedProperties = new Wrappers.LuaLayerProperties(_layerModel);
|
||||||
|
|
||||||
// Triger an update to fill up the Properties
|
// Trigger an update to fill up the Properties
|
||||||
_layerModel.Update(new ProfilePreviewDataModel(), true, false);
|
_layerModel.Update(new ProfilePreviewDataModel(), true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -192,7 +192,7 @@ namespace Artemis.Profiles
|
|||||||
|
|
||||||
public void Activate(LuaManager luaManager)
|
public void Activate(LuaManager luaManager)
|
||||||
{
|
{
|
||||||
if (!Equals(luaManager.ProfileModel, this))
|
if (!Equals(luaManager.ProfileModel, this) || luaManager.ProfileModel.LuaScript != LuaScript)
|
||||||
luaManager.SetupLua(this);
|
luaManager.SetupLua(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -53,7 +53,7 @@ using System.Windows;
|
|||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
|
||||||
[assembly: AssemblyVersion("1.7.0.0")]
|
[assembly: AssemblyVersion("1.7.1.0")]
|
||||||
[assembly: AssemblyFileVersion("1.7.0.0")]
|
[assembly: AssemblyFileVersion("1.7.1.0")]
|
||||||
[assembly: InternalsVisibleTo("Artemis.Explorables")]
|
[assembly: InternalsVisibleTo("Artemis.Explorables")]
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@ -15,6 +15,11 @@
|
|||||||
|
|
||||||
-- This event is raised after every profile update, before drawing.
|
-- This event is raised after every profile update, before drawing.
|
||||||
function updateHandler(profile, eventArgs)
|
function updateHandler(profile, eventArgs)
|
||||||
|
-- Don't do anything when previewing (this means the editor is open)
|
||||||
|
if eventArgs.Preview then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- In this example we only want to update once per frame when the keyboard is
|
-- In this example we only want to update once per frame when the keyboard is
|
||||||
-- updated. If you don't do this the updateHandler will trigger on every
|
-- updated. If you don't do this the updateHandler will trigger on every
|
||||||
-- device's update.
|
-- device's update.
|
||||||
@ -27,6 +32,11 @@ end
|
|||||||
|
|
||||||
-- This event is raised after every profile draw, after updating.
|
-- This event is raised after every profile draw, after updating.
|
||||||
function drawHandler(profile, eventArgs)
|
function drawHandler(profile, eventArgs)
|
||||||
|
-- Don't do anything when previewing (this means the editor is open)
|
||||||
|
if eventArgs.Preview then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- In this example we only want to draw to the keyboard. Each device has it's
|
-- In this example we only want to draw to the keyboard. Each device has it's
|
||||||
-- own drawing event
|
-- own drawing event
|
||||||
if eventArgs.DeviceType != "keyboard" then
|
if eventArgs.DeviceType != "keyboard" then
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
@ -16,9 +18,12 @@ 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.Properties;
|
||||||
using Artemis.Services;
|
using Artemis.Services;
|
||||||
using Artemis.Styles.DropTargetAdorners;
|
using Artemis.Styles.DropTargetAdorners;
|
||||||
using Artemis.Utilities;
|
using Artemis.Utilities;
|
||||||
|
using Caliburn.Micro;
|
||||||
|
using Castle.Core.Internal;
|
||||||
using GongSolutions.Wpf.DragDrop;
|
using GongSolutions.Wpf.DragDrop;
|
||||||
using MahApps.Metro.Controls.Dialogs;
|
using MahApps.Metro.Controls.Dialogs;
|
||||||
using Ninject;
|
using Ninject;
|
||||||
@ -43,6 +48,7 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
private ObservableCollection<string> _profileNames;
|
private ObservableCollection<string> _profileNames;
|
||||||
private bool _saving;
|
private bool _saving;
|
||||||
private ProfileModel _selectedProfile;
|
private ProfileModel _selectedProfile;
|
||||||
|
private FileSystemWatcher _watcher;
|
||||||
|
|
||||||
public ProfileEditorViewModel(DeviceManager deviceManager, LuaManager luaManager, EffectModel effectModel,
|
public ProfileEditorViewModel(DeviceManager deviceManager, LuaManager luaManager, EffectModel effectModel,
|
||||||
ProfileViewModel profileViewModel, MetroDialogService dialogService, WindowService windowService,
|
ProfileViewModel profileViewModel, MetroDialogService dialogService, WindowService windowService,
|
||||||
@ -138,7 +144,7 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
// Update the value
|
// Update the value
|
||||||
_selectedProfile = value;
|
_selectedProfile = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
NotifyOfPropertyChange(() => SelectedProfile);
|
NotifyOfPropertyChange(() => SelectedProfile);
|
||||||
NotifyOfPropertyChange(() => SelectedProfileName);
|
NotifyOfPropertyChange(() => SelectedProfileName);
|
||||||
}
|
}
|
||||||
@ -256,22 +262,26 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void LoadProfiles()
|
private void LoadProfiles()
|
||||||
{
|
{
|
||||||
ProfileNames.Clear();
|
Execute.OnUIThread(() =>
|
||||||
if (_effectModel == null || _deviceManager.ActiveKeyboard == null)
|
{
|
||||||
return;
|
ProfileNames.Clear();
|
||||||
|
if (_effectModel == null || _deviceManager.ActiveKeyboard == null)
|
||||||
|
return;
|
||||||
|
|
||||||
ProfileNames.AddRange(ProfileProvider.GetProfileNames(_deviceManager.ActiveKeyboard, _effectModel));
|
ProfileNames.AddRange(ProfileProvider.GetProfileNames(_deviceManager.ActiveKeyboard, _effectModel));
|
||||||
|
|
||||||
// If a profile name was provided, try to load it
|
// If a profile name was provided, try to load it
|
||||||
ProfileModel lastProfileModel = null;
|
ProfileModel lastProfileModel = null;
|
||||||
if (!string.IsNullOrEmpty(LastProfile))
|
if (!string.IsNullOrEmpty(LastProfile))
|
||||||
lastProfileModel = ProfileProvider.GetProfile(_deviceManager.ActiveKeyboard, _effectModel, LastProfile);
|
lastProfileModel = ProfileProvider.GetProfile(_deviceManager.ActiveKeyboard, _effectModel,
|
||||||
|
LastProfile);
|
||||||
|
|
||||||
if (lastProfileModel != null)
|
if (lastProfileModel != null)
|
||||||
SelectedProfile = lastProfileModel;
|
SelectedProfile = lastProfileModel;
|
||||||
else
|
else
|
||||||
SelectedProfile = ProfileProvider.GetProfile(_deviceManager.ActiveKeyboard, _effectModel,
|
SelectedProfile = ProfileProvider.GetProfile(_deviceManager.ActiveKeyboard, _effectModel,
|
||||||
ProfileNames.FirstOrDefault());
|
ProfileNames.FirstOrDefault());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -700,13 +710,12 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
return;
|
return;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_luaManager.SetupLua(SelectedProfile);
|
OpenEditor();
|
||||||
_luaManager.OpenEditor();
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
DialogService.ShowMessageBox("Couldn't open LUA file",
|
DialogService.ShowMessageBox("Couldn't open LUA file",
|
||||||
"Please make sure you have a program such as Notepad associated with the .lua extension.\n\n" +
|
"Please make sure you have a text editor associated with the .lua extension.\n\n" +
|
||||||
"Windows error message: \n" + e.Message);
|
"Windows error message: \n" + e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -758,5 +767,67 @@ namespace Artemis.ViewModels.Profiles
|
|||||||
}
|
}
|
||||||
_saving = false;
|
_saving = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region LUA Editor
|
||||||
|
|
||||||
|
public void OpenEditor()
|
||||||
|
{
|
||||||
|
if (SelectedProfile == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Create a temp file
|
||||||
|
var fileName = Guid.NewGuid() + ".lua";
|
||||||
|
var file = File.Create(Path.GetTempPath() + fileName);
|
||||||
|
file.Dispose();
|
||||||
|
|
||||||
|
// Add instructions to LUA script if it's a new file
|
||||||
|
if (SelectedProfile.LuaScript.IsNullOrEmpty())
|
||||||
|
SelectedProfile.LuaScript = Encoding.UTF8.GetString(Resources.lua_placeholder);
|
||||||
|
File.WriteAllText(Path.GetTempPath() + fileName, SelectedProfile.LuaScript);
|
||||||
|
|
||||||
|
// Watch the file for changes
|
||||||
|
SetupWatcher(Path.GetTempPath(), fileName);
|
||||||
|
|
||||||
|
// Open the temp file with the default editor
|
||||||
|
System.Diagnostics.Process.Start(Path.GetTempPath() + fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupWatcher(string path, string fileName)
|
||||||
|
{
|
||||||
|
if (_watcher == null)
|
||||||
|
{
|
||||||
|
_watcher = new FileSystemWatcher(Path.GetTempPath(), fileName);
|
||||||
|
_watcher.Changed += LuaFileChanged;
|
||||||
|
_watcher.EnableRaisingEvents = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
_watcher.Path = path;
|
||||||
|
_watcher.Filter = fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LuaFileChanged(object sender, FileSystemEventArgs args)
|
||||||
|
{
|
||||||
|
if (args.ChangeType != WatcherChangeTypes.Changed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (SelectedProfile == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
lock (SelectedProfile)
|
||||||
|
{
|
||||||
|
using (var fs = new FileStream(args.FullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||||
|
{
|
||||||
|
using (var sr = new StreamReader(fs))
|
||||||
|
{
|
||||||
|
SelectedProfile.LuaScript = sr.ReadToEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ProfileProvider.AddOrUpdate(SelectedProfile);
|
||||||
|
_luaManager.SetupLua(SelectedProfile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user