forked from TehCheat/HealthBars
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExtensions.cs
More file actions
88 lines (73 loc) · 1.99 KB
/
Extensions.cs
File metadata and controls
88 lines (73 loc) · 1.99 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
using System;
using ExileCore;
using ExileCore.PoEMemory.Components;
using ExileCore.Shared.Nodes;
using SharpDX;
namespace HealthBars;
public static class Extensions
{
public static Color FromHex(uint hex)
{
return Color.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 with { A = (byte)(color.A * alphaMultiplier) };
}
public static Color MultiplyAlpha(this ColorNode color, float alphaMultiplier)
{
return color.Value with { A = (byte)(color.Value.A * alphaMultiplier) };
}
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 "";
}
}
}