LMT and LMU support SaveOpt::ePreserveHeader
MODIFY
Makefile.am
Makefile.am
@@ -116,6 +116,7 @@ pkginclude_HEADERS = \
src/ini.h \
src/inireader.h \
src/lcf_options.h \
+ src/lcf_saveopt.h \
src/ldb_reader.h \
src/lmt_reader.h \
src/lmu_reader.h \

MODIFY
builds/vs2015/liblcf.vcxproj
builds/vs2015/liblcf.vcxproj
<ClInclude Include="..\..\src\lmt_reader.h" />
<ClInclude Include="..\..\src\lmu_reader.h" />
<ClInclude Include="..\..\src\lsd_reader.h" />
+ <ClInclude Include="..\..\src\lcf_saveopt.h" />
<ClInclude Include="..\..\src\reader_lcf.h" />
<ClInclude Include="..\..\src\reader_struct.h" />
<ClInclude Include="..\..\src\reader_util.h" />

MODIFY
generator/templates/rpg_header.tmpl
generator/templates/rpg_header.tmpl
@@ -19,6 +19,12 @@ namespace RPG {
{%- if struct_name == "Database" %}
std::string ldb_header;
{%- endif %}
+ {%- if struct_name == "TreeMap" %}
+ std::string lmt_header;
+ {%- endif %}
+ {%- if struct_name == "Map" %}
+ std::string lmu_header;
+ {%- endif %}
{%- if struct_name in enums %}
{%- for name, enum in enums[struct_name].items() %}
{%- if name == "Code" %}

MODIFY
src/generated/rpg_map.h
src/generated/rpg_map.h
Binary files a/src/generated/rpg_map.h and b/src/generated/rpg_map.h differ

MODIFY
src/generated/rpg_treemap.h
src/generated/rpg_treemap.h
Binary files a/src/generated/rpg_treemap.h and b/src/generated/rpg_treemap.h differ

ADD
src/lcf_saveopt.h
+/*
+ * This file is part of liblcf. Copyright (c) 2017 liblcf authors.
+ * https://github.com/EasyRPG/liblcf - https://easyrpg.org
+ *
+ * liblcf is Free/Libre Open Source Software, released under the MIT License.
+ * For the full copyright and license information, please view the COPYING
+ * file that was distributed with this source code.
+ */
+
+#ifndef LCF_SAVEOPT_H
+#define LCF_SAVEOPT_H
+
+/**
+ * Options to configure how LDB file is saved
+ */
+enum class SaveOpt {
+ eNone = 0,
+ ePreserveHeader = 1
+};
+
+constexpr SaveOpt operator|(SaveOpt l, SaveOpt r) { return SaveOpt(int(l) | int(r)); }
+constexpr SaveOpt operator&(SaveOpt l, SaveOpt r) { return SaveOpt(int(l) & int(r)); }
+constexpr SaveOpt operator^(SaveOpt l, SaveOpt r) { return SaveOpt(int(l) ^ int(r)); }
+constexpr SaveOpt operator~(SaveOpt l) { return SaveOpt(~int(l)); }
+
+#endif
+

MODIFY
src/ldb_reader.h
src/ldb_reader.h
#include "rpg_parameters.h"
#include "rpg_equipment.h"
#include "rpg_database.h"
+#include "lcf_saveopt.h"
/**
* LDB Reader namespace.
*/
namespace LDB_Reader {
- /**
- * Options to configure how LDB file is saved
- */
- enum class SaveOpt {
- eNone = 0,
- ePreserveHeader = 1
- };
-
- constexpr SaveOpt operator|(SaveOpt l, SaveOpt r) { return SaveOpt(int(l) | int(r)); }
- constexpr SaveOpt operator&(SaveOpt l, SaveOpt r) { return SaveOpt(int(l) & int(r)); }
- constexpr SaveOpt operator^(SaveOpt l, SaveOpt r) { return SaveOpt(int(l) ^ int(r)); }
- constexpr SaveOpt operator~(SaveOpt l) { return SaveOpt(~int(l)); }
-
/**
* Loads Database.
*/

MODIFY
src/lmt_reader.cpp
src/lmt_reader.cpp
@@ -26,13 +26,13 @@ bool LMT_Reader::Load(const std::string& filename, const std::string& encoding)
return LMT_Reader::Load(stream, encoding);
}
-bool LMT_Reader::Save(const std::string& filename, const std::string& encoding) {
+bool LMT_Reader::Save(const std::string& filename, const std::string& encoding, SaveOpt opt) {
std::ofstream stream(filename.c_str(), std::ios::binary);
if (!stream.is_open()) {
fprintf(stderr, "Failed to open LMT file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
return false;
}
- return LMT_Reader::Save(stream, encoding);
+ return LMT_Reader::Save(stream, encoding, opt);
}
bool LMT_Reader::SaveXml(const std::string& filename) {
@@ -68,17 +68,23 @@ bool LMT_Reader::Load(std::istream& filestream, const std::string &encoding) {
if (header != "LcfMapTree") {
fprintf(stderr, "Warning: This header is not LcfMapTree and might not be a valid RPG2000 map tree.\n");
}
+ Data::treemap.lmt_header = std::move(header);
TypeReader<RPG::TreeMap>::ReadLcf(Data::treemap, reader, 0);
return true;
}
-bool LMT_Reader::Save(std::ostream& filestream, const std::string &encoding) {
+bool LMT_Reader::Save(std::ostream& filestream, const std::string &encoding, SaveOpt opt) {
LcfWriter writer(filestream, encoding);
if (!writer.IsOk()) {
LcfReader::SetError("Couldn't parse map tree file.\n");
return false;
}
- const std::string header("LcfMapTree");
+ std::string header;
+ if ( Data::treemap.lmt_header.empty() || !bool(opt & SaveOpt::ePreserveHeader)) {
+ header = "LcfMapTree";
+ } else {
+ header= Data::treemap.lmt_header;
+ }
writer.WriteInt(header.size());
writer.Write(header);
TypeReader<RPG::TreeMap>::WriteLcf(Data::treemap, writer);

MODIFY
src/lmt_reader.h
src/lmt_reader.h
#include "writer_lcf.h"
#include "writer_xml.h"
#include "rpg_treemap.h"
+#include "lcf_saveopt.h"
/**
* LMT Reader namespace.
@@ -29,7 +30,7 @@ namespace LMT_Reader {
/**
* Saves Map Tree.
*/
- bool Save(const std::string& filename, const std::string &encoding);
+ bool Save(const std::string& filename, const std::string &encoding, SaveOpt opt = SaveOpt::eNone);
/**
* Saves Map Tree as XML.
@@ -49,7 +50,7 @@ namespace LMT_Reader {
/**
* Saves Map Tree.
*/
- bool Save(std::ostream& filestream, const std::string &encoding);
+ bool Save(std::ostream& filestream, const std::string &encoding, SaveOpt opt = SaveOpt::eNone);
/**
* Saves Map Tree as XML.

MODIFY
src/lmu_reader.cpp
src/lmu_reader.cpp
@@ -26,13 +26,13 @@ std::unique_ptr<RPG::Map> LMU_Reader::Load(const std::string& filename, const st
return LMU_Reader::Load(stream, encoding);
}
-bool LMU_Reader::Save(const std::string& filename, const RPG::Map& save, const std::string& encoding) {
+bool LMU_Reader::Save(const std::string& filename, const RPG::Map& save, const std::string& encoding, SaveOpt opt) {
std::ofstream stream(filename.c_str(), std::ios::binary);
if (!stream.is_open()) {
fprintf(stderr, "Failed to open LMU file `%s' for writing : %s\n", filename.c_str(), strerror(errno));
return false;
}
- return LMU_Reader::Save(stream, save, encoding);
+ return LMU_Reader::Save(stream, save, encoding, opt);
}
bool LMU_Reader::SaveXml(const std::string& filename, const RPG::Map& save) {
@@ -70,17 +70,23 @@ std::unique_ptr<RPG::Map> LMU_Reader::Load(std::istream& filestream, const std::
}
auto map = std::unique_ptr<RPG::Map>(new RPG::Map());
+ map->lmu_header = std::move(header);
Struct<RPG::Map>::ReadLcf(*map, reader);
return map;
}
-bool LMU_Reader::Save(std::ostream& filestream, const RPG::Map& map, const std::string& encoding) {
+bool LMU_Reader::Save(std::ostream& filestream, const RPG::Map& map, const std::string& encoding, SaveOpt opt) {
LcfWriter writer(filestream, encoding);
if (!writer.IsOk()) {
LcfReader::SetError("Couldn't parse map file.\n");
return false;
}
- const std::string header("LcfMapUnit");
+ std::string header;
+ if ( map.lmu_header.empty() || !bool(opt & SaveOpt::ePreserveHeader)) {
+ header = "LcfMapUnit";
+ } else {
+ header= map.lmu_header;
+ }
writer.WriteInt(header.size());
writer.Write(header);

MODIFY
src/lmu_reader.h
src/lmu_reader.h
#include <string>
#include <memory>
#include "rpg_map.h"
+#include "lcf_saveopt.h"
/**
* LMU Reader namespace.
@@ -27,7 +28,7 @@ namespace LMU_Reader {
/**
* Saves map.
*/
- bool Save(const std::string& filename, const RPG::Map& map, const std::string& encoding);
+ bool Save(const std::string& filename, const RPG::Map& map, const std::string& encoding, SaveOpt opt = SaveOpt::eNone);
/**
* Saves map as XML.
@@ -47,7 +48,7 @@ namespace LMU_Reader {
/**
* Saves map.
*/
- bool Save(std::ostream& filestream, const RPG::Map& map, const std::string& encoding);
+ bool Save(std::ostream& filestream, const RPG::Map& map, const std::string& encoding, SaveOpt opt = SaveOpt::eNone);
/**
* Saves map as XML.

LMT and LMU support SaveOpt::ePreserveHeader