organize launch arguments in it's own class

This commit is contained in:
Matthias Mailänder
2015-07-26 11:54:47 +02:00
parent baa798d831
commit 7c86519242
4 changed files with 49 additions and 26 deletions

View File

@@ -164,6 +164,7 @@
<Compile Include="Server\ServerOrder.cs" /> <Compile Include="Server\ServerOrder.cs" />
<Compile Include="Server\TraitInterfaces.cs" /> <Compile Include="Server\TraitInterfaces.cs" />
<Compile Include="Support\Arguments.cs" /> <Compile Include="Support\Arguments.cs" />
<Compile Include="Support\LaunchArguments.cs" />
<Compile Include="Support\PerfHistory.cs" /> <Compile Include="Support\PerfHistory.cs" />
<Compile Include="Support\Program.cs" /> <Compile Include="Support\Program.cs" />
<Compile Include="Sync.cs" /> <Compile Include="Sync.cs" />

View File

@@ -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;
}
}
}

View File

@@ -20,19 +20,7 @@ namespace OpenRA.Mods.Common.LoadScreens
{ {
public class BlankLoadScreen : ILoadScreen public class BlankLoadScreen : ILoadScreen
{ {
public class LaunchArgs public LaunchArguments Launch;
{
[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<string, string> info) { } public virtual void Init(Manifest m, Dictionary<string, string> info) { }
@@ -48,10 +36,7 @@ namespace OpenRA.Mods.Common.LoadScreens
public void StartGame(Arguments args) public void StartGame(Arguments args)
{ {
foreach (var f in Launch.GetType().GetFields()) Launch = new LaunchArguments(args);
if (args.Contains("Launch" + "." + f.Name))
FieldLoader.LoadField(Launch, f.Name, args.GetValue("Launch" + "." + f.Name, ""));
Ui.ResetAll(); Ui.ResetAll();
Game.Settings.Save(); Game.Settings.Save();
@@ -80,14 +65,7 @@ namespace OpenRA.Mods.Common.LoadScreens
} }
// Join a server directly // Join a server directly
var connect = string.Empty; var connect = Launch.GetConnectAddress();
if (!string.IsNullOrEmpty(Launch.Connect))
connect = Launch.Connect;
if (!string.IsNullOrEmpty(Launch.URI))
connect = Launch.URI.Replace("openra://", "").TrimEnd('/');
if (!string.IsNullOrEmpty(connect)) if (!string.IsNullOrEmpty(connect))
{ {
var parts = connect.Split(':'); var parts = connect.Split(':');

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
Console.WriteLine(".SH OPTIONS"); Console.WriteLine(".SH OPTIONS");
var sections = Game.Settings.Sections; 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)) foreach (var section in sections.OrderBy(s => s.Key))
{ {
var fields = section.Value.GetType().GetFields(); var fields = section.Value.GetType().GetFields();