Commit c750e332 authored by Thomas Debesse's avatar Thomas Debesse

Merge branch 'illwieckz/nonumbers' fix !95

parents 2814f078 bfc92dde
......@@ -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;
};
......
......@@ -28,7 +28,8 @@ class SimpleTokenWriter : public TokenWriter
{
public:
SimpleTokenWriter( TextOutputStream& ostream )
: m_ostream( ostream ), m_separator( '\n' ){
// HACK: \0 separator is used to tell we are at beginning of file
: m_ostream( ostream ), m_separator( '\0' ){
}
~SimpleTokenWriter(){
writeSeparator();
......@@ -63,7 +64,10 @@ void writeFloat( double f ){
private:
void writeSeparator(){
m_ostream << m_separator;
// HACK: do not write separator at beginning of file
if (m_separator != '\0') {
m_ostream << m_separator;
}
m_separator = ' ';
}
TextOutputStream& m_ostream;
......
......@@ -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
{
}
};
......
......@@ -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));
}
......@@ -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
......@@ -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);
}
......
......@@ -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)
......@@ -2295,7 +2297,8 @@ void DoFind()
void Map_constructPreferences(PreferencesPage &page)
{
page.appendCheckBox("", "Load last map on open", g_bLoadLastMap);
page.appendCheckBox("", "Load last map at startup", 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));
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment