Editor/Tool/ArchContextActions.cs
namespace Sunless.Architecture;

public readonly record struct ArchContextActionContext(
	ArchTool Tool,
	Menu Menu,
	int Level,
	Vector2 Point );

public interface IArchContextAction {
	ArchKind Kind { get; }

	bool Build( ArchContextActionContext context );
}

public sealed class ArchContextActions : ArchTable<ArchContextActions, ArchKind, IArchContextAction> {
	protected override IEnumerable<IArchContextAction> Standing() {
		yield return new ArchStairContextAction();
	}

	protected override ArchKind KeyOf( IArchContextAction action ) => action.Kind;

	protected override bool Accepts( IArchContextAction action ) => action.Kind.Known;

	protected override string Collision( IArchContextAction standing, IArchContextAction action ) {
		return $"{action.Kind.Ident} context actions are claimed by both {standing.GetType().Name} and {action.GetType().Name}";
	}

	public IArchContextAction For( ArchKind kind ) => Held( kind );

	public bool Build( ArchContextActionContext context ) {
		var built = false;

		foreach ( var action in Entries.OrderBy( candidate => candidate.Kind.Ident, StringComparer.Ordinal ) ) {
			built |= action.Build( context );
		}

		return built;
	}

	public ArchContextActions Except( ArchKind kind ) => Without( kind );
}