Skip to content

Commit

Permalink
add encoding selector and engine version check
Browse files Browse the repository at this point in the history
  • Loading branch information
lumiscosity committed Dec 18, 2024
1 parent 70f9df9 commit 2d045fc
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 17 deletions.
13 changes: 7 additions & 6 deletions src/databaseholder.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "databaseholder.h"

DatabaseHolder::DatabaseHolder(QString main, QString source, QString patch) {
p_tree = lcf::LMT_Reader::Load((patch + "/RPG_RT.lmt").toStdString(), "UTF-8");
m_tree = lcf::LMT_Reader::Load((main + "/RPG_RT.lmt").toStdString(), "UTF-8");
p_db = lcf::LDB_Reader::Load((patch + "/RPG_RT.ldb").toStdString(), "UTF-8");
s_db = lcf::LDB_Reader::Load((source + "/RPG_RT.ldb").toStdString(), "UTF-8");
m_db = lcf::LDB_Reader::Load((main + "/RPG_RT.ldb").toStdString(), "UTF-8");
DatabaseHolder::DatabaseHolder(QString main, QString source, QString patch, std::string in_encoding) {
p_tree = lcf::LMT_Reader::Load((patch + "/RPG_RT.lmt").toStdString(), in_encoding);
m_tree = lcf::LMT_Reader::Load((main + "/RPG_RT.lmt").toStdString(), in_encoding);
p_db = lcf::LDB_Reader::Load((patch + "/RPG_RT.ldb").toStdString(), in_encoding);
s_db = lcf::LDB_Reader::Load((source + "/RPG_RT.ldb").toStdString(), in_encoding);
m_db = lcf::LDB_Reader::Load((main + "/RPG_RT.ldb").toStdString(), in_encoding);
encoding = in_encoding;
}
3 changes: 2 additions & 1 deletion src/databaseholder.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

class DatabaseHolder {
public:
DatabaseHolder(QString main, QString source, QString patch);
DatabaseHolder(QString main, QString source, QString patch, std::string in_encoding);
std::unique_ptr<lcf::rpg::TreeMap> p_tree = nullptr;
std::unique_ptr<lcf::rpg::TreeMap> m_tree = nullptr;
std::unique_ptr<lcf::rpg::Database> p_db = nullptr;
std::unique_ptr<lcf::rpg::Database> s_db = nullptr;
std::unique_ptr<lcf::rpg::Database> m_db = nullptr;
std::string encoding;
};

34 changes: 34 additions & 0 deletions src/directorydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
DirectoryDialog::DirectoryDialog(QWidget *parent) : QDialog(parent), ui(new Ui::DirectoryDialog) {
ui->setupUi(this);
ui->buttonBox->buttons()[0]->setDisabled(true);
ui->encodingComboBox->addItems({"UTF-8", "932 (Japanese)", "949 (Korean)", "1250 (Central Europe)", "1251 (Cyryllic)", "1252 (Occidental)", "1253 (Greek)", "1255 (Hebrew)", "1256 (Arabic)", "874 (Thai)", "936 (Chinese Simplified)", "950 (Chinese Traditional)", "1254 (Turkish)", "1257 (Baltic)"});
}

DirectoryDialog::~DirectoryDialog() {
Expand Down Expand Up @@ -73,3 +74,36 @@ QString DirectoryDialog::source() {
QString DirectoryDialog::patch() {
return ui->patchLabel->text();
}

std::string DirectoryDialog::encoding() {
switch (ui->encodingComboBox->currentIndex()) {
case (1):
return "932";
case (2):
return "949";
case (3):
return "1250";
case (4):
return "1251";
case (5):
return "1252";
case (6):
return "1253";
case (7):
return "1255";
case (8):
return "1256";
case (9):
return "874";
case (10):
return "936";
case (11):
return "950";
case (12):
return "1254";
case (13):
return "1257";
default:
return "UTF-8";
}
}
2 changes: 2 additions & 0 deletions src/directorydialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#pragma once

#include "lcf/saveopt.h"
#include <QDialog>

namespace Ui {
Expand All @@ -34,6 +35,7 @@ class DirectoryDialog : public QDialog {
QString source();
QString patch();
void toggleOkButton();
std::string encoding();
private slots:
void on_mainPushButton_clicked();
void on_sourcePushButton_clicked();
Expand Down
14 changes: 14 additions & 0 deletions src/directorydialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QLabel" name="encodingLabel">
<property name="text">
<string>Encoding</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="encodingComboBox"/>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
Expand Down
8 changes: 4 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int main(int argc, char *argv[]) {
QString patch = w.patch();
QString source = w.source();

DatabaseHolder h(main, source, patch);
DatabaseHolder h(main, source, patch, w.encoding());

// if there is no changelog for the main copy yet, create one
if (!QFile::exists(main + "/changelog.txt")) {
Expand Down Expand Up @@ -141,15 +141,15 @@ int main(int argc, char *argv[]) {
lcf::LMT_Reader::Save(
(main + QString("/RPG_RT.lmt")).toStdString(),
*h.m_tree,
lcf::EngineVersion::e2k3,
"UTF-8",
lcf::GetEngineVersion(*h.m_db),
h.encoding,
lcf::SaveOpt::eNone);
}
if (h.m_db != nullptr) {
lcf::LDB_Reader::Save(
(main + QString("/RPG_RT.ldb")).toStdString(),
*h.m_db,
"UTF-8",
h.encoding,
lcf::SaveOpt::eNone);
}

Expand Down
8 changes: 4 additions & 4 deletions src/map_diff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ int map_diff(DatabaseHolder &d, DBAsset asset, QString main, QString source, QSt
// this actually uses an external file (and gross misuse of qsettings)
// to track which tiles have been changed in the main copy so far
// if none of the tiles overlap, we can automerge; else a manual diff is required
std::unique_ptr<lcf::rpg::Map> m_map = lcf::LMU_Reader::Load((main + QString("/Map%1.lmu").arg(paddedint(asset.id, 4))).toStdString(), "UTF-8");
std::unique_ptr<lcf::rpg::Map> s_map = lcf::LMU_Reader::Load((source + QString("/Map%1.lmu").arg(paddedint(asset.id, 4))).toStdString(), "UTF-8");
std::unique_ptr<lcf::rpg::Map> p_map = lcf::LMU_Reader::Load((patch + QString("/Map%1.lmu").arg(paddedint(asset.id, 4))).toStdString(), "UTF-8");
std::unique_ptr<lcf::rpg::Map> m_map = lcf::LMU_Reader::Load((main + QString("/Map%1.lmu").arg(paddedint(asset.id, 4))).toStdString(), d.encoding);
std::unique_ptr<lcf::rpg::Map> s_map = lcf::LMU_Reader::Load((source + QString("/Map%1.lmu").arg(paddedint(asset.id, 4))).toStdString(), d.encoding);
std::unique_ptr<lcf::rpg::Map> p_map = lcf::LMU_Reader::Load((patch + QString("/Map%1.lmu").arg(paddedint(asset.id, 4))).toStdString(), d.encoding);
QSettings tilediff(main + "/eidolist_tilediff");

if (m_map->height != s_map->height || s_map->height != p_map->height || m_map->width != s_map->width || s_map->width != p_map->width) {
Expand Down Expand Up @@ -147,7 +147,7 @@ int map_diff(DatabaseHolder &d, DBAsset asset, QString main, QString source, QSt
(main + QString("Map%1.lmu").arg(paddedint(asset.id, 4))).toStdString(),
*m_map,
lcf::GetEngineVersion(*d.m_db),
"UTF-8",
d.encoding,
lcf::SaveOpt::eNone
);

Expand Down
4 changes: 2 additions & 2 deletions src/merger_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ int dbmerge(QString main, QString source, QString patch, DBAsset dbasset, Databa
if (dbasset.folder == "Map") {
// populate the tilediff
// for more info about this check the map_diff.cpp file
std::unique_ptr<lcf::rpg::Map> s_map = lcf::LMU_Reader::Load((source + QString("/Map%1.lmu").arg(paddedint(dbasset.id, 4))).toStdString(), "UTF-8");
std::unique_ptr<lcf::rpg::Map> p_map = lcf::LMU_Reader::Load((patch + QString("/Map%1.lmu").arg(paddedint(dbasset.id, 4))).toStdString(), "UTF-8");
std::unique_ptr<lcf::rpg::Map> s_map = lcf::LMU_Reader::Load((source + QString("/Map%1.lmu").arg(paddedint(dbasset.id, 4))).toStdString(), h.encoding);
std::unique_ptr<lcf::rpg::Map> p_map = lcf::LMU_Reader::Load((patch + QString("/Map%1.lmu").arg(paddedint(dbasset.id, 4))).toStdString(), h.encoding);
if (p_map == nullptr) {
QMessageBox::warning(nullptr, "Warning", QString("Map%1 was not found in the patch copy, despite being mentioned in the changelog!").arg(paddedint(dbasset.id, 4)));
return 1;
Expand Down

0 comments on commit 2d045fc

Please sign in to comment.