summaryrefslogtreecommitdiff
path: root/ConsoleApp/TextureCommands.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-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).";
+ }
+ }
}