mirror of https://github.com/OpenTTD/OpenTTD
Fix: [Script] Reset instance when changing running scripts in scenario editor (#13906)
parent
20805ba84b
commit
b25daba561
|
@ -95,6 +95,11 @@ public:
|
|||
*/
|
||||
static class GameInstance *GetInstance() { return Game::instance.get(); }
|
||||
|
||||
/**
|
||||
* Reset the current active instance.
|
||||
*/
|
||||
static void ResetInstance();
|
||||
|
||||
/** Wrapper function for GameScanner::HasGame */
|
||||
static bool HasGame(const struct ContentInfo *ci, bool md5sum);
|
||||
static bool HasGameLibrary(const ContentInfo *ci, bool md5sum);
|
||||
|
|
|
@ -103,8 +103,7 @@
|
|||
{
|
||||
Backup<CompanyID> cur_company(_current_company);
|
||||
|
||||
Game::instance.reset();
|
||||
Game::info = nullptr;
|
||||
Game::ResetInstance();
|
||||
|
||||
cur_company.Restore();
|
||||
|
||||
|
@ -162,10 +161,7 @@
|
|||
if (!_settings_game.script_config.game->ResetInfo(true)) {
|
||||
Debug(script, 0, "After a reload, the GameScript by the name '{}' was no longer found, and removed from the list.", _settings_game.script_config.game->GetName());
|
||||
_settings_game.script_config.game->Change(std::nullopt);
|
||||
if (Game::instance != nullptr) {
|
||||
Game::instance.reset();
|
||||
Game::info = nullptr;
|
||||
}
|
||||
if (Game::instance != nullptr) Game::ResetInstance();
|
||||
} else if (Game::instance != nullptr) {
|
||||
Game::info = _settings_game.script_config.game->GetInfo();
|
||||
}
|
||||
|
@ -234,6 +230,12 @@
|
|||
return Game::scanner_library->FindLibrary(library, version);
|
||||
}
|
||||
|
||||
/* static */ void Game::ResetInstance()
|
||||
{
|
||||
Game::instance.reset();
|
||||
Game::info = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether we have an Game (library) with the exact characteristics as ci.
|
||||
* @param ci the characteristics to search on (shortname and md5sum)
|
||||
|
|
|
@ -173,8 +173,21 @@ struct ScriptListWindow : public Window {
|
|||
std::advance(it, this->selected);
|
||||
GetConfig(slot)->Change(it->second->GetName(), it->second->GetVersion());
|
||||
}
|
||||
if (_game_mode == GM_EDITOR) {
|
||||
if (slot == OWNER_DEITY) {
|
||||
if (Game::GetInstance() != nullptr) Game::ResetInstance();
|
||||
Game::StartNew();
|
||||
} else {
|
||||
Company *c = Company::GetIfValid(slot);
|
||||
if (c != nullptr && c->ai_instance != nullptr) {
|
||||
c->ai_instance.reset();
|
||||
AI::StartNew(slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
InvalidateWindowData(WC_GAME_OPTIONS, slot == OWNER_DEITY ? WN_GAME_OPTIONS_GS : WN_GAME_OPTIONS_AI);
|
||||
InvalidateWindowClassesData(WC_SCRIPT_SETTINGS);
|
||||
InvalidateWindowClassesData(WC_SCRIPT_DEBUG, -1);
|
||||
CloseWindowByClass(WC_QUERY_STRING);
|
||||
InvalidateWindowClassesData(WC_TEXTFILE);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue