C# TDFParser or TDF->XML
Moderator: Moderators
C# TDFParser or TDF->XML
Does anybody have one of these? hughperkins uses xml parsers and xml config files, and OSRTS has c+ versions, which is a downer for me in a pure C# application.
- SwiftSpear
- Classic Community Lead
- Posts: 7287
- Joined: 12 Aug 2005, 09:29
- hughperkins
- AI Developer
- Posts: 836
- Joined: 17 Oct 2006, 04:14
- hughperkins
- AI Developer
- Posts: 836
- Joined: 17 Oct 2006, 04:14
I dunno if you found the download link for the TA2SupCom or managed to contact the owner to request it? It looked like it does what we need.
Anyway, lacking patience and not finding the download link, wrote a new parser. It handles UTF8, it's case insensitive, it has a hierarchy.
The following are all valid ways to use it:
The code is under GPL at http://manageddreams.com/csai/TdfParser.cs
Anyway, lacking patience and not finding the download link, wrote a new parser. It handles UTF8, it's case insensitive, it has a hierarchy.
The following are all valid ways to use it:
Code: Select all
TdfParser tdfparser = TdfParser.FromFile("maps/Whakamatunga_Riri.sm3");
Console.WriteLine(tdfparser.RootSection.SubSection("MaP").SubSection("atmosphere").GetStringValue("fogcolor"));
Console.WriteLine(tdfparser.RootSection.GetStringValue("mydefault","MaP/atmosphere/doesntexist"));
Console.WriteLine(tdfparser.RootSection.GetStringValue("MaP/atmosphere/fogcolor"));
Console.WriteLine(tdfparser.RootSection.GetStringValue("MaP\\atmosphere\\fogcolor"));
double fogstart = tdfparser.RootSection.GetDoubleValue("MaP\\atmosphere\\fogsTaRt");
Console.WriteLine(fogstart);
Console.WriteLine(tdfparser.RootSection.SubSection("MaP/atmosphere").GetStringValue("fogcolor"));
double[] doublearray = tdfparser.RootSection.SubSection("MaP").SubSection("Atmosphere").GetDoubleArray("FogColor");
foreach (double value in doublearray)
{
Console.WriteLine(value);
}
foreach (TdfParser.Section section in tdfparser.RootSection.SubSections.Values)
{
Console.WriteLine("Section: " + section.Name);
foreach (TdfParser.Section subsection in section.SubSections.Values)
{
Console.WriteLine(" subsection: " + subsection.Name);
foreach (string valuename in subsection.Values.Keys)
{
Console.WriteLine(" value " + valuename + " = " + subsection.Values[valuename]);
}
}
}