Merge pull request #4234 from Mailaender/minimap-utility

Added a minimap renderer to OpenRA.Utility.exe
This commit is contained in:
Paul Chote
2013-12-06 11:52:19 -08:00
4 changed files with 34 additions and 13 deletions

View File

@@ -113,7 +113,7 @@ namespace OpenRA.Graphics
{ {
var mapX = x + map.Bounds.Left; var mapX = x + map.Bounds.Left;
var mapY = y + map.Bounds.Top; var mapY = y + map.Bounds.Top;
var custom = map.CustomTerrain[mapX,mapY]; var custom = map.CustomTerrain[mapX, mapY];
if (custom == null) if (custom == null)
continue; continue;
*(c + (y * bitmapData.Stride >> 2) + x) = world.TileSet.Terrain[custom].Color.ToArgb(); *(c + (y * bitmapData.Stride >> 2) + x) = world.TileSet.Terrain[custom].Color.ToArgb();
@@ -185,9 +185,9 @@ namespace OpenRA.Graphics
return bitmap; return bitmap;
} }
public static Bitmap RenderMapPreview(Map map) public static Bitmap RenderMapPreview(Map map, bool actualSize)
{ {
Bitmap terrain = TerrainBitmap(map); Bitmap terrain = TerrainBitmap(map, actualSize);
return AddStaticResources(map, terrain); return AddStaticResources(map, terrain);
} }
} }

View File

@@ -170,7 +170,7 @@ namespace OpenRA.Widgets
uid = cacheUids.Peek(); uid = cacheUids.Peek();
} }
var bitmap = Minimap.RenderMapPreview(Game.modData.AvailableMaps[uid]); var bitmap = Minimap.RenderMapPreview(Game.modData.AvailableMaps[uid], false);
lock (syncRoot) lock (syncRoot)
{ {
// TODO: We should add previews to a sheet here (with multiple previews per sheet) // TODO: We should add previews to a sheet here (with multiple previews per sheet)

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2012 The OpenRA Developers (see AUTHORS) * Copyright 2007-2012 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
@@ -286,12 +286,31 @@ namespace OpenRA.Utility
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("```"); Console.WriteLine("```");
} }
public static void GetMapHash(string[] args) public static void GetMapHash(string[] args)
{ {
var result = new Map(args[1]).Uid; var result = new Map(args[1]).Uid;
Console.WriteLine(result); Console.WriteLine(result);
}
public static void GenerateMinimap(string[] args)
{
var map = new Map(args[1]);
var mod = args.Length > 1 ? args[2] : map.RequiresMod;
Game.modData = new ModData(mod);
FileSystem.UnmountAll();
foreach (var dir in Game.modData.Manifest.Folders)
FileSystem.Mount(dir);
Rules.LoadRules(Game.modData.Manifest, map);
var minimap = Minimap.RenderMapPreview(map, true);
var dest = Path.GetFileNameWithoutExtension(args[1]) + ".png";
minimap.Save(dest);
Console.WriteLine(dest + " saved.");
} }
} }
} }

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2012 The OpenRA Developers (see AUTHORS) * Copyright 2007-2012 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
@@ -28,6 +28,7 @@ namespace OpenRA.Utility
{ "--transpose", Command.TransposeShp }, { "--transpose", Command.TransposeShp },
{ "--docs", Command.ExtractTraitDocs }, { "--docs", Command.ExtractTraitDocs },
{ "--map-hash", Command.GetMapHash }, { "--map-hash", Command.GetMapHash },
{ "--minimap", Command.GenerateMinimap },
}; };
if (args.Length == 0) { PrintUsage(); return; } if (args.Length == 0) { PrintUsage(); return; }
@@ -60,8 +61,9 @@ namespace OpenRA.Utility
Console.WriteLine(" --extract MOD[,MOD]* FILES Extract files from mod packages to the current directory"); Console.WriteLine(" --extract MOD[,MOD]* FILES Extract files from mod packages to the current directory");
Console.WriteLine(" --remap SRCMOD:PAL DESTMOD:PAL SRCSHP DESTSHP Remap SHPs to another palette"); Console.WriteLine(" --remap SRCMOD:PAL DESTMOD:PAL SRCSHP DESTSHP Remap SHPs to another palette");
Console.WriteLine(" --transpose SRCSHP DESTSHP START N M [START N M ...] Transpose the N*M block of frames starting at START."); Console.WriteLine(" --transpose SRCSHP DESTSHP START N M [START N M ...] Transpose the N*M block of frames starting at START.");
Console.WriteLine(" --docs MOD Generate trait documentation in MarkDown format."); Console.WriteLine(" --docs MOD Generate trait documentation in MarkDown format.");
Console.WriteLine(" --map-hash MAPFILE Generate hash of specified oramap file."); Console.WriteLine(" --map-hash MAPFILE Generate hash of specified oramap file.");
Console.WriteLine(" --minimap MAPFILE [MOD] Render PNG minimap of specified oramap file.");
} }
static string GetNamedArg(string[] args, string arg) static string GetNamedArg(string[] args, string arg)