Skip to content

Commit

Permalink
Mod list sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
dodad-2 committed Jan 14, 2024
1 parent 7a87a67 commit c1a669a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Mod.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using MelonLoader;
using QList;

[assembly: MelonInfo(typeof(Mod), "QList", "0.0.5", "dodad")]
[assembly: MelonInfo(typeof(Mod), "QList", "0.0.6", "dodad")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]
[assembly: MelonPriority(-99)]

Expand Down Expand Up @@ -62,6 +62,7 @@ public override void OnLateInitializeMelon()
{
Resources.Initialize();
QList.UI.Manager.Initialize();
Options.SortModList();
}
public override void OnDeinitializeMelon()
{
Expand Down
20 changes: 20 additions & 0 deletions Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace QList;
public static class Options
{
internal static Dictionary<string, ModOptionContainer> CurrentModOptions = new();
private static bool initialized;

public static void RegisterMod(MelonMod mod)
{
Expand All @@ -27,6 +28,9 @@ public static void RegisterMod(MelonMod mod)

CurrentModOptions.Add(key, new ModOptionContainer(mod, System.Reflection.Assembly.GetCallingAssembly()));

if (initialized) // Only sort after LateInitialize
SortModList();

Log.LogOutput($"Registered mod: '{mod.Info.Name}'", Log.LogLevel.Message);
}

Expand All @@ -48,6 +52,8 @@ public static void DeregisterMod(MelonMod mod)

CurrentModOptions.Remove(key);

SortModList();

Log.LogOutput($"Deregistered mod: '{mod.Info.Name}'", Log.LogLevel.Message);
}
/// <summary>
Expand Down Expand Up @@ -94,6 +100,20 @@ public static bool AddOption(BaseOption option, string? name = "", string? descr

return true;
}
internal static void SortModList()
{
var sortedKeys = CurrentModOptions.Keys.ToList();
sortedKeys.Sort();

var sortedDictionary = new Dictionary<string, ModOptionContainer>();

foreach (var key in sortedKeys)
sortedDictionary.Add(key, CurrentModOptions[key]);

CurrentModOptions = sortedDictionary;

initialized = true;
}
}

internal class ModOptionContainer
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ Option types are located at `QList.OptionTypes`. Currently available:

# Changelog

**0.0.6**

- Mod List: List is now sorted alphabetically

**0.0.5**

- Options: Added `Action<BaseOption>? OnValueChangedOption`
Expand Down

0 comments on commit c1a669a

Please sign in to comment.