Editor/Designers/ArchOpeningKinds.cs

Extension helpers for the OpeningKind enum used by the editor designer. It defines which kinds have glazes, sills, hanging behavior, which opening furniture each kind can carry, enumerates available furnishings, and whether a kind furnishes anything.

using System;
using System.Collections.Generic;
using System.Linq;

namespace Sunless.Architecture;

// The one table: generators, designer and property sheet ask here, so no control lies.
public static class ArchOpeningKinds
{
	public static bool Glazes( this OpeningKind kind ) => kind == OpeningKind.Window;

	public static bool Sills( this OpeningKind kind ) => kind == OpeningKind.Window;

	public static bool Hangs( this OpeningKind kind ) => kind is OpeningKind.Door or OpeningKind.DoubleDoor or OpeningKind.Garage;

	// Furniture is fixed to the frame the hole wears, so an archway carries none of it: its jambs are the wall's
	// own finish carried through the thickness and there is nothing there to bolt a grille to.
	public static bool Carries( this OpeningKind kind, OpeningFurniture furniture ) => furniture switch
	{
		OpeningFurniture.Bars => kind is OpeningKind.Window or OpeningKind.Hatch,
		OpeningFurniture.Boarded => kind is OpeningKind.Window or OpeningKind.Door or OpeningKind.DoubleDoor or OpeningKind.Hatch,
		OpeningFurniture.Shutter => kind is OpeningKind.Garage or OpeningKind.Window,
		OpeningFurniture.Gate => kind is OpeningKind.Door or OpeningKind.DoubleDoor,
		_ => false
	};

	// What a picker may offer, read off the same rows the generator builds from - so a form and a wall cannot
	// disagree about what a kind has.
	public static IEnumerable<OpeningFurniture> Furnishings( this OpeningKind kind )
	{
		return Enum.GetValues<OpeningFurniture>().Where( furniture => kind.Carries( furniture ) );
	}

	public static bool Furnishes( this OpeningKind kind ) => kind.Furnishings().Any();
}