From 7c86519242f5faeb5f13ee2e8329fa2be36a448a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 26 Jul 2015 11:54:47 +0200 Subject: [PATCH] organize launch arguments in it's own class --- OpenRA.Game/OpenRA.Game.csproj | 1 + OpenRA.Game/Support/LaunchArguments.cs | 44 +++++++++++++++++++ .../LoadScreens/BlankLoadScreen.cs | 28 ++---------- .../UtilityCommands/CreateManPage.cs | 2 +- 4 files changed, 49 insertions(+), 26 deletions(-) create mode 100644 OpenRA.Game/Support/LaunchArguments.cs diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index ea74fbb26a..f0e91d291e 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -164,6 +164,7 @@ + diff --git a/OpenRA.Game/Support/LaunchArguments.cs b/OpenRA.Game/Support/LaunchArguments.cs new file mode 100644 index 0000000000..16c5cae8e3 --- /dev/null +++ b/OpenRA.Game/Support/LaunchArguments.cs @@ -0,0 +1,44 @@ +#region Copyright & License Information +/* + * Copyright 2007-2015 The OpenRA Developers (see AUTHORS) + * 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 + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +namespace OpenRA +{ + public class LaunchArguments + { + [Desc("Connect to the following server given as IP:PORT on startup.")] + public string Connect; + + [Desc("Connect to the unified resource identifier openra://IP:PORT on startup.")] + public string URI; + + [Desc("Automatically start playing the given replay file.")] + public string Replay; + + public LaunchArguments(Arguments args) + { + foreach (var f in this.GetType().GetFields()) + if (args.Contains("Launch" + "." + f.Name)) + FieldLoader.LoadField(this, f.Name, args.GetValue("Launch" + "." + f.Name, "")); + } + + public string GetConnectAddress() + { + var connect = string.Empty; + + if (!string.IsNullOrEmpty(Connect)) + connect = Connect; + + if (!string.IsNullOrEmpty(URI)) + connect = URI.Replace("openra://", "").TrimEnd('/'); + + return connect; + } + } +} diff --git a/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs b/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs index d765cb411a..f356025ac8 100644 --- a/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs +++ b/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs @@ -20,19 +20,7 @@ namespace OpenRA.Mods.Common.LoadScreens { public class BlankLoadScreen : ILoadScreen { - public class LaunchArgs - { - [Desc("Connect to the following server given as IP:PORT on startup.")] - public string Connect; - - [Desc("Connect to the unified resource identifier openra://IP:PORT on startup.")] - public string URI; - - [Desc("Automatically start playing the given replay file.")] - public string Replay; - } - - public LaunchArgs Launch = new LaunchArgs(); + public LaunchArguments Launch; public virtual void Init(Manifest m, Dictionary info) { } @@ -48,10 +36,7 @@ namespace OpenRA.Mods.Common.LoadScreens public void StartGame(Arguments args) { - foreach (var f in Launch.GetType().GetFields()) - if (args.Contains("Launch" + "." + f.Name)) - FieldLoader.LoadField(Launch, f.Name, args.GetValue("Launch" + "." + f.Name, "")); - + Launch = new LaunchArguments(args); Ui.ResetAll(); Game.Settings.Save(); @@ -80,14 +65,7 @@ namespace OpenRA.Mods.Common.LoadScreens } // Join a server directly - var connect = string.Empty; - - if (!string.IsNullOrEmpty(Launch.Connect)) - connect = Launch.Connect; - - if (!string.IsNullOrEmpty(Launch.URI)) - connect = Launch.URI.Replace("openra://", "").TrimEnd('/'); - + var connect = Launch.GetConnectAddress(); if (!string.IsNullOrEmpty(connect)) { var parts = connect.Split(':'); diff --git a/OpenRA.Mods.Common/UtilityCommands/CreateManPage.cs b/OpenRA.Mods.Common/UtilityCommands/CreateManPage.cs index 880f146a2a..6f8a6090b2 100644 --- a/OpenRA.Mods.Common/UtilityCommands/CreateManPage.cs +++ b/OpenRA.Mods.Common/UtilityCommands/CreateManPage.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.UtilityCommands Console.WriteLine(".SH OPTIONS"); var sections = Game.Settings.Sections; - sections.Add("Launch", new OpenRA.Mods.Common.LoadScreens.BlankLoadScreen.LaunchArgs()); + sections.Add("Launch", new LaunchArguments(new Arguments(new string[0]))); foreach (var section in sections.OrderBy(s => s.Key)) { var fields = section.Value.GetType().GetFields();