summaryrefslogtreecommitdiff
path: root/src/SMAPI/Events/UpdateTickingEventArgs.cs
blob: 5998fd9bf7e0d7e2ec9814163c53ea47a422bec0 (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
using System;

namespace StardewModdingAPI.Events
{
    /// <summary>Event arguments for an <see cref="IGameLoopEvents.UpdateTicking"/> event.</summary>
    public class UpdateTickingEventArgs : EventArgs
    {
        /*********
        ** Accessors
        *********/
        /// <summary>The number of ticks elapsed since the game started, including the current tick.</summary>
        public uint Ticks { get; }

        /// <summary>Whether <see cref="Ticks"/> is a multiple of 60, which happens approximately once per second.</summary>
        public bool IsOneSecond { get; }


        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="ticks">The number of ticks elapsed since the game started, including the current tick.</param>
        public UpdateTickingEventArgs(uint ticks)
        {
            this.Ticks = ticks;
            this.IsOneSecond = this.IsMultipleOf(60);
        }

        /// <summary>Get whether <see cref="Ticks"/> is a multiple of the given <paramref name="number"/>. This is mainly useful if you want to run logic intermittently (e.g. <code>e.IsMultipleOf(30)</code> for every half-second).</summary>
        /// <param name="number">The factor to check.</param>
        public bool IsMultipleOf(uint number)
        {
            return this.Ticks % number == 0;
        }
    }
}