Fix player palette double-add bug

This commit is contained in:
Paul Chote
2010-02-05 00:32:15 +13:00
parent 0b16341c6f
commit e7f376dc58
3 changed files with 15 additions and 1 deletions

View File

@@ -356,6 +356,10 @@ namespace OpenRa
var d = left ? +1 : Player.PlayerColors.Count() - 1; var d = left ? +1 : Player.PlayerColors.Count() - 1;
var newIndex = ((int)Game.world.LocalPlayer.PaletteIndex + d) % Player.PlayerColors.Count(); var newIndex = ((int)Game.world.LocalPlayer.PaletteIndex + d) % Player.PlayerColors.Count();
Game.IssueOrder(
Order.Chat("color count " + Player.PlayerColors.Count()));
while (!PaletteAvailable(newIndex) && newIndex != (int)Game.world.LocalPlayer.PaletteIndex) while (!PaletteAvailable(newIndex) && newIndex != (int)Game.world.LocalPlayer.PaletteIndex)
newIndex = (newIndex + d) % Player.PlayerColors.Count(); newIndex = (newIndex + d) % Player.PlayerColors.Count();

View File

@@ -65,7 +65,9 @@ namespace OpenRa
Timer.Time( "load rules: {0}" ); Timer.Time( "load rules: {0}" );
world = null; // trying to access the old world will NRE, rather than silently doing it wrong. world = null; // trying to access the old world will NRE, rather than silently doing it wrong.
Player.ResetPlayerColorList();
world = new World(); world = new World();
Game.world.ActorAdded += a => Game.world.ActorAdded += a =>
{ {
if (a.Owner != null && a.Info.Traits.Contains<OwnedActorInfo>()) if (a.Owner != null && a.Info.Traits.Contains<OwnedActorInfo>())

View File

@@ -30,8 +30,16 @@ namespace OpenRa
public World World { get { return PlayerActor.World; } } public World World { get { return PlayerActor.World; } }
public static List<Tuple<string, string, Color>> PlayerColors = new List<Tuple<string, string, Color>>(); public static List<Tuple<string, string, Color>> PlayerColors = new List<Tuple<string, string, Color>>();
public static void ResetPlayerColorList()
{
// 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<Tuple<string, string, Color>>();
}
public static void RegisterPlayerColor(string palette, string name, Color c) public static void RegisterPlayerColor(string palette, string name, Color c)
{ {
Log.Write("Adding player color {0}",name);
PlayerColors.Add(new Tuple<string, string, Color>(palette, name, c)); PlayerColors.Add(new Tuple<string, string, Color>(palette, name, c));
} }