mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Changing game settings now takes immediate effect.
Fixes #243. Also fixed missing game defaults not being restored in UI.
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
@@ -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
@@ -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();
|
||||
|
||||
@@ -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
@@ -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") {
|
||||
|
||||
Reference in New Issue
Block a user