summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/Utilities/Countdown.cs
blob: 94c69e730a3eb53cecaac7090d4b4aa551b8ee02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
namespace StardewModdingAPI.Framework.Utilities
{
    /// <summary>Counts down from a baseline value.</summary>
    internal class Countdown
    {
        /*********
        ** Accessors
        *********/
        /// <summary>The initial value from which to count down.</summary>
        public int Initial { get; }

        /// <summary>The current value.</summary>
        public int Current { get; private set; }


        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="initial">The initial value from which to count down.</param>
        public Countdown(int initial)
        {
            this.Initial = initial;
            this.Current = initial;
        }

        /// <summary>Reduce the current value by one.</summary>
        /// <returns>Returns whether the value was decremented (i.e. wasn't already zero).</returns>
        public bool Decrement()
        {
            if (this.Current <= 0)
                return false;

            this.Current--;
            return true;
        }

        /// <summary>Restart the countdown.</summary>
        public void Reset()
        {
            this.Current = this.Initial;
        }
    }
}