Fix SquadManagerBotModule caching in RenderDebugState

This commit is contained in:
abcdefg30
2022-10-09 23:00:10 +02:00
committed by Gustas
parent d8349a429a
commit 6e6c828c85

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Traits.Render
readonly SpriteFont font; readonly SpriteFont font;
readonly Actor self; readonly Actor self;
readonly WVec offset; readonly WVec offset;
SquadManagerBotModule ai; SquadManagerBotModule[] squadManagerModules;
Color color; Color color;
string tagString; string tagString;
@@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.Traits.Render
void INotifyCreated.Created(Actor self) void INotifyCreated.Created(Actor self)
{ {
ai = self.Owner.PlayerActor.TraitsImplementing<SquadManagerBotModule>().FirstOrDefault(Exts.IsTraitEnabled); squadManagerModules = self.Owner.PlayerActor.TraitsImplementing<SquadManagerBotModule>().ToArray();
} }
void INotifyAddedToWorld.AddedToWorld(Actor self) void INotifyAddedToWorld.AddedToWorld(Actor self)
@@ -86,11 +86,8 @@ namespace OpenRA.Mods.Common.Traits.Render
if (!self.Owner.IsBot) if (!self.Owner.IsBot)
yield break; yield break;
if (ai == null) var squads = squadManagerModules.FirstEnabledConditionalTraitOrDefault()?.Squads;
yield break; var squad = squads?.FirstOrDefault(x => x.Units.Contains(self));
var squads = ai.Squads;
var squad = squads.FirstOrDefault(x => x.Units.Contains(self));
if (squad == null) if (squad == null)
yield break; yield break;