From: Thomas Debesse Date: Sat, 5 May 2018 17:35:27 +0000 (+0200) Subject: add an opt-out setting to not write entity and brush number comment on map write X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=ab35d2859c400749e32f801ad8cc5284ac0a0078;p=xonotic%2Fnetradiant.git add an opt-out setting to not write entity and brush number comment on map write --- diff --git a/include/imap.h b/include/imap.h index 396627d0..4661a794 100644 --- a/include/imap.h +++ b/include/imap.h @@ -67,7 +67,7 @@ mutable bool wrongFormat; /// \brief Read a map graph into \p root from \p outputStream, using \p entityTable to create entities. virtual void readGraph( scene::Node& root, TextInputStream& inputStream, EntityCreator& entityTable ) const = 0; /// \brief Write the map graph obtained by applying \p traverse to \p root into \p outputStream. -virtual void writeGraph( scene::Node& root, GraphTraversalFunc traverse, TextOutputStream& outputStream ) const = 0; +virtual void writeGraph( scene::Node& root, GraphTraversalFunc traverse, TextOutputStream& outputStream, bool writeComments ) const = 0; }; diff --git a/plugins/mapq3/plugin.cpp b/plugins/mapq3/plugin.cpp index 764b1d14..af04cea3 100644 --- a/plugins/mapq3/plugin.cpp +++ b/plugins/mapq3/plugin.cpp @@ -129,13 +129,13 @@ public: tokeniser.release(); } - void writeGraph(scene::Node &root, GraphTraversalFunc traverse, TextOutputStream &outputStream) const + void writeGraph(scene::Node &root, GraphTraversalFunc traverse, TextOutputStream &outputStream, bool writeComments) const { TokenWriter &writer = GlobalScripLibModule::getTable().m_pfnNewSimpleTokenWriter(outputStream); writer.writeToken("Version"); writer.writeInteger(MapVersion()); writer.nextLine(); - Map_Write(root, traverse, writer, false); + Map_Write(root, traverse, writer, false, writeComments); writer.release(); } }; @@ -208,13 +208,13 @@ public: tokeniser.release(); } - void writeGraph(scene::Node &root, GraphTraversalFunc traverse, TextOutputStream &outputStream) const + void writeGraph(scene::Node &root, GraphTraversalFunc traverse, TextOutputStream &outputStream, bool writeComments) const { TokenWriter &writer = GlobalScripLibModule::getTable().m_pfnNewSimpleTokenWriter(outputStream); writer.writeToken("Version"); writer.writeInteger(MapVersion()); writer.nextLine(); - Map_Write(root, traverse, writer, false); + Map_Write(root, traverse, writer, false, writeComments); writer.release(); } }; @@ -312,10 +312,10 @@ public: tokeniser.release(); } - void writeGraph(scene::Node &root, GraphTraversalFunc traverse, TextOutputStream &outputStream) const + void writeGraph(scene::Node &root, GraphTraversalFunc traverse, TextOutputStream &outputStream, bool writeComments) const { TokenWriter &writer = GlobalScripLibModule::getTable().m_pfnNewSimpleTokenWriter(outputStream); - Map_Write(root, traverse, writer, false); + Map_Write(root, traverse, writer, false, writeComments); writer.release(); } }; @@ -363,10 +363,10 @@ public: tokeniser.release(); } - void writeGraph(scene::Node &root, GraphTraversalFunc traverse, TextOutputStream &outputStream) const + void writeGraph(scene::Node &root, GraphTraversalFunc traverse, TextOutputStream &outputStream, bool writeComments) const { TokenWriter &writer = GlobalScripLibModule::getTable().m_pfnNewSimpleTokenWriter(outputStream); - Map_Write(root, traverse, writer, true); + Map_Write(root, traverse, writer, true, writeComments); writer.release(); } }; @@ -414,10 +414,10 @@ public: tokeniser.release(); } - void writeGraph(scene::Node &root, GraphTraversalFunc traverse, TextOutputStream &outputStream) const + void writeGraph(scene::Node &root, GraphTraversalFunc traverse, TextOutputStream &outputStream, bool writeComments) const { TokenWriter &writer = GlobalScripLibModule::getTable().m_pfnNewSimpleTokenWriter(outputStream); - Map_Write(root, traverse, writer, true); + Map_Write(root, traverse, writer, true, writeComments); writer.release(); } }; @@ -465,10 +465,10 @@ public: tokeniser.release(); } - void writeGraph(scene::Node &root, GraphTraversalFunc traverse, TextOutputStream &outputStream) const + void writeGraph(scene::Node &root, GraphTraversalFunc traverse, TextOutputStream &outputStream, bool writeComments) const { TokenWriter &writer = GlobalScripLibModule::getTable().m_pfnNewSimpleTokenWriter(outputStream); - Map_Write(root, traverse, writer, true); + Map_Write(root, traverse, writer, true, writeComments); writer.release(); } }; @@ -641,7 +641,7 @@ public: tokeniser.release(); } - void writeGraph(scene::Node &root, GraphTraversalFunc traverse, TextOutputStream &outputStream) const + void writeGraph(scene::Node &root, GraphTraversalFunc traverse, TextOutputStream &outputStream, bool writeComments) const { } }; diff --git a/plugins/mapq3/write.cpp b/plugins/mapq3/write.cpp index f37b5b03..9cf9c48a 100644 --- a/plugins/mapq3/write.cpp +++ b/plugins/mapq3/write.cpp @@ -63,9 +63,10 @@ class WriteTokensWalker : public scene::Traversable::Walker { mutable Stack m_stack; TokenWriter &m_writer; bool m_ignorePatches; + bool m_writeComments; public: - WriteTokensWalker(TokenWriter &writer, bool ignorePatches) - : m_writer(writer), m_ignorePatches(ignorePatches) + WriteTokensWalker(TokenWriter &writer, bool ignorePatches, bool writeComments) + : m_writer(writer), m_ignorePatches(ignorePatches), m_writeComments(writeComments) { } @@ -75,10 +76,12 @@ public: Entity *entity = Node_getEntity(node); if (entity != 0) { - m_writer.writeToken("//"); - m_writer.writeToken("entity"); - m_writer.writeUnsigned(g_count_entities++); - m_writer.nextLine(); + if (m_writeComments) { + m_writer.writeToken("//"); + m_writer.writeToken("entity"); + m_writer.writeUnsigned(g_count_entities++); + m_writer.nextLine(); + } m_writer.writeToken("{"); m_writer.nextLine(); @@ -89,10 +92,12 @@ public: MapExporter *exporter = Node_getMapExporter(node); if (exporter != 0 && !(m_ignorePatches && Node_isPatch(node))) { - m_writer.writeToken("//"); - m_writer.writeToken("brush"); - m_writer.writeUnsigned(g_count_brushes++); - m_writer.nextLine(); + if (m_writeComments) { + m_writer.writeToken("//"); + m_writer.writeToken("brush"); + m_writer.writeUnsigned(g_count_brushes++); + m_writer.nextLine(); + } exporter->exportTokens(m_writer); } @@ -111,8 +116,8 @@ public: } }; -void Map_Write(scene::Node &root, GraphTraversalFunc traverse, TokenWriter &writer, bool ignorePatches) +void Map_Write(scene::Node &root, GraphTraversalFunc traverse, TokenWriter &writer, bool ignorePatches, bool writeComments) { g_count_entities = 0; - traverse(root, WriteTokensWalker(writer, ignorePatches)); + traverse(root, WriteTokensWalker(writer, ignorePatches, writeComments)); } diff --git a/plugins/mapq3/write.h b/plugins/mapq3/write.h index 0fbfce0a..fbc131cf 100644 --- a/plugins/mapq3/write.h +++ b/plugins/mapq3/write.h @@ -24,6 +24,6 @@ #include "imap.h" -void Map_Write(scene::Node &root, GraphTraversalFunc traverse, TokenWriter &writer, bool ignorePatches); +void Map_Write(scene::Node &root, GraphTraversalFunc traverse, TokenWriter &writer, bool ignorePatches, bool writeComments); #endif diff --git a/plugins/mapxml/plugin.cpp b/plugins/mapxml/plugin.cpp index fb850543..73bccb17 100644 --- a/plugins/mapxml/plugin.cpp +++ b/plugins/mapxml/plugin.cpp @@ -86,7 +86,7 @@ public: Map_Read(root, inputStream, entityTable); } - void writeGraph(scene::Node &root, GraphTraversalFunc traverse, TextOutputStream &outputStream) const + void writeGraph(scene::Node &root, GraphTraversalFunc traverse, TextOutputStream &outputStream, bool writeComments) const { Map_Write(root, traverse, outputStream); } diff --git a/radiant/map.cpp b/radiant/map.cpp index 9b8e7f90..66352654 100644 --- a/radiant/map.cpp +++ b/radiant/map.cpp @@ -87,6 +87,8 @@ MapModules &ReferenceAPI_getMapModules(); #include "brushmodule.h" #include "brush.h" +bool g_writeMapComments = true; + class NameObserver { UniqueNames &m_names; CopiedString m_name; @@ -1215,7 +1217,7 @@ void Map_Traverse_Selected(scene::Node &root, const scene::Traversable::Walker & void Map_ExportSelected(TextOutputStream &out, const MapFormat &format) { - format.writeGraph(GlobalSceneGraph().root(), Map_Traverse_Selected, out); + format.writeGraph(GlobalSceneGraph().root(), Map_Traverse_Selected, out, g_writeMapComments); } void Map_Traverse(scene::Node &root, const scene::Traversable::Walker &walker) @@ -2296,6 +2298,7 @@ void DoFind() void Map_constructPreferences(PreferencesPage &page) { page.appendCheckBox("", "Load last map on open", g_bLoadLastMap); + page.appendCheckBox("", "Add entity and brush number comments on map write", g_writeMapComments); } @@ -2373,6 +2376,7 @@ void Map_Construct() GlobalPreferenceSystem().registerPreference("LastMap", make_property_string(g_strLastMap)); GlobalPreferenceSystem().registerPreference("LoadLastMap", make_property_string(g_bLoadLastMap)); GlobalPreferenceSystem().registerPreference("MapInfoDlg", make_property(g_posMapInfoWnd)); + GlobalPreferenceSystem().registerPreference("WriteMapComments", make_property_string(g_writeMapComments)); PreferencesDialog_addSettingsPreferences(makeCallbackF(Map_constructPreferences)); diff --git a/radiant/referencecache.cpp b/radiant/referencecache.cpp index 448cd913..949eb55c 100644 --- a/radiant/referencecache.cpp +++ b/radiant/referencecache.cpp @@ -59,6 +59,7 @@ ModelModules &ReferenceAPI_getModelModules(); #include "map.h" #include "filetypes.h" +extern bool g_writeMapComments; bool References_Saved(); @@ -110,7 +111,7 @@ bool MapResource_saveFile(const MapFormat &format, scene::Node &root, GraphTrave if (!file.failed()) { globalOutputStream() << "success\n"; ScopeDisableScreenUpdates disableScreenUpdates(path_get_filename_start(filename), "Saving Map"); - format.writeGraph(root, traverse, file); + format.writeGraph(root, traverse, file, g_writeMapComments); return true; }