|
| 1 | +using Microsoft.Xna.Framework; |
| 2 | +using Microsoft.Xna.Framework.Graphics; |
| 3 | +using Monocle; |
| 4 | +using MonoMod.Utils; |
| 5 | +using System; |
| 6 | +using System.Collections.Generic; |
| 7 | +using System.Linq; |
| 8 | +using System.Text; |
| 9 | +using System.Threading.Tasks; |
| 10 | + |
| 11 | +namespace Celeste.Mod.SpringCollab2020.Entities { |
| 12 | + /// <summary> |
| 13 | + /// This class adds a custom attribute to vanilla strawberries. This is not a new entity. |
| 14 | + /// </summary> |
| 15 | + class StrawberryIgnoringLighting { |
| 16 | + private static MTexture strawberryCutoutTexture; |
| 17 | + |
| 18 | + public static void Load() { |
| 19 | + On.Celeste.Strawberry.ctor += onStrawberryConstructor; |
| 20 | + On.Celeste.LightingRenderer.BeforeRender += onLightingBeforeRender; |
| 21 | + } |
| 22 | + |
| 23 | + public static void LoadContent() { |
| 24 | + strawberryCutoutTexture = GFX.Game["collectables/SpringCollab2020/strawberry/cutout"]; |
| 25 | + } |
| 26 | + |
| 27 | + public static void Unload() { |
| 28 | + On.Celeste.Strawberry.ctor -= onStrawberryConstructor; |
| 29 | + On.Celeste.LightingRenderer.BeforeRender -= onLightingBeforeRender; |
| 30 | + } |
| 31 | + |
| 32 | + private static void onStrawberryConstructor(On.Celeste.Strawberry.orig_ctor orig, Strawberry self, EntityData data, Vector2 offset, EntityID gid) { |
| 33 | + orig(self, data, offset, gid); |
| 34 | + |
| 35 | + // save the value for SpringCollab2020_ignoreLighting to the DynData for the strawberry. |
| 36 | + new DynData<Strawberry>(self)["SpringCollab2020_ignoreLighting"] = data.Bool("SpringCollab2020_ignoreLighting"); |
| 37 | + } |
| 38 | + |
| 39 | + private static void onLightingBeforeRender(On.Celeste.LightingRenderer.orig_BeforeRender orig, LightingRenderer self, Scene scene) { |
| 40 | + orig(self, scene); |
| 41 | + |
| 42 | + Draw.SpriteBatch.GraphicsDevice.SetRenderTarget(GameplayBuffers.Light); |
| 43 | + Draw.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, null, Matrix.Identity); |
| 44 | + foreach (Entity entity in scene.Entities) { |
| 45 | + if (entity is Strawberry berry) { |
| 46 | + DynData<Strawberry> berryData = new DynData<Strawberry>(berry); |
| 47 | + if (berryData.Get<bool>("SpringCollab2020_ignoreLighting")) { |
| 48 | + Draw.SpriteBatch.Draw(strawberryCutoutTexture.Texture.Texture, berry.Position + berryData.Get<Sprite>("sprite").Position - (scene as Level).Camera.Position |
| 49 | + - new Vector2(9, 8), Color.White); |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + Draw.SpriteBatch.End(); |
| 54 | + } |
| 55 | + } |
| 56 | +} |
0 commit comments