|
| 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 | +} |
0 commit comments