]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - plugins/mapxml/xmlwrite.cpp
- Updated UFA:Plugin (mattn2)
[xonotic/netradiant.git] / plugins / mapxml / xmlwrite.cpp
1 /*
2 Copyright (C) 2001-2006, William Joseph.
3 All Rights Reserved.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21
22 //
23 // writes xml tree format from internal objects
24 //
25
26 #include "xmlwrite.h"
27
28 #include "xml/xmlwriter.h"
29 #include "scenelib.h"
30 #include "entityxml.h"
31
32 inline XMLExporter* Node_getXMLExporter(scene::Node& node)
33 {
34   return NodeTypeCast<XMLExporter>::cast(node);
35 }
36
37
38 class write_all : public scene::Traversable::Walker
39 {
40   XMLImporter& m_importer;
41 public:
42   write_all(XMLImporter& importer) : m_importer(importer)
43   {
44   }
45   bool pre(scene::Node& node) const
46   {
47     Entity* entity = Node_getEntity(node);
48     if(entity != 0)
49     {
50       m_importer.write("\n", 1);
51       StaticElement element("entity");
52       m_importer.pushElement(element);
53       entity_export exporter(*entity);
54       exporter.exportXML(m_importer);
55     }
56     else
57     {
58       XMLExporter* exporter = Node_getXMLExporter(node);
59       if(exporter != 0)
60       {
61         m_importer.write("\n", 1);
62         exporter->exportXML(m_importer);
63         m_importer.write("\n", 1);
64       }
65     }
66     return true;
67   }
68   void post(scene::Node& node) const
69   {
70     if(Node_getEntity(node) != 0)
71     {
72       m_importer.write("\n", 1);
73       m_importer.popElement("entity");
74     }
75   }
76 };
77
78 void Map_Write(scene::Node& root, GraphTraversalFunc traverse, TextOutputStream& out)
79 {
80   XMLStreamWriter writer(out);
81   writer.write("\n", 1);
82   {
83     StaticElement element("mapq3");
84     writer.pushElement(element);
85
86     traverse(root, write_all(writer));
87
88     writer.write("\n", 1);
89     writer.popElement(element.name());
90   }
91 }