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 modifiers) { return modifiers.Matches(modifierType, requirement); } } public static class InputModifier { public static List Capture(bool specialA, bool specialB, bool specialC) { List 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 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 modifiers, PlayerInputModifierType modifierType, InputModifierRequirement requirement) { bool isPressed = modifiers.Has(modifierType); return requirement switch { InputModifierRequirement.Pressed => isPressed, InputModifierRequirement.Released => !isPressed, _ => true }; } } }