summaryrefslogtreecommitdiff
path: root/ConsoleApp/TextureCommands.cs
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2011-04-06 03:08:58 +0200
committerTreeki <treeki@gmail.com>2011-04-06 03:08:58 +0200
commite9769ad02f7c8c892578e24d3001489263ece727 (patch)
tree4944089a67b7556670c9714934df1838a05971d8 /ConsoleApp/TextureCommands.cs
parentc3fe440719b4e9a3fb3f4debe28c16cd7c60d7de (diff)
downloadnw4rtools-e9769ad02f7c8c892578e24d3001489263ece727.tar.gz
nw4rtools-e9769ad02f7c8c892578e24d3001489263ece727.zip
added a replace image command
Diffstat (limited to 'ConsoleApp/TextureCommands.cs')
-rw-r--r--ConsoleApp/TextureCommands.cs49
1 files changed, 49 insertions, 0 deletions
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 <brres-filename> <texture-name> <image-filename>\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).";
+ }
+ }
}