From 88e16a890de540aead93362e61bcdd20d9e5fdde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 28 Jun 2015 22:18:48 +0200 Subject: [PATCH] extract Launch args for automatic manpage creation --- .../LoadScreens/BlankLoadScreen.cs | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs b/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs index 7de5e8f276..d765cb411a 100644 --- a/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs +++ b/OpenRA.Mods.Common/LoadScreens/BlankLoadScreen.cs @@ -20,6 +20,20 @@ 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 virtual void Init(Manifest m, Dictionary info) { } public virtual void Display() @@ -34,6 +48,10 @@ 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, "")); + Ui.ResetAll(); Game.Settings.Save(); @@ -63,21 +81,12 @@ namespace OpenRA.Mods.Common.LoadScreens // Join a server directly var connect = string.Empty; - if (args != null) - { - if (args.Contains("Launch.Connect")) - connect = args.GetValue("Launch.Connect", null); - if (args.Contains("Launch.URI")) - { - connect = args.GetValue("Launch.URI", null); - if (connect != null) - { - connect = connect.Replace("openra://", ""); - connect = connect.TrimEnd('/'); - } - } - } + if (!string.IsNullOrEmpty(Launch.Connect)) + connect = Launch.Connect; + + if (!string.IsNullOrEmpty(Launch.URI)) + connect = Launch.URI.Replace("openra://", "").TrimEnd('/'); if (!string.IsNullOrEmpty(connect)) { @@ -94,12 +103,11 @@ namespace OpenRA.Mods.Common.LoadScreens } // Load a replay directly - var replayFilename = args != null ? args.GetValue("Launch.Replay", null) : null; - if (!string.IsNullOrEmpty(replayFilename)) + if (!string.IsNullOrEmpty(Launch.Replay)) { - var replayMeta = ReplayMetadata.Read(replayFilename); + var replayMeta = ReplayMetadata.Read(Launch.Replay); if (ReplayUtils.PromptConfirmReplayCompatibility(replayMeta, Game.LoadShellMap)) - Game.JoinReplay(replayFilename); + Game.JoinReplay(Launch.Replay); if (replayMeta != null) {