wire up the import from PNG to SHP button

store everything in user directory to not junk up the game
and for file permissions on Mac/Linux when installed
This commit is contained in:
Matthias Mailänder
2013-04-29 11:58:45 +02:00
parent 8f822f6cad
commit 6262aa846f
9 changed files with 101 additions and 51 deletions

View File

@@ -55,7 +55,7 @@ namespace OpenRA.Utility
ShpWriter.Write(destStream, width, srcImage.Height,
srcImage.ToFrames(width));
Console.WriteLine(dest+" saved");
Console.WriteLine(dest+" saved.");
}
static IEnumerable<byte[]> ToFrames(this Bitmap bitmap, int width)
@@ -108,10 +108,11 @@ namespace OpenRA.Utility
x += srcImage.Width;
bitmap.UnlockBits( data );
bitmap.UnlockBits(data);
}
bitmap.Save(dest);
Console.WriteLine(dest+" saved");
}
}
@@ -348,8 +349,8 @@ namespace OpenRA.Utility
if (template.Value == null)
throw new InvalidOperationException("No such template '{0}'".F(templateName));
using( var image = tileset.RenderTemplate(template.Value.Id, palette) )
image.Save( Path.ChangeExtension( templateName, ".png" ) );
using (var image = tileset.RenderTemplate(template.Value.Id, palette))
image.Save(Path.ChangeExtension(templateName, ".png"));
}
}
@@ -359,17 +360,17 @@ namespace OpenRA.Utility
var dest = args[2];
Dune2ShpReader srcImage = null;
using( var s = File.OpenRead( src ) )
using(var s = File.OpenRead(src))
srcImage = new Dune2ShpReader(s);
var size = srcImage.First().Size;
if (!srcImage.All( im => im.Size == size ))
if (!srcImage.All(im => im.Size == size))
throw new InvalidOperationException("All the frames must be the same size to convert from Dune2 to RA");
using( var destStream = File.Create(dest) )
using (var destStream = File.Create(dest))
ShpWriter.Write(destStream, size.Width, size.Height,
srcImage.Select( im => im.Image ));
srcImage.Select(im => im.Image));
}
public static void ExtractFiles(string[] args)
@@ -380,14 +381,18 @@ namespace OpenRA.Utility
var manifest = new Manifest(mods);
FileSystem.LoadFromManifest(manifest);
foreach( var f in files )
foreach (var f in files)
{
if (f == "--userdir")
break;
var src = FileSystem.Open(f);
if (src == null)
throw new InvalidOperationException("File not found: {0}".F(f));
var data = src.ReadAllBytes();
File.WriteAllBytes( f, data );
var output = args.Contains("--userdir") ? Platform.SupportDir+f : f;
File.WriteAllBytes(output, data);
Console.WriteLine(output+" saved.");
}
}

View File

@@ -60,7 +60,7 @@ namespace OpenRA.Utility
Console.WriteLine(" --shp PNGFILE FRAMEWIDTH Convert a single PNG with multiple frames appended after another to a SHP");
Console.WriteLine(" --png SHPFILE PALETTE [--noshadow] Convert a SHP to a PNG containing all of its frames, optionally removing the shadow");
Console.WriteLine(" --fromd2 DUNE2SHP C&CSHP Convert a Dune II SHP (C&C mouse cursor) to C&C SHP format.");
Console.WriteLine(" --extract MOD[,MOD]* FILES Extract files from mod packages");
Console.WriteLine(" --extract MOD[,MOD]* FILES [--userdir] Extract files from mod packages to the current (or user) directory");
Console.WriteLine(" --tmp-png MOD[,MOD]* THEATER FILES Extract terrain tiles to PNG");
Console.WriteLine(" --remap SRCMOD:PAL DESTMOD:PAL SRCSHP DESTSHP Remap SHPs to another palette");
Console.WriteLine(" --r8 R8FILE PALETTE START END FILENAME [--noshadow] [--infrantry] [--vehicle] [--projectile] [--building] [--wall] [--tileset] Convert Dune 2000 DATA.R8 to PNGs choosing start- and endframe as well as type for correct offset to append multiple frames to one PNG named by filename optionally removing the shadow.");