summaryrefslogtreecommitdiff
path: root/ConsoleApp/Main.cs
blob: 580d398e763e924ff69cf88a075e2bc2bcb0f475 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Collections.Generic;

namespace ConsoleApp {
	class MainClass {
		private static Dictionary<string, Command> CommandLookup;

		private static void SetupCommands() {
			CommandLookup = new Dictionary<string, Command>();

			CommandLookup.Add("init", new InitCommand());
			CommandLookup.Add("list", new ListCommand());
			CommandLookup.Add("list-offsets", new ListOffsetsCommand());
			CommandLookup.Add("import-obj", new ImportObjCommand());
			CommandLookup.Add("export-obj", new ExportObjCommand());
			CommandLookup.Add("export-collada", new ExportColladaCommand());
			CommandLookup.Add("export-textures", new ExportTexturesCommand());
			CommandLookup.Add("replace-image", new ReplaceImageCommand());
			CommandLookup.Add("render-model", new RenderModelCommand());
		}

		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" };
			//System.IO.Directory.SetCurrentDirectory("/home/me/Games/Newer/ModelRev");
			//args = new string[] { "import-obj", "MMFullWorld.brres", "fullworld-Z19nvrc.obj", "WorldBase", "map" };


			Console.WriteLine("NW4RTools by Treeki");
			Console.WriteLine();

			SetupCommands();

			// process the command line
			string cmd;
			string[] cmdArgs;

			if (args.Length == 0) {
				cmd = "help";
				cmdArgs = new string[0];
			} else {
				cmd = args[0];
				cmdArgs = new string[args.Length - 1];

				for (int i = 1; i < args.Length; i++) {
					cmdArgs[i - 1] = args[i];
				}
			}

			// handle Help if needed
			if (cmd == "help") {
				Help(cmdArgs);
				return;
			}

			// otherwise, pass it on
			if (CommandLookup.ContainsKey(cmd)) {
				CommandLookup[cmd].Execute(cmdArgs);
			} else {
				Console.WriteLine("Unknown command {0}. Try \"help\" for a list of usable commands", cmd);
			}
		}

		private static void Help(string[] args) {
			if (args.Length == 0) {
				Console.WriteLine("Available commands:");

				foreach (var cmd in CommandLookup) {
					Console.WriteLine("- {0}: {1}", cmd.Key, cmd.Value.Description);
				}

				Console.WriteLine();
				Console.WriteLine("For additional info, try: help <command-name>");

			} else {
				if (CommandLookup.ContainsKey(args[0])) {
					Console.WriteLine("Help for {0}:", args[0]);
					string[] helpArgs = new string[args.Length - 1];

					for (int i = 1; i < args.Length; i++) {
						helpArgs[i - 1] = args[i];
					}

					Console.WriteLine(CommandLookup[args[0]].GetHelp(helpArgs));

				} else {
					Console.WriteLine("Unknown command {0}. Try \"help\" for a list of usable commands", args[0]);
				}
			}
		}
	}
}