Skip to content

Commit 6589f69

Browse files
committed
Rainbow Spinner Color Area Controller
1 parent 73bd0d7 commit 6589f69

File tree

4 files changed

+102
-1
lines changed

4 files changed

+102
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module SpringCollab2020RainbowSpinnerColorAreaController
2+
3+
using ..Ahorn, Maple
4+
5+
@mapdef Entity "SpringCollab2020/RainbowSpinnerColorAreaController" RainbowSpinnerColorAreaController(x::Integer, y::Integer, width::Integer=Maple.defaultBlockWidth, height::Integer=Maple.defaultBlockHeight,
6+
colors::String="89E5AE,88E0E0,87A9DD,9887DB,D088E2", gradientSize::Number=280.0)
7+
8+
const placements = Ahorn.PlacementDict(
9+
"Rainbow Spinner Colour Area Controller (Spring Collab 2020)" => Ahorn.EntityPlacement(
10+
RainbowSpinnerColorAreaController,
11+
"rectangle"
12+
)
13+
)
14+
15+
Ahorn.minimumSize(entity::RainbowSpinnerColorAreaController) = 8, 8
16+
Ahorn.resizable(entity::RainbowSpinnerColorAreaController) = true, true
17+
18+
Ahorn.selection(entity::RainbowSpinnerColorAreaController) = Ahorn.getEntityRectangle(entity)
19+
20+
function Ahorn.render(ctx::Ahorn.Cairo.CairoContext, entity::RainbowSpinnerColorAreaController, room::Maple.Room)
21+
width = Int(get(entity.data, "width", 32))
22+
height = Int(get(entity.data, "height", 32))
23+
24+
Ahorn.drawRectangle(ctx, 0, 0, width, height, (0.4, 0.4, 1.0, 0.4), (0.4, 0.4, 1.0, 1.0))
25+
end
26+
27+
end

Ahorn/lang/en_gb.lang

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ placements.triggers.SpringCollab2020/MadelineSilhouetteTrigger.tooltips.enable=I
203203
placements.entities.SpringCollab2020/RainbowSpinnerColorController.tooltips.colors=The colours the rainbow spinners in the room will take, separated by commas. For example, if 3 colours A, B and C are specified, the colours will cycle in the following order: A > B > C > B > A.
204204
placements.entities.SpringCollab2020/RainbowSpinnerColorController.tooltips.gradientSize=The distance required to achieve a complete loop across all colours.
205205

206+
# Rainbow Spinner Color Area Controller
207+
placements.entities.SpringCollab2020/RainbowSpinnerColorAreaController.tooltips.colors=The colours the rainbow spinners in the area will take, separated by commas. For example, if 3 colours A, B and C are specified, the colours will cycle in the following order: A > B > C > B > A.
208+
placements.entities.SpringCollab2020/RainbowSpinnerColorAreaController.tooltips.gradientSize=The distance required to achieve a complete loop across all colours.
209+
206210
# Music Layer Fade Trigger
207211
placements.triggers.SpringCollab2020/MusicLayerFadeTrigger.tooltips.layers=Which layers the trigger should change.
208212
placements.triggers.SpringCollab2020/MusicLayerFadeTrigger.tooltips.fadeA=The first volume for the music layer.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using Celeste.Mod.Entities;
2+
using Microsoft.Xna.Framework;
3+
using Monocle;
4+
5+
namespace Celeste.Mod.SpringCollab2020.Entities {
6+
[CustomEntity("SpringCollab2020/RainbowSpinnerColorAreaController")]
7+
[Tracked]
8+
class RainbowSpinnerColorAreaController : Entity {
9+
private static bool rainbowSpinnerHueHooked = false;
10+
11+
// the parameters for this spinner controller.
12+
private Color[] colors;
13+
private float gradientSize;
14+
15+
public RainbowSpinnerColorAreaController(EntityData data, Vector2 offset) : base(data.Position + offset) {
16+
// convert the color list to Color objects
17+
string[] colorsAsStrings = data.Attr("colors", "89E5AE,88E0E0,87A9DD,9887DB,D088E2").Split(',');
18+
colors = new Color[colorsAsStrings.Length];
19+
for (int i = 0; i < colors.Length; i++) {
20+
colors[i] = Calc.HexToColor(colorsAsStrings[i]);
21+
}
22+
23+
gradientSize = data.Float("gradientSize", 280);
24+
25+
// make this controller collidable.
26+
Collider = new Hitbox(data.Width, data.Height);
27+
}
28+
29+
public override void Awake(Scene scene) {
30+
base.Awake(scene);
31+
32+
// enable the hook on rainbow spinner hue.
33+
if (!rainbowSpinnerHueHooked) {
34+
On.Celeste.CrystalStaticSpinner.GetHue += getRainbowSpinnerHue;
35+
rainbowSpinnerHueHooked = true;
36+
}
37+
}
38+
39+
public override void Removed(Scene scene) {
40+
base.Removed(scene);
41+
42+
// if this controller was the last in the scene, disable the hook on rainbow spinner hue.
43+
if (rainbowSpinnerHueHooked && scene.Tracker.CountEntities<RainbowSpinnerColorAreaController>() <= 1) {
44+
On.Celeste.CrystalStaticSpinner.GetHue -= getRainbowSpinnerHue;
45+
rainbowSpinnerHueHooked = false;
46+
}
47+
}
48+
49+
public override void SceneEnd(Scene scene) {
50+
base.SceneEnd(scene);
51+
52+
// leaving level; disable the hook on rainbow spinner hue.
53+
if (rainbowSpinnerHueHooked) {
54+
On.Celeste.CrystalStaticSpinner.GetHue -= getRainbowSpinnerHue;
55+
rainbowSpinnerHueHooked = false;
56+
};
57+
}
58+
59+
private static Color getRainbowSpinnerHue(On.Celeste.CrystalStaticSpinner.orig_GetHue orig, CrystalStaticSpinner self, Vector2 position) {
60+
RainbowSpinnerColorAreaController controller = self.CollideFirst<RainbowSpinnerColorAreaController>();
61+
if (controller != null) {
62+
// apply the color from the controller we are in.
63+
return RainbowSpinnerColorController.getModHue(controller.colors, controller.gradientSize, self.Scene, position);
64+
} else {
65+
// we are not in a controller; apply the vanilla color.
66+
return orig(self, position);
67+
}
68+
}
69+
}
70+
}

Entities/RainbowSpinnerColorController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private static Color getRainbowSpinnerHue(On.Celeste.CrystalStaticSpinner.orig_G
114114
}
115115
}
116116

117-
private static Color getModHue(Color[] colors, float gradientSize, Scene scene, Vector2 position) {
117+
internal static Color getModHue(Color[] colors, float gradientSize, Scene scene, Vector2 position) {
118118
float progress = Calc.YoYo((position.Length() + scene.TimeActive * 50f) % gradientSize / gradientSize);
119119
if (progress == 1) {
120120
return colors[colors.Length - 1];

0 commit comments

Comments
 (0)