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

Resolved issues with Splitters linking into eachother #751

Merged
merged 1 commit into from
Feb 5, 2024
Merged
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
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