From 07b0c77db450011306f3c7ea813ac11b8d17bb61 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Thu, 18 Mar 2010 13:33:43 +1300 Subject: [PATCH] undo problematic caching --- OpenRA.Game/Game.cs | 1 - OpenRA.Game/Player.cs | 22 +++++++++---------- OpenRA.Game/Traits/Util.cs | 4 +++- .../Traits/World/PlayerColorPalette.cs | 12 +++++----- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 16e3a3711d..f2a0e5f420 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -102,7 +102,6 @@ namespace OpenRA world = null; // trying to access the old world will NRE, rather than silently doing it wrong. - Player.ResetPlayerColorList(); ChromeProvider.Initialize(manifest.Chrome); world = new World(); diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index ba5c4a4298..3d5b0e423b 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -49,22 +49,20 @@ namespace OpenRA public int PowerProvided = 0; public int PowerDrained = 0; + public Shroud Shroud; + public World World { get { return PlayerActor.World; } } - public static List> PlayerColors = new List>(); - public static void ResetPlayerColorList() + public static List> PlayerColors { - // This is unsafe if the mapchange introduces/removes mods that defines new colors - // TODO: ensure that each player's palette index is reassigned appropriately - PlayerColors = new List>(); + get + { + return Game.world.WorldActor.Info.Traits.WithInterface() + .Where(p => p.Playable) + .Select(p => Tuple.New(p.Name, p.DisplayName, p.Color)) + .ToList(); + } } - - public static void RegisterPlayerColor(string palette, string name, Color c) - { - PlayerColors.Add(new Tuple(palette, name, c)); - } - - public Shroud Shroud; public Player( World world, Session.Client client ) { diff --git a/OpenRA.Game/Traits/Util.cs b/OpenRA.Game/Traits/Util.cs index 6fb76ec1b4..f0b5a53d01 100755 --- a/OpenRA.Game/Traits/Util.cs +++ b/OpenRA.Game/Traits/Util.cs @@ -19,9 +19,9 @@ #endregion using System; +using System.Drawing; using System.Linq; using OpenRA.Graphics; -using OpenRA.Traits.Activities; namespace OpenRA.Traits { @@ -161,5 +161,7 @@ namespace OpenRA.Traits return new[] { self.GetPrimaryWeapon(), self.GetSecondaryWeapon() } .Where(w => w != null).Max(w => w.Range); } + + public static Color ArrayToColor(int[] x) { return Color.FromArgb(x[0], x[1], x[2]); } } } diff --git a/OpenRA.Game/Traits/World/PlayerColorPalette.cs b/OpenRA.Game/Traits/World/PlayerColorPalette.cs index a8ce474938..98ab8968ec 100644 --- a/OpenRA.Game/Traits/World/PlayerColorPalette.cs +++ b/OpenRA.Game/Traits/World/PlayerColorPalette.cs @@ -37,6 +37,8 @@ namespace OpenRA.Traits public readonly bool Playable = true; public object Create(Actor self) { return new PlayerColorPalette(self, this); } + + public Color Color { get { return Util.ArrayToColor(DisplayColor); } } } class PlayerColorPalette @@ -46,17 +48,13 @@ namespace OpenRA.Traits var wr = self.World.WorldRenderer; var pal = wr.GetPalette(info.BasePalette); var newpal = new Palette(pal, new PlayerColorRemap( - ArrayToColor(info.Color1), - ArrayToColor(info.Color2), + Util.ArrayToColor(info.Color1), + Util.ArrayToColor(info.Color2), info.SplitRamp)); wr.AddPalette(info.Name, newpal); - - if (info.Playable) - Player.RegisterPlayerColor(info.Name, info.DisplayName, - ArrayToColor(info.DisplayColor)); } - static Color ArrayToColor(int[] x) { return Color.FromArgb(x[0], x[1], x[2]); } + } }