| | 1 | | // Copyright (c) 2020-2024 dotBunny Inc. |
| | 2 | | // dotBunny licenses this file to you under the BSL-1.0 license. |
| | 3 | | // See the LICENSE file in the project root for more information. |
| | 4 | |
|
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | #if !UNITY_DOTSRUNTIME |
| | 8 | |
|
| | 9 | | namespace GDX.Developer.Reports.Resource |
| | 10 | | { |
| | 11 | | [HideFromDocFX] |
| | 12 | | public readonly struct IntegerDiff |
| | 13 | | { |
| | 14 | | public readonly float Percentage; |
| | 15 | | public readonly int Change; |
| | 16 | | public readonly int LeftHandSide; |
| | 17 | | public readonly int RightHandSide; |
| | 18 | |
|
| | 19 | | public IntegerDiff(int lhs, int rhs) |
| 1 | 20 | | { |
| 1 | 21 | | LeftHandSide = lhs; |
| 1 | 22 | | RightHandSide = rhs; |
| | 23 | |
|
| | 24 | |
|
| 1 | 25 | | Change = rhs - lhs; |
| 1 | 26 | | if (lhs == 0) |
| 0 | 27 | | { |
| 0 | 28 | | Percentage = Change; |
| 0 | 29 | | } |
| | 30 | | else |
| 1 | 31 | | { |
| 1 | 32 | | Percentage = 100f * ((float)Change / lhs); |
| 1 | 33 | | } |
| 1 | 34 | | } |
| | 35 | |
|
| | 36 | | public string GetOutput(ResourceReportContext context, bool fullWidth = false) |
| 1 | 37 | | { |
| 1 | 38 | | if (Change == 0) |
| 0 | 39 | | { |
| 0 | 40 | | return GetBeforeAndAfterOutput(); |
| | 41 | | } |
| | 42 | |
|
| | 43 | | // We dont have an idea of the width |
| 1 | 44 | | if (fullWidth || context == null) |
| 0 | 45 | | { |
| 0 | 46 | | return LeftHandSide == 0 |
| | 47 | | ? $"{GetBeforeAndAfterOutput()} = {ResourceReport.PositiveSign(Change)}{Change.ToString()}" |
| | 48 | | : $"{GetBeforeAndAfterOutput()} = {ResourceReport.PositiveSign(Change)}{Change.ToString(),-12} {Opti |
| | 49 | | } |
| | 50 | |
|
| 1 | 51 | | return |
| | 52 | | $"{GetBeforeAndAfterOutput().PadRight(context.KeyValuePairInfoWidth)} {ResourceReport.PositiveSign(Chang |
| 1 | 53 | | } |
| | 54 | |
|
| | 55 | | string GetBeforeAndAfterOutput() |
| 1 | 56 | | { |
| 1 | 57 | | return $"{LeftHandSide.ToString()} => {RightHandSide.ToString()}"; |
| 1 | 58 | | } |
| | 59 | |
|
| | 60 | | string OptionalPercentageOutput() |
| 1 | 61 | | { |
| 1 | 62 | | if (LeftHandSide == 0) |
| 0 | 63 | | { |
| 0 | 64 | | return null; |
| | 65 | | } |
| | 66 | |
|
| 1 | 67 | | if (Percentage > 0) |
| 1 | 68 | | { |
| 1 | 69 | | return $" +{Mathf.RoundToInt(Percentage).ToString()}%"; |
| | 70 | | } |
| | 71 | |
|
| 0 | 72 | | if (Percentage < 0) |
| 0 | 73 | | { |
| 0 | 74 | | return $" {Mathf.RoundToInt(Percentage).ToString()}%"; |
| | 75 | | } |
| | 76 | |
|
| 0 | 77 | | return null; |
| 1 | 78 | | } |
| | 79 | | } |
| | 80 | | } |
| | 81 | | #endif // !UNITY_DOTSRUNTIME |