2007-03-11 06:17:24 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
|
|
namespace VisualParamGenerator
|
|
|
|
|
{
|
|
|
|
|
class VisualParamGenerator
|
|
|
|
|
{
|
2007-03-31 22:49:25 +00:00
|
|
|
public static readonly System.Globalization.CultureInfo EnUsCulture =
|
|
|
|
|
new System.Globalization.CultureInfo("en-us");
|
|
|
|
|
|
2007-03-11 06:17:24 +00:00
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
2008-06-06 18:37:22 +00:00
|
|
|
if (args.Length < 2)
|
2007-03-11 06:17:24 +00:00
|
|
|
{
|
2008-06-06 18:37:22 +00:00
|
|
|
Console.WriteLine("Usage: VisualParamGenerator.exe [template.cs] [_VisualParams_.cs]");
|
2007-03-11 06:17:24 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (!File.Exists(args[0]))
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Couldn't find file " + args[0]);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XmlNodeList list;
|
|
|
|
|
TextWriter writer;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2008-06-06 18:37:22 +00:00
|
|
|
writer = new StreamWriter(args[1]);
|
2007-03-11 06:17:24 +00:00
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
2008-06-06 18:37:22 +00:00
|
|
|
Console.WriteLine("Couldn't open " + args[1] + " for writing");
|
2007-03-11 06:17:24 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Read in the template.cs file and write it to our output
|
2008-06-06 18:37:22 +00:00
|
|
|
TextReader reader = new StreamReader(args[0]);
|
2007-03-11 06:17:24 +00:00
|
|
|
writer.WriteLine(reader.ReadToEnd());
|
|
|
|
|
reader.Close();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
2008-06-06 18:37:22 +00:00
|
|
|
Console.WriteLine("Couldn't read from file " + args[0]);
|
2007-03-11 06:17:24 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2008-06-06 18:37:22 +00:00
|
|
|
// Read in avatar_lad.xml
|
2008-07-21 21:12:59 +00:00
|
|
|
Stream stream = OpenMetaverse.Helpers.GetResourceStream("avatar_lad.xml");
|
2008-06-06 18:37:22 +00:00
|
|
|
StreamReader reader = new StreamReader(stream);
|
|
|
|
|
|
|
|
|
|
if (stream != null)
|
|
|
|
|
{
|
|
|
|
|
XmlDocument doc = new XmlDocument();
|
|
|
|
|
doc.LoadXml(reader.ReadToEnd());
|
|
|
|
|
list = doc.GetElementsByTagName("param");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Failed to load resource avatar_lad.xml. Are you missing a data folder?");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2007-03-11 06:17:24 +00:00
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e.ToString());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SortedList<int, string> IDs = new SortedList<int, string>();
|
|
|
|
|
StringWriter output = new StringWriter();
|
|
|
|
|
|
2008-06-06 23:21:23 +00:00
|
|
|
// Make sure we end up with 218 Group-0 VisualParams as a sanity check
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
2007-03-11 06:17:24 +00:00
|
|
|
foreach (XmlNode node in list)
|
|
|
|
|
{
|
2008-06-06 23:21:23 +00:00
|
|
|
if (node.Attributes["group"] == null)
|
2007-03-11 06:17:24 +00:00
|
|
|
{
|
2008-06-06 23:21:23 +00:00
|
|
|
// Sanity check that a group is assigned
|
|
|
|
|
Console.WriteLine("Encountered a param with no group set!");
|
2007-03-11 06:17:24 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if ((node.Attributes["shared"] != null) && (node.Attributes["shared"].Value.Equals("1")))
|
|
|
|
|
{
|
|
|
|
|
// This param will have been already been defined
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2008-06-06 23:21:23 +00:00
|
|
|
if ((node.Attributes["edit_group"] == null))
|
2007-03-11 06:17:24 +00:00
|
|
|
{
|
|
|
|
|
// This param is calculated by the client based on other params
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Confirm this is a valid VisualParam
|
|
|
|
|
if (node.Attributes["id"] != null &&
|
2008-06-06 23:21:23 +00:00
|
|
|
node.Attributes["name"] != null)
|
2007-03-11 06:17:24 +00:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int id = Int32.Parse(node.Attributes["id"].Value);
|
|
|
|
|
|
|
|
|
|
// Check for duplicates
|
|
|
|
|
if (IDs.ContainsKey(id))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
string name = node.Attributes["name"].Value;
|
|
|
|
|
int group = Int32.Parse(node.Attributes["group"].Value);
|
2008-06-06 23:21:23 +00:00
|
|
|
|
|
|
|
|
string wearable = "null";
|
|
|
|
|
if (node.Attributes["wearable"] != null)
|
|
|
|
|
wearable = "\"" + node.Attributes["wearable"].Value + "\"";
|
2007-03-11 06:17:24 +00:00
|
|
|
|
2008-06-06 18:37:22 +00:00
|
|
|
string label = "String.Empty";
|
2007-03-11 06:17:24 +00:00
|
|
|
if (node.Attributes["label"] != null)
|
2008-06-06 18:37:22 +00:00
|
|
|
label = "\"" + node.Attributes["label"].Value + "\"";
|
2007-03-11 06:17:24 +00:00
|
|
|
|
2008-06-06 18:37:22 +00:00
|
|
|
string label_min = "String.Empty";
|
2007-03-11 06:17:24 +00:00
|
|
|
if (node.Attributes["label_min"] != null)
|
2008-06-06 18:37:22 +00:00
|
|
|
label_min = "\"" + node.Attributes["label_min"].Value + "\"";
|
2007-03-11 06:17:24 +00:00
|
|
|
|
2008-06-06 18:37:22 +00:00
|
|
|
string label_max = "String.Empty";
|
2007-03-11 06:17:24 +00:00
|
|
|
if (node.Attributes["label_max"] != null)
|
2008-06-06 18:37:22 +00:00
|
|
|
label_max = "\"" + node.Attributes["label_max"].Value + "\"";
|
2007-03-11 06:17:24 +00:00
|
|
|
|
2007-03-31 22:49:25 +00:00
|
|
|
float min = Single.Parse(node.Attributes["value_min"].Value,
|
|
|
|
|
System.Globalization.NumberStyles.Float, EnUsCulture.NumberFormat);
|
|
|
|
|
float max = Single.Parse(node.Attributes["value_max"].Value,
|
|
|
|
|
System.Globalization.NumberStyles.Float, EnUsCulture.NumberFormat);
|
2007-03-11 06:17:24 +00:00
|
|
|
|
|
|
|
|
float def;
|
|
|
|
|
if (node.Attributes["value_default"] != null)
|
2007-03-31 22:49:25 +00:00
|
|
|
def = Single.Parse(node.Attributes["value_default"].Value,
|
|
|
|
|
System.Globalization.NumberStyles.Float, EnUsCulture.NumberFormat);
|
2007-03-11 06:17:24 +00:00
|
|
|
else
|
|
|
|
|
def = min;
|
|
|
|
|
|
2008-06-06 23:21:23 +00:00
|
|
|
IDs.Add(id,
|
|
|
|
|
String.Format(" Params[{0}] = new VisualParam({0}, \"{1}\", {2}, {3}, {4}, {5}, {6}, {7}f, {8}f, {9}f);{10}",
|
|
|
|
|
id, name, group, wearable, label, label_min, label_max, def, min, max, Environment.NewLine));
|
|
|
|
|
|
|
|
|
|
if (group == 0)
|
|
|
|
|
++count;
|
2007-03-11 06:17:24 +00:00
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-06 23:21:23 +00:00
|
|
|
if (count != 218)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Ended up with the wrong number of Group-8 VisualParams! Exiting...");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-11 06:17:24 +00:00
|
|
|
// Now that we've collected all the entries and sorted them, add them to our output buffer
|
|
|
|
|
foreach (string line in IDs.Values)
|
|
|
|
|
{
|
|
|
|
|
output.Write(line);
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-06 23:21:23 +00:00
|
|
|
output.Write(" }" + Environment.NewLine);
|
2007-03-11 06:17:24 +00:00
|
|
|
output.Write(" }" + Environment.NewLine);
|
|
|
|
|
output.Write("}" + Environment.NewLine);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
writer.Write(output.ToString());
|
|
|
|
|
writer.Close();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|