1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Storage - Added migration to clear the DB

Profile - Don't store empty visual scripts
Profile tree - Improved drag & drop
This commit is contained in:
Robert 2022-08-04 23:01:13 +02:00
parent 73a80ef476
commit e9566ca689
22 changed files with 73 additions and 515 deletions

View File

@ -140,6 +140,7 @@ public class EventCondition : CorePropertyChanged, INodeScriptCondition
valueChangedNode.UpdateOutputPins(EventPath);
}
Script.Save();
}
private void ReplaceStartNode(IEventConditionNode newStartNode)
@ -270,7 +271,7 @@ public class EventCondition : CorePropertyChanged, INodeScriptCondition
Script = _entity.Script != null
? new NodeScript<bool>($"Activate {_displayName}", $"Whether or not the event should activate the {_displayName}", _entity.Script, ProfileElement.Profile)
: new NodeScript<bool>($"Activate {_displayName}", $"Whether or not the event should activate the {_displayName}", ProfileElement.Profile);
: new NodeScript<bool>($"Activate {_displayName}", $"Whether or not the event should activate the {_displayName}", ProfileElement.Profile);
UpdateEventNode();
}
@ -281,8 +282,17 @@ public class EventCondition : CorePropertyChanged, INodeScriptCondition
_entity.OverlapMode = (int) OverlapMode;
_entity.ToggleOffMode = (int) ToggleOffMode;
Script.Save();
_entity.Script = Script?.Entity;
// If the exit node isn't connected and there are only the start- and exit node, don't save the script
if (!Script.ExitNodeConnected && Script.Nodes.Count() <= 2)
{
_entity.Script = null;
}
else
{
Script.Save();
_entity.Script = Script.Entity;
}
EventPath?.Save();
_entity.EventPath = EventPath?.Entity;
}

View File

@ -1,4 +1,5 @@
using System;
using System.Linq;
using Artemis.Storage.Entities.Profile.Abstract;
using Artemis.Storage.Entities.Profile.Conditions;
@ -123,7 +124,9 @@ namespace Artemis.Core
PlayMode = (StaticPlayMode) _entity.PlayMode;
StopMode = (StaticStopMode) _entity.StopMode;
Script = new NodeScript<bool>($"Activate {_displayName}", $"Whether or not this {_displayName} should be active", _entity.Script, ProfileElement.Profile);
Script = _entity.Script != null
? new NodeScript<bool>($"Activate {_displayName}", $"Whether or not this {_displayName} should be active", _entity.Script, ProfileElement.Profile)
: new NodeScript<bool>($"Activate {_displayName}", $"Whether or not this {_displayName} should be active", ProfileElement.Profile);
}
/// <inheritdoc />
@ -132,8 +135,16 @@ namespace Artemis.Core
_entity.PlayMode = (int) PlayMode;
_entity.StopMode = (int) StopMode;
Script.Save();
_entity.Script = Script.Entity;
// If the exit node isn't connected and there is only the exit node, don't save the script
if (!Script.ExitNodeConnected && Script.Nodes.Count() == 1)
{
_entity.Script = null;
}
else
{
Script.Save();
_entity.Script = Script.Entity;
}
}
/// <inheritdoc />

View File

@ -39,7 +39,7 @@ namespace Artemis.Core
/// Gets the layer property this data binding targets
/// </summary>
public LayerProperty<TLayerProperty> LayerProperty { get; }
/// <inheritdoc />
public INodeScript Script => _script;
@ -204,7 +204,6 @@ namespace Artemis.Core
/// <inheritdoc />
public event EventHandler<DataBindingEventArgs>? DataBindingDisabled;
#region Storage
/// <inheritdoc />
@ -231,9 +230,14 @@ namespace Artemis.Core
if (_disposed)
throw new ObjectDisposedException("DataBinding");
_script.Save();
Entity.IsEnabled = IsEnabled;
Entity.NodeScript = _script.Entity.Nodes.Any() ? _script.Entity : null;
if (_script.ExitNodeConnected || _script.Nodes.Count() > 1)
{
_script.Save();
Entity.NodeScript = _script.Entity;
}
else
Entity.NodeScript = null;
}
#endregion

View File

@ -402,6 +402,8 @@ namespace Artemis.Core
{
ExitNode = new ExitNode<T>(name, description);
AddNode(ExitNode);
Save();
}
[UsedImplicitly(ImplicitUseKindFlags.InstantiatedWithFixedConstructorSignature)]

View File

@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LiteDB" Version="5.0.11"/>
<PackageReference Include="Serilog" Version="2.10.0"/>
<PackageReference Include="LiteDB" Version="5.0.11" />
<PackageReference Include="Serilog" Version="2.10.0" />
</ItemGroup>
</Project>

View File

@ -1,18 +0,0 @@
using Artemis.Storage.Migrations.Interfaces;
using LiteDB;
namespace Artemis.Storage.Migrations
{
public class M0001AttributeBasedPropertiesMigration : IStorageMigration
{
public int UserVersion => 1;
public void Apply(LiteRepository repository)
{
// DropCollection will open a transaction so commit the current one
repository.Database.Commit();
if (repository.Database.CollectionExists("ProfileEntity"))
repository.Database.DropCollection("ProfileEntity");
}
}
}

View File

@ -1,37 +0,0 @@
using System.Collections.Generic;
using Artemis.Storage.Entities.Profile;
using Artemis.Storage.Migrations.Interfaces;
using LiteDB;
namespace Artemis.Storage.Migrations
{
public class M0002ProfileEntitiesEnabledMigration : IStorageMigration
{
public int UserVersion => 2;
public void Apply(LiteRepository repository)
{
List<ProfileEntity> profiles = repository.Query<ProfileEntity>().ToList();
foreach (ProfileEntity profileEntity in profiles)
{
foreach (FolderEntity profileEntityFolder in profileEntity.Folders)
{
profileEntityFolder.Suspended = false;
// Commented out during Avalonia port when Suspended was moved into the LayerEffect's LayerProperties
// foreach (LayerEffectEntity layerEffectEntity in profileEntityFolder.LayerEffects)
// layerEffectEntity.Suspended = false;
}
foreach (LayerEntity profileEntityLayer in profileEntity.Layers)
{
profileEntityLayer.Suspended = false;
// Commented out during Avalonia port when Suspended was moved into the LayerEffect's LayerProperties
// foreach (LayerEffectEntity layerEffectEntity in profileEntityLayer.LayerEffects)
// layerEffectEntity.Suspended = false;
}
repository.Upsert(profileEntity);
}
}
}
}

View File

@ -1,20 +0,0 @@
using Artemis.Storage.Migrations.Interfaces;
using LiteDB;
namespace Artemis.Storage.Migrations
{
public class M0003PluginEntitiesIndexChangesMigration : IStorageMigration
{
public int UserVersion => 3;
public void Apply(LiteRepository repository)
{
// DropCollection will open a transaction so commit the current one
repository.Database.Commit();
if (repository.Database.CollectionExists("PluginEntity"))
repository.Database.DropCollection("PluginEntity");
if (repository.Database.CollectionExists("PluginSettingEntity"))
repository.Database.DropCollection("PluginSettingEntity");
}
}
}

View File

@ -1,44 +0,0 @@
using Artemis.Storage.Entities.Profile;
using Artemis.Storage.Migrations.Interfaces;
using LiteDB;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Artemis.Storage.Migrations
{
public class M0004ProfileSegmentsMigration : IStorageMigration
{
public int UserVersion => 4;
public void Apply(LiteRepository repository)
{
// Lesson for next time: Use BsonDocuments in migrations
// List<ProfileEntity> profiles = repository.Query<ProfileEntity>().ToList();
// foreach (ProfileEntity profileEntity in profiles)
// {
// foreach (FolderEntity folder in profileEntity.Folders.Where(f => f.MainSegmentLength == TimeSpan.Zero))
// {
// if (folder.PropertyEntities.Any(p => p.KeyframeEntities.Any()))
// folder.MainSegmentLength = folder.PropertyEntities.Where(p => p.KeyframeEntities.Any()).Max(p => p.KeyframeEntities.Max(k => k.Position));
// if (folder.MainSegmentLength == TimeSpan.Zero)
// folder.MainSegmentLength = TimeSpan.FromSeconds(5);
//
// folder.PlayMode = 0;
// }
//
// foreach (LayerEntity layer in profileEntity.Layers.Where(l => l.MainSegmentLength == TimeSpan.Zero))
// {
// if (layer.PropertyEntities.Any(p => p.KeyframeEntities.Any()))
// layer.MainSegmentLength = layer.PropertyEntities.Where(p => p.KeyframeEntities.Any()).Max(p => p.KeyframeEntities.Max(k => k.Position));
// if (layer.MainSegmentLength == TimeSpan.Zero)
// layer.MainSegmentLength = TimeSpan.FromSeconds(5);
//
// layer.PlayMode = 0;
// }
//
// repository.Update(profileEntity);
// }
}
}
}

View File

@ -1,31 +0,0 @@
using Artemis.Storage.Migrations.Interfaces;
using LiteDB;
namespace Artemis.Storage.Migrations
{
public class M0005DataBindingTypes : IStorageMigration
{
public int UserVersion => 5;
public void Apply(LiteRepository repository)
{
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
foreach (BsonDocument bsonDocument in collection.FindAll())
{
foreach (BsonValue bsonLayer in bsonDocument["Layers"].AsArray)
{
foreach (BsonValue bsonPropertyEntity in bsonLayer["PropertyEntities"].AsArray)
bsonPropertyEntity["DataBindingEntities"].AsArray.Clear();
}
foreach (BsonValue bsonLayer in bsonDocument["Folders"].AsArray)
{
foreach (BsonValue bsonPropertyEntity in bsonLayer["PropertyEntities"].AsArray)
bsonPropertyEntity["DataBindingEntities"].AsArray.Clear();
}
collection.Update(bsonDocument);
}
}
}
}

View File

@ -1,49 +0,0 @@
using System;
using Artemis.Storage.Migrations.Interfaces;
using LiteDB;
namespace Artemis.Storage.Migrations
{
public class M0006PredicateAbstraction : IStorageMigration
{
public int UserVersion => 6;
public void Apply(LiteRepository repository)
{
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
foreach (BsonDocument bsonDocument in collection.FindAll())
{
foreach (BsonValue bsonLayer in bsonDocument["Layers"].AsArray)
Migrate(bsonLayer);
foreach (BsonValue bsonLayer in bsonDocument["Folders"].AsArray)
Migrate(bsonLayer);
collection.Update(bsonDocument);
}
}
private void Migrate(BsonValue bsonValue)
{
if (bsonValue.IsArray)
{
foreach (BsonValue child in bsonValue.AsArray)
Migrate(child);
return;
}
if (bsonValue.IsDocument)
{
// See if the document has a type
if (bsonValue.AsDocument.TryGetValue("_type", out BsonValue typeValue))
{
if (typeValue.AsString == "Artemis.Storage.Entities.Profile.Conditions.DataModelConditionPredicateEntity, Artemis.Storage")
bsonValue.AsDocument["_type"] = "Artemis.Storage.Entities.Profile.Conditions.DataModelConditionGeneralPredicateEntity, Artemis.Storage";
}
foreach (BsonValue documentValue in bsonValue.AsDocument.Values)
Migrate(documentValue);
}
}
}
}

View File

@ -1,124 +0,0 @@
using System.Collections.Generic;
using Artemis.Storage.Migrations.Interfaces;
using LiteDB;
namespace Artemis.Storage.Migrations
{
public class M0008PluginFeatures : IStorageMigration
{
private void Migrate(BsonValue bsonValue, Dictionary<string, string> pluginMap)
{
if (bsonValue.IsArray)
{
foreach (BsonValue child in bsonValue.AsArray)
Migrate(child, pluginMap);
return;
}
if (bsonValue.IsDocument)
{
// Data model paths
ReplaceIfFound(bsonValue, "DataModelGuid", "DataModelId", pluginMap);
// Layer effects
if (bsonValue.AsDocument.ContainsKey("EffectType"))
ReplaceIfFound(bsonValue, "PluginGuid", "ProviderId", pluginMap);
// Properties
if (bsonValue.AsDocument.ContainsKey("KeyframesEnabled"))
ReplaceIfFound(bsonValue, "PluginGuid", "FeatureId", pluginMap);
foreach (BsonValue documentValue in bsonValue.AsDocument.Values)
Migrate(documentValue, pluginMap);
}
}
private bool ReplaceIfFound(BsonValue bsonValue, string oldKey, string newKey, Dictionary<string, string> pluginMap)
{
if (bsonValue.AsDocument.TryGetValue(oldKey, out BsonValue dataModelValue))
if (pluginMap.TryGetValue(dataModelValue.AsGuid.ToString(), out string featureId))
{
bsonValue.AsDocument[newKey] = featureId;
bsonValue.AsDocument.Remove(oldKey);
return true;
}
return false;
}
public int UserVersion => 8;
public void Apply(LiteRepository repository)
{
Dictionary<string, string> pluginMap = new()
{
{"ffffffff-ffff-ffff-ffff-ffffffffffff", "Artemis.Core.CorePluginFeature-ffffffff"},
{"ab41d601-35e0-4a73-bf0b-94509b006ab0", "Artemis.Plugins.DataModelExpansions.TestData.PluginDataModelExpansion-ab41d601"},
{"c20e876f-7cb0-4fa1-b0cc-ae1afb5865d1", "Artemis.Plugins.Devices.Asus.AsusDeviceProvider-c20e876f"},
{"b78f644b-827f-4bb4-bf03-2adaa365b58b", "Artemis.Plugins.Devices.CoolerMaster.CoolerMasterDeviceProvider-b78f644b"},
{"926629ab-8170-42f3-be18-22c694aa91cd", "Artemis.Plugins.Devices.Corsair.CorsairDeviceProvider-926629ab"},
{"cad475d3-c621-4ec7-bbfc-784e3b4723ce", "Artemis.Plugins.Devices.Debug.DebugDeviceProvider-cad475d3"},
{"6f073d4d-d97d-4040-9750-841fdbe06915", "Artemis.Plugins.Devices.DMX.DMXDeviceProvider-6f073d4d"},
{"62a45c0c-884c-4868-9fd7-3c5987fe07ca", "Artemis.Plugins.Devices.Logitech.LogitechDeviceProvider-62a45c0c"},
{"9177c320-1206-48a3-af52-b1749c758786", "Artemis.Plugins.Devices.Msi.MsiDeviceProvider-9177c320"},
{"a487332f-c4b3-43e7-b80f-f33adc6fff87", "Artemis.Plugins.Devices.Novation.NovationDeviceProvider-a487332f"},
{"58a3d80e-d5cb-4a40-9465-c0a5d54825d6", "Artemis.Plugins.Devices.Razer.RazerDeviceProvider-58a3d80e"},
{"10049953-94c1-4102-988b-9e4f0b64c232", "Artemis.Plugins.Devices.Roccat.RoccatDeviceProvider-10049953"},
{"27945704-6edd-48b4-bc0e-319cce9693fc", "Artemis.Plugins.Devices.SteelSeries.SteelSeriesDeviceProvider-27945704"},
{"e70fd5ba-9881-480a-8ff6-078ed5f747fa", "Artemis.Plugins.Devices.Wooting.WootingDeviceProvider-e70fd5ba"},
{"ec86de32-1010-4bf7-97d7-1dcc46659ab6", "Artemis.Plugins.Devices.WS281X.WS281XDeviceProvider-ec86de32"},
{"92a9d6ba-6f7a-4937-94d5-c1d715b4141a", "Artemis.Plugins.LayerBrushes.Color.ColorBrushProvider-92a9d6ba"},
{"0bbf931b-87ad-4809-9cd9-bda33f4d4695", "Artemis.Plugins.LayerBrushes.ColorRgbNet.RgbNetColorBrushProvider-0bbf931b"},
{"61cbbf01-8d69-4ede-a972-f3f269da66d9", "Artemis.Plugins.LayerBrushes.Noise.NoiseBrushProvider-61cbbf01"},
{"0cb99d89-915b-407e-82ac-8316d0559c4e", "Artemis.Plugins.LayerBrushes.Chroma.ChromaLayerBrushProvider-0cb99d89"},
{"bf9cf3ac-9f97-4328-b32f-aa39df1698ff", "Artemis.Plugins.LayerBrushes.Gif.GifLayerBrushProvider-bf9cf3ac"},
{"4570510a-7c8b-4324-b915-cea738a65ac2", "Artemis.Plugins.LayerBrushes.Particle.ParticleLayerBrushProvider-4570510a"},
{"245aa860-4224-4d1c-ab81-2d6b5593a9fa", "Artemis.Plugins.LayerBrushes.Spectrum.PluginLayerBrushProvider-245aa860"},
{"fca5b5d6-3f86-4ea7-a271-06ec3fc219e2", "Artemis.Plugins.LayerEffects.Filter.FilterEffectProvider-fca5b5d6"},
{"0de2991a-d7b8-4f61-ae4e-6623849215b5", "Artemis.Plugins.Modules.General.GeneralModule-0de2991a"},
{"29e3ff97-83a5-44fc-a2dc-04f446b54146", "Artemis.Plugins.Modules.Overlay.OverlayModule-29e3ff97"},
{"ea2064cc-63ad-4a22-93e3-bfc71beb6c4b", "Artemis.Plugins.Modules.Fallout4.Fallout4Module-ea2064cc"},
{"a34dd13c-2d66-47a3-91fc-265749144d01", "Artemis.Plugins.Modules.LeagueOfLegends.LeagueOfLegendsModule-a34dd13c"},
{"49dff3a6-3d2a-444a-8346-582b2d61b776", "Module.EliteDangerous.EliteDangerousModule-49dff3a6"},
{"8f493ff1-0590-4c70-8a1d-e599e5580d21", "Artemis.Plugins.Modules.TruckSimulator.TruckSimulatorModule-8f493ff1"},
{"184ce933-b8ff-465f-b3d2-a23a17b35f65", "Artemis.Plugins.PhilipsHue.HueDataModelExpansion-184ce933"}
};
// Remove the default brush the user selected, this will make the UI pick a new one
repository.Database.Execute("DELETE PluginSettingEntity WHERE $.Name = \"ProfileEditor.DefaultLayerBrushDescriptor\"");
// Profiles
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
foreach (BsonDocument bsonDocument in collection.FindAll())
{
ReplaceIfFound(bsonDocument, "PluginGuid", "ModuleId", pluginMap);
foreach (BsonValue bsonLayer in bsonDocument["Layers"].AsArray)
{
Migrate(bsonLayer, pluginMap);
MigrateProperties(bsonLayer, pluginMap);
}
foreach (BsonValue bsonLayer in bsonDocument["Folders"].AsArray)
{
Migrate(bsonLayer, pluginMap);
MigrateProperties(bsonLayer, pluginMap);
}
collection.Update(bsonDocument);
}
}
private void MigrateProperties(BsonValue profileElementBson, Dictionary<string, string> pluginMap)
{
foreach (BsonValue bsonValue in profileElementBson["PropertyEntities"].AsArray)
{
if (bsonValue["Path"].AsString == "General.BrushReference")
{
bsonValue["Value"] = bsonValue["Value"].AsString.Replace("BrushPluginGuid", "LayerBrushProviderId");
foreach ((string key, string value) in pluginMap)
bsonValue["Value"] = bsonValue["Value"].AsString.Replace(key, value);
}
}
}
}
}

View File

@ -1,27 +0,0 @@
using Artemis.Storage.Migrations.Interfaces;
using LiteDB;
namespace Artemis.Storage.Migrations
{
public class M0009DeviceCalibration : IStorageMigration
{
public int UserVersion => 9;
/// <inheritdoc />
public void Apply(LiteRepository repository)
{
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("SurfaceEntity");
foreach (BsonDocument bsonDocument in collection.FindAll())
{
foreach (BsonValue bsonDevice in bsonDocument["DeviceEntities"].AsArray)
{
bsonDevice["RedScale"] = 1d;
bsonDevice["GreenScale"] = 1d;
bsonDevice["BlueScale"] = 1d;
}
collection.Update(bsonDocument);
}
}
}
}

View File

@ -1,55 +0,0 @@
using Artemis.Storage.Migrations.Interfaces;
using LiteDB;
namespace Artemis.Storage.Migrations
{
public class M0010BetterDataBindings : IStorageMigration
{
private void Migrate(BsonValue bsonValue)
{
if (!bsonValue.IsDocument || !bsonValue.AsDocument.TryGetValue("PropertyEntities", out BsonValue propertyEntities))
return;
foreach (BsonValue propertyEntity in propertyEntities.AsArray)
{
if (!propertyEntity.AsDocument.TryGetValue("DataBindingEntities", out BsonValue dataBindingEntities))
continue;
foreach (BsonValue dataBindingEntity in dataBindingEntities.AsArray)
{
if (!dataBindingEntity.AsDocument.TryGetValue("TargetExpression", out BsonValue targetExpression))
continue;
string value = targetExpression.AsString;
if (value == "value => value" || value == "b => b")
{
dataBindingEntity.AsDocument["Identifier"] = "Value";
}
else
{
string selector = value.Split("=>")[1];
string property = selector.Split(".")[1];
dataBindingEntity.AsDocument["Identifier"] = property;
}
dataBindingEntity.AsDocument.Remove("TargetExpression");
}
}
}
public int UserVersion => 10;
public void Apply(LiteRepository repository)
{
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
foreach (BsonDocument bsonDocument in collection.FindAll())
{
foreach (BsonValue bsonLayer in bsonDocument["Layers"].AsArray)
Migrate(bsonLayer);
foreach (BsonValue bsonLayer in bsonDocument["Folders"].AsArray)
Migrate(bsonLayer);
collection.Update(bsonDocument);
}
}
}
}

View File

@ -1,46 +0,0 @@
using Artemis.Storage.Migrations.Interfaces;
using LiteDB;
namespace Artemis.Storage.Migrations
{
public class M0011ColorGradients : IStorageMigration
{
private void Migrate(BsonValue bsonValue)
{
if (!bsonValue.IsDocument || !bsonValue.AsDocument.TryGetValue("PropertyEntities", out BsonValue propertyEntities))
return;
foreach (BsonValue propertyEntity in propertyEntities.AsArray)
{
if (propertyEntity["Value"] == null)
continue;
string valueString = propertyEntity["Value"].AsString;
if (valueString == null)
continue;
if (!valueString.StartsWith("{\"Stops\":[{") || !valueString.EndsWith("}]}"))
continue;
valueString = valueString.Replace("{\"Stops\":[{", "[{");
valueString = valueString.Replace("}]}", "}]");
propertyEntity["Value"] = valueString;
}
}
public int UserVersion => 11;
public void Apply(LiteRepository repository)
{
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
foreach (BsonDocument bsonDocument in collection.FindAll())
{
foreach (BsonValue bsonLayer in bsonDocument["Layers"].AsArray)
Migrate(bsonLayer);
foreach (BsonValue bsonLayer in bsonDocument["Folders"].AsArray)
Migrate(bsonLayer);
collection.Update(bsonDocument);
}
}
}
}

View File

@ -1,48 +0,0 @@
using System.Linq;
using Artemis.Storage.Entities.Profile;
using Artemis.Storage.Migrations.Interfaces;
using LiteDB;
namespace Artemis.Storage.Migrations
{
public class M0012ProfileCategories : IStorageMigration
{
public int UserVersion => 12;
public void Apply(LiteRepository repository)
{
ILiteCollection<ProfileCategoryEntity> profileCategories = repository.Database.GetCollection<ProfileCategoryEntity>();
profileCategories.EnsureIndex(s => s.Name, true);
ProfileCategoryEntity profileCategoryEntity = profileCategories.Find(c => c.Name == "Converted").FirstOrDefault();
if (profileCategoryEntity == null)
{
profileCategoryEntity = new ProfileCategoryEntity {Name = "Imported"};
profileCategories.Insert(profileCategoryEntity);
}
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
foreach (BsonDocument bsonDocument in collection.FindAll())
{
// Profiles with a ModuleId have not been converted
if (bsonDocument.ContainsKey("ModuleId"))
{
string moduleId = bsonDocument["ModuleId"].AsString;
bsonDocument.Remove("ModuleId");
ProfileConfigurationEntity profileConfiguration = new()
{
Name = bsonDocument["Name"].AsString,
MaterialIcon = "ApplicationImport",
ModuleId = moduleId,
ProfileId = bsonDocument["_id"].AsGuid
};
profileCategoryEntity.ProfileConfigurations.Add(profileConfiguration);
collection.Update(bsonDocument);
}
}
profileCategories.Update(profileCategoryEntity);
}
}
}

View File

@ -0,0 +1,22 @@
using System.Collections.Generic;
using System.Linq;
using Artemis.Storage.Entities.Profile;
using Artemis.Storage.Migrations.Interfaces;
using LiteDB;
namespace Artemis.Storage.Migrations
{
public class M0020AvaloniaReset : IStorageMigration
{
public int UserVersion => 20;
public void Apply(LiteRepository repository)
{
repository.Database.Commit();
List<string> collectionNames = repository.Database.GetCollectionNames().ToList();
foreach (string collectionName in collectionNames)
repository.Database.DropCollection(collectionName);
}
}
}

View File

@ -38,7 +38,7 @@ public class NodeEditorService : INodeEditorService
try
{
NodeEditorHistory history = GetHistory(nodeScript);
// If a scope is active add the command to it, the scope will execute it immediately
_nodeEditorCommandScopes.TryGetValue(nodeScript, out NodeEditorCommandScope? scope);
if (scope != null)

View File

@ -81,5 +81,6 @@ public class EventConditionViewModel : ActivatableViewModelBase
private async Task ExecuteOpenEditor()
{
await _windowService.ShowDialogAsync<NodeScriptWindowViewModel, bool>(("nodeScript", _eventCondition.Script));
await _profileEditorService.SaveProfileAsync();
}
}

View File

@ -52,5 +52,6 @@ public class StaticConditionViewModel : ActivatableViewModelBase
private async Task ExecuteOpenEditor()
{
await _windowService.ShowDialogAsync<NodeScriptWindowViewModel, bool>(("nodeScript", _staticCondition.Script));
await _profileEditorService.SaveProfileAsync();
}
}

View File

@ -63,7 +63,8 @@ public class ProfileTreeViewDropHandler : DropHandlerBase
TreeDropType dropType = TreeDropType.Before;
if (!targetNode.SupportsChildren)
{
if (position.Y > targetVisual.Bounds.Top + targetVisual.Bounds.Height / 2)
position = e.GetPosition(targetVisual);
if (position.Y > targetVisual.Bounds.Height / 2)
dropType = TreeDropType.After;
}
else
@ -71,10 +72,11 @@ public class ProfileTreeViewDropHandler : DropHandlerBase
IVisual? header = targetVisual.GetVisualDescendants().FirstOrDefault(d => d is Border b && b.Name == "PART_LayoutRoot");
if (header != null)
{
position = e.GetPosition(header);
double segments = header.Bounds.Height / 3.0;
if (position.Y > targetVisual.Bounds.Top + segments * 2)
if (position.Y > segments * 2)
dropType = TreeDropType.After;
else if (position.Y > targetVisual.Bounds.Top + segments)
else if (position.Y > segments)
dropType = TreeDropType.Into;
}
}

View File

@ -10,6 +10,7 @@ using Artemis.UI.Ninject.Factories;
using Artemis.UI.Screens.VisualScripting;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using Artemis.UI.Shared.Services.NodeEditor;
using Artemis.UI.Shared.Services.ProfileEditor;
using Artemis.UI.Shared.Services.ProfileEditor.Commands;
using Avalonia.Threading;
@ -72,7 +73,10 @@ public class DataBindingViewModel : ActivatableViewModelBase
public async Task OpenEditor()
{
if (LayerProperty != null && LayerProperty.BaseDataBinding.IsEnabled)
{
await _windowService.ShowDialogAsync<NodeScriptWindowViewModel, bool>(("nodeScript", LayerProperty.BaseDataBinding.Script));
await _profileEditorService.SaveProfileAsync();
}
}
private void Update(object? sender, EventArgs e)