Scripting - Enabled scripting (#638)

* Scripting - Simplified view model structure
* Scripting - Removed Layer and LayerProperty scripts
This commit is contained in:
Robert Beekman authored and GitHub committed 2021-07-04 11:45:32 +02:00
1 parent ee16d69fb3
commit 631d8de2c3
26 files changed
+278 -578

No files matched your search

@@ -18,8 +18,7 @@ namespace Artemis.Core.Services
/// </summary>
/// <param name="scriptConfiguration">The script configuration of the script</param>
/// <returns>
/// If the <see cref="ScriptingProvider" /> was found an instance of the script; otherwise <see langword="null" />
/// .
/// If the <see cref="ScriptingProvider" /> was found an instance of the script; otherwise <see langword="null" />.
/// </returns>
GlobalScript? CreateScriptInstance(ScriptConfiguration scriptConfiguration);
@@ -29,33 +28,10 @@ namespace Artemis.Core.Services
/// <param name="profile">The profile the script configuration is configured for</param>
/// <param name="scriptConfiguration">The script configuration of the script</param>
/// <returns>
/// If the <see cref="ScriptingProvider" /> was found an instance of the script; otherwise <see langword="null" />
/// .
/// If the <see cref="ScriptingProvider" /> was found an instance of the script; otherwise <see langword="null" />.
/// </returns>
ProfileScript? CreateScriptInstance(Profile profile, ScriptConfiguration scriptConfiguration);
/// <summary>
/// Creates a <see cref="LayerScript" /> instance for the given <paramref name="scriptConfiguration" />
/// </summary>
/// <param name="layer">The layer the script configuration is configured fo</param>
/// <param name="scriptConfiguration">The script configuration of the script</param>
/// <returns>
/// If the <see cref="ScriptingProvider" /> was found an instance of the script; otherwise <see langword="null" />
/// .
/// </returns>
LayerScript? CreateScriptInstance(Layer layer, ScriptConfiguration scriptConfiguration);
/// <summary>
/// Creates a <see cref="PropertyScript" /> instance for the given <paramref name="scriptConfiguration" />
/// </summary>
/// <param name="layerProperty">The layer property the script configuration is configured fo</param>
/// <param name="scriptConfiguration">The script configuration of the script</param>
/// <returns>
/// If the <see cref="ScriptingProvider" /> was found an instance of the script; otherwise <see langword="null" />
/// .
/// </returns>
PropertyScript? CreateScriptInstance(ILayerProperty layerProperty, ScriptConfiguration scriptConfiguration);
/// <summary>
/// Deletes the provided global script by it's configuration
/// </summary>
+9 -65
View File
@@ -12,11 +12,13 @@ namespace Artemis.Core.Services
internal class ScriptingService : IScriptingService
{
private readonly IPluginManagementService _pluginManagementService;
private readonly IProfileService _profileService;
private List<ScriptingProvider> _scriptingProviders;
public ScriptingService(IPluginManagementService pluginManagementService, IProfileService profileService)
{
_pluginManagementService = pluginManagementService;
_profileService = profileService;
InternalGlobalScripts = new List<GlobalScript>();
@@ -27,7 +29,7 @@ namespace Artemis.Core.Services
// No need to sub to Deactivated, scripts will deactivate themselves
profileService.ProfileActivated += ProfileServiceOnProfileActivated;
foreach (ProfileConfiguration profileConfiguration in profileService.ProfileConfigurations)
foreach (ProfileConfiguration profileConfiguration in _profileService.ProfileConfigurations)
{
if (profileConfiguration.Profile != null)
InitializeProfileScripts(profileConfiguration.Profile);
@@ -54,6 +56,12 @@ namespace Artemis.Core.Services
private void PluginManagementServiceOnPluginFeatureToggled(object? sender, PluginFeatureEventArgs e)
{
_scriptingProviders = _pluginManagementService.GetFeaturesOfType<ScriptingProvider>();
foreach (ProfileConfiguration profileConfiguration in _profileService.ProfileConfigurations)
{
if (profileConfiguration.Profile != null)
InitializeProfileScripts(profileConfiguration.Profile);
}
}
private void ProfileServiceOnProfileActivated(object? sender, ProfileConfigurationEventArgs e)
@@ -67,30 +75,6 @@ namespace Artemis.Core.Services
// Initialize the scripts on the profile
foreach (ScriptConfiguration scriptConfiguration in profile.ScriptConfigurations.Where(c => c.Script == null))
CreateScriptInstance(profile, scriptConfiguration);
foreach (Layer layer in profile.GetAllLayers())
{
// Initialize the scripts on the layers
foreach (ScriptConfiguration scriptConfiguration in layer.ScriptConfigurations.Where(c => c.Script == null))
CreateScriptInstance(layer, scriptConfiguration);
// Initialize the scripts on the layer properties of layers
foreach (ILayerProperty layerProperty in layer.GetAllLayerProperties())
{
foreach (ScriptConfiguration scriptConfiguration in layerProperty.ScriptConfigurations.Where(c => c.Script == null))
CreateScriptInstance(layerProperty, scriptConfiguration);
}
}
foreach (Folder folder in profile.GetAllFolders())
{
// Initialize the scripts on the layer properties of folders
foreach (ILayerProperty layerProperty in folder.GetAllLayerProperties())
{
foreach (ScriptConfiguration scriptConfiguration in layerProperty.ScriptConfigurations.Where(c => c.Script == null))
CreateScriptInstance(layerProperty, scriptConfiguration);
}
}
}
public ReadOnlyCollection<GlobalScript> GlobalScripts => InternalGlobalScripts.AsReadOnly();
@@ -136,46 +120,6 @@ namespace Artemis.Core.Services
return script;
}
public LayerScript? CreateScriptInstance(Layer layer, ScriptConfiguration scriptConfiguration)
{
if (scriptConfiguration.Script != null)
throw new ArtemisCoreException("The provided script configuration already has an active script");
ScriptingProvider? provider = _scriptingProviders.FirstOrDefault(p => p.Id == scriptConfiguration.ScriptingProviderId);
if (provider == null)
return null;
LayerScript script = (LayerScript) provider.Plugin.Kernel!.Get(
provider.LayerScriptType,
CreateScriptConstructorArgument(provider.LayerScriptType, layer),
CreateScriptConstructorArgument(provider.LayerScriptType, scriptConfiguration)
);
script.ScriptingProvider = provider;
provider.InternalScripts.Add(script);
return script;
}
public PropertyScript? CreateScriptInstance(ILayerProperty layerProperty, ScriptConfiguration scriptConfiguration)
{
if (scriptConfiguration.Script != null)
throw new ArtemisCoreException("The provided script configuration already has an active script");
ScriptingProvider? provider = _scriptingProviders.FirstOrDefault(p => p.Id == scriptConfiguration.ScriptingProviderId);
if (provider == null)
return null;
PropertyScript script = (PropertyScript) provider.Plugin.Kernel!.Get(
provider.PropertyScriptType,
CreateScriptConstructorArgument(provider.PropertyScriptType, layerProperty),
CreateScriptConstructorArgument(provider.PropertyScriptType, scriptConfiguration)
);
script.ScriptingProvider = provider;
provider.InternalScripts.Add(script);
return script;
}
/// <inheritdoc />
public void DeleteScript(ScriptConfiguration scriptConfiguration)
{