Skip to content

Commit 4dfff27

Browse files
authored
Merge pull request #9 from CptWesley/program-parameters#3
Program parameters
2 parents 202c420 + e0d177d commit 4dfff27

2 files changed

Lines changed: 54 additions & 10 deletions

File tree

src/Brush.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ public static Brush CreateFromCode(string[] code)
2424
// Creates the needed clipping planes based on code.
2525
private static ClippingPlane[] CreateClippingPlanes(string[] code)
2626
{
27-
string pattern = @"(\(\s?-?\d+(\.\d+)?\s-?\d+(\.\d+)?\s-?\d+(\.\d+)?\s?\))\s?" // First vertex
28-
+ @"(\(\s?-?\d+(\.\d+)?\s-?\d+(\.\d+)?\s-?\d+(\.\d+)?\s?\))\s?" // Second vertex
29-
+ @"(\(\s?-?\d+(\.\d+)?\s-?\d+(\.\d+)?\s-?\d+(\.\d+)?\s?\))\s" // Third vertex
30-
+ @"(\w+(\/\S*)*)" // Texture
27+
string pattern = @"(\(\s?-?\d+(\.\d+)?\s-?\d+(\.\d+)?\s-?\d+(\.\d+)?\s?\))\s?" // First vertex [1]
28+
+ @"(\(\s?-?\d+(\.\d+)?\s-?\d+(\.\d+)?\s-?\d+(\.\d+)?\s?\))\s?" // Second vertex [5]
29+
+ @"(\(\s?-?\d+(\.\d+)?\s-?\d+(\.\d+)?\s-?\d+(\.\d+)?\s?\))\s" // Third vertex [9]
30+
+ @"(\w+(\/\S*)*)" // Texture [13]
3131
+ @".*"; // Leftovers
3232
Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
3333

src/Program.cs

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,42 @@
11
using System;
22
using System.IO;
33
using System.Reflection;
4+
using System.Text.RegularExpressions;
45

56
namespace RadiantMapToWavefrontObj
67
{
78
internal class Program
89
{
10+
private static double _scale = 0.01;
11+
private static bool _autoclose = false;
12+
913
static void Main(string[] args)
1014
{
1115
Version version = Assembly.GetExecutingAssembly().GetName().Version;
1216
Console.WriteLine("RadiantMapToWavefrontObj version " + version.Major + '.' + version.Minor + '.' + version.Build);
1317

14-
// Check if the file exists.
15-
if (args.Length > 0 && File.Exists(args[0]))
16-
ConvertFile(args[0]);
17-
else
18+
bool success = false;
19+
20+
// Check for each argument if it is a .map we should convert.
21+
foreach (string arg in args)
22+
{
23+
if (File.Exists(arg) && Path.GetExtension(arg) == ".map")
24+
{
25+
ConvertFile(arg);
26+
success = true;
27+
}
28+
else
29+
HandleArgument(arg);
30+
}
31+
32+
if (!success)
1833
Console.WriteLine("Invalid file.");
1934

2035
// Wait for console input before closing.
2136
Console.WriteLine("\nPress any key to close this window...");
22-
Console.ReadKey();
37+
38+
if (!_autoclose)
39+
Console.ReadKey();
2340
}
2441

2542
// Convert .map file to .obj file.
@@ -32,10 +49,37 @@ private static void ConvertFile(string path)
3249
RadiantMap map = RadiantMap.Parse(path);
3350
WavefrontObj obj = WavefrontObj.CreateFromRadiantMap(map);
3451

35-
obj.SaveFile(Path.GetFileNameWithoutExtension(path) + ".obj", 0.01);
52+
obj.SaveFile(Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path)) + ".obj", _scale);
3653

3754
DateTime endTime = DateTime.Now;
3855
Console.WriteLine("Finished in: " + (endTime-startTime).Milliseconds + "ms.");
3956
}
57+
58+
// Handle a settings argument.
59+
private static void HandleArgument(string arg)
60+
{
61+
string pattern = @"-(\w+)=(\w+)";
62+
Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
63+
Match m = regex.Match(arg);
64+
if (m.Success)
65+
{
66+
string type = m.Groups[1].ToString();
67+
string mode = m.Groups[2].ToString();
68+
69+
if (type == "autoclose")
70+
{
71+
if (mode == "false" || mode == "0")
72+
_autoclose = false;
73+
else if (mode == "true" || mode == "1")
74+
_autoclose = true;
75+
}
76+
else if (type == "scale")
77+
{
78+
double scale;
79+
if (Double.TryParse(mode, out scale))
80+
_scale = scale;
81+
}
82+
}
83+
}
4084
}
4185
}

0 commit comments

Comments
 (0)