From 29c5265fa438de980ed2acd3fa451a1312acea8a Mon Sep 17 00:00:00 2001 From: Emik Date: Wed, 30 Oct 2024 18:17:45 +0100 Subject: [PATCH] Use methods to save on binary size --- wawa.Modules/Source/ModdedModule.cs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/wawa.Modules/Source/ModdedModule.cs b/wawa.Modules/Source/ModdedModule.cs index bc467e3..7859c42 100755 --- a/wawa.Modules/Source/ModdedModule.cs +++ b/wawa.Modules/Source/ModdedModule.cs @@ -13,10 +13,6 @@ const string ExceptionStackTrace = "Rethrow as ", NoComponent = $"There is no attached {nameof(KMBombModule)} or {nameof(KMNeedyModule)}.", NotFound = "[[HYPERLINK BLOCKED]]", - LengthNotSet = - $"The {nameof(KMSelectable)} attached to this {nameof(GameObject)} has a " + - $"{nameof(KMSelectable.ChildRowLength)} set to 0 or less. Be sure to set this to a natural number so " + - "that the matrix can be instantiated properly.", Prefix = @" | ", TooFewAudioSources = $"{nameof(Play)} Error: You need a {nameof(KMAudio)} component to play a sound. " + @@ -54,7 +50,7 @@ const string [PublicAPI] public IList Children { - [ItemCanBeNull, NotNull, MustUseReturnValue] get => Get().Children; + [ItemCanBeNull, NotNull, MustUseReturnValue] get => GetChildSelectables(); } /// Gets the children of the top-level selectable. @@ -73,10 +69,7 @@ public IList Children public IList> Matrix { [ItemCanBeNull, NotNull, MustUseReturnValue] - get => - _matrix ??= Get().ChildRowLength > 0 - ? new MatrixFactory.Matrix(() => Children, () => Get().ChildRowLength) - : throw new InvalidOperationException(LengthNotSet); + get => _matrix ??= new Matrix(GetChildSelectables, GetChildSelectableRowLength); } /// Gets the current solve/strike status of the module. @@ -620,6 +613,11 @@ bool OnStrike() return false; } + /// Gets the child row length. + /// The number of elements in a row. + [MustUseReturnValue] + int GetChildSelectableRowLength() => Get().ChildRowLength; + /// Gets the coroutine for solving the module and running the auto-solver. /// The coroutine for solving. [NotNull, Pure] @@ -634,4 +632,9 @@ IEnumerator WaitForSolve() if (GetComponent() is var solver && solver as Object) yield return solver.ForceTPSolve(); } + + /// Gets the children. + /// The children selectables. + [ItemCanBeNull, MustUseReturnValue, NotNull] + KMSelectable[] GetChildSelectables() => Get().Children; }