Fix most of the style violations in Game.cs.

This commit is contained in:
Paul Chote
2013-12-18 21:41:12 +13:00
parent ff5cbc65c5
commit b96c36f38f

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS) * Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
@@ -81,11 +81,10 @@ namespace OpenRA
static ConnectionState lastConnectionState = ConnectionState.PreConnecting; static ConnectionState lastConnectionState = ConnectionState.PreConnecting;
public static int LocalClientId { get { return orderManager.Connection.LocalClientId; } } public static int LocalClientId { get { return orderManager.Connection.LocalClientId; } }
// Hacky workaround for orderManager visibility // Hacky workaround for orderManager visibility
public static Widget OpenWindow(World world, string widget) public static Widget OpenWindow(World world, string widget)
{ {
return Ui.OpenWindow(widget, new WidgetArgs() {{ "world", world }, { "orderManager", orderManager }, { "worldRenderer", worldRenderer }}); return Ui.OpenWindow(widget, new WidgetArgs() { { "world", world }, { "orderManager", orderManager }, { "worldRenderer", worldRenderer } });
} }
// Who came up with the great idea of making these things // Who came up with the great idea of making these things
@@ -220,7 +219,7 @@ namespace OpenRA
LobbyInfoChanged(); LobbyInfoChanged();
} }
public static event Action BeforeGameStart = () => {}; public static event Action BeforeGameStart = () => { };
internal static void StartGame(string mapUID, bool isShellmap) internal static void StartGame(string mapUID, bool isShellmap)
{ {
BeforeGameStart(); BeforeGameStart();
@@ -249,9 +248,9 @@ namespace OpenRA
{ {
get get
{ {
var client= orderManager.LobbyInfo.ClientWithIndex( var id = orderManager.Connection.LocalClientId;
orderManager.Connection.LocalClientId); var client = orderManager.LobbyInfo.ClientWithIndex(id);
return ((client!=null) && client.IsAdmin); return client != null && client.IsAdmin;
} }
} }
@@ -284,7 +283,7 @@ namespace OpenRA
} }
FileSystem.Mount("."); // Needed to access shaders FileSystem.Mount("."); // Needed to access shaders
var renderers = new [] { Settings.Graphics.Renderer, "Sdl2", "Gl", "Cg", null }; var renderers = new[] { Settings.Graphics.Renderer, "Sdl2", "Gl", "Cg", null };
foreach (var r in renderers) foreach (var r in renderers)
{ {
if (r == null) if (r == null)
@@ -302,6 +301,7 @@ namespace OpenRA
Console.WriteLine("Renderer initialization failed. Fallback in place. Check graphics.log for details."); Console.WriteLine("Renderer initialization failed. Fallback in place. Check graphics.log for details.");
} }
} }
Renderer = new Renderer(); Renderer = new Renderer();
try try
@@ -317,26 +317,22 @@ namespace OpenRA
} }
Console.WriteLine("Available mods:"); Console.WriteLine("Available mods:");
foreach(var mod in Mod.AllMods) foreach (var mod in Mod.AllMods)
Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version); Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version);
InitializeWithMod(Settings.Game.Mod); InitializeWithMod(Settings.Game.Mod);
if (Settings.Server.DiscoverNatDevices) if (Settings.Server.DiscoverNatDevices)
{ RunAfterDelay(Settings.Server.NatDiscoveryTimeout, UPnP.TryStoppingNatDiscovery);
RunAfterDelay(Settings.Server.NatDiscoveryTimeout, () =>
UPnP.TryStoppingNatDiscovery()
);
}
} }
public static void InitializeWithMod(string mod) public static void InitializeWithMod(string mod)
{ {
// Clear static state if we have switched mods // Clear static state if we have switched mods
LobbyInfoChanged = () => {}; LobbyInfoChanged = () => { };
AddChatLine = (a,b,c) => {}; AddChatLine = (a, b, c) => { };
ConnectionStateChanged = om => {}; ConnectionStateChanged = om => { };
BeforeGameStart = () => {}; BeforeGameStart = () => { };
Ui.ResetAll(); Ui.ResetAll();
worldRenderer = null; worldRenderer = null;
@@ -378,21 +374,23 @@ namespace OpenRA
{ {
System.Threading.Thread.Sleep(100); System.Threading.Thread.Sleep(100);
if ((server.State == Server.ServerState.GameStarted) if (server.State == Server.ServerState.GameStarted && server.Conns.Count <= 1)
&& (server.Conns.Count<=1))
{ {
Console.WriteLine("No one is playing, shutting down..."); Console.WriteLine("No one is playing, shutting down...");
server.Shutdown(); server.Shutdown();
break; break;
} }
} }
if (Settings.Server.DedicatedLoop) if (Settings.Server.DedicatedLoop)
{ {
Console.WriteLine("Starting a new server instance..."); Console.WriteLine("Starting a new server instance...");
continue; continue;
} }
break; break;
} }
Environment.Exit(0); Environment.Exit(0);
} }
else else
@@ -419,7 +417,7 @@ namespace OpenRA
} }
static bool quit; static bool quit;
public static event Action OnQuit = () => {}; public static event Action OnQuit = () => { };
internal static void Run() internal static void Run()
{ {
@@ -449,11 +447,11 @@ namespace OpenRA
public static void Exit() { quit = true; } public static void Exit() { quit = true; }
public static Action<Color,string,string> AddChatLine = (c,n,s) => {}; public static Action<Color, string, string> AddChatLine = (c, n, s) => { };
public static void Debug(string s, params object[] args) public static void Debug(string s, params object[] args)
{ {
AddChatLine(Color.White, "Debug", String.Format(s,args)); AddChatLine(Color.White, "Debug", string.Format(s, args));
} }
public static void Disconnect() public static void Disconnect()
@@ -472,7 +470,7 @@ namespace OpenRA
server.Shutdown(); server.Shutdown();
} }
public static T CreateObject<T>( string name ) public static T CreateObject<T>(string name)
{ {
return modData.ObjectCreator.CreateObject<T>(name); return modData.ObjectCreator.CreateObject<T>(name);
} }
@@ -507,11 +505,11 @@ namespace OpenRA
try try
{ {
var mod = Game.modData.Manifest.Mod; var mod = Game.modData.Manifest.Mod;
var dirPath = new [] { Platform.SupportDir, "maps", mod.Id }.Aggregate(Path.Combine); var dirPath = new[] { Platform.SupportDir, "maps", mod.Id }.Aggregate(Path.Combine);
if (!Directory.Exists(dirPath)) if (!Directory.Exists(dirPath))
Directory.CreateDirectory(dirPath); Directory.CreateDirectory(dirPath);
var mapPath = Path.Combine(dirPath, mapHash+".oramap"); var mapPath = Path.Combine(dirPath, mapHash + ".oramap");
Console.Write("Trying to download map to {0} ... ".F(mapPath)); Console.Write("Trying to download map to {0} ... ".F(mapPath));
WebClient webClient = new WebClient(); WebClient webClient = new WebClient();