Editor/Layers/ArchPlanHosts.cs
using System;
using System.Collections.Generic;
using System.Linq;
namespace Sunless.Architecture;
// Every host of a given type standing in the plan - ONE walk for Unfile, derived from the walks the manifests
// carried by hand.
public static class ArchPlanHosts {
public static IEnumerable<object> Of( ArchPlan plan, IEnumerable<Type> types ) {
if ( plan is null || types is null ) {
yield break;
}
foreach ( var type in types ) {
foreach ( var host in HostsOf( plan, type ) ) {
yield return host;
}
}
}
static IEnumerable<object> HostsOf( ArchPlan plan, Type type ) {
if ( type == typeof( ArchBuilding ) ) {
return plan.Buildings;
}
if ( type == typeof( ArchRoom ) ) {
return plan.AllRooms();
}
if ( type == typeof( ArchRoofPart ) ) {
return plan.AllRoofs();
}
if ( type == typeof( ArchWall ) ) {
return plan.AllWalls();
}
if ( type == typeof( ArchPorchPart ) ) {
return plan.AllRooms().SelectMany( room => room.Porches );
}
if ( type == typeof( ArchRoadPart ) ) {
return plan.Roads();
}
return Array.Empty<object>();
}
}