diff --git a/CHANGELOG.md b/CHANGELOG.md index f03860f..9465a3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ Additions - Added consuming variants of IsPressed methods to InputHandler and Keybind - Added SpriteBatchContext struct and extensions - Added InputHandler.InvertPressBehavior -- Added ReverseInput and ReverseOutput to Easings +- Added ReverseInput, ReverseOutput and AndThen to Easings ### MLEM.Ui Additions diff --git a/MLEM/Misc/Easings.cs b/MLEM/Misc/Easings.cs index 457f195..2c7ccd9 100644 --- a/MLEM/Misc/Easings.cs +++ b/MLEM/Misc/Easings.cs @@ -142,6 +142,34 @@ namespace MLEM.Misc { return p => p <= 0.5F ? easing(p * 2) : easing(1 - (p - 0.5F) * 2); } + /// + /// Causes the easing function to play fully, followed by playing fully, in the span between an input of 0 and 1. + /// Note that provides a version of this method for any amount of follow-up easing functions. + /// + /// The first easing function to play. + /// The second easing function to play. + /// A combined easing function of the two functions passed. + public static Easing AndThen(this Easing easing, Easing other) { + return p => p <= 0.5F ? easing(p * 2) : other((p - 0.5F) * 2); + } + + /// + /// Causes the easing function to play fully, followed by all elements of playing fully, in the span between an input of 0 and 1. + /// This is an any-amount version of . + /// + /// The first easing function to play. + /// The next easing functions to play. + /// A combined easing function of all of the functions passed. + public static Easing AndThen(this Easing easing, params Easing[] others) { + var interval = 1F / (others.Length + 1); + return p => { + if (p <= interval) + return easing(p / interval); + var index = (int) ((p - interval) * (others.Length + 1)); + return others[index]((p - (index + 1) * interval) / interval); + }; + } + /// /// A delegate method used by . ///