Fixed an issue where the game-end event was triggered immediately if running in the background.

This commit is contained in:
Leon Styhre 2022-05-16 22:34:51 +02:00
parent 859e769bb4
commit 41357ce7f5
3 changed files with 26 additions and 3 deletions

View file

@ -1394,9 +1394,22 @@ void FileData::launchGame()
#endif #endif
} }
Scripting::fireEvent("game-end", romPath, getSourceFileData()->metadata.get("name"), // If running in the background then don't trigger the game-end event, which will instead be
getSourceFileData()->getSystem()->getName(), // triggered in ViewController when manually waking up the application.
getSourceFileData()->getSystem()->getFullName()); if (!runInBackground) {
Scripting::fireEvent("game-end", romPath, getSourceFileData()->metadata.get("name"),
getSourceFileData()->getSystem()->getName(),
getSourceFileData()->getSystem()->getFullName());
}
else {
std::vector<std::string>& gameEndParams {
ViewController::getInstance()->getGameEndEventParams()};
gameEndParams.emplace_back("game-end");
gameEndParams.emplace_back(romPath);
gameEndParams.emplace_back(getSourceFileData()->metadata.get("name"));
gameEndParams.emplace_back(getSourceFileData()->getSystem()->getName());
gameEndParams.emplace_back(getSourceFileData()->getSystem()->getFullName());
}
// Unless we're running in the background while the game is launched, re-enable the text // Unless we're running in the background while the game is launched, re-enable the text
// scrolling that was disabled in ViewController. // scrolling that was disabled in ViewController.

View file

@ -15,6 +15,7 @@
#include "FileFilterIndex.h" #include "FileFilterIndex.h"
#include "InputManager.h" #include "InputManager.h"
#include "Log.h" #include "Log.h"
#include "Scripting.h"
#include "Settings.h" #include "Settings.h"
#include "Sound.h" #include "Sound.h"
#include "SystemData.h" #include "SystemData.h"
@ -828,6 +829,13 @@ bool ViewController::input(InputConfig* config, Input input)
// queued when leaving the game. // queued when leaving the game.
if (config->isMappedTo("a", input) && input.value != 0) if (config->isMappedTo("a", input) && input.value != 0)
return true; return true;
// Trigger the game-end event.
if (mGameEndEventParams.size() == 5) {
Scripting::fireEvent(mGameEndEventParams[0], mGameEndEventParams[1],
mGameEndEventParams[2], mGameEndEventParams[3],
mGameEndEventParams[4]);
mGameEndEventParams.clear();
}
} }
// Open the main menu. // Open the main menu.

View file

@ -79,6 +79,7 @@ public:
mLockInput = true; mLockInput = true;
}; };
bool getGameLaunchTriggered() { return (mGameToLaunch != nullptr); } bool getGameLaunchTriggered() { return (mGameToLaunch != nullptr); }
std::vector<std::string>& getGameEndEventParams() { return mGameEndEventParams; }
bool input(InputConfig* config, Input input) override; bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override; void update(int deltaTime) override;
@ -170,6 +171,7 @@ private:
std::map<SystemData*, std::shared_ptr<GamelistView>> mGamelistViews; std::map<SystemData*, std::shared_ptr<GamelistView>> mGamelistViews;
std::shared_ptr<SystemView> mSystemListView; std::shared_ptr<SystemView> mSystemListView;
std::vector<std::string> mGameEndEventParams;
FileData* mGameToLaunch; FileData* mGameToLaunch;
State mState; State mState;