summaryrefslogtreecommitdiff
path: root/src/mg_schematic.cpp
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2015-05-07 02:54:30 -0400
committerkwolekr <kwolekr@minetest.net>2015-05-07 02:54:35 -0400
commitb246812455737b2d0337dec905ba0256adefd105 (patch)
treecea90089c81f83011895a19e60d194c92379766b /src/mg_schematic.cpp
parent656575b59d4f0d67452cca7409c9064f690f038c (diff)
downloadminetest-b246812455737b2d0337dec905ba0256adefd105.tar.gz
minetest-b246812455737b2d0337dec905ba0256adefd105.tar.bz2
minetest-b246812455737b2d0337dec905ba0256adefd105.zip
Schematics: Add indent-with-space option for schematic Lua table serialization
Diffstat (limited to 'src/mg_schematic.cpp')
-rw-r--r--src/mg_schematic.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/mg_schematic.cpp b/src/mg_schematic.cpp
index 3100637ae..bea08ef12 100644
--- a/src/mg_schematic.cpp
+++ b/src/mg_schematic.cpp
@@ -309,14 +309,18 @@ bool Schematic::serializeToMts(std::ostream *os,
bool Schematic::serializeToLua(std::ostream *os,
- const std::vector<std::string> &names, bool use_comments)
+ const std::vector<std::string> &names, bool use_comments, u32 indent_spaces)
{
std::ostream &ss = *os;
+ std::string indent("\t");
+ if (indent_spaces > 0)
+ indent.assign(indent_spaces, ' ');
+
//// Write header
{
ss << "schematic = {" << std::endl;
- ss << "\tsize = "
+ ss << indent << "size = "
<< "{x=" << size.X
<< ", y=" << size.Y
<< ", z=" << size.Z
@@ -325,33 +329,34 @@ bool Schematic::serializeToLua(std::ostream *os,
//// Write y-slice probabilities
{
- ss << "\tyslice_prob = {" << std::endl;
+ ss << indent << "yslice_prob = {" << std::endl;
for (u16 y = 0; y != size.Y; y++) {
- ss << "\t\t{"
+ ss << indent << indent << "{"
<< "ypos=" << y
<< ", prob=" << (u16)slice_probs[y]
<< "}," << std::endl;
}
- ss << "\t}," << std::endl;
+ ss << indent << "}," << std::endl;
}
//// Write node data
{
- ss << "\tdata = {" << std::endl;
+ ss << indent << "data = {" << std::endl;
u32 i = 0;
for (u16 z = 0; z != size.Z; z++)
for (u16 y = 0; y != size.Y; y++) {
if (use_comments) {
ss << std::endl
- << "\t\t-- z=" << z
+ << indent << indent
+ << "-- z=" << z
<< ", y=" << y << std::endl;
}
for (u16 x = 0; x != size.X; x++, i++) {
- ss << "\t\t{"
+ ss << indent << indent << "{"
<< "name=\"" << names[schemdata[i].getContent()]
<< "\", param1=" << (u16)schemdata[i].param1
<< ", param2=" << (u16)schemdata[i].param2
@@ -359,7 +364,7 @@ bool Schematic::serializeToLua(std::ostream *os,
}
}
- ss << "\t}," << std::endl;
+ ss << indent << "}," << std::endl;
}
ss << "}" << std::endl;