summaryrefslogtreecommitdiff
path: root/src/SMAPI/Events
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-12-25 15:10:22 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-12-25 15:10:22 -0500
commit8e0573d7d9f18792a19e741660b6a090cca1fb38 (patch)
tree8a23c73502a6ab17a0fbac8934107a89fe543be8 /src/SMAPI/Events
parent6ad52d607c49b16c6933060375086830edd9a1f9 (diff)
downloadSMAPI-8e0573d7d9f18792a19e741660b6a090cca1fb38.tar.gz
SMAPI-8e0573d7d9f18792a19e741660b6a090cca1fb38.tar.bz2
SMAPI-8e0573d7d9f18792a19e741660b6a090cca1fb38.zip
add GameLoop.OneSecondUpdateTicking/Ticked
Diffstat (limited to 'src/SMAPI/Events')
-rw-r--r--src/SMAPI/Events/IGameLoopEvents.cs6
-rw-r--r--src/SMAPI/Events/OneSecondUpdateTickedEventArgs.cs32
-rw-r--r--src/SMAPI/Events/OneSecondUpdateTickingEventArgs.cs32
3 files changed, 70 insertions, 0 deletions
diff --git a/src/SMAPI/Events/IGameLoopEvents.cs b/src/SMAPI/Events/IGameLoopEvents.cs
index ea79aa74..6fb56c8b 100644
--- a/src/SMAPI/Events/IGameLoopEvents.cs
+++ b/src/SMAPI/Events/IGameLoopEvents.cs
@@ -14,6 +14,12 @@ namespace StardewModdingAPI.Events
/// <summary>Raised after the game state is updated (≈60 times per second).</summary>
event EventHandler<UpdateTickedEventArgs> UpdateTicked;
+ /// <summary>Raised once per second before the game state is updated.</summary>
+ event EventHandler<OneSecondUpdateTickingEventArgs> OneSecondUpdateTicking;
+
+ /// <summary>Raised once per second after the game state is updated.</summary>
+ event EventHandler<OneSecondUpdateTickedEventArgs> OneSecondUpdateTicked;
+
/// <summary>Raised before the game creates a new save file.</summary>
event EventHandler<SaveCreatingEventArgs> SaveCreating;
diff --git a/src/SMAPI/Events/OneSecondUpdateTickedEventArgs.cs b/src/SMAPI/Events/OneSecondUpdateTickedEventArgs.cs
new file mode 100644
index 00000000..d330502a
--- /dev/null
+++ b/src/SMAPI/Events/OneSecondUpdateTickedEventArgs.cs
@@ -0,0 +1,32 @@
+using System;
+
+namespace StardewModdingAPI.Events
+{
+ /// <summary>Event arguments for an <see cref="IGameLoopEvents.OneSecondUpdateTicked"/> event.</summary>
+ public class OneSecondUpdateTickedEventArgs : EventArgs
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The number of ticks elapsed since the game started, including the current tick.</summary>
+ public uint Ticks { 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>
+ internal OneSecondUpdateTickedEventArgs(uint ticks)
+ {
+ this.Ticks = ticks;
+ }
+
+ /// <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;
+ }
+ }
+}
diff --git a/src/SMAPI/Events/OneSecondUpdateTickingEventArgs.cs b/src/SMAPI/Events/OneSecondUpdateTickingEventArgs.cs
new file mode 100644
index 00000000..cdd9f4cc
--- /dev/null
+++ b/src/SMAPI/Events/OneSecondUpdateTickingEventArgs.cs
@@ -0,0 +1,32 @@
+using System;
+
+namespace StardewModdingAPI.Events
+{
+ /// <summary>Event arguments for an <see cref="IGameLoopEvents.OneSecondUpdateTicking"/> event.</summary>
+ public class OneSecondUpdateTickingEventArgs : EventArgs
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The number of ticks elapsed since the game started, including the current tick.</summary>
+ public uint Ticks { 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>
+ internal OneSecondUpdateTickingEventArgs(uint ticks)
+ {
+ this.Ticks = ticks;
+ }
+
+ /// <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;
+ }
+ }
+}