From 7dacfeb52b2616421a566badaacce25fe3357a82 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 9 Feb 2023 11:28:55 -0500 Subject: [PATCH 1/6] Add script load warning --- include/config.h | 4 ++++ include/scripting.h | 1 + src/config.cpp | 12 ++++++++++++ src/scriptapi/scripting.cpp | 20 +++++++++++++++++++- 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/include/config.h b/include/config.h index af649e8f..27beb112 100644 --- a/include/config.h +++ b/include/config.h @@ -61,6 +61,7 @@ public: this->theme = "default"; this->textEditorOpenFolder = ""; this->textEditorGotoLine = ""; + this->warnScriptLoad = true; } void setRecentProject(QString project); void setReopenOnLaunch(bool enabled); @@ -78,6 +79,7 @@ public: void setShowGrid(bool enabled); void setMonitorFiles(bool monitor); void setTilesetCheckerboardFill(bool checkerboard); + void setWarnScriptLoad(bool enabled); void setTheme(QString theme); void setTextEditorOpenFolder(const QString &command); void setTextEditorGotoLine(const QString &command); @@ -97,6 +99,7 @@ public: bool getShowGrid(); bool getMonitorFiles(); bool getTilesetCheckerboardFill(); + bool getWarnScriptLoad(); QString getTheme(); QString getTextEditorOpenFolder(); QString getTextEditorGotoLine(); @@ -132,6 +135,7 @@ private: bool showGrid; bool monitorFiles; bool tilesetCheckerboardFill; + bool warnScriptLoad; QString theme; QString textEditorOpenFolder; QString textEditorGotoLine; diff --git a/include/scripting.h b/include/scripting.h index 873e24c2..28354d9b 100644 --- a/include/scripting.h +++ b/include/scripting.h @@ -61,6 +61,7 @@ public: static QJSValue dialogInput(QJSValue input, bool selectedOk); private: + MainWindow *mainWindow; QJSEngine *engine; QStringList filepaths; QList modules; diff --git a/src/config.cpp b/src/config.cpp index b1f2f03f..780e0389 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -240,6 +240,8 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) { this->monitorFiles = getConfigBool(key, value); } else if (key == "tileset_checkerboard_fill") { this->tilesetCheckerboardFill = getConfigBool(key, value); + } else if (key == "warn_script_load") { + this->warnScriptLoad = getConfigBool(key, value); } else if (key == "theme") { this->theme = value; } else if (key == "text_editor_open_directory") { @@ -275,6 +277,7 @@ QMap PorymapConfig::getKeyValueMap() { map.insert("show_grid", this->showGrid ? "1" : "0"); map.insert("monitor_files", this->monitorFiles ? "1" : "0"); map.insert("tileset_checkerboard_fill", this->tilesetCheckerboardFill ? "1" : "0"); + map.insert("warn_script_load", this->warnScriptLoad ? "1" : "0"); map.insert("theme", this->theme); map.insert("text_editor_open_directory", this->textEditorOpenFolder); map.insert("text_editor_goto_line", this->textEditorGotoLine); @@ -329,6 +332,11 @@ void PorymapConfig::setTilesetCheckerboardFill(bool checkerboard) { this->save(); } +void PorymapConfig::setWarnScriptLoad(bool enabled) { + this->warnScriptLoad = enabled; + this->save(); +} + void PorymapConfig::setMainGeometry(QByteArray mainWindowGeometry_, QByteArray mainWindowState_, QByteArray mapSplitterState_, QByteArray mainSplitterState_) { this->mainWindowGeometry = mainWindowGeometry_; @@ -486,6 +494,10 @@ bool PorymapConfig::getTilesetCheckerboardFill() { return this->tilesetCheckerboardFill; } +bool PorymapConfig::getWarnScriptLoad() { + return this->warnScriptLoad; +} + QString PorymapConfig::getTheme() { return this->theme; } diff --git a/src/scriptapi/scripting.cpp b/src/scriptapi/scripting.cpp index 97e0eaf9..a534c2e5 100644 --- a/src/scriptapi/scripting.cpp +++ b/src/scriptapi/scripting.cpp @@ -33,6 +33,7 @@ void Scripting::init(MainWindow *mainWindow) { } Scripting::Scripting(MainWindow *mainWindow) { + this->mainWindow = mainWindow; this->engine = new QJSEngine(mainWindow); this->engine->installExtensions(QJSEngine::ConsoleExtension); for (QString script : userConfig.getCustomScripts()) { @@ -48,7 +49,24 @@ void Scripting::loadModules(QStringList moduleFiles) { if (module.isError()) { QString relativePath = QDir::cleanPath(userConfig.getProjectDir() + QDir::separator() + filepath); module = this->engine->importModule(relativePath); - if (tryErrorJS(module)) continue; + if (tryErrorJS(module)) { + if (porymapConfig.getWarnScriptLoad()) { + QMessageBox messageBox(this->mainWindow); + messageBox.setText("Failed to load script"); + messageBox.setInformativeText(QString("An error occurred while loading custom script file '%1'").arg(filepath)); + messageBox.setDetailedText(getMostRecentError()); + messageBox.setIcon(QMessageBox::Warning); + messageBox.addButton(QMessageBox::Ok); + messageBox.setDefaultButton(QMessageBox::Ok); + QCheckBox * checkbox = new QCheckBox("Don't show this warning again"); + messageBox.setCheckBox(checkbox); + QObject::connect(checkbox, &QCheckBox::stateChanged, [](int state) { + porymapConfig.setWarnScriptLoad(static_cast(state) != Qt::CheckState::Checked); + }); + messageBox.exec(); + } + continue; + } } logInfo(QString("Successfully loaded custom script file '%1'").arg(filepath)); From 880dabade39adc9c28fb37500d9f05168191827e Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 9 Feb 2023 13:15:02 -0500 Subject: [PATCH 2/6] Add script action warning --- include/config.h | 4 ++++ src/config.cpp | 12 ++++++++++++ src/scriptapi/scripting.cpp | 17 +++++++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/include/config.h b/include/config.h index 27beb112..24d88a1e 100644 --- a/include/config.h +++ b/include/config.h @@ -62,6 +62,7 @@ public: this->textEditorOpenFolder = ""; this->textEditorGotoLine = ""; this->warnScriptLoad = true; + this->warnScriptAction = true; } void setRecentProject(QString project); void setReopenOnLaunch(bool enabled); @@ -80,6 +81,7 @@ public: void setMonitorFiles(bool monitor); void setTilesetCheckerboardFill(bool checkerboard); void setWarnScriptLoad(bool enabled); + void setWarnScriptAction(bool enabled); void setTheme(QString theme); void setTextEditorOpenFolder(const QString &command); void setTextEditorGotoLine(const QString &command); @@ -100,6 +102,7 @@ public: bool getMonitorFiles(); bool getTilesetCheckerboardFill(); bool getWarnScriptLoad(); + bool getWarnScriptAction(); QString getTheme(); QString getTextEditorOpenFolder(); QString getTextEditorGotoLine(); @@ -136,6 +139,7 @@ private: bool monitorFiles; bool tilesetCheckerboardFill; bool warnScriptLoad; + bool warnScriptAction; QString theme; QString textEditorOpenFolder; QString textEditorGotoLine; diff --git a/src/config.cpp b/src/config.cpp index 780e0389..a7269026 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -242,6 +242,8 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) { this->tilesetCheckerboardFill = getConfigBool(key, value); } else if (key == "warn_script_load") { this->warnScriptLoad = getConfigBool(key, value); + } else if (key == "warn_script_action") { + this->warnScriptAction = getConfigBool(key, value); } else if (key == "theme") { this->theme = value; } else if (key == "text_editor_open_directory") { @@ -278,6 +280,7 @@ QMap PorymapConfig::getKeyValueMap() { map.insert("monitor_files", this->monitorFiles ? "1" : "0"); map.insert("tileset_checkerboard_fill", this->tilesetCheckerboardFill ? "1" : "0"); map.insert("warn_script_load", this->warnScriptLoad ? "1" : "0"); + map.insert("warn_script_action", this->warnScriptAction ? "1" : "0"); map.insert("theme", this->theme); map.insert("text_editor_open_directory", this->textEditorOpenFolder); map.insert("text_editor_goto_line", this->textEditorGotoLine); @@ -337,6 +340,11 @@ void PorymapConfig::setWarnScriptLoad(bool enabled) { this->save(); } +void PorymapConfig::setWarnScriptAction(bool enabled) { + this->warnScriptAction = enabled; + this->save(); +} + void PorymapConfig::setMainGeometry(QByteArray mainWindowGeometry_, QByteArray mainWindowState_, QByteArray mapSplitterState_, QByteArray mainSplitterState_) { this->mainWindowGeometry = mainWindowGeometry_; @@ -498,6 +506,10 @@ bool PorymapConfig::getWarnScriptLoad() { return this->warnScriptLoad; } +bool PorymapConfig::getWarnScriptAction() { + return this->warnScriptAction; +} + QString PorymapConfig::getTheme() { return this->theme; } diff --git a/src/scriptapi/scripting.cpp b/src/scriptapi/scripting.cpp index a534c2e5..2680dc83 100644 --- a/src/scriptapi/scripting.cpp +++ b/src/scriptapi/scripting.cpp @@ -57,7 +57,6 @@ void Scripting::loadModules(QStringList moduleFiles) { messageBox.setDetailedText(getMostRecentError()); messageBox.setIcon(QMessageBox::Warning); messageBox.addButton(QMessageBox::Ok); - messageBox.setDefaultButton(QMessageBox::Ok); QCheckBox * checkbox = new QCheckBox("Don't show this warning again"); messageBox.setCheckBox(checkbox); QObject::connect(checkbox, &QCheckBox::stateChanged, [](int state) { @@ -159,8 +158,22 @@ void Scripting::invokeAction(QString actionName) { QJSValue result = callbackFunction.call(QJSValueList()); if (tryErrorJS(result)) continue; } - if (!foundFunction) + if (!foundFunction) { logError(QString("Unknown custom script function '%1'").arg(functionName)); + if (porymapConfig.getWarnScriptAction()) { + QMessageBox messageBox(instance->mainWindow); + messageBox.setText("Failed to run custom action"); + messageBox.setInformativeText(getMostRecentError()); + messageBox.setIcon(QMessageBox::Warning); + messageBox.addButton(QMessageBox::Ok); + QCheckBox * checkbox = new QCheckBox("Don't show this warning again"); + messageBox.setCheckBox(checkbox); + QObject::connect(checkbox, &QCheckBox::stateChanged, [](int state) { + porymapConfig.setWarnScriptAction(static_cast(state) != Qt::CheckState::Checked); + }); + messageBox.exec(); + } + } } void Scripting::cb_ProjectOpened(QString projectPath) { From 314e6fff53cf52010700af42010ef950e1dda3de Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 9 Feb 2023 13:55:25 -0500 Subject: [PATCH 3/6] Allow script actions with the same name --- include/scripting.h | 2 +- include/scriptutility.h | 4 ++-- src/scriptapi/apiutility.cpp | 21 +++++++++++++++------ src/scriptapi/scripting.cpp | 4 ++-- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/include/scripting.h b/include/scripting.h index 28354d9b..7a0b1a67 100644 --- a/include/scripting.h +++ b/include/scripting.h @@ -35,7 +35,7 @@ public: static QJSEngine *getEngine(); static void registerAction(QString functionName, QString actionName); static int numRegisteredActions(); - static void invokeAction(QString actionName); + static void invokeAction(int actionIndex); static void cb_ProjectOpened(QString projectPath); static void cb_ProjectClosed(QString projectPath); static void cb_MetatileChanged(int x, int y, Block prevBlock, Block newBlock); diff --git a/include/scriptutility.h b/include/scriptutility.h index bcc475d5..5b6882c6 100644 --- a/include/scriptutility.h +++ b/include/scriptutility.h @@ -11,7 +11,7 @@ class ScriptUtility : public QObject public: ScriptUtility(MainWindow *mainWindow); void clearActions(); - QString getActionFunctionName(QString actionName); + QString getActionFunctionName(int actionIndex); Q_INVOKABLE void registerAction(QString functionName, QString actionName, QString shortcut = ""); Q_INVOKABLE void setTimeout(QJSValue callback, int milliseconds); Q_INVOKABLE void log(QString message); @@ -58,7 +58,7 @@ private: MainWindow *window; QList registeredActions; - QMap actionMap; + QHash actionMap; }; #endif // SCRIPTUTILITY_H diff --git a/src/scriptapi/apiutility.cpp b/src/scriptapi/apiutility.cpp index 7445a67d..0678a5e0 100644 --- a/src/scriptapi/apiutility.cpp +++ b/src/scriptapi/apiutility.cpp @@ -11,17 +11,26 @@ void ScriptUtility::registerAction(QString functionName, QString actionName, QSt if (!window || !window->ui || !window->ui->menuTools) return; - this->actionMap.insert(actionName, functionName); - if (this->actionMap.size() == 1) { + if (functionName.isEmpty() || actionName.isEmpty()) { + logError("Failed to register script action. 'functionName' and 'actionName' must be non-empty."); + return; + } + + if (this->registeredActions.size() == 0) { QAction *section = window->ui->menuTools->addSection("Custom Actions"); this->registeredActions.append(section); } - QAction *action = window->ui->menuTools->addAction(actionName, [actionName](){ - Scripting::invokeAction(actionName); + + const int actionIndex = this->registeredActions.size(); + QAction *action = window->ui->menuTools->addAction(actionName, [actionIndex](){ + Scripting::invokeAction(actionIndex); }); + if (!shortcut.isEmpty()) { action->setShortcut(QKeySequence(shortcut)); } + + this->actionMap.insert(actionIndex, functionName); this->registeredActions.append(action); } @@ -31,8 +40,8 @@ void ScriptUtility::clearActions() { } } -QString ScriptUtility::getActionFunctionName(QString actionName) { - return this->actionMap.value(actionName); +QString ScriptUtility::getActionFunctionName(int actionIndex) { + return this->actionMap.value(actionIndex); } void ScriptUtility::setTimeout(QJSValue callback, int milliseconds) { diff --git a/src/scriptapi/scripting.cpp b/src/scriptapi/scripting.cpp index 2680dc83..1310a99c 100644 --- a/src/scriptapi/scripting.cpp +++ b/src/scriptapi/scripting.cpp @@ -142,9 +142,9 @@ void Scripting::invokeCallback(CallbackType type, QJSValueList args) { } } -void Scripting::invokeAction(QString actionName) { +void Scripting::invokeAction(int actionIndex) { if (!instance || !instance->scriptUtility) return; - QString functionName = instance->scriptUtility->getActionFunctionName(actionName); + QString functionName = instance->scriptUtility->getActionFunctionName(actionIndex); if (functionName.isEmpty()) return; bool foundFunction = false; From bf0ec3395d06a4bfaef99a6123ead43abcb95605 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 9 Feb 2023 14:09:40 -0500 Subject: [PATCH 4/6] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41a10d05..ed364d63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d ## [Unreleased] ### Changed - Change encounter tab copy and paste behavior. +- A warning will appear if a custom script fails to load or an action fails to run. ### Fixed - Fix tilesets that share part of their name loading incorrectly. @@ -18,6 +19,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d - Fix bug which caused encounter configurator to crash if last field was deleted. - Fix map render when collision view was active while map changed. - Fix the updated pokefirered region map graphics appearing in grayscale. +- Fix the API function `registerAction` not correctly handling actions with the same name. ## [5.1.0] - 2023-01-22 ### Added From bc256053d0eebe13dbd8f3847743f620fa5d3abd Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 10 Feb 2023 11:46:19 -0500 Subject: [PATCH 5/6] Add registerToggleAction --- CHANGELOG.md | 3 +++ docsrc/manual/scripting-capabilities.rst | 9 +++++++++ include/scripting.h | 2 -- include/scriptutility.h | 3 ++- src/scriptapi/apiutility.cpp | 16 +++++++++++++--- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed364d63..7961c104 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project somewhat adheres to [Semantic Versioning](https://semver.org/sp The **"Breaking Changes"** listed below are changes that have been made in the decompilation projects (e.g. pokeemerald), which porymap requires in order to work properly. It also includes changes to the scripting API that may change the behavior of existing porymap scripts. If porymap is used with a project or API script that is not up-to-date with the breaking changes, then porymap will likely break or behave improperly. ## [Unreleased] +### Added +- Add `registerToggleAction` to the scripting API + ### Changed - Change encounter tab copy and paste behavior. - A warning will appear if a custom script fails to load or an action fails to run. diff --git a/docsrc/manual/scripting-capabilities.rst b/docsrc/manual/scripting-capabilities.rst index 903ab51c..3b397b72 100644 --- a/docsrc/manual/scripting-capabilities.rst +++ b/docsrc/manual/scripting-capabilities.rst @@ -1406,6 +1406,15 @@ All utility functions are callable via the global ``utility`` object. :param string actionName: name of the action that will be displayed in the ``Tools`` menu :param string shortcut: optional keyboard shortcut +.. js:function:: utility.registerToggleAction(functionName, actionName, shortcut = "", checked = false) + + Registers a JavaScript function to an action that can be manually triggered in Porymap's ``Tools`` menu. Optionally, a keyboard shortcut (e.g. ``"Ctrl+P"``) can also be specified, assuming it doesn't collide with any existing shortcuts used by Porymap. A check mark will be toggled next to the action name each time its activated. Whether the check mark is initially present can be set with ``checked``. The function specified by ``functionName`` must have the ``export`` keyword. + + :param string functionName: name of the JavaScript function + :param string actionName: name of the action that will be displayed in the ``Tools`` menu + :param string shortcut: optional keyboard shortcut + :param boolean checked: whether the action initially has a check mark. Defaults to ``false``. + .. js:function:: utility.setTimeout(func, delayMs) This behaves essentially the same as JavaScript's ``setTimeout()`` that is used in web browsers or NodeJS. The ``func`` argument is a JavaScript function (NOT the name of a function) which will be executed after a delay. This is useful for creating animations or refreshing the overlay at constant intervals. diff --git a/include/scripting.h b/include/scripting.h index 7a0b1a67..ce435236 100644 --- a/include/scripting.h +++ b/include/scripting.h @@ -33,8 +33,6 @@ public: static void init(MainWindow *mainWindow); static void populateGlobalObject(MainWindow *mainWindow); static QJSEngine *getEngine(); - static void registerAction(QString functionName, QString actionName); - static int numRegisteredActions(); static void invokeAction(int actionIndex); static void cb_ProjectOpened(QString projectPath); static void cb_ProjectClosed(QString projectPath); diff --git a/include/scriptutility.h b/include/scriptutility.h index 5b6882c6..639e71f6 100644 --- a/include/scriptutility.h +++ b/include/scriptutility.h @@ -12,7 +12,8 @@ public: ScriptUtility(MainWindow *mainWindow); void clearActions(); QString getActionFunctionName(int actionIndex); - Q_INVOKABLE void registerAction(QString functionName, QString actionName, QString shortcut = ""); + Q_INVOKABLE bool registerAction(QString functionName, QString actionName, QString shortcut = ""); + Q_INVOKABLE bool registerToggleAction(QString functionName, QString actionName, QString shortcut = "", bool checked = false); Q_INVOKABLE void setTimeout(QJSValue callback, int milliseconds); Q_INVOKABLE void log(QString message); Q_INVOKABLE void warn(QString message); diff --git a/src/scriptapi/apiutility.cpp b/src/scriptapi/apiutility.cpp index 0678a5e0..baeb2017 100644 --- a/src/scriptapi/apiutility.cpp +++ b/src/scriptapi/apiutility.cpp @@ -7,13 +7,13 @@ ScriptUtility::ScriptUtility(MainWindow *mainWindow) { this->window = mainWindow; } -void ScriptUtility::registerAction(QString functionName, QString actionName, QString shortcut) { +bool ScriptUtility::registerAction(QString functionName, QString actionName, QString shortcut) { if (!window || !window->ui || !window->ui->menuTools) - return; + return false; if (functionName.isEmpty() || actionName.isEmpty()) { logError("Failed to register script action. 'functionName' and 'actionName' must be non-empty."); - return; + return false; } if (this->registeredActions.size() == 0) { @@ -32,6 +32,16 @@ void ScriptUtility::registerAction(QString functionName, QString actionName, QSt this->actionMap.insert(actionIndex, functionName); this->registeredActions.append(action); + return true; +} + +bool ScriptUtility::registerToggleAction(QString functionName, QString actionName, QString shortcut, bool checked) { + if (!registerAction(functionName, actionName, shortcut)) + return false; + QAction *action = this->registeredActions.last(); + action->setCheckable(true); + action->setChecked(checked); + return true; } void ScriptUtility::clearActions() { From f4f93f4c98c4b888e5b0e6ac29fe204766610725 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 12 Feb 2023 14:09:25 -0500 Subject: [PATCH 6/6] Remove option to turn off script warning messages --- include/config.h | 8 -------- src/config.cpp | 24 ---------------------- src/scriptapi/scripting.cpp | 40 ++++++++++++------------------------- 3 files changed, 13 insertions(+), 59 deletions(-) diff --git a/include/config.h b/include/config.h index 24d88a1e..af649e8f 100644 --- a/include/config.h +++ b/include/config.h @@ -61,8 +61,6 @@ public: this->theme = "default"; this->textEditorOpenFolder = ""; this->textEditorGotoLine = ""; - this->warnScriptLoad = true; - this->warnScriptAction = true; } void setRecentProject(QString project); void setReopenOnLaunch(bool enabled); @@ -80,8 +78,6 @@ public: void setShowGrid(bool enabled); void setMonitorFiles(bool monitor); void setTilesetCheckerboardFill(bool checkerboard); - void setWarnScriptLoad(bool enabled); - void setWarnScriptAction(bool enabled); void setTheme(QString theme); void setTextEditorOpenFolder(const QString &command); void setTextEditorGotoLine(const QString &command); @@ -101,8 +97,6 @@ public: bool getShowGrid(); bool getMonitorFiles(); bool getTilesetCheckerboardFill(); - bool getWarnScriptLoad(); - bool getWarnScriptAction(); QString getTheme(); QString getTextEditorOpenFolder(); QString getTextEditorGotoLine(); @@ -138,8 +132,6 @@ private: bool showGrid; bool monitorFiles; bool tilesetCheckerboardFill; - bool warnScriptLoad; - bool warnScriptAction; QString theme; QString textEditorOpenFolder; QString textEditorGotoLine; diff --git a/src/config.cpp b/src/config.cpp index a7269026..b1f2f03f 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -240,10 +240,6 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) { this->monitorFiles = getConfigBool(key, value); } else if (key == "tileset_checkerboard_fill") { this->tilesetCheckerboardFill = getConfigBool(key, value); - } else if (key == "warn_script_load") { - this->warnScriptLoad = getConfigBool(key, value); - } else if (key == "warn_script_action") { - this->warnScriptAction = getConfigBool(key, value); } else if (key == "theme") { this->theme = value; } else if (key == "text_editor_open_directory") { @@ -279,8 +275,6 @@ QMap PorymapConfig::getKeyValueMap() { map.insert("show_grid", this->showGrid ? "1" : "0"); map.insert("monitor_files", this->monitorFiles ? "1" : "0"); map.insert("tileset_checkerboard_fill", this->tilesetCheckerboardFill ? "1" : "0"); - map.insert("warn_script_load", this->warnScriptLoad ? "1" : "0"); - map.insert("warn_script_action", this->warnScriptAction ? "1" : "0"); map.insert("theme", this->theme); map.insert("text_editor_open_directory", this->textEditorOpenFolder); map.insert("text_editor_goto_line", this->textEditorGotoLine); @@ -335,16 +329,6 @@ void PorymapConfig::setTilesetCheckerboardFill(bool checkerboard) { this->save(); } -void PorymapConfig::setWarnScriptLoad(bool enabled) { - this->warnScriptLoad = enabled; - this->save(); -} - -void PorymapConfig::setWarnScriptAction(bool enabled) { - this->warnScriptAction = enabled; - this->save(); -} - void PorymapConfig::setMainGeometry(QByteArray mainWindowGeometry_, QByteArray mainWindowState_, QByteArray mapSplitterState_, QByteArray mainSplitterState_) { this->mainWindowGeometry = mainWindowGeometry_; @@ -502,14 +486,6 @@ bool PorymapConfig::getTilesetCheckerboardFill() { return this->tilesetCheckerboardFill; } -bool PorymapConfig::getWarnScriptLoad() { - return this->warnScriptLoad; -} - -bool PorymapConfig::getWarnScriptAction() { - return this->warnScriptAction; -} - QString PorymapConfig::getTheme() { return this->theme; } diff --git a/src/scriptapi/scripting.cpp b/src/scriptapi/scripting.cpp index 1310a99c..9aa6963c 100644 --- a/src/scriptapi/scripting.cpp +++ b/src/scriptapi/scripting.cpp @@ -50,20 +50,13 @@ void Scripting::loadModules(QStringList moduleFiles) { QString relativePath = QDir::cleanPath(userConfig.getProjectDir() + QDir::separator() + filepath); module = this->engine->importModule(relativePath); if (tryErrorJS(module)) { - if (porymapConfig.getWarnScriptLoad()) { - QMessageBox messageBox(this->mainWindow); - messageBox.setText("Failed to load script"); - messageBox.setInformativeText(QString("An error occurred while loading custom script file '%1'").arg(filepath)); - messageBox.setDetailedText(getMostRecentError()); - messageBox.setIcon(QMessageBox::Warning); - messageBox.addButton(QMessageBox::Ok); - QCheckBox * checkbox = new QCheckBox("Don't show this warning again"); - messageBox.setCheckBox(checkbox); - QObject::connect(checkbox, &QCheckBox::stateChanged, [](int state) { - porymapConfig.setWarnScriptLoad(static_cast(state) != Qt::CheckState::Checked); - }); - messageBox.exec(); - } + QMessageBox messageBox(this->mainWindow); + messageBox.setText("Failed to load script"); + messageBox.setInformativeText(QString("An error occurred while loading custom script file '%1'").arg(filepath)); + messageBox.setDetailedText(getMostRecentError()); + messageBox.setIcon(QMessageBox::Warning); + messageBox.addButton(QMessageBox::Ok); + messageBox.exec(); continue; } } @@ -160,19 +153,12 @@ void Scripting::invokeAction(int actionIndex) { } if (!foundFunction) { logError(QString("Unknown custom script function '%1'").arg(functionName)); - if (porymapConfig.getWarnScriptAction()) { - QMessageBox messageBox(instance->mainWindow); - messageBox.setText("Failed to run custom action"); - messageBox.setInformativeText(getMostRecentError()); - messageBox.setIcon(QMessageBox::Warning); - messageBox.addButton(QMessageBox::Ok); - QCheckBox * checkbox = new QCheckBox("Don't show this warning again"); - messageBox.setCheckBox(checkbox); - QObject::connect(checkbox, &QCheckBox::stateChanged, [](int state) { - porymapConfig.setWarnScriptAction(static_cast(state) != Qt::CheckState::Checked); - }); - messageBox.exec(); - } + QMessageBox messageBox(instance->mainWindow); + messageBox.setText("Failed to run custom action"); + messageBox.setInformativeText(getMostRecentError()); + messageBox.setIcon(QMessageBox::Warning); + messageBox.addButton(QMessageBox::Ok); + messageBox.exec(); } }