From 9e4d40ec5e865ac7980a7ee81492956a25669707 Mon Sep 17 00:00:00 2001 From: DemoJameson Date: Tue, 10 Oct 2023 17:47:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=A7=BB=E9=99=A4=20cast?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Entities/FeatherBarrier.cs | 10 ++++----- Triggers/ChangeBossPatternTrigger.cs | 6 ++---- Triggers/ChangeSpinnerColorTrigger.cs | 31 +++++++++++++-------------- Triggers/ClimbBlockerTrigger.cs | 18 +++++++--------- 4 files changed, 29 insertions(+), 36 deletions(-) diff --git a/Entities/FeatherBarrier.cs b/Entities/FeatherBarrier.cs index 08865e0..4845b67 100644 --- a/Entities/FeatherBarrier.cs +++ b/Entities/FeatherBarrier.cs @@ -8,7 +8,7 @@ using Monocle; using MonoMod.Cil; -namespace Celeste.Mod.DJMapHelper.Entities; +namespace Celeste.Mod.DJMapHelper.Entities; [Tracked] [CustomEntity("DJMapHelper/featherBarrier")] @@ -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().Cast().ToList(); + var featherBarriers = self.Scene.Tracker.GetEntitiesCopy(); TryMakeBarrierCollidable(self, featherBarriers); orig(self, move); } private static void PlayerOnUpdate(On.Celeste.Player.orig_Update orig, Player self) { - var featherBarriers = - self.Scene.Tracker.GetEntities().Cast().ToList(); + var featherBarriers = self.Scene.Tracker.GetEntitiesCopy(); if (self.SceneAs().Wind == Vector2.Zero || self.Get() == null) { TryMakeBarrierCollidable(self, featherBarriers); } @@ -207,7 +205,7 @@ private static void PlayerOnUpdate(On.Celeste.Player.orig_Update orig, Player se } } - private static void TryMakeBarrierCollidable(Player player, List featherBarriers) { + private static void TryMakeBarrierCollidable(Player player, List featherBarriers) { var flyColor = StarFlyColorGetter(player); foreach (FeatherBarrier featherBarrier in featherBarriers) { if (flyColor != featherBarrier.barrieColor || player.StateMachine.State != Player.StStarFly) { diff --git a/Triggers/ChangeBossPatternTrigger.cs b/Triggers/ChangeBossPatternTrigger.cs index 86f1463..7bb9fe8 100644 --- a/Triggers/ChangeBossPatternTrigger.cs +++ b/Triggers/ChangeBossPatternTrigger.cs @@ -5,7 +5,7 @@ using Microsoft.Xna.Framework; using Monocle; -namespace Celeste.Mod.DJMapHelper.Triggers; +namespace Celeste.Mod.DJMapHelper.Triggers; [Tracked] [CustomEntity("DJMapHelper/changeBossPatternTrigger")] @@ -48,9 +48,7 @@ public override void OnEnter(Player player) { return; } - var bosses = level.Tracker.GetEntities().Cast().ToList(); - - foreach (FinalBoss finalBoss in bosses) { + foreach (FinalBoss finalBoss in level.Tracker.GetEntitiesCopy()) { if (mode == Modes.All || CollideCheck(finalBoss)) { if (patternIndex == (int) PatternIndexFieldInfo.GetValue(finalBoss)) continue; if (((Vector2[]) NodesFieldInfo.GetValue(finalBoss)).Length == 0) continue; diff --git a/Triggers/ChangeSpinnerColorTrigger.cs b/Triggers/ChangeSpinnerColorTrigger.cs index 82e9bf8..1e264a9 100644 --- a/Triggers/ChangeSpinnerColorTrigger.cs +++ b/Triggers/ChangeSpinnerColorTrigger.cs @@ -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 { @@ -120,23 +120,22 @@ public override void OnEnter(Player player) { if (mode == Modes.OnPlayerEnter) { Level level = player.SceneAs(); SaveColorToSession(color); - level.Tracker.GetEntities().Cast().ToList().ForEach( - entity => { - if (color != null) { - entity.Add(new ChangeColorComponent(entity, (CrystalColor) color)); - return; + foreach (CrystalStaticSpinner spinner in level.Tracker.GetEntitiesCopy()) { + 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)); + } + } } } diff --git a/Triggers/ClimbBlockerTrigger.cs b/Triggers/ClimbBlockerTrigger.cs index 4169db0..ddf527f 100644 --- a/Triggers/ClimbBlockerTrigger.cs +++ b/Triggers/ClimbBlockerTrigger.cs @@ -3,7 +3,7 @@ using Microsoft.Xna.Framework; using Monocle; -namespace Celeste.Mod.DJMapHelper.Triggers; +namespace Celeste.Mod.DJMapHelper.Triggers; [Tracked] [CustomEntity("DJMapHelper/climbBlockerTrigger")] @@ -46,11 +46,10 @@ public static void OnUnLoad() { } private static void PlayerOnClimbJump(On.Celeste.Player.orig_ClimbJump orig, Player self) { - var triggers = - self.CollideAll().Cast().ToList(); + var triggers = self.CollideAll(); bool wallJump; if (triggers.Count > 0) { - wallJump = triggers.All(trigger => trigger.wallJump); + wallJump = triggers.All(trigger => ((ClimbBlockerTrigger)trigger).wallJump); } else { Session session = self.SceneAs().Session; wallJump = !session.GetFlag(BlockWallJumpKey); @@ -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().Cast().ToList(); - + var triggers = self.CollideAll(); + bool wallJump; bool climb; - + Session session = self.SceneAs().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);