2025-11-25 08:19:33 -05:00
using System ;
using UnityEngine ;
namespace Cielonos.MainGame.Characters
{
2026-07-18 03:16:20 -04:00
public partial class PlayerInputSubcontroller
2025-11-25 08:19:33 -05:00
{
2026-07-18 03:16:20 -04:00
public class PlayerPreinputSubmodule : SubmoduleBase < PlayerInputSubcontroller >
2025-11-25 08:19:33 -05:00
{
2026-07-18 03:16:20 -04:00
public const int DashDodgePreinputPriority = 100 ;
2025-11-25 08:19:33 -05:00
2026-07-18 03:16:20 -04:00
public class PlayerPreinputRequest
{
public string actionId ;
public int priority ;
public Action action ;
2025-11-25 08:19:33 -05:00
2026-07-18 03:16:20 -04:00
public PlayerPreinputRequest ( string actionId , Action action , int priority )
{
this . actionId = actionId ;
this . action = action ;
this . priority = priority ;
}
public void Execute ( )
{
action ? . Invoke ( ) ;
}
}
public bool isReceivingPreinput ;
public int currentPreinputPriority ;
public PlayerPreinputRequest currentRequest ;
public PlayerPreinputSubmodule ( PlayerInputSubcontroller owner ) : base ( owner )
2025-11-25 08:19:33 -05:00
{
Reset ( ) ;
}
2026-07-18 03:16:20 -04:00
public void Reset ( )
{
isReceivingPreinput = false ;
currentPreinputPriority = int . MinValue ;
currentRequest = null ;
}
public void Update ( bool isReceiving , bool canExecute )
{
isReceivingPreinput = isReceiving ;
if ( canExecute )
{
//Debug.Log($"Executing preinput action with priority {currentPreinputPriority}");
currentRequest ? . Execute ( ) ;
Reset ( ) ;
}
}
public void RegisterPreinputAction ( Action action , int priority )
{
RegisterPreinputAction ( null , action , priority ) ;
}
public void RegisterPreinputAction ( string actionId , Action action , int priority )
2025-11-25 08:19:33 -05:00
{
2026-07-18 03:16:20 -04:00
//Debug.Log($"Registering preinput action with priority {priority}, current priority is {currentPreinputPriority}, isReceivingPreinput: {isReceivingPreinput}");
if ( isReceivingPreinput & & priority > = currentPreinputPriority )
{
//Debug.Log($"Preinput action registered.");
currentRequest = new PlayerPreinputRequest ( actionId , action , priority ) ;
currentPreinputPriority = priority ;
}
2025-11-25 08:19:33 -05:00
}
}
2026-07-18 03:16:20 -04:00
}
}