Editor/Porch/ArchPorchGen.cs

Editor-side static generator for porch architecture meshes. It resolves porch shape and paints deck, plinth, posts, beams, railings, ceiling/canopy and flashing on the provided ArchMesh canvas using kit and style brushes.

File Access
using System;
using System.Collections.Generic;
using System.Linq;
using Sandbox;

namespace Sunless.Architecture;

public static partial class ArchPorchGen
{
	public static void Build( ArchMesh canvas, ArchPorchPart porch, ArchRoom room, ArchBuilding building, ArchKit kit, ArchStyle style )
	{
		var shape = ArchPorchShape.Resolve( porch, room, building, kit );

		if ( !shape.IsUsable )
		{
			return;
		}

		var chain = new[] { porch.Palette, room.Palette, building.Palette };
		var deck = style.Brush( ArchSurface.Deck, chain );
		var joinery = style.Brush( ArchSurface.Railing, chain );
		var roofed = porch.RoofId != 0;

		if ( porch.Deck )
		{
			using ( canvas.Part( ArchPieces.Deck ) )
			{
				if ( porch.Plinth && porch.DeckDrop > 2f )
				{
					using ( canvas.Part( ArchPieces.Plinth ) )
					{
						Plinth( canvas, shape, kit, style.Brush( ArchSurface.Baseboard, chain ) );
					}
				}

				Deck( canvas, shape, kit, deck );
				Nosing( canvas, shape, kit, deck );
			}
		}

		var bays = Bays( shape, porch, kit );

		if ( porch.Posts )
		{
			using ( canvas.Part( ArchPieces.Posts ) )
			{
				foreach ( var post in ArchBays.Posts( bays ) )
				{
					Stand( canvas, post.Point, kit, shape.Deck, shape.Head, joinery );
				}
			}
		}

		if ( porch.Beam && roofed )
		{
			using ( canvas.Part( ArchPieces.Beams ) )
			{
				Beam( canvas, shape, kit, joinery );
			}
		}

		if ( porch.Railings )
		{
			using ( canvas.Part( ArchPieces.Balustrade ) )
			{
				foreach ( var bay in bays.Where( bay => !bay.Gated ) )
				{
					Railing( canvas, bay, shape, kit, joinery );
				}
			}
		}

		if ( roofed )
		{
			// Rafters replace the ceiling - two answers to the same question.
			if ( !porch.Rafters )
			{
				using ( canvas.Part( ArchPieces.Ceiling ) )
				{
					Ceiling( canvas, shape, kit, style.Brush( ArchSurface.Ceiling, chain ), style.Brush( ArchSurface.Trim, chain ) );
				}
			}

			using ( canvas.Part( ArchPieces.Canopy ) )
			{
				Canopy( canvas, shape, porch, building, kit, joinery );
			}

			using ( canvas.Part( ArchPieces.Flashing ) )
			{
				Flashing( canvas, shape, porch, building, kit, style.Brush( ArchSurface.WallCap, chain ) );
			}
		}
	}
}