Files
SoulliesOfficial 39b43680a9 爆更
2026-07-18 03:16:20 -04:00

79 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using Sirenix.OdinInspector;
namespace Cielonos.MainGame.Characters
{
public enum PlayerInputModifierType
{
SpecialA,
SpecialB,
SpecialC
}
public enum InputModifierRequirement
{
Pressed,
Released
}
[Serializable]
public class InputModifierCondition
{
[HorizontalGroup("Condition", Width = 0.5f)]
[HideLabel]
public PlayerInputModifierType modifierType;
[HorizontalGroup("Condition", Width = 0.5f)]
[HideLabel]
public InputModifierRequirement requirement = InputModifierRequirement.Pressed;
public bool Matches(List<PlayerInputModifierType> modifiers)
{
return modifiers.Matches(modifierType, requirement);
}
}
public static class InputModifier
{
public static List<PlayerInputModifierType> Capture(bool specialA, bool specialB, bool specialC)
{
List<PlayerInputModifierType> modifiers = new();
if (specialA) modifiers.Add(PlayerInputModifierType.SpecialA);
if (specialB) modifiers.Add(PlayerInputModifierType.SpecialB);
if (specialC) modifiers.Add(PlayerInputModifierType.SpecialC);
return modifiers;
}
public static bool Has(this IReadOnlyList<PlayerInputModifierType> modifiers, PlayerInputModifierType modifierType)
{
if (modifiers == null) return false;
foreach (var type in modifiers)
{
if (type == modifierType)
{
return true;
}
}
return false;
}
public static bool Matches(this IReadOnlyList<PlayerInputModifierType> modifiers,
PlayerInputModifierType modifierType, InputModifierRequirement requirement)
{
bool isPressed = modifiers.Has(modifierType);
return requirement switch
{
InputModifierRequirement.Pressed => isPressed,
InputModifierRequirement.Released => !isPressed,
_ => true
};
}
}
}