|
@ -25,6 +25,14 @@ namespace IPA.Loader.Features |
|
|
/// <returns><see langword="true"/> if the feature is valid for the plugin, <see langword="false"/> otherwise</returns>
|
|
|
/// <returns><see langword="true"/> if the feature is valid for the plugin, <see langword="false"/> otherwise</returns>
|
|
|
public abstract bool Initialize(PluginLoader.PluginMetadata meta, string[] parameters); |
|
|
public abstract bool Initialize(PluginLoader.PluginMetadata meta, string[] parameters); |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Evaluates the Feature for use in conditional meta-Features. This should be re-calculated on every call, unless it can be proven to not change.
|
|
|
|
|
|
///
|
|
|
|
|
|
/// This will be called on every feature that returns <see langword="true" /> from <see cref="Initialize"/>
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>the truthiness of the Feature.</returns>
|
|
|
|
|
|
public virtual bool Evaluate() => true; |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// The message to be logged when the feature is not valid for a plugin.
|
|
|
/// The message to be logged when the feature is not valid for a plugin.
|
|
|
/// This should also be set whenever either <see cref="BeforeLoad"/> or <see cref="BeforeInit"/> returns false.
|
|
|
/// This should also be set whenever either <see cref="BeforeLoad"/> or <see cref="BeforeInit"/> returns false.
|
|
@ -61,11 +69,15 @@ namespace IPA.Loader.Features |
|
|
/// <param name="plugin">the plugin to ensure is loaded.</param>
|
|
|
/// <param name="plugin">the plugin to ensure is loaded.</param>
|
|
|
protected void RequireLoaded(PluginLoader.PluginMetadata plugin) => PluginLoader.Load(plugin); |
|
|
protected void RequireLoaded(PluginLoader.PluginMetadata plugin) => PluginLoader.Load(plugin); |
|
|
|
|
|
|
|
|
|
|
|
internal virtual bool StoreOnPlugin => true; |
|
|
|
|
|
|
|
|
private static readonly Dictionary<string, Type> featureTypes = new Dictionary<string, Type> |
|
|
private static readonly Dictionary<string, Type> featureTypes = new Dictionary<string, Type> |
|
|
{ |
|
|
{ |
|
|
{ "define-feature", typeof(DefineFeature) } |
|
|
{ "define-feature", typeof(DefineFeature) } |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
internal static bool HasFeature(string name) => featureTypes.ContainsKey(name); |
|
|
|
|
|
|
|
|
internal static bool RegisterFeature(string name, Type type) |
|
|
internal static bool RegisterFeature(string name, Type type) |
|
|
{ |
|
|
{ |
|
|
if (!typeof(Feature).IsAssignableFrom(type)) |
|
|
if (!typeof(Feature).IsAssignableFrom(type)) |
|
@ -103,7 +115,7 @@ namespace IPA.Loader.Features |
|
|
var parameters = new List<string>(); |
|
|
var parameters = new List<string>(); |
|
|
|
|
|
|
|
|
bool escape = false; |
|
|
bool escape = false; |
|
|
bool readingParams = false; |
|
|
|
|
|
|
|
|
int parens = 0; |
|
|
bool removeWhitespace = true; |
|
|
bool removeWhitespace = true; |
|
|
foreach (var chr in featureString) |
|
|
foreach (var chr in featureString) |
|
|
{ |
|
|
{ |
|
@ -119,18 +131,20 @@ namespace IPA.Loader.Features |
|
|
case '\\': |
|
|
case '\\': |
|
|
escape = true; |
|
|
escape = true; |
|
|
break; |
|
|
break; |
|
|
case '(' when !readingParams: |
|
|
|
|
|
|
|
|
case '(': |
|
|
|
|
|
parens++; |
|
|
|
|
|
if (parens != 1) goto default; |
|
|
removeWhitespace = true; |
|
|
removeWhitespace = true; |
|
|
readingParams = true; |
|
|
|
|
|
name = builder.ToString(); |
|
|
name = builder.ToString(); |
|
|
builder.Clear(); |
|
|
builder.Clear(); |
|
|
break; |
|
|
break; |
|
|
case ')' when readingParams: |
|
|
|
|
|
readingParams = false; |
|
|
|
|
|
|
|
|
case ')': |
|
|
|
|
|
parens--; |
|
|
|
|
|
if (parens != 0) goto default; |
|
|
goto case ','; |
|
|
goto case ','; |
|
|
case ',': |
|
|
case ',': |
|
|
|
|
|
if (parens > 1) goto default; |
|
|
parameters.Add(builder.ToString()); |
|
|
parameters.Add(builder.ToString()); |
|
|
if (!readingParams) break; |
|
|
|
|
|
builder.Clear(); |
|
|
builder.Clear(); |
|
|
removeWhitespace = true; |
|
|
removeWhitespace = true; |
|
|
break; |
|
|
break; |
|
@ -149,7 +163,7 @@ namespace IPA.Loader.Features |
|
|
|
|
|
|
|
|
parsed = new FeatureParse(name, parameters.ToArray()); |
|
|
parsed = new FeatureParse(name, parameters.ToArray()); |
|
|
|
|
|
|
|
|
if (readingParams) |
|
|
|
|
|
|
|
|
if (parens != 0) |
|
|
{ |
|
|
{ |
|
|
failException = new Exception("Malformed feature definition"); |
|
|
failException = new Exception("Malformed feature definition"); |
|
|
return false; |
|
|
return false; |
|
|