Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 36 additions & 23 deletions Code/CustomWindSnow.cs
Original file line number Diff line number Diff line change
@@ -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<Color>();
string[] colorStrings = colors.Split(',');
foreach(string color in colorStrings)
colors = new List<Color>();
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<float>();
string[] alphaStrings = alphas.Split(',');
foreach(string alpha in alphaStrings)
alphas = new List<float>();
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;
Expand All @@ -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++)
Expand All @@ -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)
Expand All @@ -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;
}
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}
}
25 changes: 0 additions & 25 deletions Code/VitModule.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 5 additions & 1 deletion Loenn/effects/custom_wind_snow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions Loenn/lang/en_gb.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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 -

Expand Down