diff --git a/OpenRA.Mods.Common/Scripting/Global/EffectGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/EffectGlobal.cs index e4669aade6..b25cea7f5d 100644 --- a/OpenRA.Mods.Common/Scripting/Global/EffectGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/EffectGlobal.cs @@ -9,6 +9,7 @@ #endregion using System.Collections.Generic; +using Eluant; using OpenRA.Mods.Common.Traits; using OpenRA.Scripting; @@ -18,11 +19,13 @@ namespace OpenRA.Mods.Common.Scripting public class EffectGlobal : ScriptGlobal { readonly IEnumerable fpes; + readonly GlobalLightingPaletteEffect lighting; public EffectGlobal(ScriptContext context) : base(context) { fpes = context.World.WorldActor.TraitsImplementing(); + lighting = context.World.WorldActor.TraitOrDefault(); } [Desc("Controls the `FlashPaletteEffect` trait.")] @@ -32,5 +35,17 @@ namespace OpenRA.Mods.Common.Scripting if (fpe.Info.Type == type) fpe.Enable(ticks); } + + [Desc("Dynamically adjusts the `GlobalLightingPaletteEffect` trait.")] + public void ChangeLighting(double red, double green, double blue, double ambient) + { + if (lighting == null) + throw new LuaException("GlobalLightingPaletteEffect needs to be added to the World actor first."); + + lighting.Red = (float)red; + lighting.Green = (float)green; + lighting.Blue = (float)blue; + lighting.Ambient = (float)ambient; + } } } diff --git a/OpenRA.Mods.Common/Traits/PaletteEffects/GlobalLightingPaletteEffect.cs b/OpenRA.Mods.Common/Traits/PaletteEffects/GlobalLightingPaletteEffect.cs index e59d1e106a..f48b1bd729 100644 --- a/OpenRA.Mods.Common/Traits/PaletteEffects/GlobalLightingPaletteEffect.cs +++ b/OpenRA.Mods.Common/Traits/PaletteEffects/GlobalLightingPaletteEffect.cs @@ -36,9 +36,19 @@ namespace OpenRA.Mods.Common.Traits { readonly GlobalLightingPaletteEffectInfo info; + public float Red; + public float Green; + public float Blue; + public float Ambient; + public GlobalLightingPaletteEffect(GlobalLightingPaletteEffectInfo info) { this.info = info; + + Red = info.Red; + Green = info.Green; + Blue = info.Blue; + Ambient = info.Ambient; } public void AdjustPalette(IReadOnlyDictionary palettes) @@ -56,9 +66,9 @@ namespace OpenRA.Mods.Common.Traits for (var x = 0; x < Palette.Size; x++) { var from = palette.GetColor(x); - var red = (int)(from.R * info.Ambient * info.Red).Clamp(0, 255); - var green = (int)(from.G * info.Ambient * info.Green).Clamp(0, 255); - var blue = (int)(from.B * info.Ambient * info.Blue).Clamp(0, 255); + var red = (int)(from.R * Ambient * Red).Clamp(0, 255); + var green = (int)(from.G * Ambient * Green).Clamp(0, 255); + var blue = (int)(from.B * Ambient * Blue).Clamp(0, 255); palette.SetColor(x, Color.FromArgb(from.A, red, green, blue)); } }