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/ConsoleApp.pidb | Bin 0 -> 10847 bytes ConsoleApp/Main.cs | 8 ++++++- ConsoleApp/TextureCommands.cs | 49 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 ConsoleApp/ConsoleApp.pidb diff --git a/ConsoleApp/ConsoleApp.pidb b/ConsoleApp/ConsoleApp.pidb new file mode 100644 index 0000000..0683120 Binary files /dev/null and b/ConsoleApp/ConsoleApp.pidb differ diff --git a/ConsoleApp/Main.cs b/ConsoleApp/Main.cs index 9a180f6..56f2a8d 100644 --- a/ConsoleApp/Main.cs +++ b/ConsoleApp/Main.cs @@ -15,9 +15,16 @@ namespace ConsoleApp { CommandLookup.Add("export-obj", new ExportObjCommand()); CommandLookup.Add("export-collada", new ExportColladaCommand()); CommandLookup.Add("export-textures", new ExportTexturesCommand()); + CommandLookup.Add("replace-image", new ReplaceImageCommand()); } public static void Main(string[] args) { + // Debugging BS + //args = new string[] { "list", "/home/me/Dropbox/NEWERsmbw/bigbrick/big_renga_block.brres" }; + //System.IO.Directory.SetCurrentDirectory("/home/me/Games/Newer/CGround"); + //args = new string[] { "export-collada", "regular.brres", "large.dae", "circle_ground_L" }; + + Console.WriteLine("NW4RTools by Treeki"); Console.WriteLine(); @@ -82,4 +89,3 @@ namespace ConsoleApp { } } } - 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