add an opt-out setting to not write entity and brush number comment on map write
authorThomas Debesse <dev@illwieckz.net>
Sat, 5 May 2018 17:35:27 +0000 (19:35 +0200)
committerThomas Debesse <dev@illwieckz.net>
Tue, 2 Oct 2018 23:43:43 +0000 (01:43 +0200)
include/imap.h
plugins/mapq3/plugin.cpp
plugins/mapq3/write.cpp
plugins/mapq3/write.h
plugins/mapxml/plugin.cpp
radiant/map.cpp
radiant/referencecache.cpp

index 396627d..4661a79 100644 (file)
@@ -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;
 };
 
 
index 764b1d1..af04cea 100644 (file)
@@ -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
     {
     }
 };
index f37b5b0..9cf9c48 100644 (file)
@@ -63,9 +63,10 @@ class WriteTokensWalker : public scene::Traversable::Walker {
     mutable Stack<bool> 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));
 }
index 0fbfce0..fbc131c 100644 (file)
@@ -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
index fb85054..73bccb1 100644 (file)
@@ -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);
     }
index 9b8e7f9..6635265 100644 (file)
@@ -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<WindowPosition_String>(g_posMapInfoWnd));
+       GlobalPreferenceSystem().registerPreference("WriteMapComments", make_property_string(g_writeMapComments));
 
     PreferencesDialog_addSettingsPreferences(makeCallbackF(Map_constructPreferences));
 
index 448cd91..949eb55 100644 (file)
@@ -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;
     }