Extension methods operating on ArchPlan for querying ArchCutPart objects. Provides enumeration of all cuts, finding a cut by id, getting the owner building of a cut, and finding the list that holds a given cut (from buildings or roads).
using System.Collections.Generic;
using System.Linq;
namespace Sunless.Architecture;
public static class ArchPlanCuts
{
// Every cut in the plan, wherever it is filed. A cut is world-space and a road holds its own, so anything that
// walked Buildings alone quietly stopped seeing half of them.
public static IEnumerable<ArchCutPart> AllCuts( this ArchPlan plan ) => plan.Units.SelectMany( unit => unit.Cuts );
public static ArchCutPart FindCut( this ArchPlan plan, int id ) => plan.AllCuts().FirstOrDefault( cut => cut.Id == id );
public static ArchBuilding OwnerOf( this ArchPlan plan, ArchCutPart cut ) => plan.HostOf<ArchBuilding>( cut );
public static List<ArchCutPart> CutsHolding( this ArchPlan plan, ArchCutPart cut )
{
return plan.Buildings.FirstOrDefault( building => building.Cuts.Contains( cut ) )?.Cuts
?? plan.Roads().FirstOrDefault( road => road.Cuts.Contains( cut ) )?.Cuts;
}
}