Defines a static registry of editor subtools (ArchSubtoolEntry instances) grouped by shell name and ordered. Provides methods to get all entries for a shell, visible entries (respecting hidden settings), and the distinct list of shells.
using System;
using System.Collections.Generic;
using System.Linq;
namespace Sunless.Architecture;
// Every subtool the tool stands, and the order it stands them in. Written out rather than discovered: one assembly
// declares them all, so scanning the type library for them would only be a slower way of naming what this file
// names, and every type handle that scan walks is held for the life of an editor that never unloads an assembly.
//
// A tool the author does not want is hidden in the settings, not uninstalled - see ArchToolSettings.
public static class ArchShelves
{
public static IReadOnlyList<ArchSubtoolEntry> On( string shell ) => All( shell )
.Where( entry => entry.Fixed || !ArchToolSettings.Hidden( entry.Ident ) )
.ToList();
public static IReadOnlyList<ArchSubtoolEntry> All( string shell ) => Standing()
.Where( entry => Same( entry.Shell, shell ) )
.OrderBy( entry => entry.Order )
.ToList();
public static IReadOnlyList<string> Shells => Standing()
.Select( entry => entry.Shell )
.Distinct( StringComparer.OrdinalIgnoreCase )
.OrderBy( shell => shell, StringComparer.OrdinalIgnoreCase )
.ToList();
static IEnumerable<ArchSubtoolEntry> Standing()
{
yield return new( "select", ArchShells.Buildings, 0, owner => new ArchSelectSubtool( owner ) ) { Fixed = true };
yield return new( "building", ArchShells.Buildings, 10, owner => new ArchBuildingSubtool( owner ) );
yield return new( "wall", ArchShells.Buildings, 20, owner => new ArchWallSubtool( owner ) );
yield return new( "opening", ArchShells.Buildings, 30, owner => new ArchOpeningSubtool( owner ) );
yield return new( "window", ArchShells.Buildings, 40, owner => new ArchWindowSubtool( owner ) );
yield return new( "walkway", ArchShells.Buildings, 50, owner => new ArchWalkwaySubtool( owner ) );
yield return new( "roof", ArchShells.Buildings, 60, owner => new ArchRoofSubtool( owner ) );
yield return new( "pillar", ArchShells.Buildings, 70, owner => new ArchPillarSubtool( owner ) );
yield return new( "span", ArchShells.Buildings, 75, owner => new ArchSpanSubtool( owner ) );
yield return new( "stair", ArchShells.Buildings, 80, owner => new ArchStairSubtool( owner ) );
yield return new( "pipe", ArchShells.Buildings, 90, owner => new ArchPipeSubtool( owner ) );
yield return new( "bracket", ArchShells.Buildings, 100, owner => new ArchBracketSubtool( owner ) );
yield return new( "porch", ArchShells.Buildings, 110, owner => new ArchPorchSubtool( owner ) );
yield return new( "fence", ArchShells.Buildings, 120, owner => new ArchFenceSubtool( owner ) );
yield return new( "bool", ArchShells.Buildings, 130, owner => new ArchBoolSubtool( owner ) );
yield return new( "select", ArchShells.Roads, 0, owner => new ArchSelectSubtool( owner ) ) { Fixed = true };
yield return new( "road", ArchShells.Roads, 10, owner => new ArchRoadSubtool( owner ) );
yield return new( "crossing", ArchShells.Roads, 20, owner => new ArchCrossingSubtool( owner ) );
yield return new( "bridge", ArchShells.Roads, 30, owner => new ArchBridgeSubtool( owner ) );
yield return new( "tunnel", ArchShells.Roads, 40, owner => new ArchTunnelSubtool( owner ) );
}
static bool Same( string one, string other ) => string.Equals( one, other, StringComparison.OrdinalIgnoreCase );
}