Simplify NoPlugin

This commit is contained in:
Thorsten Sommer 2025-03-21 20:31:59 +01:00
parent 51f34392ed
commit 8fc6cb326b
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 6 additions and 7 deletions

View File

@ -5,6 +5,5 @@ namespace AIStudio.Tools.PluginSystem;
/// <summary>
/// Represents a plugin that could not be loaded.
/// </summary>
/// <param name="state">The Lua state that the plugin was loaded into.</param>
/// <param name="parsingError">The error message that occurred while parsing the plugin.</param>
public sealed class NoPlugin(LuaState state, string parsingError) : PluginBase(string.Empty, state, PluginType.NONE, parsingError);
public sealed class NoPlugin(string parsingError) : PluginBase(string.Empty, LuaState.Create(), PluginType.NONE, parsingError);

View File

@ -100,23 +100,23 @@ public static class PluginFactory
}
catch (LuaParseException e)
{
return new NoPlugin(state, $"Was not able to parse the plugin: {e.Message}");
return new NoPlugin($"Was not able to parse the plugin: {e.Message}");
}
if (!state.Environment["TYPE"].TryRead<string>(out var typeText))
return new NoPlugin(state, "TYPE does not exist or is not a valid string.");
return new NoPlugin("TYPE does not exist or is not a valid string.");
if (!Enum.TryParse<PluginType>(typeText, out var type))
return new NoPlugin(state, $"TYPE is not a valid plugin type. Valid types are: {CommonTools.GetAllEnumValues<PluginType>()}");
return new NoPlugin($"TYPE is not a valid plugin type. Valid types are: {CommonTools.GetAllEnumValues<PluginType>()}");
if(type is PluginType.NONE)
return new NoPlugin(state, $"TYPE is not a valid plugin type. Valid types are: {CommonTools.GetAllEnumValues<PluginType>()}");
return new NoPlugin($"TYPE is not a valid plugin type. Valid types are: {CommonTools.GetAllEnumValues<PluginType>()}");
return type switch
{
PluginType.LANGUAGE => new PluginLanguage(path, state, type),
_ => new NoPlugin(state, "This plugin type is not supported yet. Please try again with a future version of AI Studio.")
_ => new NoPlugin("This plugin type is not supported yet. Please try again with a future version of AI Studio.")
};
}
}