Editor-side helper that discovers and runs implementations of IArchDoorFitter. It defines the IArchDoorFitter interface and a container ArchDoorFitters that loads enrolled fitters via ArchDiscovery, holds them in a list, and invokes their Fit method for a given GameObject and mapping Door.
using System.Collections.Generic;
using Sandbox;
using MapDoor = Sandbox.Mapping.Door;
namespace Sunless.Architecture;
// The tool stands the engine door and can never name a game's runtime type, so the game hangs its own half here.
public interface IArchDoorFitter
{
void Fit( GameObject node, MapDoor door );
}
// Never cached across builds, for the reason ArchDrawers is not: hotload carries statics over.
public sealed class ArchDoorFitters
{
readonly List<IArchDoorFitter> fitters = new();
// Nothing enrolled is the tool standing without a game around it - the door still swings, for nobody.
public static ArchDoorFitters None => new();
public static ArchDoorFitters Load()
{
var built = new ArchDoorFitters();
foreach ( var fitter in ArchDiscovery.Enrolled<IArchDoorFitter>() )
{
built.fitters.Add( fitter );
}
return built;
}
public int Count => fitters.Count;
public void Fit( GameObject node, MapDoor door )
{
foreach ( var fitter in fitters )
{
fitter.Fit( node, door );
}
}
}