Skip to content

Commit d58f5e4

Browse files
committed
Copy-paste Speed-Based Music Param Trigger and Blackhole w/ Custom Colors from max480's Helping Hand
... I am max480 and gave permission for this.
1 parent 325bd22 commit d58f5e4

File tree

7 files changed

+125
-7
lines changed

7 files changed

+125
-7
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module SpringCollab2020BlackholeCustomColors
2+
3+
using ..Ahorn, Maple
4+
5+
@mapdef Effect "SpringCollab2020/BlackholeCustomColors" BlackholeCustomColors(only::String="*", exclude::String="", colorsMild::String="6e3199,851f91,3026b0", colorsWild::String="ca4ca7,b14cca,ca4ca7",
6+
bgColorInner::String="000000", bgColorOuterMild::String="512a8b", bgColorOuterWild::String="bd2192", alpha::Number=1.0)
7+
8+
placements = BlackholeCustomColors
9+
10+
function Ahorn.canFgBg(effect::BlackholeCustomColors)
11+
return true, true
12+
end
13+
14+
end

Ahorn/lang/en_gb.lang

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,11 @@ placements.triggers.SpringCollab2020/ColorGradeFadeTrigger.tooltips.direction=Th
313313

314314
# Speed-Based Music Param Trigger
315315
placements.triggers.SpringCollab2020/SpeedBasedMusicParamTrigger.tooltips.paramName=The name of the music parameter to change.
316-
placements.triggers.SpringCollab2020/SpeedBasedMusicParamTrigger.tooltips.minSpeed=The minimum value the music parameter can take.
317-
placements.triggers.SpringCollab2020/SpeedBasedMusicParamTrigger.tooltips.maxSpeed=The maximum value the music parameter can take.
318-
placements.triggers.SpringCollab2020/SpeedBasedMusicParamTrigger.tooltips.activate=If ticked, the trigger will start adjusting the music parameter to match the player's speed.\nIf unticked, the trigger will stop adjusting that music parameter, and set it to minSpeed.
316+
placements.triggers.SpringCollab2020/SpeedBasedMusicParamTrigger.tooltips.minSpeed=The minimum speed at which the music parameter will change.
317+
placements.triggers.SpringCollab2020/SpeedBasedMusicParamTrigger.tooltips.maxSpeed=The maximum speed at which the music parameter will change.
318+
placements.triggers.SpringCollab2020/SpeedBasedMusicParamTrigger.tooltips.minParamValue=The value the music parameter will take when the player speed is "Min Speed" or below.
319+
placements.triggers.SpringCollab2020/SpeedBasedMusicParamTrigger.tooltips.maxParamValue=The value the music parameter will take when the player speed is "Max Speed" or above.
320+
placements.triggers.SpringCollab2020/SpeedBasedMusicParamTrigger.tooltips.activate=If ticked, the trigger will start adjusting the music parameter to match the player's speed.\nIf unticked, the trigger will stop adjusting that music parameter, and set it to the "Min Param Value".
319321

320322
# Foreground Reflection Tentacles
321323
placements.entities.SpringCollab2020/ForegroundReflectionTentacles.tooltips.slide_until=Changes how far tentacles fall back when Madeline comes into fear distance.
@@ -336,3 +338,10 @@ placements.effects.SpringCollab2020/CustomSnow.tooltips.colors=Comma-separated l
336338

337339
# Change Theme Trigger
338340
placements.triggers.SpringCollab2020/ChangeThemeTrigger.tooltips.enable=Whether the theme is enabled when entering this zone.
341+
342+
# Blackhole with Custom Colors
343+
placements.effects.SpringCollab2020/BlackholeCustomColors.tooltips.colorsMild=Colors of the shapes going towards the center of the screen when the blackhole strength is Mild.\nThere should be as many colors defined in Colors Mild and in Colors Wild for both to work.
344+
placements.effects.SpringCollab2020/BlackholeCustomColors.tooltips.colorsWild=Colors of the shapes going towards the center of the screen when the blackhole strength is Wild.\nThere should be as many colors defined in Colors Mild and in Colors Wild for both to work.
345+
placements.effects.SpringCollab2020/BlackholeCustomColors.tooltips.bgColorInner=The color used for the background at the center of the screen.
346+
placements.effects.SpringCollab2020/BlackholeCustomColors.tooltips.bgColorOuterMild=The color used for the background at the edges of the screen, when the blackhole strength is Mild.
347+
placements.effects.SpringCollab2020/BlackholeCustomColors.tooltips.bgColorOuterWild=The color used for the background at the edges of the screen, when the blackhole strength is Wild.

Ahorn/triggers/speedBasedMusicParamTrigger.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module SpringCollab2020SpeedBasedMusicParamTrigger
33
using ..Ahorn, Maple
44

55
@mapdef Trigger "SpringCollab2020/SpeedBasedMusicParamTrigger" SpeedBasedMusicParamTrigger(x::Integer, y::Integer, width::Integer=Maple.defaultTriggerWidth, height::Integer=Maple.defaultTriggerHeight,
6-
paramName::String="fade", minSpeed::Number=0.0, maxSpeed::Number=1.0, activate::Bool=true)
6+
paramName::String="fade", minSpeed::Number=0.0, maxSpeed::Number=90.0, minParamValue::Number=0.0, maxParamValue::Number=1.0, activate::Bool=true)
77

88
const placements = Ahorn.PlacementDict(
99
"Speed-Based Music Param (Spring Collab 2020)" => Ahorn.EntityPlacement(
@@ -12,4 +12,6 @@ const placements = Ahorn.PlacementDict(
1212
)
1313
)
1414

15+
Ahorn.editingOrder(entity::SpeedBasedMusicParamTrigger) = String["x", "y", "width", "height", "minSpeed", "maxSpeed", "minParamValue", "maxParamValue"]
16+
1517
end

Effects/BlackholeCustomColors.cs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using Microsoft.Xna.Framework;
2+
using Mono.Cecil.Cil;
3+
using Monocle;
4+
using MonoMod.Cil;
5+
using MonoMod.Utils;
6+
using System;
7+
8+
namespace Celeste.Mod.SpringCollab2020.Effects {
9+
/**
10+
* Port of the blackhole with custom colors from max480's Helping Hand:
11+
* https://github.com/max4805/MaxHelpingHand/blob/master/Effects/BlackholeCustomColors.cs
12+
*/
13+
static class BlackholeCustomColors {
14+
private static Color[] colorsMild;
15+
16+
public static void Load() {
17+
IL.Celeste.BlackholeBG.ctor += onBlackholeConstructor;
18+
}
19+
20+
public static void Unload() {
21+
IL.Celeste.BlackholeBG.ctor -= onBlackholeConstructor;
22+
}
23+
24+
private static void onBlackholeConstructor(ILContext il) {
25+
ILCursor cursor = new ILCursor(il);
26+
27+
// we want to insert code at the beginning of the constructor, but after the variable initialization code,
28+
// because colorsMild is used right in the constructor.
29+
// the "first line" of the constructor is: bgTexture = GFX.Game["objects/temple/portal/portal"];
30+
if (cursor.TryGotoNext(MoveType.Before,
31+
instr => instr.MatchLdarg(0),
32+
instr => instr.MatchLdsfld(typeof(GFX), "Game"))) {
33+
34+
Logger.Log("SpringCollab2020/BlackholeCustomColors", $"Replacing colorsMild at {cursor.Index} in IL code for BlackholeBG constructor");
35+
cursor.Emit(OpCodes.Ldarg_0);
36+
cursor.EmitDelegate<Action<BlackholeBG>>(self => {
37+
if (colorsMild != null) {
38+
new DynData<BlackholeBG>(self)["colorsMild"] = colorsMild;
39+
colorsMild = null;
40+
}
41+
});
42+
}
43+
}
44+
45+
public static BlackholeBG CreateBlackholeWithCustomColors(BinaryPacker.Element effectData) {
46+
// set up colorsMild for the hook above. we can't use DynData to pass this over, since the object does not exist yet!
47+
colorsMild = parseColors(effectData.Attr("colorsMild", "6e3199,851f91,3026b0"));
48+
for (int i = 0; i < colorsMild.Length; i++) {
49+
colorsMild[i] *= 0.8f;
50+
}
51+
52+
// build the blackhole: the hook will take care of setting colorsMild.
53+
BlackholeBG blackhole = new BlackholeBG();
54+
55+
// ... now we've got to set everything else.
56+
DynData<BlackholeBG> blackholeData = new DynData<BlackholeBG>(blackhole);
57+
blackholeData["colorsWild"] = parseColors(effectData.Attr("colorsWild", "ca4ca7,b14cca,ca4ca7"));
58+
blackholeData["bgColorInner"] = Calc.HexToColor(effectData.Attr("bgColorInner", "000000"));
59+
blackholeData["bgColorOuterMild"] = Calc.HexToColor(effectData.Attr("bgColorOuterMild", "512a8b"));
60+
blackholeData["bgColorOuterWild"] = Calc.HexToColor(effectData.Attr("bgColorOuterWild", "bd2192"));
61+
blackhole.Alpha = effectData.AttrFloat("alpha", 1f);
62+
63+
return blackhole;
64+
}
65+
66+
private static Color[] parseColors(string input) {
67+
string[] colorsAsStrings = input.Split(',');
68+
Color[] colors = new Color[colorsAsStrings.Length];
69+
for (int i = 0; i < colors.Length; i++) {
70+
colors[i] = Calc.HexToColor(colorsAsStrings[i]);
71+
}
72+
return colors;
73+
}
74+
}
75+
}

SpringCollab2020Module.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ private Backdrop onLoadBackdrop(MapData map, BinaryPacker.Element child, BinaryP
119119

120120
return new CustomSnow(colors, child.AttrBool("foreground"));
121121
}
122+
if (child.Name.Equals("SpringCollab2020/BlackholeCustomColors", StringComparison.OrdinalIgnoreCase)) {
123+
return BlackholeCustomColors.CreateBlackholeWithCustomColors(child);
124+
}
122125
return null;
123126
}
124127

SpringCollab2020Session.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public class MultiRoomStrawberrySeedInfo {
2323
public class SpeedBasedMusicParamInfo {
2424
public float MinimumSpeed { get; set; }
2525
public float MaximumSpeed { get; set; }
26+
public float MinimumParamValue { get; set; }
27+
public float MaximumParamValue { get; set; }
2628
}
2729

2830
public Dictionary<string, SpeedBasedMusicParamInfo> ActiveSpeedBasedMusicParams = new Dictionary<string, SpeedBasedMusicParamInfo>();

Triggers/SpeedBasedMusicParamTrigger.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
using Celeste.Mod.Entities;
2+
using Monocle;
23
using Microsoft.Xna.Framework;
34
using System.Collections.Generic;
45

56
namespace Celeste.Mod.SpringCollab2020.Triggers {
7+
/**
8+
* Port of the speed-based music param trigger from max480's Helping Hand:
9+
* https://github.com/max4805/MaxHelpingHand/blob/master/Triggers/SpeedBasedMusicParamTrigger.cs
10+
*/
611
[CustomEntity("SpringCollab2020/SpeedBasedMusicParamTrigger")]
712
class SpeedBasedMusicParamTrigger : Trigger {
813
public static void Load() {
@@ -24,7 +29,9 @@ private static void onPlayerUpdate(On.Celeste.Player.orig_Update orig, Player se
2429
foreach (KeyValuePair<string, SpringCollab2020Session.SpeedBasedMusicParamInfo> musicParam
2530
in SpringCollab2020Module.Instance.Session.ActiveSpeedBasedMusicParams) {
2631

27-
audio.Music.Param(musicParam.Key, MathHelper.Clamp(playerSpeed, musicParam.Value.MinimumSpeed, musicParam.Value.MaximumSpeed));
32+
audio.Music.Param(musicParam.Key, Calc.ClampedMap(playerSpeed,
33+
musicParam.Value.MinimumSpeed, musicParam.Value.MaximumSpeed,
34+
musicParam.Value.MinimumParamValue, musicParam.Value.MaximumParamValue));
2835
}
2936

3037
audio.Apply();
@@ -34,12 +41,16 @@ private static void onPlayerUpdate(On.Celeste.Player.orig_Update orig, Player se
3441
private string paramName;
3542
private float minSpeed;
3643
private float maxSpeed;
44+
private float minParamValue;
45+
private float maxParamValue;
3746
private bool activate;
3847

3948
public SpeedBasedMusicParamTrigger(EntityData data, Vector2 offset) : base(data, offset) {
4049
paramName = data.Attr("paramName");
4150
minSpeed = data.Float("minSpeed");
4251
maxSpeed = data.Float("maxSpeed");
52+
minParamValue = data.Float("minParamValue");
53+
maxParamValue = data.Float("maxParamValue");
4354
activate = data.Bool("activate");
4455
}
4556

@@ -50,14 +61,16 @@ public override void OnEnter(Player player) {
5061
// register the speed-based music param as active to keep it updated.
5162
SpringCollab2020Module.Instance.Session.ActiveSpeedBasedMusicParams[paramName] = new SpringCollab2020Session.SpeedBasedMusicParamInfo() {
5263
MinimumSpeed = minSpeed,
53-
MaximumSpeed = maxSpeed
64+
MaximumSpeed = maxSpeed,
65+
MinimumParamValue = minParamValue,
66+
MaximumParamValue = maxParamValue
5467
};
5568
} else {
5669
// unregister the param, and set the music param to the minimum value.
5770
SpringCollab2020Module.Instance.Session.ActiveSpeedBasedMusicParams.Remove(paramName);
5871

5972
AudioState audio = SceneAs<Level>().Session.Audio;
60-
audio.Music.Param(paramName, minSpeed);
73+
audio.Music.Param(paramName, minParamValue);
6174
audio.Apply();
6275
}
6376
}

0 commit comments

Comments
 (0)