Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions BepisModSettings/ConfigAttributes/ActionConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;

namespace BepisModSettings.ConfigAttributes;

public class ActionConfig(Delegate action)
{
public Delegate Action { get; } = action ?? throw new ArgumentNullException(nameof(action));

public object Invoke(params object[] args) => Action.DynamicInvoke(args);
}

public class ActionConfig<T>(Action<T> action) : ActionConfig(action)
{
public void Invoke(T arg) => ((Action<T>)Action)(arg);
}

public class ActionConfig<T1, T2>(Action<T1, T2> action) : ActionConfig(action)
{
public void Invoke(T1 arg1, T2 arg2) => ((Action<T1, T2>)Action)(arg1, arg2);
}

public class FuncConfig<TResult>(Func<TResult> func) : ActionConfig(func)
{
public TResult Invoke() => ((Func<TResult>)Action)();
}

public class FuncConfig<T, TResult>(Func<T, TResult> func) : ActionConfig(func)
{
public TResult Invoke(T arg) => ((Func<T, TResult>)Action)(arg);
}
Comment thread
EIA485 marked this conversation as resolved.
19 changes: 19 additions & 0 deletions BepisModSettings/ConfigAttributes/CustomDataFeed.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using FrooxEngine;

namespace BepisModSettings.ConfigAttributes;

public delegate IAsyncEnumerable<DataFeedItem> DataFeedMethod(IReadOnlyList<string> path, IReadOnlyList<string> groupKeys);

public sealed class CustomDataFeed(DataFeedMethod action)
{
private readonly DataFeedMethod _action = action ?? throw new ArgumentNullException(nameof(action));

public IAsyncEnumerable<DataFeedItem> Build(IReadOnlyList<string> path, IReadOnlyList<string> groupKeys)
{
ArgumentNullException.ThrowIfNull(path);

return _action(path, groupKeys);
}
}
3 changes: 3 additions & 0 deletions BepisModSettings/ConfigAttributes/HiddenConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace BepisModSettings.ConfigAttributes;

public class HiddenConfig { }
8 changes: 8 additions & 0 deletions BepisModSettings/ConfigAttributes/ProtectedConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace BepisModSettings.ConfigAttributes;

public class ProtectedConfig(string maskString)
{
public ProtectedConfig() : this("*") { }

public string MaskString { get; } = maskString;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should document how this works as to not force mod devs to read the source

}
6 changes: 3 additions & 3 deletions BepisModSettings/DataFeeds/BepisNestedCategoryPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ internal static async IAsyncEnumerable<DataFeedItem> Enumerate(IReadOnlyList<str
}
else
{
DataFeedLabel noConfigs = new DataFeedLabel();
noConfigs.InitBase("InvalidCategory", path, null, "Settings.BepInEx.Plugins.Error".AsLocaleKey());
yield return noConfigs;
DataFeedLabel invalidCategory = new DataFeedLabel();
invalidCategory.InitBase("InvalidCategory", path, null, "Settings.BepInEx.Plugins.Error".AsLocaleKey());
yield return invalidCategory;
}
}
}
72 changes: 46 additions & 26 deletions BepisModSettings/DataFeeds/BepisPluginPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using BepInEx.NET.Common;
using BepInExResoniteShim;
using BepisLocaleLoader;
using BepisModSettings.ConfigAttributes;
using Elements.Core;
using FrooxEngine;
using FrooxEngine.UIX;
Expand Down Expand Up @@ -73,7 +74,7 @@
modGroup.InitBase("Metadata", path, null, "Settings.BepInEx.Plugins.Metadata".AsLocaleKey());
yield return modGroup;

string[] metadataGroup = new[] { "Metadata" };
string[] metadataGroup = ["Metadata"];

DataFeedIndicator<string> idIndicator = new DataFeedIndicator<string>();
idIndicator.InitBase("Id", path, metadataGroup, "Settings.BepInEx.Plugins.Guid".AsLocaleKey());
Expand Down Expand Up @@ -119,6 +120,8 @@
List<string> added = new List<string>();
foreach (ConfigEntryBase config in configFile.Values)
{
if (!Plugin.ShowHidden.Value && config.Description.Tags.Any(x => x is HiddenConfig)) continue;

Type valueType = config.SettingType;

string section = config.Definition.Section;
Expand Down Expand Up @@ -147,22 +150,24 @@
string initKey = section + "." + config.Definition.Key;
string key = added.Contains(initKey) ? initKey + added.Count : initKey;

// TODO: Figure out how to actually Localize config keys.
// TODO: Add Key for SubCategories
// TODO: Somehow support subcategories
LocaleString nameKey = config.Definition.Key;
LocaleString descKey = config.Description.Description;
LocaleString defaultKey = $"{config.Definition.Key} : {valueType}";
LocaleString valueKey = $"{config.Definition.Key} : {config.BoxedValue}";

string defaultKey = $"{config.Definition.Key} : {valueType}"; // "Settings.BepInEx.Plugins.Configs.Default".AsLocaleKey(("name", config.Definition.Key), ("type", valueType));
string valueKey = $"{config.Definition.Key} : {config.BoxedValue}"; // "Settings.BepInEx.Plugins.Configs.Value".AsLocaleKey(("name", config.Definition.Key), ("value", config.BoxedValue));
string nameKey = config.Definition.Key; // "Settings.BepInEx.Plugins.Configs.Name".AsLocaleKey(("name", config.Definition.Key));
string descKey = config.Description.Description; // "Settings.BepInEx.Plugins.Configs.Description".AsLocaleKey(("description", config.Description.Description));
bool hasLocale = LocaleLoader.PluginsWithLocales.Any(x => x.Metadata.GUID == metaData.ID);
if (hasLocale && config.Description.Tags.FirstOrDefault(x => x is ConfigLocale) is ConfigLocale localeString)

Check failure on line 160 in BepisModSettings/DataFeeds/BepisPluginPage.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ConfigLocale' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 160 in BepisModSettings/DataFeeds/BepisPluginPage.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ConfigLocale' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 160 in BepisModSettings/DataFeeds/BepisPluginPage.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ConfigLocale' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 160 in BepisModSettings/DataFeeds/BepisPluginPage.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ConfigLocale' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 160 in BepisModSettings/DataFeeds/BepisPluginPage.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ConfigLocale' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 160 in BepisModSettings/DataFeeds/BepisPluginPage.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ConfigLocale' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 160 in BepisModSettings/DataFeeds/BepisPluginPage.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ConfigLocale' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 160 in BepisModSettings/DataFeeds/BepisPluginPage.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ConfigLocale' could not be found (are you missing a using directive or an assembly reference?)
{
nameKey = localeString.Name;
descKey = localeString.Description;

// if (SettingsLocaleHelper.PluginsWithLocales.Any(x => x.Metadata.GUID == metaData.ID))
// {
// nameKey = config.Definition.Key.AsLocaleKey();
// descKey = config.Description.Description.AsLocaleKey();
//
// defaultKey = $"Settings.{metaData.ID}.Configs.Default".AsLocaleKey(("name", nameKey.content), ("type", valueType));
// valueKey = $"Settings.{metaData.ID}.Configs.Value".AsLocaleKey(("name", nameKey.content), ("value", config.BoxedValue));
// }
string formatted = localeString.Name.content.GetFormattedLocaleString();
defaultKey = $"{formatted} : {valueType}";
valueKey = $"{formatted} : {config.BoxedValue}";
}

InternalLocale internalLocale = new InternalLocale(nameKey, descKey);

added.Add(key);

Expand All @@ -172,7 +177,7 @@
{
DataFeedItem dummyField = null;

if (config.Description.Tags.Contains("Action") && config.Description.Tags.FirstOrDefault(x => x is Delegate) is Delegate del)
if (config.Description.Tags.FirstOrDefault(x => x is ActionConfig) is ActionConfig action)
{
DataFeedAction actionField = new DataFeedAction();
actionField.InitBase(key, path, groupingKeys, nameKey, descKey);
Expand All @@ -181,23 +186,37 @@
Button btn = syncDelegate.Slot.GetComponent<Button>();
if (btn == null) return;

btn.LocalPressed += (_, _) => del.DynamicInvoke();
btn.LocalPressed += (_, _) => action.Invoke();
});

dummyField = actionField;
}

if (dummyField == null)
bool customUi = false;
if (config.Description.Tags.FirstOrDefault(x => x is CustomDataFeed) is CustomDataFeed customDataFeed)
{
customUi = true;
IAsyncEnumerable<DataFeedItem> datafeed = customDataFeed.Build(path, groupingKeys);
await foreach (DataFeedItem item in datafeed)
{
yield return item;
}
}

if (dummyField == null && !customUi)
{
dummyField = new DataFeedValueField<dummy>();
dummyField.InitBase(key, path, groupingKeys, nameKey, descKey);
}

yield return dummyField;

if (!customUi)
{
yield return dummyField;
}
}
else if (valueType == typeof(bool))
{
yield return DataFeedHelpers.GenerateToggle(key, path, groupingKeys, config);
yield return DataFeedHelpers.GenerateToggle(key, path, groupingKeys, internalLocale, config);
}
else if (valueType.IsEnum)
{
Expand All @@ -215,7 +234,7 @@
}
else
{
enumItem = (DataFeedItem)DataFeedHelpers.GenerateEnumItemsAsync.MakeGenericMethod(valueType).Invoke(null, [key, path, groupingKeys, config]);
enumItem = (DataFeedItem)DataFeedHelpers.GenerateEnumItemsAsync.MakeGenericMethod(valueType).Invoke(null, [key, path, groupingKeys, internalLocale, config]);
}
}
catch (Exception e)
Expand All @@ -236,7 +255,7 @@

try
{
nullableEnumItems = (IAsyncEnumerable<DataFeedItem>)DataFeedHelpers.GenerateNullableEnumItemsAsync.MakeGenericMethod(nullableType).Invoke(null, [key, path, groupingKeys, config]);
nullableEnumItems = (IAsyncEnumerable<DataFeedItem>)DataFeedHelpers.GenerateNullableEnumItemsAsync.MakeGenericMethod(nullableType).Invoke(null, [key, path, groupingKeys, internalLocale, config]);
}
catch (Exception e)
{
Expand All @@ -261,11 +280,11 @@
{
if (!config.SettingType.IsTypeInjectable() && TomlTypeConverter.CanConvert(config.SettingType))
{
valueItem = DataFeedHelpers.GenerateProxyField(key, path, groupingKeys, config);
valueItem = DataFeedHelpers.GenerateProxyField(key, path, groupingKeys, internalLocale, config);
}
else
{
valueItem = (DataFeedItem)DataFeedHelpers.GenerateValueField.MakeGenericMethod(valueType).Invoke(null, [key, path, groupingKeys, config]);
valueItem = (DataFeedItem)DataFeedHelpers.GenerateValueField.MakeGenericMethod(valueType).Invoke(null, [key, path, groupingKeys, internalLocale, config]);
}
}
catch (Exception e)
Expand All @@ -292,7 +311,7 @@
{
Button btn = syncDelegate.Slot.GetComponent<Button>();
if (btn == null) return;

btn.LocalPressed += (_, _) => LoadConfigs(metaData.ID);
});
yield return loadAct;
Expand Down Expand Up @@ -348,6 +367,7 @@

yield return item;
}

private static void LoadConfigs(string pluginId)
{
Plugin.Log.LogDebug($"Loading Configs for {pluginId}");
Expand Down
4 changes: 2 additions & 2 deletions BepisModSettings/DataFeeds/BepisSettingsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal static async IAsyncEnumerable<DataFeedItem> Enumerate(IReadOnlyList<str
pluginsGrid.InitBase("PluginsGrid", path, ["BepInExPlugins"], "Settings.BepInEx.LoadedPlugins".AsLocaleKey());
yield return pluginsGrid;

string[] loadedPluginsGroup = new[] { "BepInExPlugins", "PluginsGrid" };
string[] loadedPluginsGroup = ["BepInExPlugins", "PluginsGrid"];

if (NetChainloader.Instance.Plugins.Count > 0)
{
Expand Down Expand Up @@ -65,7 +65,7 @@ internal static async IAsyncEnumerable<DataFeedItem> Enumerate(IReadOnlyList<str
coreGroup.InitBase("BepInExCore", path, null, "Settings.BepInEx.Core".AsLocaleKey());
yield return coreGroup;

string[] coreGroupParam = new[] { "BepInExCore" };
string[] coreGroupParam = ["BepInExCore"];

DataFeedCategory bepisCategory = new DataFeedCategory();
bepisCategory.InitBase("BepInEx.Core.Config", path, coreGroupParam, "Settings.BepInEx.Core.Config".AsLocaleKey());
Expand Down
Loading
Loading