generated from Distance-Modding/Template.CSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial codebase commit with original working goal for the mod: * Support for changing Workshop LevelSet. * Remove or change level limit. * Optionally filter out levels in personal playlists. * Up to 3 layers of sorting methods with option to reverse individual methods.
- Loading branch information
1 parent
10e25ec
commit f8a8021
Showing
19 changed files
with
1,122 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
SOLUTION=Mod.Template.sln | ||
ARTIFACTS=Build/Distance Mod Template.zip | ||
RELEASE_BODY=This release was automatically generated as part of a GitHub workflow. Please read the repository README for more info. | ||
SOLUTION=Distance.LevelSelectAdditions.sln | ||
ARTIFACTS=Build/Distance Level Select Additions.zip | ||
RELEASE_BODY=This release was automatically generated as part of a GitHub workflow. Please read the repository README for more info. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"FriendlyName": "Level Select Additions", | ||
"Description": "Extends the level selection UI by adding more options.", | ||
"Author": "trigger_segfault", | ||
"Contact": "Github: @trigger-segfault; Discord: trigger_segfault#7281", | ||
"ModuleFileName": "Distance.LevelSelectAdditions.dll", | ||
"RequiredGSLs": [ | ||
"com.github.reherc/Centrifuge.Distance" | ||
], | ||
"SkipLoad": false, | ||
"Priority": 10 | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
using Reactor.API.Configuration; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
using SortingMethod = LevelSelectMenuLogic.SortingMethod; | ||
|
||
namespace Distance.LevelSelectAdditions | ||
{ | ||
public class ConfigurationLogic : MonoBehaviour | ||
{ | ||
#region Properties | ||
|
||
private const string HideWorkshopLevelsInPlaylists_ID = "workshop.hide_levels_in_playlists"; | ||
public bool HideWorkshopLevelsInPlaylists | ||
{ | ||
get => Get<bool>(HideWorkshopLevelsInPlaylists_ID); | ||
set => Set(HideWorkshopLevelsInPlaylists_ID, value); | ||
} | ||
|
||
private const string WorkshopLevelLimit_ID = "workshop.level_limit"; | ||
public int WorkshopLevelLimit | ||
{ | ||
get => Get<int>(WorkshopLevelLimit_ID); | ||
set => Set(WorkshopLevelLimit_ID, value); | ||
} | ||
|
||
private const string WorkshopSortingMethod_ID = "workshop.sorting_method"; | ||
public SortingMethod WorkshopSortingMethod | ||
{ | ||
get => Get<SortingMethod>(WorkshopSortingMethod_ID); | ||
set => Set(WorkshopSortingMethod_ID, value); | ||
} | ||
|
||
private const string WorkshopSortingMethod2_ID = "workshop.sorting_method2"; | ||
public SortingMethod WorkshopSortingMethod2 | ||
{ | ||
get => Get<SortingMethod>(WorkshopSortingMethod2_ID); | ||
set => Set(WorkshopSortingMethod2_ID, value); | ||
} | ||
|
||
private const string WorkshopSortingMethod3_ID = "workshop.sorting_method3"; | ||
public SortingMethod WorkshopSortingMethod3 | ||
{ | ||
get => Get<SortingMethod>(WorkshopSortingMethod3_ID); | ||
set => Set(WorkshopSortingMethod3_ID, value); | ||
} | ||
|
||
private const string WorkshopReverseSortingMethod_ID = "workshop.reverse_sorting_method"; | ||
public bool WorkshopReverseSortingMethod | ||
{ | ||
get => Get<bool>(WorkshopReverseSortingMethod_ID); | ||
set => Set(WorkshopReverseSortingMethod_ID, value); | ||
} | ||
|
||
private const string WorkshopReverseSortingMethod2_ID = "workshop.reverse_sorting_method2"; | ||
public bool WorkshopReverseSortingMethod2 | ||
{ | ||
get => Get<bool>(WorkshopReverseSortingMethod2_ID); | ||
set => Set(WorkshopReverseSortingMethod2_ID, value); | ||
} | ||
|
||
private const string WorkshopReverseSortingMethod3_ID = "workshop.reverse_sorting_method3"; | ||
public bool WorkshopReverseSortingMethod3 | ||
{ | ||
get => Get<bool>(WorkshopReverseSortingMethod3_ID); | ||
set => Set(WorkshopReverseSortingMethod3_ID, value); | ||
} | ||
|
||
// Future plans: | ||
/*private const string EnableRecentlDownloadsLevelSet_ID = "recentdownloads.enable"; | ||
public bool EnableRecentlDownloadsLevelSet | ||
{ | ||
get => Get<bool>(EnableRecentlDownloadsLevelSet_ID); | ||
set => Set(EnableRecentlDownloadsLevelSet_ID, value); | ||
} | ||
private const string RecentDownloadedsTimeInDays_ID = "recentdownloads.time_in_days"; | ||
public double RecentDownloadedsTimeInDays | ||
{ | ||
get => Get<double>(RecentDownloadedsTimeInDays_ID); | ||
set => Set(RecentDownloadedsTimeInDays_ID, value); | ||
} | ||
private const string HideRecentDownloadsLevelsInPlaylists_ID = "recentdownloads.hide_levels_in_playlists"; | ||
public bool HideRecentDownloadsLevelsInPlaylists | ||
{ | ||
get => Get<bool>(HideRecentDownloadsLevelsInPlaylists_ID); | ||
set => Set(HideRecentDownloadsLevelsInPlaylists_ID, value); | ||
} | ||
private const string RecentDownloadsLevelLimit_ID = "recentdownloads.level_limit"; | ||
public int RecentDownloadsLevelLimit | ||
{ | ||
get => Get<int>(RecentDownloadsLevelLimit_ID); | ||
set => Set(RecentDownloadsLevelLimit_ID, value); | ||
}*/ | ||
|
||
#endregion | ||
|
||
#region Helpers | ||
|
||
public SortingMethod[] GetWorkshopSortingMethods() | ||
{ | ||
return new SortingMethod[] | ||
{ | ||
WorkshopSortingMethod, | ||
WorkshopSortingMethod2, | ||
WorkshopSortingMethod3, | ||
}; | ||
} | ||
public bool[] GetWorkshopReverseSortingMethods() | ||
{ | ||
return new bool[] | ||
{ | ||
WorkshopReverseSortingMethod, | ||
WorkshopReverseSortingMethod2, | ||
WorkshopReverseSortingMethod3, | ||
}; | ||
} | ||
|
||
#endregion | ||
|
||
internal Settings Config; | ||
|
||
public event Action<ConfigurationLogic> OnChanged; | ||
|
||
private void Load() | ||
{ | ||
Config = new Settings("Config");// Mod.FullName); | ||
} | ||
|
||
public void Awake() | ||
{ | ||
Load(); | ||
|
||
// Assign default settings (if not already assigned). | ||
Get(HideWorkshopLevelsInPlaylists_ID, false); | ||
Get(WorkshopLevelLimit_ID, 1000); | ||
Get(WorkshopSortingMethod_ID, LevelSort.Recently_Downloaded); | ||
Get(WorkshopSortingMethod2_ID, LevelSort.None); | ||
Get(WorkshopSortingMethod3_ID, LevelSort.None); | ||
Get(WorkshopReverseSortingMethod_ID, false); | ||
Get(WorkshopReverseSortingMethod2_ID, false); | ||
Get(WorkshopReverseSortingMethod3_ID, false); | ||
|
||
// Save settings, and any defaults that may have been added. | ||
Save(); | ||
} | ||
|
||
public T Get<T>(string key, T @default = default) | ||
{ | ||
return Config.GetOrCreate(key, @default); | ||
} | ||
|
||
public void Set<T>(string key, T value) | ||
{ | ||
Config[key] = value; | ||
Save(); | ||
} | ||
|
||
public void Save() | ||
{ | ||
Config?.Save(); | ||
OnChanged?.Invoke(this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
Mod.Template/Mod.Template.targets → ...ons/Distance.LevelSelectAdditions.targets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<ModName>Distance Mod Template</ModName> | ||
<ModName>Distance Level Select Additions</ModName> | ||
</PropertyGroup> | ||
</Project> | ||
</Project> | ||
|
||
|
60 changes: 60 additions & 0 deletions
60
Distance.LevelSelectAdditions/Harmony/Assembly-CSharp/LevelGridMenu/CreateAndAddLevelSet.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using HarmonyLib; | ||
using System; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
//using SortingMethod = LevelSelectMenuLogic.SortingMethod; | ||
|
||
namespace Distance.LevelSelectAdditions.Harmony | ||
{ | ||
/// <summary> | ||
/// A patch applied to the method that handles preparing and adding LevelSets to the list. | ||
/// <para/> | ||
/// Here we need to add our own handling for Workshop LevelSets and remove the original <c>levelPlaylist.LimitCountTo(100)</c>. | ||
/// </summary> | ||
[HarmonyPatch(typeof(LevelGridMenu), nameof(LevelGridMenu.CreateAndAddLevelSet))] | ||
internal static class LevelGridMenu__CreateAndAddLevelSet | ||
{ | ||
|
||
internal static bool Prefix(LevelGridMenu __instance, LevelSet set, string name, LevelGridMenu.PlaylistEntry.Type type, LevelGroupFlags flags) | ||
{ | ||
// Only perform special handling for Workshop LevelSets (since that's all that's currently supported). | ||
if (type == LevelGridMenu.PlaylistEntry.Type.Workshop) | ||
{ | ||
LevelPlaylist levelPlaylist = LevelPlaylist.Create(set, name, flags); | ||
LevelGridMenu.PlaylistEntry.UnlockStyle unlockStyle = LevelGridMenu.PlaylistEntry.UnlockStyle.None; | ||
|
||
// Filter out levels in personal playlists, if the user has specified this. | ||
if (Mod.Instance.Config.HideWorkshopLevelsInPlaylists) | ||
{ | ||
LevelFilter.ExcludeLevelsInPersonalPlaylists(levelPlaylist, __instance.modeID_); | ||
} | ||
|
||
// Apply custom sorting. | ||
{ | ||
var sorter = new LevelSort(Mod.Instance.Config.GetWorkshopSortingMethods(), | ||
Mod.Instance.Config.GetWorkshopReverseSortingMethods()); | ||
sorter.SortPlaylist(__instance, levelPlaylist); | ||
} | ||
|
||
// Finally apply limit after sorting and potentially removing levels that were in playlists. | ||
if (Mod.Instance.Config.WorkshopLevelLimit != LevelFilter.Infinite) | ||
{ | ||
LevelFilter.LimitLevels(levelPlaylist, Mod.Instance.Config.WorkshopLevelLimit); | ||
} | ||
|
||
|
||
// All done! Add the organized LevelPlaylist entry. | ||
__instance.CreateAndAddEntry(levelPlaylist, type, true, unlockStyle, string.Empty); | ||
|
||
|
||
// Skip the original method, since we've fully handled this level set. | ||
return false; | ||
} | ||
|
||
// Fallback to the original method for anything that's not a Workshop LevelSet. | ||
return true; | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.