diff --git a/Code/CustomWindSnow.cs b/Code/CustomWindSnow.cs index 6adfb36..6239588 100644 --- a/Code/CustomWindSnow.cs +++ b/Code/CustomWindSnow.cs @@ -1,34 +1,37 @@ using Celeste; +using Celeste.Mod; +using Celeste.Mod.Backdrops; using Microsoft.Xna.Framework; using Monocle; using System; -using System.Collections; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace vitmod { + [CustomBackdrop("CrystallineHelper/CustomWindSnow")] public class CustomWindSnow : Backdrop { - public CustomWindSnow(string colors, string alphas, int amount, float speedX, float speedY, bool ignoreWind) : base() + public CustomWindSnow(BinaryPacker.Element data) : base() { - this.colors = new List(); - string[] colorStrings = colors.Split(','); - foreach(string color in colorStrings) + colors = new List(); + string[] colorStrings = data.Attr("colors", "ffffff").Split(','); + foreach (string color in colorStrings) { - this.colors.Add(Calc.HexToColor(color)); + colors.Add(Calc.HexToColor(color)); } - this.alphas = new List(); - string[] alphaStrings = alphas.Split(','); - foreach(string alpha in alphaStrings) + alphas = new List(); + string[] alphaStrings = data.Attr("alphas", "1").Split(','); + foreach (string alpha in alphaStrings) { - this.alphas.Add(float.Parse(alpha)); + alphas.Add(float.Parse(alpha)); } - this.amount = amount; - addSpeed = new Vector2(speedX * 100f, speedY * 100f); - this.ignoreWind = ignoreWind; + amount = data.AttrInt("amount", 240); + addSpeed = new Vector2(data.AttrFloat("speedX", 0f) * 100f, data.AttrFloat("speedY", 0f) * 100f); + ignoreWind = data.AttrBool("ignoreWind", false); + windMultiplier = data.AttrFloat("windMultiplier", 1f); + amplifyVerticalWind = data.AttrBool("amplifyVerticalWind", true); + scaleMultiplier = data.AttrFloat("scale", 1f); + deformationStrength = data.AttrFloat("deformationStrength", 1f); Color = Color.White; CameraOffset = Vector2.Zero; @@ -41,7 +44,7 @@ public CustomWindSnow(string colors, string alphas, int amount, float speedX, fl for (int i = 0; i < positions.Length; i++) { positions[i] = Calc.Random.Range(new Vector2(0f, 0f), new Vector2(640f, 360f)); - particleColors[i] = rng.Next(0, this.colors.Count); + particleColors[i] = rng.Next(0, colors.Count); } sines = new SineWave[amount / 15]; for (int i = 0; i < sines.Length; i++) @@ -55,17 +58,19 @@ public override void Update(Scene scene) { base.Update(scene); Level level = scene as Level; - visibleFade = Calc.Approach(visibleFade, IsVisible(level) ? 1f : 0f, Engine.DeltaTime * 2f); - foreach(SineWave sine in sines) + visibleFade = Calc.Approach(visibleFade, IsVisible(level) ? 1f : 0f, Engine.DeltaTime * 2f); + foreach (SineWave sine in sines) { sine.Update(); } - windVector = ignoreWind ? Vector2.Zero : level.Wind; + windVector = ignoreWind ? Vector2.Zero : level.Wind * windMultiplier; windVector += addSpeed; scale.X = Math.Max(1f, Math.Abs(windVector.Length()) / 100f); float vertical = (float)Math.Abs(Math.Sin(Math.Atan2(windVector.Y, windVector.X))); - scale.X /= Math.Max(1f - vertical, 0.4f); + scale.X /= Math.Max(1f - vertical, 0.4f); scale.Y = 1f / Math.Max(1f, scale.X * 0.25f); + scale = Vector2.Lerp(Vector2.One, scale, deformationStrength) * scaleMultiplier; + rotation %= (float)Math.PI * 2; float target_rot = (float)Math.Atan2(windVector.Y, windVector.X); if (Math.Abs(rotation - target_rot) == Math.PI) @@ -84,7 +89,7 @@ public override void Update(Scene scene) } } rotation = Calc.Approach(rotation, target_rot, Engine.DeltaTime * 8f); - if (windVector.X == 0f) + if (amplifyVerticalWind && windVector.X == 0f) { windVector.Y *= 3f; } @@ -110,7 +115,7 @@ public override void Render(Scene scene) limit = 0f; } limit = 0.6f + (1 - limit) * 0.4f; - foreach(Vector2 init in positions) + foreach (Vector2 init in positions) { Color color = colors[particleColors[index]]; if (alphas.Count == colors.Count) @@ -173,5 +178,13 @@ public override void Render(Scene scene) private float rotation; private float visibleFade; + + private float windMultiplier; + + private bool amplifyVerticalWind; + + private float scaleMultiplier; + + private float deformationStrength; } } diff --git a/Code/VitModule.cs b/Code/VitModule.cs index 5130247..11e8d52 100644 --- a/Code/VitModule.cs +++ b/Code/VitModule.cs @@ -1,11 +1,9 @@ using Celeste; using Celeste.Mod; -using MonoMod.Utils; using Microsoft.Xna.Framework; using Monocle; using System; using System.Reflection; -using System.Collections; using System.Collections.Generic; using MonoMod.RuntimeDetour; using MonoMod.Cil; @@ -317,9 +315,6 @@ public override void Load() On.Celeste.Player.CallDashEvents += Player_CallDashEvents; On.Celeste.PlayerHair.GetHairColor += PlayerHair_GetHairColor; - //effects - Everest.Events.Level.OnLoadBackdrop += Level_OnLoadBackdrop; - //misc On.Celeste.Level.LoadLevel += Level_LoadLevel; On.Celeste.Level.Reload += Level_Reload; @@ -794,25 +789,6 @@ private Color PlayerHair_GetHairColor(On.Celeste.PlayerHair.orig_GetHairColor or return orig(self, index); } - private Backdrop Level_OnLoadBackdrop(MapData map, BinaryPacker.Element child, BinaryPacker.Element above) - { - Backdrop result; - switch (child.Name) - { - case "CrystallineHelper/CustomWindSnow": - result = new CustomWindSnow( - child.Attr("colors", "ffffff"), - child.Attr("alphas", "1"), - child.AttrInt("amount", 240), - child.AttrFloat("speedX", 0f), - child.AttrFloat("speedY", 0f), - child.AttrBool("ignoreWind", false) - ); - return result; - } - return null; - } - public static bool GetClassName(string name, Entity entity) { return entity.GetType().FullName == name || entity.GetType().Name == name; @@ -862,7 +838,6 @@ public override void Unload() On.Celeste.Player.Die -= Player_Die; On.Celeste.Player.CallDashEvents -= Player_CallDashEvents; On.Celeste.PlayerHair.GetHairColor -= PlayerHair_GetHairColor; - Everest.Events.Level.OnLoadBackdrop -= Level_OnLoadBackdrop; On.Celeste.Level.LoadLevel -= Level_LoadLevel; On.Celeste.Level.Reload -= Level_Reload; } diff --git a/Loenn/effects/custom_wind_snow.lua b/Loenn/effects/custom_wind_snow.lua index 0745db4..0e0cf19 100644 --- a/Loenn/effects/custom_wind_snow.lua +++ b/Loenn/effects/custom_wind_snow.lua @@ -8,7 +8,11 @@ customWindSnow.defaultData = { amount = 240, speedX = 0.0, speedY = 0.0, - ignoreWind = false + ignoreWind = false, + windMultiplier = 1.0, + amplifyVerticalWind = true, + scale = 1.0, + deformationStrength = 1.0 } return customWindSnow diff --git a/Loenn/lang/en_gb.lang b/Loenn/lang/en_gb.lang index af3df4d..820d47c 100644 --- a/Loenn/lang/en_gb.lang +++ b/Loenn/lang/en_gb.lang @@ -108,6 +108,10 @@ triggers.vitellary/flaginsidetrigger.placements.name.flag_inside=Flag Inside Tri # Effects style.effects.CrystallineHelper/CustomWindSnow.name=Custom Wind Snow +style.effects.CrystallineHelper/CustomWindSnow.description.windMultiplier=How much wind speed affects the snow. +style.effects.CrystallineHelper/CustomWindSnow.description.amplifyVerticalWind=If set, the effect of purely vertical wind is multiplied by 3, similar to vanilla Wind Snow. +style.effects.CrystallineHelper/CustomWindSnow.description.scale=The scale multiplier for particles. +style.effects.CrystallineHelper/CustomWindSnow.description.deformationStrength=How much particles are squashed and stretched by wind speed. # - Tooltips -