Skip to content

Commit

Permalink
Added OpenToCustomPage
Browse files Browse the repository at this point in the history
  • Loading branch information
HumabHatterZed committed Sep 12, 2024
1 parent 67d56f7 commit 63819ee
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@
- Added additional methods to RuleBookManager: ItemShouldBeAdded, BoonShouldBeAdded, SlotModShouldBeAdded, GetUnformattedPageId
- Added GetFullBoon and GetFullConsumableItemData extension methods
- Added extension methods for adding text redirects to abilities, stat icons, items, boons, slot modifications, and rulebook pages
- Added ModificationType.SetSharedRulebook - used for slot modifications that should share their rulebook entry with other slot modifications
- Added support for multiple rulebook sprites for slot modifications (SetRulebookP03Sprite, SetRulebookGrimoraSprite, SetRulebookMagnificusSprite)
- Added RuleBookController.Instance.OpenToCustomPage
- Fixed RuleBook construction patches having lower patch priority than intended
- Fixed slot modification interactable being enabled when no rulebook entry exists
- Fixed slot modification rulebook pages not working in Act 3
- Fixed rulebook sprites being smaller than normal after flipping to a slot modification rulebook page
- Moved ConsumableItemManager patches to a separate ConsumableItemPatches class
- Modified implementation of rulebook fill page logic to let modders patch the API logic
- Patch 'RuleBookManagerPatches.FillPage' to do this
- Tweaked how custom rulebook pages are added and detected
- Tweaked wiki page for adding custom rulebook sections
- Added wiki section on adding text redirects
- Wiki: Tweaked page for adding custom rulebook sections
- Wiki: Added section on adding text redirects

# 2.21.1
- Fixed RuleBookManager not syncing when playing with no custom rulebook sections
Expand Down
19 changes: 19 additions & 0 deletions InscryptionAPI/Rulebook/RuleBookManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,25 @@ public static string GetUnformattedPageId(string pageId)
return pageId;
}

/// <summary>
/// Opens the rulebook to the page with the given pageId.
/// </summary>
/// <param name="instance">RuleBookController.Instance.</param>
/// <param name="pageId">The value to compare each rulebook pages' id against. If this starts with "[API_" then it will check against a page's unformatted id.</param>
/// <param name="offsetView">Whether to offset the camera view down when opening the rulebook.</param>
public static void OpenToCustomPage(this RuleBookController instance, string pageId, bool offsetView = false)
{
instance.SetShown(shown: true, offsetView);
int pageIndex = -1;
if (pageId.StartsWith(RuleBookManagerPatches.API_ID))
pageIndex = instance.PageData.IndexOf(instance.PageData.Find(x => !string.IsNullOrEmpty(x.pageId) && x.pageId == pageId));
else
pageIndex = instance.PageData.IndexOf(instance.PageData.Find(x => !string.IsNullOrEmpty(x.pageId) && GetUnformattedPageId(x.pageId) == pageId));

instance.StopAllCoroutines();
instance.StartCoroutine(instance.flipper.FlipToPage(pageIndex, 0.2f));
}

public static bool ItemShouldBeAdded(ConsumableItemData item, AbilityMetaCategory metaCategory)
{
return item.rulebookCategory == metaCategory || item.GetFullConsumableItemData()?.rulebookMetaCategories.Contains(metaCategory) == true;
Expand Down
4 changes: 2 additions & 2 deletions InscryptionAPI/Rulebook/RuleBookManagerPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Reflection;
using System.Reflection.Emit;
using TMPro;
using UnityEngine;

using static InscryptionAPI.RuleBook.RuleBookManager;

namespace InscryptionAPI.RuleBook;
Expand Down Expand Up @@ -112,7 +112,7 @@ private static void SyncRuleBookRedirectsForEachPage(List<RuleBookPageInfo> __re
[HarmonyPatch(typeof(ItemPage), "FillPage")]
private static bool FixFillPage(RuleBookPage __instance, string headerText, params object[] otherArgs)
{
if (otherArgs?.Length > 0 && otherArgs.Last() is string pageId && pageId.StartsWith(API_ID))
if (otherArgs?.Length > 0 && otherArgs.LastOrDefault() is string pageId && pageId.StartsWith(API_ID))
{
string sectionId = pageId.Replace(API_ID, "");
FullRuleBookRangeInfo fullInfo = AllRuleBookInfos.Find(x => sectionId.StartsWith(x.SubSectionName));
Expand Down

0 comments on commit 63819ee

Please sign in to comment.