mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-21 00:25:44 +00:00
Add AbstractTextDumper to implement stream holding and indendation
This commit is contained in:
parent
c9a0392fc1
commit
b48d55671e
28
src/ObjWriting/Dumping/AbstractTextDumper.cpp
Normal file
28
src/ObjWriting/Dumping/AbstractTextDumper.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include "AbstractTextDumper.h"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
AbstractTextDumper::AbstractTextDumper(std::ostream& stream)
|
||||||
|
: m_stream(stream),
|
||||||
|
m_indent(0u)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractTextDumper::Indent() const
|
||||||
|
{
|
||||||
|
for (auto i = 0u; i < m_indent; i++)
|
||||||
|
m_stream << " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractTextDumper::IncIndent()
|
||||||
|
{
|
||||||
|
++m_indent;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractTextDumper::DecIndent()
|
||||||
|
{
|
||||||
|
assert(m_indent > 0);
|
||||||
|
if (m_indent > 0)
|
||||||
|
m_indent--;
|
||||||
|
}
|
16
src/ObjWriting/Dumping/AbstractTextDumper.h
Normal file
16
src/ObjWriting/Dumping/AbstractTextDumper.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
|
class AbstractTextDumper
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
std::ostream& m_stream;
|
||||||
|
size_t m_indent;
|
||||||
|
|
||||||
|
void Indent() const;
|
||||||
|
void IncIndent();
|
||||||
|
void DecIndent();
|
||||||
|
|
||||||
|
explicit AbstractTextDumper(std::ostream& stream);
|
||||||
|
};
|
@ -2,8 +2,8 @@
|
|||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
StringFileDumper::StringFileDumper(Zone* zone, std::ostream& stream)
|
StringFileDumper::StringFileDumper(Zone* zone, std::ostream& stream)
|
||||||
: m_zone(zone),
|
: AbstractTextDumper(stream),
|
||||||
m_stream(stream),
|
m_zone(zone),
|
||||||
m_language_caps("ENGLISH"),
|
m_language_caps("ENGLISH"),
|
||||||
m_wrote_header(false)
|
m_wrote_header(false)
|
||||||
{
|
{
|
||||||
@ -42,7 +42,7 @@ void StringFileDumper::WriteLocalizeEntry(const std::string& reference, const st
|
|||||||
WriteHeader();
|
WriteHeader();
|
||||||
|
|
||||||
m_stream << "\n";
|
m_stream << "\n";
|
||||||
m_stream << "REFERENCE " << reference <<"\n";
|
m_stream << "REFERENCE " << reference << "\n";
|
||||||
|
|
||||||
auto escapedValue = std::regex_replace(value, std::regex("\n"), "\\n");
|
auto escapedValue = std::regex_replace(value, std::regex("\n"), "\\n");
|
||||||
escapedValue = std::regex_replace(escapedValue, std::regex("\r"), "\\r");
|
escapedValue = std::regex_replace(escapedValue, std::regex("\r"), "\\r");
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ostream>
|
#include "Dumping/AbstractTextDumper.h"
|
||||||
|
|
||||||
#include "Zone/Zone.h"
|
#include "Zone/Zone.h"
|
||||||
|
|
||||||
class StringFileDumper
|
class StringFileDumper : AbstractTextDumper
|
||||||
{
|
{
|
||||||
Zone* m_zone;
|
Zone* m_zone;
|
||||||
std::ostream& m_stream;
|
|
||||||
|
|
||||||
std::string m_config_file;
|
std::string m_config_file;
|
||||||
std::string m_notes;
|
std::string m_notes;
|
||||||
|
@ -32,32 +32,13 @@ MapFileDumper::PhysicsCylinder::PhysicsCylinder(const Vec3 middlePoint, const fl
|
|||||||
}
|
}
|
||||||
|
|
||||||
MapFileDumper::MapFileDumper(std::ostream& stream)
|
MapFileDumper::MapFileDumper(std::ostream& stream)
|
||||||
: m_stream(stream),
|
: AbstractTextDumper(stream),
|
||||||
m_flags{},
|
m_flags{},
|
||||||
m_indent(0u),
|
|
||||||
m_entity_index(0u),
|
m_entity_index(0u),
|
||||||
m_brush_index(0u)
|
m_brush_index(0u)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapFileDumper::Indent() const
|
|
||||||
{
|
|
||||||
for (auto i = 0u; i < m_indent; i++)
|
|
||||||
m_stream << " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
void MapFileDumper::IncIndent()
|
|
||||||
{
|
|
||||||
++m_indent;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MapFileDumper::DecIndent()
|
|
||||||
{
|
|
||||||
assert(m_indent > 0);
|
|
||||||
if (m_indent > 0)
|
|
||||||
m_indent--;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MapFileDumper::Init() const
|
void MapFileDumper::Init() const
|
||||||
{
|
{
|
||||||
m_stream << "iwmap 4\n";
|
m_stream << "iwmap 4\n";
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
class MapFileDumper
|
#include "Dumping/AbstractTextDumper.h"
|
||||||
|
|
||||||
|
class MapFileDumper : AbstractTextDumper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
union Vec3
|
union Vec3
|
||||||
@ -13,6 +15,7 @@ public:
|
|||||||
float m_y;
|
float m_y;
|
||||||
float m_z;
|
float m_z;
|
||||||
};
|
};
|
||||||
|
|
||||||
float v[3];
|
float v[3];
|
||||||
|
|
||||||
Vec3(float x, float y, float z);
|
Vec3(float x, float y, float z);
|
||||||
@ -39,21 +42,15 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::ostream& m_stream;
|
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
bool m_in_entity : 1;
|
bool m_in_entity : 1;
|
||||||
bool m_in_brush : 1;
|
bool m_in_brush : 1;
|
||||||
} m_flags;
|
} m_flags;
|
||||||
size_t m_indent;
|
|
||||||
size_t m_entity_index;
|
size_t m_entity_index;
|
||||||
size_t m_brush_index;
|
size_t m_brush_index;
|
||||||
|
|
||||||
void Indent() const;
|
|
||||||
void IncIndent();
|
|
||||||
void DecIndent();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MapFileDumper(std::ostream& stream);
|
explicit MapFileDumper(std::ostream& stream);
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ SndCurveDumper::SndCurveDumper(std::ostream& stream)
|
|||||||
}
|
}
|
||||||
|
|
||||||
SndCurveDumper::SndCurveDumper(std::ostream& stream, const size_t precision)
|
SndCurveDumper::SndCurveDumper(std::ostream& stream, const size_t precision)
|
||||||
: m_stream(stream),
|
: AbstractTextDumper(stream),
|
||||||
m_precision(precision),
|
m_precision(precision),
|
||||||
m_current_knot(0u),
|
m_current_knot(0u),
|
||||||
m_total_knots(0u)
|
m_total_knots(0u)
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
class SndCurveDumper
|
#include "Dumping/AbstractTextDumper.h"
|
||||||
|
|
||||||
|
class SndCurveDumper : AbstractTextDumper
|
||||||
{
|
{
|
||||||
static constexpr auto DEFAULT_PRECISION = 4;
|
static constexpr auto DEFAULT_PRECISION = 4;
|
||||||
|
|
||||||
std::ostream& m_stream;
|
|
||||||
size_t m_precision;
|
size_t m_precision;
|
||||||
size_t m_current_knot;
|
size_t m_current_knot;
|
||||||
size_t m_total_knots;
|
size_t m_total_knots;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user