C# TDFParser or TDF->XML

C# TDFParser or TDF->XML

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

C# TDFParser or TDF->XML

Post by AF »

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.
User avatar
SwiftSpear
Classic Community Lead
Posts: 7287
Joined: 12 Aug 2005, 09:29

Post by SwiftSpear »

You're asking for a parser that can read TDF files in C# format? Either that or a parser that parses TDF files to XML files? As far as I know one doesn't exist currently, although if someone were to take on the project it shouldn't explode you to try to write one...
User avatar
Maelstrom
Posts: 1950
Joined: 23 Jul 2005, 14:52

Post by Maelstrom »

Ive got a PHP script that loads TDF files into an associative array, so it should be very simple to get it to write it out as XML. Ill edit it and upload it somewhere, if its at all helpful
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

Look for the TA2Supcom tool (supremecommander.net), it has a C# TDF parser in it.
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Post by hughperkins »

Edit: answered a different question from the one being asked ;-)
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

well I'm not sure I can ask all the ppl who use my program to install and setup php.

Thanks jelmer.
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Post by hughperkins »

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:

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]);
                        }
                    }
                }
The code is under GPL at http://manageddreams.com/csai/TdfParser.cs
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

yaaaaaaaaay!!!

Image
Post Reply

Return to “Engine”