diff --git a/Assets/Scripts/Domain/CustomInput.cs b/Assets/Scripts/Domain/CustomInput.cs index dc9f2ac..c4f49b0 100644 --- a/Assets/Scripts/Domain/CustomInput.cs +++ b/Assets/Scripts/Domain/CustomInput.cs @@ -1,34 +1,34 @@ using System; using System.Collections.Generic; +using System.Linq; using Domain.Input; namespace Domain { public class CustomInput { - private readonly Dictionary _readers = new(); + private readonly List _readers = new(); private readonly KeyHistory _history; public CustomInput() { _history = new KeyHistory(); - _readers.Add(typeof(CedillaReader), new CedillaReader()); - _readers.Add(typeof(GeminadaReader), new GeminadaReader(_history)); - _readers.Add(typeof(TxReader), new TxReader(_history)); - _readers.Add(typeof(IxReader), new IxReader(_history)); - _readers.Add(typeof(NyReader), new NyReader(_history)); - _readers.Add(typeof(TgReader), new TgReader(_history)); - _readers.Add(typeof(TjReader), new TjReader(_history)); - _readers.Add(typeof(LlReader), new LlReader(_history)); - _readers.Add(typeof(SsReader), new SsReader(_history)); - _readers.Add(typeof(AObertaReader), new AObertaReader(_history)); + _readers.Add(new CedillaReader()); + _readers.Add(new GeminadaReader(_history)); + _readers.Add(new TxReader(_history)); + _readers.Add(new IxReader(_history)); + _readers.Add(new NyReader(_history)); + _readers.Add(new TgReader(_history)); + _readers.Add(new TjReader(_history)); + _readers.Add(new LlReader(_history)); + _readers.Add(new SsReader(_history)); + _readers.Add(new AObertaReader(_history)); } public void UpdateInput() { _history.CheckPresses(); - foreach (KeyValuePair reader in _readers) { - reader.Value.UpdateInput(); - } + foreach (InputReader reader in _readers) + reader.UpdateInput(); } - public bool KeyDown(Type key) => _readers[key].KeyDown(); + public bool AnyKeyDown() => _readers.Any(reader => reader.KeyDown()); } } \ No newline at end of file diff --git a/Assets/Scripts/View/UI/ExpressionInput.cs b/Assets/Scripts/View/UI/ExpressionInput.cs index 17466c9..2c721cc 100644 --- a/Assets/Scripts/View/UI/ExpressionInput.cs +++ b/Assets/Scripts/View/UI/ExpressionInput.cs @@ -26,34 +26,16 @@ namespace View.UI { CheckInput(); } - private void CheckInput() { - _customInput.UpdateInput(); - - if (_customInput.KeyDown(typeof(GeminadaReader))) - _click.Execute(); - if (_customInput.KeyDown(typeof(CedillaReader))) - _click.Execute(); - if (_customInput.KeyDown(typeof(IxReader))) - _click.Execute(); - if (_customInput.KeyDown(typeof(LlReader))) - _click.Execute(); - if (_customInput.KeyDown(typeof(NyReader))) - _click.Execute(); - if (_customInput.KeyDown(typeof(SsReader))) - _click.Execute(); - if (_customInput.KeyDown(typeof(TgReader))) - _click.Execute(); - if (_customInput.KeyDown(typeof(TjReader))) - _click.Execute(); - if (_customInput.KeyDown(typeof(TxReader))) - _click.Execute(); - if(_customInput.KeyDown(typeof(AObertaReader))) - _click.Execute(); - } - public void UpdateView(int score) { animator.PlayUntil(_model.GrowPercentage); text.text = score.ToString(); } + + private void CheckInput() { + _customInput.UpdateInput(); + + if (_customInput.AnyKeyDown()) + _click.Execute(); + } } } \ No newline at end of file