| | 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 | | #if !UNITY_DOTSRUNTIME |
| | 6 | |
|
| | 7 | | using UnityEngine; |
| | 8 | |
|
| | 9 | | namespace GDX.Developer.Reports.Resource |
| | 10 | | { |
| | 11 | | [HideFromDocFX] |
| | 12 | | public readonly struct LongDiff |
| | 13 | | { |
| | 14 | | public readonly float Percentage; |
| | 15 | | public readonly long Change; |
| | 16 | | public readonly long LeftHandSide; |
| | 17 | | public readonly long RightHandSide; |
| | 18 | |
|
| | 19 | | public LongDiff(long lhs, long rhs) |
| 18 | 20 | | { |
| 18 | 21 | | LeftHandSide = lhs; |
| 18 | 22 | | RightHandSide = rhs; |
| | 23 | |
|
| 18 | 24 | | Change = rhs - lhs; |
| 18 | 25 | | if (lhs == 0) |
| 2 | 26 | | { |
| 2 | 27 | | Percentage = Change; |
| 2 | 28 | | } |
| | 29 | | else |
| 16 | 30 | | { |
| 16 | 31 | | Percentage = 100f * ((float)Change / lhs); |
| 16 | 32 | | } |
| 18 | 33 | | } |
| | 34 | |
|
| | 35 | |
|
| | 36 | | public string GetSizeOutput(ResourceReportContext context, bool fileSize = true, bool fullWidth = false) |
| 18 | 37 | | { |
| 18 | 38 | | if (Change == 0) |
| 6 | 39 | | { |
| 6 | 40 | | return GetBeforeAndAfterOutput(); |
| | 41 | | } |
| | 42 | |
|
| | 43 | | // We dont have an idea of the width |
| 12 | 44 | | if (!fullWidth && context != null) |
| 12 | 45 | | { |
| 12 | 46 | | return fileSize |
| | 47 | | ? $"{GetBeforeAndAfterOutput().PadRight(context.KeyValuePairInfoWidth)} {ResourceReport.PositiveSign |
| | 48 | | : $"{GetBeforeAndAfterOutput().PadRight(context.KeyValuePairInfoWidth)} {ResourceReport.PositiveSign |
| | 49 | | } |
| | 50 | |
|
| 0 | 51 | | if (fileSize) |
| 0 | 52 | | { |
| 0 | 53 | | return LeftHandSide == 0 |
| | 54 | | ? $"{GetBeforeAndAfterOutput()} = {ResourceReport.PositiveSign(Change)}{Localization.GetHumanReadabl |
| | 55 | | : $"{GetBeforeAndAfterOutput()} = {ResourceReport.PositiveSign(Change)}{Localization.GetHumanReadabl |
| | 56 | | } |
| | 57 | |
|
| 0 | 58 | | return LeftHandSide == 0 |
| | 59 | | ? $"{GetBeforeAndAfterOutput()} = {ResourceReport.PositiveSign(Change)}{Change.ToString()}" |
| | 60 | | : $"{GetBeforeAndAfterOutput()} = {ResourceReport.PositiveSign(Change)}{Change.ToString(),-12} {Optional |
| 18 | 61 | | } |
| | 62 | |
|
| | 63 | | string GetBeforeAndAfterOutput() |
| 18 | 64 | | { |
| 18 | 65 | | return $"{LeftHandSide.ToString()} => {RightHandSide.ToString()}"; |
| 18 | 66 | | } |
| | 67 | |
|
| | 68 | | string OptionalPercentageOutput() |
| 12 | 69 | | { |
| 12 | 70 | | if (LeftHandSide == 0) |
| 1 | 71 | | { |
| 1 | 72 | | return null; |
| | 73 | | } |
| | 74 | |
|
| 11 | 75 | | if (Percentage > 0) |
| 1 | 76 | | { |
| 1 | 77 | | return $" +{Mathf.RoundToInt(Percentage).ToString()}%"; |
| | 78 | | } |
| | 79 | |
|
| 10 | 80 | | if (Percentage < 0) |
| 10 | 81 | | { |
| 10 | 82 | | return $" {Mathf.RoundToInt(Percentage).ToString()}%"; |
| | 83 | | } |
| | 84 | |
|
| 0 | 85 | | return null; |
| 12 | 86 | | } |
| | 87 | | } |
| | 88 | | } |
| | 89 | | #endif // !UNITY_DOTSRUNTIME |