| 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 | return NodeTypeCast<XMLExporter>::cast( node ); |
| 34 | } |
| 35 | |
| 36 | |
| 37 | class write_all : public scene::Traversable::Walker |
| 38 | { |
| 39 | XMLImporter& m_importer; |
| 40 | public: |
| 41 | write_all( XMLImporter& importer ) : m_importer( importer ){ |
| 42 | } |
| 43 | bool pre( scene::Node& node ) const { |
| 44 | Entity* entity = Node_getEntity( node ); |
| 45 | if ( entity != 0 ) { |
| 46 | m_importer.write( "\n", 1 ); |
| 47 | StaticElement element( "entity" ); |
| 48 | m_importer.pushElement( element ); |
| 49 | entity_export exporter( *entity ); |
| 50 | exporter.exportXML( m_importer ); |
| 51 | } |
| 52 | else |
| 53 | { |
| 54 | XMLExporter* exporter = Node_getXMLExporter( node ); |
| 55 | if ( exporter != 0 ) { |
| 56 | m_importer.write( "\n", 1 ); |
| 57 | exporter->exportXML( m_importer ); |
| 58 | m_importer.write( "\n", 1 ); |
| 59 | } |
| 60 | } |
| 61 | return true; |
| 62 | } |
| 63 | void post( scene::Node& node ) const { |
| 64 | if ( Node_getEntity( node ) != 0 ) { |
| 65 | m_importer.write( "\n", 1 ); |
| 66 | m_importer.popElement( "entity" ); |
| 67 | } |
| 68 | } |
| 69 | }; |
| 70 | |
| 71 | void Map_Write( scene::Node& root, GraphTraversalFunc traverse, TextOutputStream& out ){ |
| 72 | XMLStreamWriter writer( out ); |
| 73 | writer.write( "\n", 1 ); |
| 74 | { |
| 75 | StaticElement element( "mapdoom3" ); |
| 76 | writer.pushElement( element ); |
| 77 | |
| 78 | traverse( root, write_all( writer ) ); |
| 79 | |
| 80 | writer.write( "\n", 1 ); |
| 81 | writer.popElement( element.name() ); |
| 82 | } |
| 83 | } |