Skip to content

Commit

Permalink
Initial codebase commit (v1.0.0.0)
Browse files Browse the repository at this point in the history
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
trigger-segfault committed Jun 29, 2022
1 parent 10e25ec commit f8a8021
Show file tree
Hide file tree
Showing 19 changed files with 1,122 additions and 197 deletions.
8 changes: 5 additions & 3 deletions .env
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.


Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<SharedGUID>4e7d37c7-8afe-4f79-baf6-4ce82d05e091</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>Mod.Template.Content</Import_RootNamespace>
<Import_RootNamespace>Distance.LevelSelectAdditions.Content</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)Mod\mod.json">
Expand All @@ -16,4 +16,6 @@
<ItemGroup>
<Folder Include="$(MSBuildThisFileDirectory)Mod\" />
</ItemGroup>
</Project>
</Project>


Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="15.0">
<PropertyGroup Label="Globals">
<ProjectGuid>4e7d37c7-8afe-4f79-baf6-4ce82d05e091</ProjectGuid>
Expand All @@ -8,6 +8,8 @@
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="Mod.Template.Content.projitems" Label="Shared" />
<Import Project="Distance.LevelSelectAdditions.Content.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
</Project>


14 changes: 14 additions & 0 deletions Distance.LevelSelectAdditions.Content/Mod/mod.json
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
}


9 changes: 6 additions & 3 deletions Mod.Template.sln → Distance.LevelSelectAdditions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31515.178
MinimumVisualStudioVersion = 10.0.40219.1
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Mod.Template.Content", "Mod.Template.Content\Mod.Template.Content.shproj", "{4E7D37C7-8AFE-4F79-BAF6-4CE82D05E091}"
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Distance.LevelSelectAdditions.Content", "Distance.LevelSelectAdditions.Content\Distance.LevelSelectAdditions.Content.shproj", "{4E7D37C7-8AFE-4F79-BAF6-4CE82D05E091}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mod.Template", "Mod.Template\Mod.Template.csproj", "{7BCB2908-B003-45D9-BE68-50CBA5217603}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Distance.LevelSelectAdditions", "Distance.LevelSelectAdditions\Distance.LevelSelectAdditions.csproj", "{7BCB2908-B003-45D9-BE68-50CBA5217603}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{08A1C9FA-7DC2-4A60-B9A6-AC0EB7132893}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -17,7 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Mod.Template.Content\Mod.Template.Content.projitems*{4e7d37c7-8afe-4f79-baf6-4ce82d05e091}*SharedItemsImports = 13
Distance.LevelSelectAdditions.Content\Distance.LevelSelectAdditions.Content.projitems*{4e7d37c7-8afe-4f79-baf6-4ce82d05e091}*SharedItemsImports = 13
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -36,3 +36,6 @@ Global
SolutionGuid = {E6970D48-CD23-4427-951B-448B144F30DA}
EndGlobalSection
EndGlobal



169 changes: 169 additions & 0 deletions Distance.LevelSelectAdditions/ConfigurationLogic.cs
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<ProjectGuid>{7BCB2908-B003-45D9-BE68-50CBA5217603}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Mod.Template</RootNamespace>
<AssemblyName>Mod.Template</AssemblyName>
<RootNamespace>Distance.LevelSelectAdditions</RootNamespace>
<AssemblyName>Distance.LevelSelectAdditions</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
Expand Down Expand Up @@ -86,13 +86,18 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ConfigurationLogic.cs" />
<Compile Include="Harmony\Assembly-CSharp\LevelGridMenu\CreateAndAddLevelSet.cs" />
<Compile Include="Mod.cs" />
<Compile Include="LevelFilter.cs" />
<Compile Include="LevelSort.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Mod.Template.targets" />
<None Include="Distance.LevelSelectAdditions.targets" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<!-- 15.0 is for VS2017, adjust if necessary -->
Expand Down
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>


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;
}

}
}
Loading

0 comments on commit f8a8021

Please sign in to comment.