Skip to content

Commit 99203a9

Browse files
Added raid zone effects.
1 parent a98b3bd commit 99203a9

13 files changed

Lines changed: 1187 additions & 215 deletions

Chromatics/Core/AppSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static class AppSettings
1414
private static SettingsModel _settings = new SettingsModel();
1515

1616
public static readonly string currentSettingsVersion = "2";
17-
public static readonly string currentEffectsVersion = "1";
17+
public static readonly string currentEffectsVersion = "2";
1818
public static readonly string currentPalettesVersion = "1";
1919
public static readonly string currentMappingLayerVersion = "1";
2020

Chromatics/Enums/PaletteTypes.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using System.Text;
77
using System.Threading.Tasks;
8+
using System.Xml.Linq;
89

910
namespace Chromatics.Enums
1011
{
@@ -35,9 +36,11 @@ public enum PaletteTypes
3536
[Display(Name = "Reactive Weather")]
3637
ReactiveWeather = 10,
3738
[Display(Name = "Job Classes")]
38-
JobClasses = 11
39+
JobClasses = 11,
40+
[Display(Name = "Raid Effects")]
41+
RaidEffects = 12
3942
}
4043

41-
public static int TypeCount = 11;
44+
public static int TypeCount = 12;
4245
}
4346
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
using RGB.NET.Core;
2+
using System;
3+
using System.Collections.Concurrent;
4+
using System.Collections.Generic;
5+
using System.Diagnostics;
6+
using System.Linq;
7+
using Color = RGB.NET.Core.Color;
8+
9+
namespace Chromatics.Extensions.RGB.NET.Decorators
10+
{
11+
public class ArenaLightShowDecorator : AbstractUpdateAwareDecorator, ILedGroupDecorator
12+
{
13+
private readonly ListLedGroup ledGroup;
14+
private readonly Random random = new Random();
15+
private readonly double interval;
16+
private readonly double waveSpeed;
17+
private readonly double waveFrequency;
18+
private readonly Color[] colors;
19+
private readonly Color baseColor;
20+
private ConcurrentDictionary<Led, double> ledPositions;
21+
private Dictionary<Led, float> currentBrightness;
22+
private Dictionary<Led, Color> currentColors;
23+
private double Timing;
24+
25+
public ArenaLightShowDecorator(ListLedGroup _ledGroup, double interval, double waveSpeed, double waveFrequency, Color[] colors, RGBSurface surface, bool updateIfDisabled = false, Color baseColor = default(Color)) : base(surface, updateIfDisabled)
26+
{
27+
this.ledGroup = _ledGroup;
28+
this.interval = interval;
29+
this.waveSpeed = waveSpeed;
30+
this.waveFrequency = waveFrequency;
31+
this.colors = colors;
32+
this.baseColor = baseColor == default(Color) ? Color.Transparent : baseColor;
33+
34+
ledPositions = new ConcurrentDictionary<Led, double>();
35+
currentBrightness = new Dictionary<Led, float>();
36+
currentColors = new Dictionary<Led, Color>();
37+
Timing = 0;
38+
}
39+
40+
public override void OnAttached(IDecoratable decoratable)
41+
{
42+
base.OnAttached(decoratable);
43+
ledGroup.Detach();
44+
45+
Debug.WriteLine("Arena Light Show Decorator Attached");
46+
47+
foreach (var led in ledGroup)
48+
{
49+
ledPositions.TryAdd(led, random.NextDouble() * Math.PI * 2);
50+
currentColors.TryAdd(led, colors[random.Next(colors.Length)]);
51+
}
52+
}
53+
54+
public override void OnDetached(IDecoratable decoratable)
55+
{
56+
base.OnDetached(decoratable);
57+
ledPositions.Clear();
58+
currentColors.Clear();
59+
currentBrightness.Clear();
60+
Timing = 0;
61+
62+
Debug.WriteLine("Arena Light Show Decorator Detached");
63+
}
64+
65+
protected override void Update(double deltaTime)
66+
{
67+
try
68+
{
69+
if (ledGroup == null) return;
70+
71+
Timing += deltaTime * waveSpeed;
72+
73+
foreach (var led in ledGroup)
74+
{
75+
if (!ledPositions.ContainsKey(led)) continue;
76+
77+
double position = ledPositions[led] + Timing;
78+
double intensity = (Math.Sin(position * waveFrequency) + 1) / 2; // Sine wave for smooth transition
79+
80+
var colorIndex = (int)(Math.Floor((position / Math.PI) % colors.Length));
81+
var nextColorIndex = (colorIndex + 1) % colors.Length;
82+
83+
var currentColor = colors[colorIndex];
84+
var nextColor = colors[nextColorIndex];
85+
86+
var color = Lerp(currentColor, nextColor, (float)intensity);
87+
88+
var newCol = new Color(
89+
(int)(color.R * 255 * intensity + baseColor.R * (1 - intensity)),
90+
(int)(color.G * 255 * intensity + baseColor.G * (1 - intensity)),
91+
(int)(color.B * 255 * intensity + baseColor.B * (1 - intensity))
92+
);
93+
94+
led.Color = newCol;
95+
}
96+
}
97+
catch (Exception ex)
98+
{
99+
#if DEBUG
100+
Debug.WriteLine($"Exception: {ex.Message}");
101+
#endif
102+
}
103+
}
104+
105+
private static Color Lerp(Color start, Color end, float amount)
106+
{
107+
float r = start.R + (end.R - start.R) * amount;
108+
float g = start.G + (end.G - start.G) * amount;
109+
float b = start.B + (end.B - start.B) * amount;
110+
111+
return new Color((int)(r * 255), (int)(g * 255), (int)(b * 255));
112+
}
113+
}
114+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
using RGB.NET.Core;
2+
using System;
3+
using System.Collections.Concurrent;
4+
using System.Collections.Generic;
5+
using System.Diagnostics;
6+
using System.Linq;
7+
using Color = RGB.NET.Core.Color;
8+
9+
namespace Chromatics.Extensions.RGB.NET.Decorators
10+
{
11+
public class BPMPWMDecorator : AbstractUpdateAwareDecorator, ILedGroupDecorator
12+
{
13+
private readonly ListLedGroup ledGroup;
14+
private readonly Random random = new Random();
15+
private readonly double waveFrequency;
16+
private readonly Color[] colors;
17+
private readonly Color baseColor;
18+
private readonly int groupSize;
19+
private readonly List<Led> leds;
20+
private ConcurrentDictionary<Led, double> ledPositions;
21+
private Dictionary<Led, Color> currentColors;
22+
private Dictionary<Led, Color> targetColors;
23+
private Dictionary<Led, double> transitionStartTimes;
24+
private double Timing;
25+
private double nextBeatTime;
26+
private double interval;
27+
private int bpm;
28+
private double fadeTime;
29+
30+
public BPMPWMDecorator(ListLedGroup _ledGroup, int bpm, double waveFrequency, Color[] colors, double fadeTime, int groupSize, RGBSurface surface, bool updateIfDisabled = false, Color baseColor = default(Color)) : base(surface, updateIfDisabled)
31+
{
32+
this.ledGroup = _ledGroup;
33+
this.bpm = bpm;
34+
this.waveFrequency = waveFrequency;
35+
this.colors = colors;
36+
this.baseColor = baseColor == default(Color) ? Color.Transparent : baseColor;
37+
this.fadeTime = fadeTime;
38+
this.groupSize = groupSize;
39+
40+
leds = ledGroup.OrderBy(led => led.Id).ToList(); // Ensure the list is ordered correctly
41+
CalculateInterval();
42+
ledPositions = new ConcurrentDictionary<Led, double>();
43+
currentColors = new Dictionary<Led, Color>();
44+
targetColors = new Dictionary<Led, Color>();
45+
transitionStartTimes = new Dictionary<Led, double>();
46+
Timing = 0;
47+
nextBeatTime = interval; // Initialize nextBeatTime
48+
}
49+
50+
private void CalculateInterval()
51+
{
52+
// Convert BPM to interval in seconds (interval = 60 / BPM)
53+
interval = 60.0 / bpm;
54+
}
55+
56+
public override void OnAttached(IDecoratable decoratable)
57+
{
58+
base.OnAttached(decoratable);
59+
ledGroup.Detach();
60+
61+
Debug.WriteLine("Arena Light Show Decorator Attached");
62+
63+
foreach (var led in leds)
64+
{
65+
ledPositions.TryAdd(led, random.NextDouble() * Math.PI * 2);
66+
var initialColor = colors[random.Next(colors.Length)];
67+
currentColors[led] = initialColor;
68+
targetColors[led] = initialColor;
69+
transitionStartTimes[led] = 0;
70+
}
71+
}
72+
73+
public override void OnDetached(IDecoratable decoratable)
74+
{
75+
base.OnDetached(decoratable);
76+
ledPositions.Clear();
77+
currentColors.Clear();
78+
targetColors.Clear();
79+
transitionStartTimes.Clear();
80+
Timing = 0;
81+
nextBeatTime = interval;
82+
83+
Debug.WriteLine("Arena Light Show Decorator Detached");
84+
}
85+
86+
protected override void Update(double deltaTime)
87+
{
88+
try
89+
{
90+
if (ledGroup == null) return;
91+
92+
Timing += deltaTime;
93+
94+
// Check if it's time for the next beat
95+
if (Timing >= nextBeatTime)
96+
{
97+
nextBeatTime += interval; // Schedule next beat
98+
99+
foreach (var led in leds)
100+
{
101+
int groupIndex = groupSize == 0 ? random.Next(leds.Count) : (int)(leds.IndexOf(led) % groupSize);
102+
int colorIndex = (groupIndex + (int)(Timing / interval)) % colors.Length;
103+
104+
targetColors[led] = colors[colorIndex];
105+
transitionStartTimes[led] = Timing;
106+
}
107+
}
108+
109+
foreach (var led in leds)
110+
{
111+
if (!ledPositions.ContainsKey(led)) continue;
112+
113+
double timeSinceTransitionStart = Timing - transitionStartTimes[led];
114+
float transitionProgress = fadeTime > 0 ? (float)Math.Min(timeSinceTransitionStart / fadeTime, 1.0) : 1.0f;
115+
116+
var color = fadeTime == 0 ? targetColors[led] : Lerp(currentColors[led], targetColors[led], transitionProgress);
117+
led.Color = color;
118+
119+
// Update the current color if the transition is complete
120+
if (transitionProgress >= 1.0)
121+
{
122+
currentColors[led] = targetColors[led];
123+
}
124+
}
125+
}
126+
catch (Exception ex)
127+
{
128+
#if DEBUG
129+
Debug.WriteLine($"Exception: {ex.Message}");
130+
#endif
131+
}
132+
}
133+
134+
private static Color Lerp(Color start, Color end, float amount)
135+
{
136+
float r = start.R + (end.R - start.R) * amount;
137+
float g = start.G + (end.G - start.G) * amount;
138+
float b = start.B + (end.B - start.B) * amount;
139+
140+
return new Color((byte)(r * 255), (byte)(g * 255), (byte)(b * 255));
141+
}
142+
}
143+
}

0 commit comments

Comments
 (0)