move legacy map import into the command line utility

closes #4368
This commit is contained in:
Matthias Mailänder
2013-12-28 22:10:04 +01:00
parent d20a47d37a
commit 50bc073791
7 changed files with 19 additions and 58 deletions

View File

@@ -85,8 +85,6 @@ namespace OpenRA.Editor
this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.redAlertMapToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.miniMapExport = new System.Windows.Forms.ToolStripMenuItem();
this.miniMapToPng = new System.Windows.Forms.ToolStripMenuItem();
this.fullMapRenderToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@@ -582,7 +580,6 @@ namespace OpenRA.Editor
this.saveToolStripMenuItem,
this.saveAsToolStripMenuItem,
this.toolStripSeparator2,
this.toolStripMenuItem1,
this.miniMapExport,
this.toolStripSeparator3,
this.exitToolStripMenuItem});
@@ -639,25 +636,6 @@ namespace OpenRA.Editor
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(120, 6);
//
// toolStripMenuItem1
//
this.toolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.redAlertMapToolStripMenuItem});
this.toolStripMenuItem1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripMenuItem1.Image")));
this.toolStripMenuItem1.ImageTransparentColor = System.Drawing.Color.Magenta;
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(123, 22);
this.toolStripMenuItem1.Text = "&Import";
//
// cCRedAlertMapToolStripMenuItem
//
this.redAlertMapToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("cCRedAlertMapToolStripMenuItem.Image")));
this.redAlertMapToolStripMenuItem.Name = "cCRedAlertMapToolStripMenuItem";
this.redAlertMapToolStripMenuItem.Size = new System.Drawing.Size(188, 22);
this.redAlertMapToolStripMenuItem.Text = "&Legacy Map Format...";
this.redAlertMapToolStripMenuItem.ToolTipText = "Import an original C&C / Red Alert and convert it to the .oramap format.";
this.redAlertMapToolStripMenuItem.Click += new System.EventHandler(this.ImportLegacyMapClicked);
//
// mnuExport
//
this.miniMapExport.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@@ -1097,8 +1075,6 @@ namespace OpenRA.Editor
private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem saveAsToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1;
private System.Windows.Forms.ToolStripMenuItem redAlertMapToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem miniMapExport;
private System.Windows.Forms.ToolStripMenuItem miniMapToPng;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;

View File

@@ -437,37 +437,6 @@ namespace OpenRA.Editor
Close();
}
void ImportLegacyMapClicked(object sender, EventArgs e)
{
using (var ofd = new OpenFileDialog { RestoreDirectory = true,
Filter = "Legacy maps (*.ini;*.mpr)|*.ini;*.mpr" })
if (DialogResult.OK == ofd.ShowDialog())
{
/* massive hack: we should be able to call NewMap() with the imported Map object,
* but something's not right internally in it, unless loaded via the real maploader */
var savePath = Path.Combine(Path.GetTempPath(), "OpenRA.Import");
Directory.CreateDirectory(savePath);
var errors = new List<string>();
var map = LegacyMapImporter.Import(ofd.FileName, a => errors.Add(a));
if (errors.Count > 0)
using (var eld = new ErrorListDialog(errors))
eld.ShowDialog();
map.MakeDefaultPlayers();
map.Save(savePath);
LoadMap(savePath);
loadedMapName = null; /* editor needs to think this hasnt been saved */
Directory.Delete(savePath, true);
MakeDirty();
}
}
void OnFormClosing(object sender, FormClosingEventArgs e)
{
if (!dirty) return;

View File

@@ -96,7 +96,6 @@
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="ITool.cs" />
<Compile Include="LegacyMapImporter.cs" />
<Compile Include="MapSelect.cs">
<SubType>Form</SubType>
</Compile>

View File

@@ -331,5 +331,20 @@ namespace OpenRA.Utility
Game.modData = new ModData(mod);
new Map(map, mod);
}
[Desc("MOD", "FILENAME", "Convert a legacy INI/MPR map to the OpenRA format.")]
public static void ImportLegacyMap(string[] args)
{
var mod = args[1];
var filename = args[2];
Game.modData = new ModData(mod);
Rules.LoadRules(Game.modData.Manifest, new Map());
var map = LegacyMapImporter.Import(filename, e => Console.WriteLine(e));
map.RequiresMod = mod;
map.MakeDefaultPlayers();
var dest = map.Title + ".oramap";
map.Save(dest);
Console.WriteLine(dest + " saved.");
}
}
}

View File

@@ -1,6 +1,6 @@
#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
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
@@ -18,7 +18,7 @@ using System.Text;
using OpenRA.FileFormats;
using OpenRA.Traits;
namespace OpenRA.Editor
namespace OpenRA.Utility
{
public class LegacyMapImporter
{

View File

@@ -77,6 +77,7 @@
<Compile Include="Command.cs" />
<Compile Include="Program.cs" />
<Compile Include="UpgradeRules.cs" />
<Compile Include="LegacyMapImporter.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -32,6 +32,7 @@ namespace OpenRA.Utility
{ "--map-upgrade-v5", Command.UpgradeV5Map },
{ "--upgrade-map", UpgradeRules.UpgradeMap },
{ "--upgrade-mod", UpgradeRules.UpgradeMod },
{ "--map-import", Command.ImportLegacyMap }
};
static void Main(string[] args)