From e9769ad02f7c8c892578e24d3001489263ece727 Mon Sep 17 00:00:00 2001 From: Treeki Date: Wed, 6 Apr 2011 03:08:58 +0200 Subject: added a replace image command --- ConsoleApp/TextureCommands.cs | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'ConsoleApp/TextureCommands.cs') diff --git a/ConsoleApp/TextureCommands.cs b/ConsoleApp/TextureCommands.cs index 3fad0c7..834b32e 100644 --- a/ConsoleApp/TextureCommands.cs +++ b/ConsoleApp/TextureCommands.cs @@ -71,5 +71,54 @@ namespace ConsoleApp { + " texture-names is a list of textures. if not specified, every texture is exported."; } } + + + public class ReplaceImageCommand : ResFileCommand { + public ReplaceImageCommand() : base("replace image used for a texture") { + } + + protected override void OperateOnFile(string[] args) { + if (args.Length != 2) { + Console.WriteLine("invalid syntax.\n" + GetHelp(null)); + return; + } + + var texDict = TargetFile.GetTextureGroup(); + if (texDict == null || texDict.Count == 0) { + Console.WriteLine("this file has no textures."); + return; + } + + if (!texDict.ContainsKey(args[0])) { + Console.WriteLine("the specified texture [{0}] does not exist", args[0]); + return; + } + + var texture = texDict[args[0]]; + Console.WriteLine("texture {0}: {1} image(s)", args[0], texture.Images.Length); + + System.Drawing.Bitmap bitmap; + + try { + bitmap = new System.Drawing.Bitmap(args[1]); + } catch (Exception ex) { + Console.WriteLine("error reading image [{0}]:", args[1]); + Console.WriteLine(ex.ToString()); + return; + } + + texture.Images[0] = bitmap; + Console.WriteLine("replaced"); + + SaveFile(); + } + + public override string GetHelp(string[] args) { + return "syntax: replace-image \n" + + " replaces the image used by a texture.\n\n" + + " texture-name is the affected texture.\n" + + " image-filename is the image to replace it with (preferably a PNG)."; + } + } } -- cgit v1.2.3