Editor/Stair/ArchStairGhost.cs
namespace Sunless.Architecture;

public static class ArchStairGhost {
	public static void Blueprint( ArchStairPart stair ) {
		if ( stair?.Core is not { } core || stair.Lanes.Count == 0 ) {
			return;
		}

		var bases = ArchStairEdges.Bases( stair );

		for ( var index = 0; index < stair.Lanes.Count; index++ ) {
			ArchGhost.Quad( stair.Lanes[index].Loop( core ), bases[index], ArchGhost.Nth( index ) );
		}
	}

	public static void Flight( ArchStairShape shape, float soffit, int? level = null ) {
		foreach ( var run in shape.Runs ) {
			if ( level is { } runLevel && run.Level != runLevel ) {
				continue;
			}

			foreach ( var lane in new[] { 0f, run.Width } ) {
				for ( var step = 0; step < run.Steps; step++ ) {
					var nose = step * run.Going;
					var top = run.StepTop( step );

					Gizmo.Draw.Line( run.Axes.Point( nose, lane, top - run.Rise ), run.Axes.Point( nose, lane, top ) );
					Gizmo.Draw.Line( run.Axes.Point( nose, lane, top ), run.Axes.Point( nose + run.Going, lane, top ) );
				}
			}
		}

		Gizmo.Draw.Color = ArchGhost.Accent;

		foreach ( var pad in shape.Pads ) {
			if ( level is { } padLevel && pad.Storey != padLevel ) {
				continue;
			}

			ArchGhost.Ring( pad.Loop(), pad.Height );
		}

		Gizmo.Draw.Color = ArchGhost.Ground;

		foreach ( var well in shape.Levels ) {
			if ( level is { } wellLevel && well.Level != wellLevel + 1 ) {
				continue;
			}

			foreach ( var loop in well.Loops ) {
				ArchGhost.Ring( loop, well.Height );
			}

			if ( well.Level == shape.TopLevel ) {
				foreach ( var loop in well.Loops ) {
					ArchGhost.Ring( loop, soffit );

					foreach ( var corner in loop ) {
						Gizmo.Draw.Line( new Vector3( corner.x, corner.y, shape.BaseHeight ), new Vector3( corner.x, corner.y, soffit ) );
					}
				}
			}
		}

		Gizmo.Draw.Color = ArchGhost.Line;
	}
}