A game framework written with osu! in mind.
at master 1.5 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using System; 5 6namespace osu.Framework.Testing.Drawables.Steps 7{ 8 public class RepeatStepButton : StepButton 9 { 10 private readonly int count; 11 private int invocations; 12 13 public override int RequiredRepetitions => count; 14 15 private string text; 16 17 public new string Text 18 { 19 get => text; 20 set => base.Text = text = value; 21 } 22 23 public RepeatStepButton(Action action, int count = 1, bool isSetupStep = false) 24 : base(isSetupStep) 25 { 26 this.count = count; 27 Action = action; 28 29 updateText(); 30 } 31 32 public override void PerformStep(bool userTriggered = false) 33 { 34 if (invocations == count && !userTriggered) throw new InvalidOperationException("Repeat step was invoked too many times"); 35 36 invocations++; 37 38 base.PerformStep(userTriggered); 39 40 if (invocations >= count) // Allows for manual execution beyond the invocation limit. 41 Success(); 42 43 updateText(); 44 } 45 46 public override void Reset() 47 { 48 base.Reset(); 49 50 invocations = 0; 51 updateText(); 52 } 53 54 private void updateText() => base.Text = $@"{Text} {invocations}/{count}"; 55 56 public override string ToString() => "Repeat: " + base.ToString(); 57 } 58}