Skip to content

Commit

Permalink
Recompile for rimworld 2xth Oct. update
Browse files Browse the repository at this point in the history
  • Loading branch information
VinaLx committed Oct 25, 2021
1 parent 07fa688 commit 30697a2
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 12 deletions.
2 changes: 1 addition & 1 deletion About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<version>1.2.0.1</version>
<version>1.3.0.1</version>
<manifestUri>https://raw.githubusercontent.com/VinaLx/RimWorld-ResearchPal/master/About/Manifest.xml</manifestUri>
<downloadUri>https://github.com/VinaLx/RimWorld-ResearchPal</downloadUri>
</Manifest>
Binary file modified Assemblies/ResearchTree.dll
Binary file not shown.
56 changes: 56 additions & 0 deletions Source/CompatibilityHooks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RimWorld;
using Verse;

namespace ResearchPal
{
/* Currently Does not work */

// This static class contains hooks that supported altered behavior of
// researchpal for the convenience of other awesome modders that try to
// make their mods compatible. These methods are assumed to be patched
// with harmony. The patch should perform incrementally, e.g. the postfix
// patch of `IsHidden` should never returns `true`, but `true || __result`
// (well I guess in this case you just returns `__result` XD)
//
// I'm not a professional C# user, but I assume harmony is a powerful enough
// tool to patch the method to serve appropriate purposes. So if you have
// suggestions on how to accomplish certain goal more properly, feel free to
// lecture me on the steam workshop page.
//
// If you don't find the method you need here, and you believe it would be
// way simpler for your compatibility patch if I provide one, also feel free
// put your suggestion in the "Mod Compatibility" discussion.
public static class CompatibilityHooks {
// Returns true if a research node shouldn't be drawn on the research
// tab.
// if `IsHidden(research) == true`, then all the children node of
// `research` will be hidden.
public static bool IsHidden(ResearchProjectDef r) {
return false;
}

// If there are additional unlock requirements for your modded research
// other than the vanilla special requirements (research bench,
// research facility and techprints).
// The research node will be grayed out (just like lacking techprints)
// if this function returns false on the according research.
public static bool PassCustomUnlockRequirements(
ResearchProjectDef p) {
return true;
}

// Returns a list of prompts that tell the player what should be done if
// the tech is locked behind a modded requirement.
// A tooltip will be displayed when hovering the locked techs
// (and only the locked techs)
public static List<string> CustomUnlockRequirementPrompts(
ResearchProjectDef p) {
return new List<string>();
}
}
}
23 changes: 15 additions & 8 deletions Source/Graph/ResearchNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,11 @@ private void HandleTooltips() {
MissingFacilities().Select( td => td.LabelCap )
.ToArray())));
}
if (!PassCustomUnlockRequirements(Research)) {
if (! PassCustomUnlockRequirements(Research)
|| CompatibilityHooks.PassCustomUnlockRequirements(Research)) {
var prompts = CustomUnlockRequirementPrompts(Research);
prompts.AddRange(CompatibilityHooks.
CustomUnlockRequirementPrompts(Research));
foreach (var prompt in prompts) {
TooltipHandler.TipRegion(Rect, prompt);
}
Expand Down Expand Up @@ -802,15 +805,16 @@ public bool Completed() {
return Research.IsFinished;
}

// For modders to patch,
// Returns true if research project p passes the custom unlock requirements, if any.
// deprecated
// patch `CompatibilityHooks.PassCustomUnlockRequirements` instead
public static bool PassCustomUnlockRequirements(ResearchProjectDef p) {
return true;
}

// For modders to patch
// Returns a list containing information users need to understand the custom unlock requirements
public static List<string> CustomUnlockRequirementPrompts(ResearchProjectDef p) {
// deprecated
// patch `CompatibilityHooks.CustomUnlockRequirementPrompts` instead
public static List<string>
CustomUnlockRequirementPrompts(ResearchProjectDef p) {
return new List<string>();
}

Expand All @@ -819,8 +823,11 @@ public bool GetAvailable() {
(DebugSettings.godMode
|| (BuildingPresent()
&& TechprintAvailable()
&& MainTabWindow_ResearchTree.AllowedTechlevel(Research.techLevel)
&& PassCustomUnlockRequirements(Research)));
&& MainTabWindow_ResearchTree.AllowedTechlevel(
Research.techLevel)
&& PassCustomUnlockRequirements(Research)
&& CompatibilityHooks.PassCustomUnlockRequirements(
Research)));
}

public bool Available() {
Expand Down
4 changes: 1 addition & 3 deletions Source/MainTabWindow_ResearchTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ public override void PreOpen() {

SetRects();

if (Settings.shouldPause) {
forcePause = Settings.shouldPause;
}
forcePause = Settings.shouldPause;

if (Settings.shouldReset) {
ResetSearch();
Expand Down
1 change: 1 addition & 0 deletions Source/ResearchTree.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Assets.cs" />
<Compile Include="CompatibilityHooks.cs" />
<Compile Include="Constants.cs" />
<Compile Include="Extensions\Building_ResearchBench_Extensions.cs" />
<Compile Include="Extensions\Def_Extensions.cs" />
Expand Down

0 comments on commit 30697a2

Please sign in to comment.