Entities/Player.AbilityInput.cs

Partial Player class code handling ability input and aim. It reads an ability-aim bitmask from input, converts it to a world-space 2D direction with optional neutral fallback to the player's jump screen direction, and provides a helper to map a Direction enum to a unit vector.

namespace BlockParty;

// Shared with ability regression harnesses so they compile the player's real aim/version logic.
public sealed partial class Player
{
	internal bool UsesAbilityButtons => Stage.SimVersion >= Sim.ABILITY_BUTTONS;

	/// <summary>World-space ability aim, before the gravity-aware Jump action is merged into movement.
	/// Opposite directions cancel; neutral activation keeps the old shortcut's away-from-floor fallback.</summary>
	internal Vector2 ReadAbilityDirection( bool neutralFallback = true )
	{
		int mask = AbilityAim.ReadMask( _input, Stage.SimVersion );
		float x = ((mask & 2) != 0 ? 1f : 0f) - ((mask & 1) != 0 ? 1f : 0f);
		float y = ((mask & 4) != 0 ? 1f : 0f) - ((mask & 8) != 0 ? 1f : 0f);
		Vector2 direction = new( x, y );
		if ( direction.LengthSquared > 0f ) return Utils.Normalized( direction );
		return neutralFallback ? DirectionVector( JumpScreenDirection ) : Vector2.Zero;
	}

	static Vector2 DirectionVector( Direction direction ) => direction switch
	{
		Direction.Left => new Vector2( -1f, 0f ),
		Direction.Right => new Vector2( 1f, 0f ),
		Direction.Up => new Vector2( 0f, 1f ),
		Direction.Down => new Vector2( 0f, -1f ),
		_ => Vector2.Zero,
	};
}