Changing game settings now takes immediate effect.

Fixes #243. Also fixed missing game defaults not being restored in UI.
This commit is contained in:
WrinklyNinja
2014-08-24 12:15:32 +01:00
parent 0c127614aa
commit 6eadc9c4b3
6 changed files with 59 additions and 10 deletions
+10 -2
View File
@@ -753,10 +753,18 @@ function closeSettingsDialog(evt) {
settings
]
});
loot.query(request).catch(processCefError);
loot.query(request).then(function(result){
loot.settings = settings;
try {
loot.installedGames = JSON.parse(result);
} catch (e) {
console.log(e);
console.log('getInstalledGames response: ' + results[1]);
}
loot.settings = settings;
updateSettingsUI();
}).catch(processCefError);
} else {
/* Re-apply the existing settings to the settings dialog elements. */
updateSettingsUI();
+4 -1
View File
@@ -44,7 +44,7 @@ namespace lc = boost::locale;
namespace loot {
std::vector<Game> GetGames(const YAML::Node& settings) {
std::vector<Game> GetGames(YAML::Node& settings) {
vector<Game> games;
if (settings["games"])
@@ -62,6 +62,9 @@ namespace loot {
if (find(games.begin(), games.end(), Game(Game::fonv)) == games.end())
games.push_back(Game(Game::fonv));
// If there were any missing defaults, make sure they're in settings now.
settings["games"] = games;
return games;
}
+1 -1
View File
@@ -161,7 +161,7 @@ namespace loot {
void CreateLOOTGameFolder();
};
std::vector<Game> GetGames(const YAML::Node& settings);
std::vector<Game> GetGames(YAML::Node& settings);
size_t SelectGame(const YAML::Node& settings, const std::vector<Game>& games, const std::string& cmdLineGame);
}
+34 -3
View File
@@ -240,11 +240,42 @@ namespace loot {
return _initErrors;
}
void LootState::UpdateGames(std::vector<Game>& games) {
unordered_set<string> newGameFolders;
// Update existing games, add new games.
for (auto &game : games) {
auto pos = find(_games.begin(), _games.end(), game);
if (pos != _games.end()) {
pos->SetDetails(game.Name(), game.Master(), game.RepoURL(), game.RepoBranch(), game.GamePath().string(), game.RegistryKey());
}
else {
_games.push_back(game);
}
newGameFolders.insert(game.FolderName());
}
// Remove deleted games. As the current game is stored using its index,
// removing an earlier game may invalidate it.
for (auto it = _games.begin(); it != _games.end();) {
if (newGameFolders.find(it->FolderName()) == newGameFolders.end()) {
if (distance(_games.begin(), it) < _currentGame) {
// Deleting a game before the current game, so the current game's
// index decreases by one.
--_currentGame;
}
it = _games.erase(it);
}
else
++it;
}
}
void LootState::ChangeGame(const std::string& newGameFolder) {
BOOST_LOG_TRIVIAL(debug) << "Changing current game to that with folder: " << newGameFolder;
auto it = std::find_if(_games.begin(), _games.end(), [&newGameFolder](const Game& game){
return game.FolderName() == newGameFolder;
});
auto it = find(_games.begin(), _games.end(), newGameFolder);
_currentGame = std::distance(_games.begin(), it);
_games[_currentGame].Init();
+1
View File
@@ -72,6 +72,7 @@ namespace loot {
Game& CurrentGame();
void ChangeGame(const std::string& newGameFolder);
void UpdateGames(std::vector<Game>& games);
// Get the folder names of the installed games.
std::vector<std::string> InstalledGames() const;
+9 -3
View File
@@ -278,11 +278,17 @@ namespace loot {
}
else if (requestName == "closeSettings") {
BOOST_LOG_TRIVIAL(trace) << "Settings dialog closed and changes accepted, updating settings object.";
g_app_state.UpdateSettings(request["args"][0]);
// Also update the game details.
// Update the game details and settings.
g_app_state.UpdateSettings(request["args"][0]);
// If the user has deleted a default game, we don't want to restore it now.
// It will be restored when LOOT is next loaded.
vector<Game> games(request["args"][0]["games"].as< vector<Game> >());
callback->Success("");
g_app_state.UpdateGames(games);
// Now send back the new list of installed games to the UI.
callback->Success(GetInstalledGames());
return true;
}
else if (requestName == "applySort") {