-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathExtensions.cs
More file actions
89 lines (74 loc) · 2.04 KB
/
Extensions.cs
File metadata and controls
89 lines (74 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Drawing;
using ExileCore2;
using ExileCore2.PoEMemory.Components;
using ExileCore2.Shared.Helpers;
using ExileCore2.Shared.Nodes;
namespace HealthBars;
public static class Extensions
{
public static Color FromHex(uint hex)
{
return ConvertHelper.FromAbgr((hex << 8) + 0xff);
}
public static string FormatHp(this long hp)
{
if (Math.Abs(hp) >= 100_000_000)
{
return ((double)hp / 1_000_000).ToString("0M");
}
if (Math.Abs(hp) >= 10_000_000)
{
return ((double)hp / 1_000_000).ToString("0.0M");
}
if (Math.Abs(hp) >= 1_000_000)
{
return ((double)hp / 1_000_000).ToString("0.00M");
}
if (Math.Abs(hp) >= 100_000)
{
return ((double)hp / 1_000).ToString("0K");
}
if (Math.Abs(hp) >= 10_000)
{
return ((double)hp / 1_000).ToString("0.0K");
}
if (Math.Abs(hp) >= 1_000)
{
return ((double)hp / 1_000).ToString("0.00K");
}
return hp.ToString("0");
}
public static string FormatHp(this int hp)
{
return ((long)hp).FormatHp();
}
public static string FormatHp(this double hp)
{
return ((long)hp).FormatHp();
}
public static Color MultiplyAlpha(this Color color, float alphaMultiplier)
{
return Color.FromArgb((byte)(color.A * alphaMultiplier), color);
}
public static Color MultiplyAlpha(this ColorNode color, float alphaMultiplier)
{
return Color.FromArgb((byte)(color.Value.A * alphaMultiplier), color);
}
public static string Truncate(this string text, int maxLength)
{
return text.Length <= maxLength ? text : text[..maxLength];
}
public static string StageNameSafe(this AnimationStage stage)
{
try
{
return stage.StageName;
}
catch (Exception ex)
{
DebugWindow.LogError(ex.ToString());
return "";
}
}
}