2020-08-03 01:06:55 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright <EFBFBD> 2020 Vsevolod Kremianskii
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-08-02 15:47:59 +00:00
|
|
|
|
#include "tools.h"
|
|
|
|
|
|
|
|
|
|
#include <boost/property_tree/json_parser.hpp>
|
|
|
|
|
|
2020-08-03 13:16:58 +00:00
|
|
|
|
#include "src/resources/2dafile.h"
|
2020-08-02 15:47:59 +00:00
|
|
|
|
|
2020-08-08 04:27:15 +00:00
|
|
|
|
using namespace std;
|
|
|
|
|
|
2020-08-02 15:47:59 +00:00
|
|
|
|
using namespace reone::resources;
|
|
|
|
|
|
|
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
|
namespace pt = boost::property_tree;
|
|
|
|
|
|
|
|
|
|
namespace reone {
|
|
|
|
|
|
|
|
|
|
namespace tools {
|
|
|
|
|
|
|
|
|
|
void TwoDaTool::convert(const fs::path &path, const fs::path &destPath) const {
|
|
|
|
|
TwoDaFile twoDa;
|
|
|
|
|
twoDa.load(path);
|
|
|
|
|
|
|
|
|
|
pt::ptree tree;
|
|
|
|
|
pt::ptree children;
|
2020-08-08 04:27:15 +00:00
|
|
|
|
shared_ptr<TwoDaTable> table(twoDa.table());
|
2020-08-02 15:47:59 +00:00
|
|
|
|
auto &headers = table->headers();
|
|
|
|
|
auto &rows = table->rows();
|
|
|
|
|
|
|
|
|
|
for (auto &row : rows) {
|
|
|
|
|
auto &values = row.values;
|
|
|
|
|
pt::ptree child;
|
|
|
|
|
for (int i = 0; i < headers.size(); ++i) {
|
2020-08-08 04:27:15 +00:00
|
|
|
|
const string &val = values[i];
|
2020-08-02 15:47:59 +00:00
|
|
|
|
child.put(headers[i], val);
|
|
|
|
|
}
|
2020-08-08 04:27:15 +00:00
|
|
|
|
children.push_back(make_pair("", child));
|
2020-08-02 15:47:59 +00:00
|
|
|
|
}
|
|
|
|
|
tree.add_child("rows", children);
|
|
|
|
|
|
|
|
|
|
fs::path jsonPath(destPath);
|
|
|
|
|
jsonPath.append(path.filename().string() + ".json");
|
|
|
|
|
|
|
|
|
|
fs::ofstream json(jsonPath);
|
|
|
|
|
pt::write_json(json, tree);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace tools
|
|
|
|
|
|
|
|
|
|
} // namespace reone
|