-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSubTextureModifier.cs
More file actions
44 lines (37 loc) · 1.3 KB
/
SubTextureModifier.cs
File metadata and controls
44 lines (37 loc) · 1.3 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
using Microsoft.Xna.Framework;
using Monocle;
using TowerFall;
namespace MiasmaColors;
public class SubTextureModifier
{
private string subtextureName;
private Color[] originalColors;
private Subtexture texture;
public SubTextureModifier(string subtextureName)
{
this.subtextureName = subtextureName;
texture = TFGame.Atlas[subtextureName];
originalColors = new Color[texture.Width * texture.Height];
TFGame.Atlas.Texture2D.GetData(0, texture.Rect, originalColors, 0, originalColors.Length);
}
public void ApplyHueShift(float angle)
{
Color[] newColors = new Color[originalColors.Length];
for (int i = 0; i < newColors.Length; i++)
{
if (originalColors[i].A == 0)
{
newColors[i] = originalColors[i];
continue;
}
HSV hsvColor = ColorUtils.ColorToHSV(originalColors[i]);
ColorUtils.HueShift(ref hsvColor, angle);
newColors[i] = ColorUtils.HSVToColor(hsvColor, originalColors[i].A);
}
TFGame.Atlas.Texture2D.SetData(0, texture.Rect, newColors, 0, newColors.Length);
}
public void Reset()
{
TFGame.Atlas.Texture2D.SetData(0, texture.Rect, originalColors, 0, originalColors.Length);
}
}