From 929dccb75a1405737975d76648e015a3e7c00177 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 7 Oct 2017 23:07:10 -0400 Subject: reorganise repo structure --- .../Framework/Utilities/ContextHash.cs | 61 ---------------------- .../Framework/Utilities/Countdown.cs | 44 ---------------- 2 files changed, 105 deletions(-) delete mode 100644 src/StardewModdingAPI/Framework/Utilities/ContextHash.cs delete mode 100644 src/StardewModdingAPI/Framework/Utilities/Countdown.cs (limited to 'src/StardewModdingAPI/Framework/Utilities') diff --git a/src/StardewModdingAPI/Framework/Utilities/ContextHash.cs b/src/StardewModdingAPI/Framework/Utilities/ContextHash.cs deleted file mode 100644 index 6c0fdc90..00000000 --- a/src/StardewModdingAPI/Framework/Utilities/ContextHash.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace StardewModdingAPI.Framework.Utilities -{ - /// A wrapper meant for tracking recursive contexts. - /// The key type. - internal class ContextHash : HashSet - { - /********* - ** Public methods - *********/ - /// Construct an instance. - public ContextHash() { } - - /// Construct an instance. - /// The implementation to use when comparing values in the set, or null to use the default comparer for the set type. - public ContextHash(IEqualityComparer comparer) - : base(comparer) { } - - /// Add a key while an action is in progress, and remove it when it completes. - /// The key to add. - /// The action to perform. - /// The specified key is already added. - public void Track(T key, Action action) - { - if (this.Contains(key)) - throw new InvalidOperationException($"Can't track context for key {key} because it's already added."); - - this.Add(key); - try - { - action(); - } - finally - { - this.Remove(key); - } - } - - /// Add a key while an action is in progress, and remove it when it completes. - /// The value type returned by the method. - /// The key to add. - /// The action to perform. - public TResult Track(T key, Func action) - { - if (this.Contains(key)) - throw new InvalidOperationException($"Can't track context for key {key} because it's already added."); - - this.Add(key); - try - { - return action(); - } - finally - { - this.Remove(key); - } - } - } -} diff --git a/src/StardewModdingAPI/Framework/Utilities/Countdown.cs b/src/StardewModdingAPI/Framework/Utilities/Countdown.cs deleted file mode 100644 index 921a35ce..00000000 --- a/src/StardewModdingAPI/Framework/Utilities/Countdown.cs +++ /dev/null @@ -1,44 +0,0 @@ -namespace StardewModdingAPI.Framework.Utilities -{ - /// Counts down from a baseline value. - internal class Countdown - { - /********* - ** Accessors - *********/ - /// The initial value from which to count down. - public int Initial { get; } - - /// The current value. - public int Current { get; private set; } - - - /********* - ** Public methods - *********/ - /// Construct an instance. - /// The initial value from which to count down. - public Countdown(int initial) - { - this.Initial = initial; - this.Current = initial; - } - - /// Reduce the current value by one. - /// Returns whether the value was decremented (i.e. wasn't already zero). - public bool Decrement() - { - if (this.Current <= 0) - return false; - - this.Current--; - return true; - } - - /// Restart the countdown. - public void Reset() - { - this.Current = this.Initial; - } - } -} -- cgit