diff options
Diffstat (limited to 'ConsoleApp/TextureCommands.cs')
| -rw-r--r-- | ConsoleApp/TextureCommands.cs | 75 | 
1 files changed, 75 insertions, 0 deletions
| diff --git a/ConsoleApp/TextureCommands.cs b/ConsoleApp/TextureCommands.cs new file mode 100644 index 0000000..3fad0c7 --- /dev/null +++ b/ConsoleApp/TextureCommands.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.IO; +using NW4RTools; + +namespace ConsoleApp { +	public class ExportTexturesCommand : ResFileCommand { +		public ExportTexturesCommand() : base("export texture(s) to PNG") { +		} + +		protected override void OperateOnFile(string[] args) { +			if (args.Length < 1) { +				Console.WriteLine("invalid syntax.\n" + GetHelp(null)); +				return; +			} + +			bool exportAll = (args.Length == 1); +			var list = new List<string>(); + +			for (int i = 1; i < args.Length; i++) { +				list.Add(args[i]); +			} + + +			var texDict = TargetFile.GetTextureGroup(); +			if (texDict == null || texDict.Count == 0) { +				Console.WriteLine("this file has no textures."); +				return; +			} + +			int exportCount = 0; +			 +			string currentDir = Directory.GetCurrentDirectory(); +			string imgDir = Path.Combine(currentDir, args[0]); + +			// one last check +			if (!Directory.Exists(imgDir)) { +				Console.WriteLine("the destination directory does not exist:\n  {0}", imgDir); +				return; +			} + +			foreach (var kv in texDict) { +				if (exportAll || list.Contains(kv.Key)) { +					for (int i = 0; i < kv.Value.Images.Length; i++) { +						var img = kv.Value.Images[i]; + +						string imgName; +						if (i == 0) { +							// first (possibly only?) mipmap +							imgName = String.Format("{0}.png", kv.Key); +						} else { +							imgName = String.Format("{0}__{1}.png", kv.Key, i); +						} + +						Console.WriteLine("{0}[{4}] {1}x{2} {3}", kv.Key, img.Width, img.Height, kv.Value.Format, i); + +						img.Save(Path.Combine(imgDir, imgName)); +					} + +					exportCount++; +				} +			} + +			Console.WriteLine("done! {0} textures exported", exportCount); +		} + +		public override string GetHelp(string[] args) { +			return "syntax: export-textures <brres-filename> <dest-path> [texture-names...]\n" +					+ "  exports texture(s) as .png files.\n\n" +					+ "  dest-path will be the folder in which the textures are placed (eg. images).\n" +					+ "  texture-names is a list of textures. if not specified, every texture is exported."; +		} +	} +} + | 
