]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
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 396627d0226b126c5d1c9061f9fcbb9958fff976..4661a794768fb349f2bf3247aee9567dfbedfec9 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 764b1d140441e6be8d43348d66357d9b76ad35f4..af04cea37239148d48142016c0ab14264652bbc2 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 f37b5b03b076e18c79bd61dd7cda68543168013f..9cf9c48abfddb4349dc0a5e161a51a8387696880 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 0fbfce0ae9aef1c20db69cd6cf8d8e18725cb942..fbc131cf1211b312c679c3b1e808f0e9f918ea05 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 fb850543765efbb2bc20396ef3410b0b6c46fc3d..73bccb1745ede52d50c6e95649b8b13cf9fedfbf 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 9b8e7f90b0abc6d746480f34148aae6b7c35ce53..6635265417918242bdac1c47494e54b3568f8a56 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 448cd913c7054eef66e4dbf08124b9692ffd4c85..949eb55c9724d114ee8d136d523e30b11a333ba2 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;
     }