Skip to content

Commit ea19846

Browse files
committed
Snow effect with custom colors
1 parent 3ef3c8d commit ea19846

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

Ahorn/effects/customSnow.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module SpringCollab2020CustomSnow
2+
3+
using ..Ahorn, Maple
4+
5+
@mapdef Effect "SpringCollab2020/CustomSnow" CustomSnow(only::String="*", exclude::String="", color::String="FFFFFF,FFFFFF")
6+
7+
placements = CustomSnow
8+
9+
function Ahorn.canFgBg(effect::CustomSnow)
10+
return true, true
11+
end
12+
13+
end

Ahorn/lang/en_gb.lang

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,6 @@ placements.triggers.SpringCollab2020/BadelineBounceDirectionTrigger.tooltips.bou
327327
# Wall Booster
328328
placements.entities.SpringCollab2020/NonCoreModeWallBooster.tooltips.left=Whether the entity attaches to the left wall or not.
329329
placements.entities.SpringCollab2020/NonCoreModeWallBooster.tooltips.notCoreMode=Determines whether the entity should ignore the current core mode and default to ice variant.
330+
331+
# Custom Snow
332+
placements.effects.SpringCollab2020/CustomSnow.tooltips.colors=Comma-separated list of all colors the particles can take from.

Effects/CustomSnow.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.Xna.Framework;
2+
using MonoMod.Utils;
3+
using System;
4+
using System.Reflection;
5+
6+
namespace Celeste.Mod.SpringCollab2020.Effects {
7+
public class CustomSnow : Snow {
8+
private static MethodInfo particleInit = typeof(Snow).GetNestedType("Particle", BindingFlags.NonPublic).GetMethod("Init");
9+
10+
public CustomSnow(Color[] colors, bool foreground) : base(foreground) {
11+
DynData<Snow> selfData = new DynData<Snow>(this);
12+
13+
// redo the same operations as the vanilla constructor, but with our custom set of colors.
14+
selfData["colors"] = colors;
15+
selfData["blendedColors"] = new Color[colors.Length];
16+
Array particles = selfData.Get<Array>("particles");
17+
int speedMin = foreground ? 120 : 40;
18+
int speedMax = foreground ? 300 : 100;
19+
for (int i = 0; i < particles.Length; i++) {
20+
// Particle is a private struct, so getting it gets a copy that we should set back afterwards.
21+
object particle = particles.GetValue(i);
22+
particleInit.Invoke(particle, new object[] { colors.Length, speedMin, speedMax });
23+
particles.SetValue(particle, i);
24+
}
25+
}
26+
}
27+
}

SpringCollab2020Module.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Celeste.Mod.SpringCollab2020.Entities;
33
using Celeste.Mod.SpringCollab2020.Triggers;
44
using Microsoft.Xna.Framework;
5+
using Monocle;
56
using System;
67

78
namespace Celeste.Mod.SpringCollab2020 {
@@ -94,6 +95,15 @@ private Backdrop onLoadBackdrop(MapData map, BinaryPacker.Element child, BinaryP
9495
if (child.Name.Equals("SpringCollab2020/HeatWaveNoColorGrade", StringComparison.OrdinalIgnoreCase)) {
9596
return new HeatWaveNoColorGrade();
9697
}
98+
if (child.Name.Equals("SpringCollab2020/CustomSnow", StringComparison.OrdinalIgnoreCase)) {
99+
string[] colorsAsStrings = child.Attr("colors").Split(',');
100+
Color[] colors = new Color[colorsAsStrings.Length];
101+
for (int i = 0; i < colors.Length; i++) {
102+
colors[i] = Calc.HexToColor(colorsAsStrings[i]);
103+
}
104+
105+
return new CustomSnow(colors, child.AttrBool("foreground"));
106+
}
97107
return null;
98108
}
99109

0 commit comments

Comments
 (0)