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
}
Scripting::fireEvent("game-end", romPath, getSourceFileData()->metadata.get("name"),
getSourceFileData()->getSystem()->getName(),
getSourceFileData()->getSystem()->getFullName());
// If running in the background then don't trigger the game-end event, which will instead be
// triggered in ViewController when manually waking up the application.
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
// scrolling that was disabled in ViewController.

View file

@ -15,6 +15,7 @@
#include "FileFilterIndex.h"
#include "InputManager.h"
#include "Log.h"
#include "Scripting.h"
#include "Settings.h"
#include "Sound.h"
#include "SystemData.h"
@ -828,6 +829,13 @@ bool ViewController::input(InputConfig* config, Input input)
// queued when leaving the game.
if (config->isMappedTo("a", input) && input.value != 0)
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.

View file

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