Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration with [LTO] Colony Groups #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/ImprovedWorkbenches/Custom Storage/ExtendedBillDataStorage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -202,6 +203,36 @@ public void MirrorBills(Bill_Production sourceBill, Bill_Production destinationB
destinationBill.paused = sourceBill.paused;
destinationBill.SetPawnRestriction(sourceBill.PawnRestriction);

// Colony Groups integration
if (Main.Instance.ColonyGroupsBillToPawnGroupDictGetter != null)
{
try
{
var billToPawnGroupDict = Main.Instance.ColonyGroupsBillToPawnGroupDictGetter();

if (billToPawnGroupDict.Contains(sourceBill))
{
var pawnGroup = billToPawnGroupDict[sourceBill];
// Main.Instance.Logger.Message(
// $"Setting PawnGroup of bill {destinationBill} to that of {sourceBill} ({pawnGroup})");
billToPawnGroupDict[destinationBill] = pawnGroup;
}
else
{
// Main.Instance.Logger.Message(
// $"Removing PawnGroup assignment of bill {destinationBill} to mirror bill {sourceBill}");
billToPawnGroupDict.Remove(destinationBill);
}
}
catch (Exception e)
{
Main.Instance.Logger.ReportException(
e, reportOnceOnly: true,
location:
"attempt to copy pawn group assignment of a bill to another bill (ColonyGroups integration)");
}
}

if (Main.Instance.ShouldMirrorSuspendedStatus())
{
destinationBill.suspended = sourceBill.suspended;
Expand Down
38 changes: 37 additions & 1 deletion src/ImprovedWorkbenches/Main.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using HarmonyLib;
using HugsLib.Settings;
using HugsLib.Utils;
Expand Down Expand Up @@ -59,6 +60,8 @@ public override void DefsLoaded()
IntegrateWithRimFactory();

IntegrateWithNoMaxBills();

IntegrateWithColonyGroups();
}

private void IntegrateWithOutfitter()
Expand Down Expand Up @@ -124,6 +127,29 @@ private void IntegrateWithNoMaxBills()
}
}

private void IntegrateWithColonyGroups()
{
try
{
var groupBillsType = GenTypes.GetTypeInAnyAssembly("TacticalGroups.HarmonyPatches_GroupBills");

if (groupBillsType == null) { return; }

Logger.Message("Adding support for Colony Groups");

var getterMethodInfo = AccessTools.Property(groupBillsType, "BillsSelectedGroup").GetMethod;

ColonyGroupsBillToPawnGroupDictGetter =
AccessTools.MethodDelegate<Func<IDictionary>>(getterMethodInfo);
}
catch (Exception e)
{
Logger.Error("Exception while trying to detect the Colony Groups mod:");
Logger.Error(e.Message);
Logger.Error(e.StackTrace);
}
}

public bool IsOfTypeRimFactoryBillsTab(InspectTabBase tab)
{
return _isRimfactoryLoaded && tab?.GetType() == _rimFactoryBillsTabType;
Expand Down Expand Up @@ -196,13 +222,23 @@ public int GetMaxBills()

private ExtendedBillDataStorage _extendedBillDataStorage;

// RImFactory support
// RimFactory support
private bool _isRimfactoryLoaded;

private Type _rimFactoryBillsTabType;

private Type _rimFactoryBuildingType;

private bool _isNoMaxBillsLoaded;

/// <summary>
/// For integration with Colony Groups. null if Colony Groups is not loaded.
///
/// This refers to the getter of <c>TacticalGroups.HarmonyPatches_GroupBills.BillsSelectedGroup</c>, which contains
/// the pawn group to which a bill is restricted, if any.
///
/// Actual returned type is <c>Dictionary&lt;Bill_Production, PawnGroup></c>.
/// </summary>
public Func<IDictionary> ColonyGroupsBillToPawnGroupDictGetter { get; private set; }
}
}