|
| 1 | +namespace LCDPossible.Core.Configuration; |
| 2 | + |
| 3 | +/// <summary> |
| 4 | +/// Manages page effects - loads built-in effects and provides access to them. |
| 5 | +/// </summary> |
| 6 | +public class PageEffectManager |
| 7 | +{ |
| 8 | + private static readonly Lazy<PageEffectManager> _instance = new(() => new PageEffectManager()); |
| 9 | + private readonly Dictionary<string, PageEffect> _effects = new(StringComparer.OrdinalIgnoreCase); |
| 10 | + |
| 11 | + /// <summary> |
| 12 | + /// Gets the singleton instance. |
| 13 | + /// </summary> |
| 14 | + public static PageEffectManager Instance => _instance.Value; |
| 15 | + |
| 16 | + private PageEffectManager() |
| 17 | + { |
| 18 | + RegisterBuiltInEffects(); |
| 19 | + } |
| 20 | + |
| 21 | + /// <summary> |
| 22 | + /// Gets all registered effects. |
| 23 | + /// </summary> |
| 24 | + public IReadOnlyDictionary<string, PageEffect> Effects => _effects; |
| 25 | + |
| 26 | + /// <summary> |
| 27 | + /// Gets an effect by ID, or null if not found. |
| 28 | + /// Use "random" to get a random effect. |
| 29 | + /// </summary> |
| 30 | + public PageEffect? GetEffect(string? id) |
| 31 | + { |
| 32 | + if (string.IsNullOrEmpty(id) || id == "none") |
| 33 | + return null; |
| 34 | + |
| 35 | + if (id.Equals("random", StringComparison.OrdinalIgnoreCase)) |
| 36 | + return GetRandomEffect(); |
| 37 | + |
| 38 | + return _effects.TryGetValue(id, out var effect) ? effect : null; |
| 39 | + } |
| 40 | + |
| 41 | + /// <summary> |
| 42 | + /// Gets a random effect from all registered effects. |
| 43 | + /// </summary> |
| 44 | + public PageEffect GetRandomEffect() |
| 45 | + { |
| 46 | + var effects = _effects.Values.ToList(); |
| 47 | + return effects[Random.Shared.Next(effects.Count)]; |
| 48 | + } |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// Gets a random effect from a specific category. |
| 52 | + /// </summary> |
| 53 | + public PageEffect? GetRandomEffectFromCategory(PageEffectCategory category) |
| 54 | + { |
| 55 | + var effects = _effects.Values.Where(e => e.Category == category).ToList(); |
| 56 | + if (effects.Count == 0) return null; |
| 57 | + return effects[Random.Shared.Next(effects.Count)]; |
| 58 | + } |
| 59 | + |
| 60 | + /// <summary> |
| 61 | + /// Gets all effects in a category. |
| 62 | + /// </summary> |
| 63 | + public IEnumerable<PageEffect> GetEffectsByCategory(PageEffectCategory category) |
| 64 | + { |
| 65 | + return _effects.Values.Where(e => e.Category == category); |
| 66 | + } |
| 67 | + |
| 68 | + /// <summary> |
| 69 | + /// Registers a custom effect. |
| 70 | + /// </summary> |
| 71 | + public void RegisterEffect(PageEffect effect) |
| 72 | + { |
| 73 | + _effects[effect.Id] = effect; |
| 74 | + } |
| 75 | + |
| 76 | + private void RegisterBuiltInEffects() |
| 77 | + { |
| 78 | + // Value Change Effects |
| 79 | + Register("glow-on-change", "Glow on Change", |
| 80 | + "Values that changed since last frame emit a brief glow/pulse", |
| 81 | + PageEffectCategory.ValueChange); |
| 82 | + |
| 83 | + Register("flip-digits", "Flip Digits", |
| 84 | + "Numbers flip like an airport departure board when changing", |
| 85 | + PageEffectCategory.ValueChange); |
| 86 | + |
| 87 | + Register("slide-numbers", "Slide Numbers", |
| 88 | + "Digits slide up/down like a slot machine when values change", |
| 89 | + PageEffectCategory.ValueChange); |
| 90 | + |
| 91 | + Register("typewriter", "Typewriter", |
| 92 | + "Text types out character by character on change", |
| 93 | + PageEffectCategory.ValueChange); |
| 94 | + |
| 95 | + Register("particle-burst", "Particle Burst", |
| 96 | + "Particles burst from widgets when values change significantly", |
| 97 | + PageEffectCategory.ValueChange); |
| 98 | + |
| 99 | + // Container Animation Effects |
| 100 | + Register("gentle-float", "Gentle Float", |
| 101 | + "Containers float up/down subtly (breathing effect)", |
| 102 | + PageEffectCategory.ContainerAnimation); |
| 103 | + |
| 104 | + Register("tilt-3d", "3D Tilt", |
| 105 | + "Containers have slight 3D tilt/perspective that shifts", |
| 106 | + PageEffectCategory.ContainerAnimation); |
| 107 | + |
| 108 | + Register("shake-on-warning", "Shake on Warning", |
| 109 | + "Containers shake when values hit warning/critical thresholds", |
| 110 | + PageEffectCategory.ContainerAnimation); |
| 111 | + |
| 112 | + Register("bounce-in", "Bounce In", |
| 113 | + "Widgets bounce in when panel first loads", |
| 114 | + PageEffectCategory.ContainerAnimation); |
| 115 | + |
| 116 | + Register("wave", "Wave", |
| 117 | + "Widgets wave in a sine pattern across the grid", |
| 118 | + PageEffectCategory.ContainerAnimation); |
| 119 | + |
| 120 | + // Background/Overlay Effects |
| 121 | + Register("scanlines", "Scanlines", |
| 122 | + "CRT/retro scanline overlay", |
| 123 | + PageEffectCategory.BackgroundOverlay); |
| 124 | + |
| 125 | + Register("matrix-rain", "Matrix Rain", |
| 126 | + "Digital rain falling behind widgets", |
| 127 | + PageEffectCategory.BackgroundOverlay); |
| 128 | + |
| 129 | + Register("particle-field", "Particle Field", |
| 130 | + "Floating particles in the background", |
| 131 | + PageEffectCategory.BackgroundOverlay); |
| 132 | + |
| 133 | + Register("grid-pulse", "Grid Pulse", |
| 134 | + "Grid lines pulse outward from center", |
| 135 | + PageEffectCategory.BackgroundOverlay); |
| 136 | + |
| 137 | + Register("hologram", "Hologram", |
| 138 | + "Holographic shimmer/interference pattern", |
| 139 | + PageEffectCategory.BackgroundOverlay); |
| 140 | + |
| 141 | + // Character/Mascot Effects |
| 142 | + Register("vanna-white", "Vanna White", |
| 143 | + "Character walks up to tiles and gestures at them", |
| 144 | + PageEffectCategory.CharacterMascot); |
| 145 | + |
| 146 | + Register("pixel-mascot", "Pixel Mascot", |
| 147 | + "Retro pixel character reacts to values", |
| 148 | + PageEffectCategory.CharacterMascot); |
| 149 | + |
| 150 | + Register("robot-assistant", "Robot Assistant", |
| 151 | + "Cute robot points at important metrics", |
| 152 | + PageEffectCategory.CharacterMascot); |
| 153 | + |
| 154 | + // Alert/Status Effects |
| 155 | + Register("warning-flash", "Warning Flash", |
| 156 | + "Panel border flashes when any value is critical", |
| 157 | + PageEffectCategory.AlertStatus); |
| 158 | + |
| 159 | + Register("spotlight", "Spotlight", |
| 160 | + "Roaming spotlight illuminates different widgets", |
| 161 | + PageEffectCategory.AlertStatus); |
| 162 | + |
| 163 | + Register("neon-trails", "Neon Trails", |
| 164 | + "Neon light trails follow value changes", |
| 165 | + PageEffectCategory.AlertStatus); |
| 166 | + |
| 167 | + Register("glitch", "Glitch", |
| 168 | + "Random digital glitch effects on high values", |
| 169 | + PageEffectCategory.AlertStatus); |
| 170 | + |
| 171 | + // Debug/Test Effects |
| 172 | + Register("red-man", "Red Man", |
| 173 | + "Debug overlay - full panel red at 55% opacity", |
| 174 | + PageEffectCategory.Other); |
| 175 | + } |
| 176 | + |
| 177 | + private void Register(string id, string displayName, string description, PageEffectCategory category) |
| 178 | + { |
| 179 | + _effects[id] = new PageEffect |
| 180 | + { |
| 181 | + Id = id, |
| 182 | + DisplayName = displayName, |
| 183 | + Description = description, |
| 184 | + Category = category, |
| 185 | + RequiresLiveMode = true |
| 186 | + }; |
| 187 | + } |
| 188 | +} |
0 commit comments