-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* PR * Update PDAEncyclopediaPatcher.cs * Nitpicks. * Other nitpicks. * Fix else for Lee. * GUID thing. * Fixed BZ compile error. * Fix something before bed. * Whoops, forgot something. * Stuff with docs. * Forgot to make static haha. * fix: string stuff. * fix: forgot something. * make ECM happy. * Update PDAEncyclopediaTabPatcher.cs * Update PDAEncyclopediaTabPatcher.cs * Update and rename ModDataBankHandler.cs to ModDatabankHandler.cs * Update OptionsPanelPatcher.cs * depend on different PR. * Update PDAHandler.cs * Update PDAHandler.cs * realization that I forgot to change something * Update ModDatabankHandler.cs * Update PDAEncyclopediaTabPatcher.cs * Update ConfigExamples.cs * compile error fixes --------- Co-authored-by: Lee23 <[email protected]>
- Loading branch information
1 parent
ee7d204
commit 2996e3f
Showing
7 changed files
with
138 additions
and
7 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
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,110 @@ | ||
using BepInEx; | ||
using Nautilus.Utility; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace Nautilus.Handlers; | ||
/// <summary> | ||
/// A handler class for adding databank entries for mods. | ||
/// </summary> | ||
public static class ModDatabankHandler | ||
{ | ||
private static bool _isInit; | ||
private static List<PDAEncyclopedia.EntryData> _waitList = new(); | ||
internal static bool _isEnabled = true; | ||
internal static void Initialize() | ||
{ | ||
LanguageHandler.SetLanguageLine("EncyPath_Mods", "Mods"); | ||
_isInit = true; | ||
foreach (var data in _waitList) | ||
{ | ||
CompleteRegister(data); | ||
} | ||
} | ||
private static void CompleteRegister(PDAEncyclopedia.EntryData data) | ||
{ | ||
if (_isInit && _isEnabled) | ||
{ | ||
InternalLogger.Info($"{data.key} entry added."); | ||
PDAHandler.AddEncyclopediaEntry(data); | ||
#if BZ_STABLE | ||
PDAEncyclopedia.Add(data.key, true, false); | ||
#else | ||
PDAEncyclopedia.Add(data.key, true); | ||
#endif | ||
} | ||
else | ||
{ | ||
_waitList.Add(data); | ||
} | ||
} | ||
/// <summary> | ||
/// Automatically adds info about your mod to the game's databank under a tab named Mods using your mod's PluginInfo. | ||
/// </summary> | ||
/// <param name="info">The PluginInfo for your mod. Pass in Info from your BepInPlugin class</param> | ||
public static void RegisterMod(BepInEx.PluginInfo info) | ||
{ | ||
var bepinplugindata = info.Metadata; | ||
var entrydata = new PDAEncyclopedia.EntryData() | ||
{ | ||
image = null, | ||
key = bepinplugindata.GUID, | ||
unlocked = true, | ||
path = "Mods", | ||
nodes = PDAEncyclopedia.ParsePath("Mods") | ||
}; | ||
LanguageHandler.SetLanguageLine($"Ency_{bepinplugindata.GUID}", $"{bepinplugindata.Name} {bepinplugindata.Version.ToString()}"); | ||
LanguageHandler.SetLanguageLine($"EncyDesc_{bepinplugindata.GUID}", "A BepInEx plugin using Nautilus."); | ||
CompleteRegister(entrydata); | ||
} | ||
/// <summary> | ||
/// Automatically adds info about your mod to the game's databank under a tab named Mods using supplied ModData instance. | ||
/// </summary> | ||
/// <param name="data"></param> | ||
public static void RegisterMod(ModData data) | ||
{ | ||
var entrydata = new PDAEncyclopedia.EntryData() | ||
{ | ||
image = data.image, | ||
key = data.guid, | ||
unlocked = true, | ||
path = "Mods", | ||
nodes = PDAEncyclopedia.ParsePath("Mods") | ||
}; | ||
if(data.desc != null) | ||
{ | ||
LanguageHandler.SetLanguageLine($"EncyDesc_{data.guid}", data.desc); | ||
} | ||
if(data.name != null) | ||
{ | ||
LanguageHandler.SetLanguageLine($"Ency_{data.guid}", $"{data.name} {data.version ?? ""}"); | ||
} | ||
CompleteRegister(entrydata); | ||
} | ||
/// <summary> | ||
/// Data for the encyclopedia entry of your mod. | ||
/// </summary> | ||
public record struct ModData | ||
{ | ||
/// <summary> | ||
/// Name of your mod, not optional. | ||
/// </summary> | ||
public required string name; | ||
/// <summary> | ||
/// GUID, just an identifier, not optional. | ||
/// </summary> | ||
public required string guid; | ||
/// <summary> | ||
/// Mod version, optional. | ||
/// </summary> | ||
public string version; | ||
/// <summary> | ||
/// Mod description, optional. | ||
/// </summary> | ||
public string desc; | ||
/// <summary> | ||
/// Databank image, optional. | ||
/// </summary> | ||
public Texture2D image; | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -33,4 +33,4 @@ internal static void InitializePostfix() | |
} | ||
} | ||
} | ||
} | ||
} |
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,19 @@ | ||
using HarmonyLib; | ||
using Nautilus.Handlers; | ||
|
||
namespace Nautilus.Patchers; | ||
|
||
internal class PDAEncyclopediaTabPatcher | ||
{ | ||
internal static void Patch(Harmony harmony) | ||
{ | ||
harmony.PatchAll(typeof(PDAEncyclopediaTabPatcher)); | ||
} | ||
[HarmonyPatch(typeof(uGUI_EncyclopediaTab))] | ||
[HarmonyPatch(nameof(uGUI_EncyclopediaTab.Awake))] | ||
[HarmonyPostfix] | ||
internal static void EncyTabAwakePostfix(uGUI_EncyclopediaTab __instance) | ||
{ | ||
ModDatabankHandler.Initialize(); | ||
} | ||
} |