Add Project::getMapScriptsFilePath() and rename text editor config members

This commit is contained in:
BigBahss 2020-11-21 17:33:16 -05:00
parent 662fb2a367
commit 3478846b60
5 changed files with 26 additions and 15 deletions

View file

@ -61,7 +61,7 @@ public:
void setMonitorFiles(bool monitor); void setMonitorFiles(bool monitor);
void setRegionMapDimensions(int width, int height); void setRegionMapDimensions(int width, int height);
void setTheme(QString theme); void setTheme(QString theme);
void setTextEditorCommand(const QString &command); void setTextEditorCommandTemplate(const QString &commandTemplate);
QString getRecentProject(); QString getRecentProject();
QString getRecentMap(); QString getRecentMap();
MapSortOrder getMapSortOrder(); MapSortOrder getMapSortOrder();
@ -77,7 +77,7 @@ public:
bool getMonitorFiles(); bool getMonitorFiles();
QSize getRegionMapDimensions(); QSize getRegionMapDimensions();
QString getTheme(); QString getTheme();
QString getTextEditorCommand(); QString getTextEditorCommandTemplate();
protected: protected:
virtual QString getConfigFilepath() override; virtual QString getConfigFilepath() override;
virtual void parseConfigKeyValue(QString key, QString value) override; virtual void parseConfigKeyValue(QString key, QString value) override;
@ -109,7 +109,7 @@ private:
bool monitorFiles; bool monitorFiles;
QSize regionMapDimensions; QSize regionMapDimensions;
QString theme; QString theme;
QString textEditorCommand; QString textEditorCommandTemplate;
}; };
extern PorymapConfig porymapConfig; extern PorymapConfig porymapConfig;

View file

@ -172,8 +172,9 @@ public:
QString fixPalettePath(QString path); QString fixPalettePath(QString path);
QString fixGraphicPath(QString path); QString fixGraphicPath(QString path);
QString getScriptFileExtension(bool usePoryScript); QString getScriptFileExtension(bool usePoryScript) const;
QString getScriptDefaultString(bool usePoryScript, QString mapName); QString getScriptDefaultString(bool usePoryScript, QString mapName) const;
QString getMapScriptsFilePath(const QString &mapName) const;
bool loadMapBorder(Map *map); bool loadMapBorder(Map *map);

View file

@ -188,7 +188,7 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
} else if (key == "theme") { } else if (key == "theme") {
this->theme = value; this->theme = value;
} else if (key == "text_editor") { } else if (key == "text_editor") {
this->textEditorCommand = value; this->textEditorCommandTemplate = value;
} else { } else {
logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->getConfigFilepath()).arg(key)); logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->getConfigFilepath()).arg(key));
} }
@ -218,7 +218,7 @@ QMap<QString, QString> PorymapConfig::getKeyValueMap() {
map.insert("region_map_dimensions", QString("%1x%2").arg(this->regionMapDimensions.width()) map.insert("region_map_dimensions", QString("%1x%2").arg(this->regionMapDimensions.width())
.arg(this->regionMapDimensions.height())); .arg(this->regionMapDimensions.height()));
map.insert("theme", this->theme); map.insert("theme", this->theme);
map.insert("text_editor", this->textEditorCommand); map.insert("text_editor", this->textEditorCommandTemplate);
return map; return map;
} }
@ -319,8 +319,8 @@ void PorymapConfig::setTheme(QString theme) {
this->theme = theme; this->theme = theme;
} }
void PorymapConfig::setTextEditorCommand(const QString &command) { void PorymapConfig::setTextEditorCommandTemplate(const QString &commandTemplate) {
this->textEditorCommand = command; this->textEditorCommandTemplate = commandTemplate;
this->save(); this->save();
} }
@ -406,8 +406,8 @@ QString PorymapConfig::getTheme() {
return this->theme; return this->theme;
} }
QString PorymapConfig::getTextEditorCommand() { QString PorymapConfig::getTextEditorCommandTemplate() {
return this->textEditorCommand; return this->textEditorCommandTemplate;
} }
const QMap<BaseGameVersion, QString> baseGameVersionMap = { const QMap<BaseGameVersion, QString> baseGameVersionMap = {

View file

@ -2410,7 +2410,7 @@ QString Project::fixGraphicPath(QString path) {
return path; return path;
} }
QString Project::getScriptFileExtension(bool usePoryScript) { QString Project::getScriptFileExtension(bool usePoryScript) const {
if(usePoryScript) { if(usePoryScript) {
return ".pory"; return ".pory";
} else { } else {
@ -2418,13 +2418,23 @@ QString Project::getScriptFileExtension(bool usePoryScript) {
} }
} }
QString Project::getScriptDefaultString(bool usePoryScript, QString mapName) { QString Project::getScriptDefaultString(bool usePoryScript, QString mapName) const {
if(usePoryScript) if(usePoryScript)
return QString("mapscripts %1_MapScripts {}").arg(mapName); return QString("mapscripts %1_MapScripts {}").arg(mapName);
else else
return QString("%1_MapScripts::\n\t.byte 0\n").arg(mapName); return QString("%1_MapScripts::\n\t.byte 0\n").arg(mapName);
} }
QString Project::getMapScriptsFilePath(const QString &mapName) const {
const bool usePoryscript = projectConfig.getUsePoryScript();
auto path = QDir::cleanPath(root + "/data/maps/" + mapName + "/scripts");
auto extension = getScriptFileExtension(usePoryscript);
if (usePoryscript && !QFile::exists(path + extension))
extension = getScriptFileExtension(false);
path += extension;
return path;
}
void Project::loadEventPixmaps(QList<Event*> objects) { void Project::loadEventPixmaps(QList<Event*> objects) {
bool needs_update = false; bool needs_update = false;
for (Event *object : objects) { for (Event *object : objects) {

View file

@ -30,7 +30,7 @@ PreferenceEditor::~PreferenceEditor()
} }
void PreferenceEditor::populateFields() { void PreferenceEditor::populateFields() {
ui->lineEdit_TextEditor->setText(porymapConfig.getTextEditorCommand()); ui->lineEdit_TextEditor->setText(porymapConfig.getTextEditorCommandTemplate());
QStringList themes = { "default" }; QStringList themes = { "default" };
QRegularExpression re(":/themes/([A-z0-9_-]+).qss"); QRegularExpression re(":/themes/([A-z0-9_-]+).qss");
@ -44,7 +44,7 @@ void PreferenceEditor::populateFields() {
} }
void PreferenceEditor::saveFields() { void PreferenceEditor::saveFields() {
porymapConfig.setTextEditorCommand(ui->lineEdit_TextEditor->text()); porymapConfig.setTextEditorCommandTemplate(ui->lineEdit_TextEditor->text());
if (themeSelector->currentText() != porymapConfig.getTheme()) { if (themeSelector->currentText() != porymapConfig.getTheme()) {
const auto theme = themeSelector->currentText(); const auto theme = themeSelector->currentText();