Skip to content

Commit

Permalink
feat: 移除 cast
Browse files Browse the repository at this point in the history
  • Loading branch information
DemoJameson committed Oct 11, 2023
1 parent 3bd0a08 commit 9e4d40e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 36 deletions.
10 changes: 4 additions & 6 deletions Entities/FeatherBarrier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Monocle;
using MonoMod.Cil;

namespace Celeste.Mod.DJMapHelper.Entities;
namespace Celeste.Mod.DJMapHelper.Entities;

[Tracked]
[CustomEntity("DJMapHelper/featherBarrier")]
Expand Down Expand Up @@ -186,16 +186,14 @@ private static void CheckCollide(Player player, CollisionData data) {
}

private static void PlayerOnWindMove(On.Celeste.Player.orig_WindMove orig, Player self, Vector2 move) {
var featherBarriers =
self.Scene.Tracker.GetEntities<FeatherBarrier>().Cast<FeatherBarrier>().ToList();
var featherBarriers = self.Scene.Tracker.GetEntitiesCopy<FeatherBarrier>();
TryMakeBarrierCollidable(self, featherBarriers);

orig(self, move);
}

private static void PlayerOnUpdate(On.Celeste.Player.orig_Update orig, Player self) {
var featherBarriers =
self.Scene.Tracker.GetEntities<FeatherBarrier>().Cast<FeatherBarrier>().ToList();
var featherBarriers = self.Scene.Tracker.GetEntitiesCopy<FeatherBarrier>();
if (self.SceneAs<Level>().Wind == Vector2.Zero || self.Get<WindMover>() == null) {
TryMakeBarrierCollidable(self, featherBarriers);
}
Expand All @@ -207,7 +205,7 @@ private static void PlayerOnUpdate(On.Celeste.Player.orig_Update orig, Player se
}
}

private static void TryMakeBarrierCollidable(Player player, List<FeatherBarrier> featherBarriers) {
private static void TryMakeBarrierCollidable(Player player, List<Entity> featherBarriers) {
var flyColor = StarFlyColorGetter(player);
foreach (FeatherBarrier featherBarrier in featherBarriers) {
if (flyColor != featherBarrier.barrieColor || player.StateMachine.State != Player.StStarFly) {
Expand Down
6 changes: 2 additions & 4 deletions Triggers/ChangeBossPatternTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Microsoft.Xna.Framework;
using Monocle;

namespace Celeste.Mod.DJMapHelper.Triggers;
namespace Celeste.Mod.DJMapHelper.Triggers;

[Tracked]
[CustomEntity("DJMapHelper/changeBossPatternTrigger")]
Expand Down Expand Up @@ -48,9 +48,7 @@ public override void OnEnter(Player player) {
return;
}

var bosses = level.Tracker.GetEntities<FinalBoss>().Cast<FinalBoss>().ToList();

foreach (FinalBoss finalBoss in bosses) {
foreach (FinalBoss finalBoss in level.Tracker.GetEntitiesCopy<FinalBoss>()) {
if (mode == Modes.All || CollideCheck(finalBoss)) {
if (patternIndex == (int) PatternIndexFieldInfo.GetValue(finalBoss)) continue;
if (((Vector2[]) NodesFieldInfo.GetValue(finalBoss)).Length == 0) continue;
Expand Down
31 changes: 15 additions & 16 deletions Triggers/ChangeSpinnerColorTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Microsoft.Xna.Framework;
using Monocle;

namespace Celeste.Mod.DJMapHelper.Triggers;
namespace Celeste.Mod.DJMapHelper.Triggers;

[CustomEntity("DJMapHelper/changeSpinnerColorTrigger")]
public class ChangeSpinnerColorTrigger : Trigger {
Expand Down Expand Up @@ -120,23 +120,22 @@ public override void OnEnter(Player player) {
if (mode == Modes.OnPlayerEnter) {
Level level = player.SceneAs<Level>();
SaveColorToSession(color);
level.Tracker.GetEntities<CrystalStaticSpinner>().Cast<CrystalStaticSpinner>().ToList().ForEach(
entity => {
if (color != null) {
entity.Add(new ChangeColorComponent(entity, (CrystalColor) color));
return;
foreach (CrystalStaticSpinner spinner in level.Tracker.GetEntitiesCopy<CrystalStaticSpinner>()) {
if (color != null) {
spinner.Add(new ChangeColorComponent(spinner, (CrystalColor) color));
continue;
}

if (DJMapHelperModule.Session.CachedSpinnerColors.TryGetValue(spinner, out CrystalColor origColor)) {
if (origColor == ~CrystalColor.Blue) {
origColor = level.CoreMode != Session.CoreModes.Cold
? CrystalColor.Red
: CrystalColor.Blue;
}

if (DJMapHelperModule.Session.CachedSpinnerColors.TryGetValue(entity, out CrystalColor origColor)) {
if (origColor == ~CrystalColor.Blue) {
origColor = level.CoreMode != Session.CoreModes.Cold
? CrystalColor.Red
: CrystalColor.Blue;
}
entity.Add(new ChangeColorComponent(entity, origColor));
}
});
spinner.Add(new ChangeColorComponent(spinner, origColor));
}
}
}
}

Expand Down
18 changes: 8 additions & 10 deletions Triggers/ClimbBlockerTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Microsoft.Xna.Framework;
using Monocle;

namespace Celeste.Mod.DJMapHelper.Triggers;
namespace Celeste.Mod.DJMapHelper.Triggers;

[Tracked]
[CustomEntity("DJMapHelper/climbBlockerTrigger")]
Expand Down Expand Up @@ -46,11 +46,10 @@ public static void OnUnLoad() {
}

private static void PlayerOnClimbJump(On.Celeste.Player.orig_ClimbJump orig, Player self) {
var triggers =
self.CollideAll<ClimbBlockerTrigger>().Cast<ClimbBlockerTrigger>().ToList();
var triggers = self.CollideAll<ClimbBlockerTrigger>();
bool wallJump;
if (triggers.Count > 0) {
wallJump = triggers.All(trigger => trigger.wallJump);
wallJump = triggers.All(trigger => ((ClimbBlockerTrigger)trigger).wallJump);
} else {
Session session = self.SceneAs<Level>().Session;
wallJump = !session.GetFlag(BlockWallJumpKey);
Expand All @@ -62,16 +61,15 @@ private static void PlayerOnClimbJump(On.Celeste.Player.orig_ClimbJump orig, Pla

private static bool PlayerOnClimbBoundsCheck(On.Celeste.Player.orig_ClimbBoundsCheck orig, Player self,
int dir) {
var triggers =
self.CollideAll<ClimbBlockerTrigger>().Cast<ClimbBlockerTrigger>().ToList();

var triggers = self.CollideAll<ClimbBlockerTrigger>();

bool wallJump;
bool climb;

Session session = self.SceneAs<Level>().Session;
if (triggers.Count > 0) {
wallJump = triggers.All(trigger => trigger.wallJump);
climb = triggers.All(trigger => trigger.climb);
wallJump = triggers.All(trigger => ((ClimbBlockerTrigger)trigger).wallJump);
climb = triggers.All(trigger => ((ClimbBlockerTrigger)trigger).climb);
} else {
wallJump = !session.GetFlag(BlockWallJumpKey);
climb = !session.GetFlag(BlockClimbKey);
Expand Down

0 comments on commit 9e4d40e

Please sign in to comment.