Skip to content

Commit 76b8674

Browse files
committed
Replace reflection with DynData
1 parent e4ecf94 commit 76b8674

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Entities/MultiRoomStrawberrySeed.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.Xna.Framework;
33
using Microsoft.Xna.Framework.Graphics;
44
using Monocle;
5+
using MonoMod.Utils;
56
using System;
67
using System.Reflection;
78

@@ -52,9 +53,7 @@ private static void onLightingBeforeRender(On.Celeste.LightingRenderer.orig_Befo
5253
Draw.SpriteBatch.End();
5354
}
5455

55-
private static FieldInfo seedFollower = typeof(StrawberrySeed).GetField("follower", BindingFlags.NonPublic | BindingFlags.Instance);
56-
private static FieldInfo seedCanLoseTimer = typeof(StrawberrySeed).GetField("canLoseTimer", BindingFlags.NonPublic | BindingFlags.Instance);
57-
private static FieldInfo seedSprite = typeof(StrawberrySeed).GetField("sprite", BindingFlags.NonPublic | BindingFlags.Instance);
56+
private DynData<StrawberrySeed> selfStrawberrySeed;
5857

5958
private int index;
6059
public EntityID BerryID;
@@ -70,6 +69,8 @@ private static void onLightingBeforeRender(On.Celeste.LightingRenderer.orig_Befo
7069
private MTexture cutoutTexture;
7170

7271
public MultiRoomStrawberrySeed(Vector2 position, int index, bool ghost, string sprite, string ghostSprite, bool ignoreLighting) : base(null, position, index, ghost) {
72+
selfStrawberrySeed = new DynData<StrawberrySeed>(this);
73+
7374
this.index = index;
7475
this.ghost = ghost;
7576
this.sprite = ghost ? ghostSprite : sprite;
@@ -128,7 +129,7 @@ public override void Awake(Scene scene) {
128129

129130
if ((ghost && sprite != "ghostberry/seed") || (!ghost && sprite != "strawberry/seed")) {
130131
// the sprite is non-default. replace it.
131-
Sprite vanillaSprite = (Sprite) seedSprite.GetValue(this);
132+
Sprite vanillaSprite = selfStrawberrySeed.Get<Sprite>("sprite");
132133

133134
// build the new sprite.
134135
MTexture frame0 = GFX.Game["collectables/" + sprite + "00"];
@@ -153,24 +154,24 @@ public override void Awake(Scene scene) {
153154
// and replace it for good
154155
Remove(vanillaSprite);
155156
Add(modSprite);
156-
seedSprite.SetValue(this, modSprite);
157+
selfStrawberrySeed["sprite"] = modSprite;
157158
}
158159

159160
if (spawnedAsFollower) {
160-
player.Leader.GainFollower((Follower) seedFollower.GetValue(this));
161+
player.Leader.GainFollower(selfStrawberrySeed.Get<Follower>("follower"));
161162
canLoseTimerMirror = 0.25f;
162163
Collidable = false;
163164
Depth = -1000000;
164165
AddTag(Tags.Persistent);
165166
}
166167

167168
// get a reference to the sprite. this will be used to "cut out" the lighting renderer.
168-
spriteObject = (Sprite) seedSprite.GetValue(this);
169+
spriteObject = selfStrawberrySeed.Get<Sprite>("sprite");
169170
}
170171

171172
private void OnPlayer(Player player) {
172173
Audio.Play("event:/game/general/seed_touch", Position, "count", index);
173-
player.Leader.GainFollower((Follower) seedFollower.GetValue(this));
174+
player.Leader.GainFollower(selfStrawberrySeed.Get<Follower>("follower"));
174175
canLoseTimerMirror = 0.25f;
175176
Collidable = false;
176177
Depth = -1000000;
@@ -192,7 +193,7 @@ public override void Update() {
192193
canLoseTimerMirror -= Engine.DeltaTime;
193194
if (canLoseTimerMirror < 1f) {
194195
canLoseTimerMirror = 1000f;
195-
seedCanLoseTimer.SetValue(this, 1000f);
196+
selfStrawberrySeed["canLoseTimer"] = 1000f;
196197
}
197198
}
198199
}

0 commit comments

Comments
 (0)