Skip to content

Commit

Permalink
Merge pull request #751 from zymex22/issue452
Browse files Browse the repository at this point in the history
Resolved issues with Splitters linking into eachother
  • Loading branch information
Sn1p3rr3c0n authored Feb 5, 2024
2 parents 5f26ae9 + 40d463f commit acffd97
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,35 @@ public override void Link(IBeltConveyorLinkable link)
incomingLinks.Add(link);
if (PositionToRot4(link, out Rot4 r))
{
if (outputLinks.TryGetValue(r, out OutputLink output))
if (outputLinks.TryGetValue(r, out OutputLink output) && IsInputtingIntoThis(link, r))
{
output.Active = false;
}
}
}
}


/// <summary>
/// Helper Function use to Check if a IBeltConveyorLinkable is acting as an Input for this building
/// </summary>
/// <param name="link">IBeltConveyorLinkable</param>
/// <param name="r">Direction of the IBeltConveyorLinkable</param>
/// <returns>True if link acts as an Input</returns>
public bool IsInputtingIntoThis(IBeltConveyorLinkable link, Rot4 r)
{
if (link is Building_BeltSplitter building_Belt)
{
building_Belt.outputLinks.TryGetValue(r.Opposite, out OutputLink output);
return output is not null && output.Active;
}
else
{
return link.Rotation.Opposite == r;
}
}


// Utility fn for linking to belt link
private bool PositionToRot4(IBeltConveyorLinkable link, out Rot4 r)
{
Expand Down
19 changes: 4 additions & 15 deletions Source/ProjectRimFactory/AutoMachineTool/ITab_ConveyorFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UIElements;
using Verse;
using static ProjectRimFactory.AutoMachineTool.Ops;

Expand Down Expand Up @@ -154,25 +155,13 @@ protected override void FillTab()
}

bool selref = selectedDir == dir;

bool isInput = false;

foreach (IBeltConveyorLinkable linkable in Splitter.IncomingLinks.Where(l => l.Position == (Splitter.Position + dir.FacingCell)))
{
if ((linkable as Building_BeltConveyor) != null || (linkable as Building_BeltConveyorUGConnector) != null)
{
if (OppositeRot(linkable.Rotation) == dir)
{
isInput = true;
break;
}
}
else if ((linkable as Building_BeltSplitter) != null)
{
//Seperate Logic for splitters
if ((linkable as Building_BeltSplitter).OutputLinks.Keys.Contains(OppositeRot(dir)) && (linkable as Building_BeltSplitter).OutputLinks[OppositeRot(dir)].Active) isInput = true;

}

isInput = Splitter.IsInputtingIntoThis(linkable, dir);
if (isInput) break;
}


Expand Down

0 comments on commit acffd97

Please sign in to comment.