Skip to content

Commit d4fed7b

Browse files
committed
Split CreationClubPlugins out from Game
1 parent 2bb51ce commit d4fed7b

File tree

7 files changed

+145
-132
lines changed

7 files changed

+145
-132
lines changed

resources/l10n/template.pot

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: LOOT 0.25.2\n"
1010
"Report-Msgid-Bugs-To: https://github.com/loot/loot/issues\n"
11-
"POT-Creation-Date: 2025-04-03 18:20+0100\n"
11+
"POT-Creation-Date: 2025-04-03 20:52+0100\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -23,11 +23,11 @@ msgstr ""
2323
msgid "\"{0}\" contains a condition that could not be evaluated. Details: {1}"
2424
msgstr ""
2525

26-
#: src/gui/plugin_item.cpp:194
26+
#: src/gui/plugin_item.cpp:195
2727
msgid "Location"
2828
msgstr ""
2929

30-
#: src/gui/plugin_item.cpp:199
30+
#: src/gui/plugin_item.cpp:200
3131
#, c++-format
3232
msgid "Location {0}"
3333
msgstr ""
@@ -1177,17 +1177,7 @@ msgstr ""
11771177
msgid "The group \"{0}\" does not exist."
11781178
msgstr ""
11791179

1180-
#: src/gui/state/game/game.cpp:821
1181-
msgid ""
1182-
"Sorting failed because there is at least one installed plugin that depends "
1183-
"on at least one plugin that is not installed."
1184-
msgstr ""
1185-
1186-
#: src/gui/state/game/game.cpp:858
1187-
msgid "You have not sorted your load order this session."
1188-
msgstr ""
1189-
1190-
#: src/gui/state/game/game.cpp:936
1180+
#: src/gui/state/game/game.cpp:570
11911181
#, c++-format
11921182
msgid ""
11931183
"An error occurred while parsing the metadata list(s): {0}.\n"
@@ -1206,7 +1196,17 @@ msgid ""
12061196
"[LOOT's website]({1})."
12071197
msgstr ""
12081198

1209-
#: src/gui/state/game/game.cpp:1115
1199+
#: src/gui/state/game/game.cpp:970
1200+
msgid ""
1201+
"Sorting failed because there is at least one installed plugin that depends "
1202+
"on at least one plugin that is not installed."
1203+
msgstr ""
1204+
1205+
#: src/gui/state/game/game.cpp:1007
1206+
msgid "You have not sorted your load order this session."
1207+
msgstr ""
1208+
1209+
#: src/gui/state/game/game.cpp:1127
12101210
msgid ""
12111211
"Failed to load the current load order, information displayed may be "
12121212
"incorrect."

src/gui/plugin_item.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ PluginItem::PluginItem(GameId gameId,
141141
isLightPlugin(plugin.IsLightPlugin()),
142142
isMediumPlugin(plugin.IsMediumPlugin()),
143143
loadsArchive(plugin.LoadsArchive()),
144-
isCreationClubPlugin(game.IsCreationClubPlugin(plugin.GetName())) {
144+
isCreationClubPlugin(
145+
game.GetCreationClubPlugins().IsCreationClubPlugin(plugin.GetName())) {
145146
auto userMetadata = game.GetUserMetadata(plugin.GetName());
146147
if (userMetadata.has_value()) {
147148
hasUserMetadata =

src/gui/qt/main_window.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ void MainWindow::handleGameDataLoaded(QueryResult result) {
13831383

13841384
filtersWidget->setGroups(GetGroupNames(state.GetCurrentGame()));
13851385
filtersWidget->showCreationClubPluginsFilter(
1386-
state.GetCurrentGame().HadCreationClub());
1386+
HadCreationClub(state.GetCurrentGame().GetSettings().Id()));
13871387

13881388
pluginEditorWidget->setBashTagCompletions(
13891389
state.GetCurrentGame().GetKnownBashTags());

src/gui/query/types/get_game_data_query.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class GetGameDataQuery : public Query {
4343
sendProgressUpdate_(sendProgressUpdate) {}
4444

4545
QueryResult executeLogic() override {
46-
sendProgressUpdate_(boost::locale::translate(
47-
"Parsing, merging and evaluating metadata…"));
46+
sendProgressUpdate_(
47+
boost::locale::translate("Parsing, merging and evaluating metadata…"));
4848

4949
/* If the game's plugins object is empty, this is the first time loading
5050
the game data, so also load the metadata lists. */
@@ -77,7 +77,8 @@ class GetGameDataQuery : public Query {
7777

7878
threads.push_back(std::thread([&]() {
7979
try {
80-
game_.LoadCreationClubPluginNames();
80+
game_.GetCreationClubPlugins().Load(game_.GetSettings().Id(),
81+
game_.GetSettings().GamePath());
8182
} catch (...) {
8283
if (exceptionPointer == nullptr) {
8384
exceptionPointer = std::current_exception();

src/gui/state/game/game.cpp

Lines changed: 59 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,55 @@ std::vector<LoadOrderTuple> MapToLoadOrderTuples(
471471
return data;
472472
}
473473

474+
bool HadCreationClub(GameId gameId) {
475+
return gameId == GameId::tes5se || gameId == GameId::fo4;
476+
}
477+
478+
void CreationClubPlugins::Load(GameId gameId,
479+
const std::filesystem::path& gamePath) {
480+
const auto logger = getLogger();
481+
482+
creationClubPlugins_.clear();
483+
484+
if (!HadCreationClub(gameId)) {
485+
if (logger) {
486+
logger->debug(
487+
"The current game was not part of the Creation Club while it was "
488+
"active, skipping loading Creation Club plugin names.");
489+
}
490+
return;
491+
}
492+
493+
const auto cccFilename = GetCCCFilename(gameId);
494+
495+
if (!cccFilename.has_value()) {
496+
if (logger) {
497+
logger->debug(
498+
"The current game does not have a CCC file, the Creation Club filter "
499+
"will have no effect.");
500+
}
501+
return;
502+
}
503+
504+
const auto cccFilePath = gamePath / cccFilename.value();
505+
506+
if (!fs::exists(cccFilePath)) {
507+
if (logger) {
508+
logger->debug(
509+
"The CCC file at {} does not exist, the Creation Club filter "
510+
"will have no effect.",
511+
cccFilePath.u8string());
512+
}
513+
return;
514+
}
515+
516+
creationClubPlugins_ = ReadFilenamesInFile(cccFilePath);
517+
}
518+
519+
bool CreationClubPlugins::IsCreationClubPlugin(const std::string& name) const {
520+
return creationClubPlugins_.count(Filename(name)) != 0;
521+
}
522+
474523
namespace gui {
475524
Game::Game(const GameSettings& gameSettings,
476525
const std::filesystem::path& lootDataPath,
@@ -484,6 +533,7 @@ Game::Game(const GameSettings& gameSettings,
484533

485534
Game::Game(Game&& game) {
486535
settings_ = std::move(game.settings_);
536+
creationClubPlugins_ = std::move(game.creationClubPlugins_);
487537
gameHandle_ = std::move(game.gameHandle_);
488538
messages_ = std::move(game.messages_);
489539
lootDataPath_ = std::move(game.lootDataPath_);
@@ -497,6 +547,7 @@ Game::Game(Game&& game) {
497547
Game& Game::operator=(Game&& game) {
498548
if (&game != this) {
499549
settings_ = std::move(game.settings_);
550+
creationClubPlugins_ = std::move(game.creationClubPlugins_);
500551
gameHandle_ = std::move(game.gameHandle_);
501552
messages_ = std::move(game.messages_);
502553
lootDataPath_ = std::move(game.lootDataPath_);
@@ -514,6 +565,14 @@ const GameSettings& Game::GetSettings() const { return settings_; }
514565

515566
GameSettings& Game::GetSettings() { return settings_; }
516567

568+
const CreationClubPlugins& Game::GetCreationClubPlugins() const {
569+
return creationClubPlugins_;
570+
}
571+
572+
CreationClubPlugins& Game::GetCreationClubPlugins() {
573+
return creationClubPlugins_;
574+
}
575+
517576
void Game::Init() {
518577
auto logger = getLogger();
519578
if (logger) {
@@ -596,52 +655,6 @@ void Game::RedatePlugins() {
596655
}
597656
}
598657

599-
void Game::LoadCreationClubPluginNames() {
600-
const auto logger = getLogger();
601-
602-
creationClubPlugins_.clear();
603-
604-
if (!HadCreationClub()) {
605-
if (logger) {
606-
logger->debug(
607-
"The current game was not part of the Creation Club while it was "
608-
"active, skipping loading Creation Club plugin names.");
609-
}
610-
return;
611-
}
612-
613-
const auto cccFilename = GetCCCFilename(settings_.Id());
614-
615-
if (!cccFilename.has_value()) {
616-
if (logger) {
617-
logger->debug(
618-
"The current game does not have a CCC file, the Creation Club filter "
619-
"will have no effect.");
620-
}
621-
return;
622-
}
623-
624-
const auto cccFilePath = settings_.GamePath() / cccFilename.value();
625-
626-
if (!fs::exists(cccFilePath)) {
627-
if (logger) {
628-
logger->debug(
629-
"The CCC file at {} does not exist, the Creation Club filter "
630-
"will have no effect.",
631-
cccFilePath.u8string());
632-
}
633-
return;
634-
}
635-
636-
creationClubPlugins_ = ReadFilenamesInFile(cccFilePath);
637-
}
638-
639-
bool Game::HadCreationClub() const {
640-
// The Creation Club has been replaced, but while it was active it was
641-
// available for Skyrim SE and Fallout 4.
642-
return settings_.Id() == GameId::tes5se || settings_.Id() == GameId::fo4;
643-
}
644-
645658
void Game::LoadAllInstalledPlugins(bool headersOnly) {
646659
LoadCurrentLoadOrderState();
647660

@@ -1081,10 +1094,6 @@ void Game::AppendMessages(std::vector<SourcedMessage> messages) {
10811094
}
10821095
}
10831096

1084-
bool Game::IsCreationClubPlugin(const std::string& name) const {
1085-
return creationClubPlugins_.count(Filename(name)) != 0;
1086-
}
1087-
10881097
std::optional<std::filesystem::path> Game::ResolveGameFilePath(
10891098
const std::string& filePath) const {
10901099
return loot::ResolveGameFilePath(settings_.Id(),

src/gui/state/game/game.h

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ std::filesystem::path GetMasterlistPath(
6565
void InitLootGameFolder(const std::filesystem::path& lootDataPath_,
6666
const GameSettings& settings);
6767

68+
// The Creation Club has been replaced, but while it was active it was
69+
// available for Skyrim SE and Fallout 4.
70+
bool HadCreationClub(GameId gameId);
71+
72+
class CreationClubPlugins {
73+
public:
74+
void Load(GameId gameId, const std::filesystem::path& gamePath);
75+
76+
bool IsCreationClubPlugin(const std::string& name) const;
77+
78+
private:
79+
// Use Filename to benefit from libloot's case-insensitive comparisons.
80+
std::set<Filename> creationClubPlugins_;
81+
};
82+
6883
namespace gui {
6984
class Game {
7085
public:
@@ -81,6 +96,9 @@ class Game {
8196
const GameSettings& GetSettings() const;
8297
GameSettings& GetSettings();
8398

99+
const CreationClubPlugins& GetCreationClubPlugins() const;
100+
CreationClubPlugins& GetCreationClubPlugins();
101+
84102
void Init();
85103
bool IsInitialised() const;
86104

@@ -93,10 +111,6 @@ class Game {
93111

94112
void RedatePlugins(); // Change timestamps to match load order (Skyrim only).
95113

96-
void LoadCreationClubPluginNames();
97-
bool HadCreationClub() const;
98-
bool IsCreationClubPlugin(const std::string& name) const;
99-
100114
void LoadAllInstalledPlugins(
101115
bool headersOnly); // Loads all installed plugins.
102116
bool ArePluginsFullyLoaded()
@@ -165,6 +179,7 @@ class Game {
165179
void LoadCurrentLoadOrderState();
166180

167181
GameSettings settings_;
182+
CreationClubPlugins creationClubPlugins_;
168183
std::unique_ptr<GameInterface> gameHandle_;
169184
std::vector<SourcedMessage> messages_;
170185
std::filesystem::path lootDataPath_;
@@ -173,9 +188,6 @@ class Game {
173188
bool pluginsFullyLoaded_{false};
174189
bool isMicrosoftStoreInstall_{false};
175190
bool supportsLightPlugins_{false};
176-
177-
// Use Filename to benefit from libloot's case-insensitive comparisons.
178-
std::set<Filename> creationClubPlugins_;
179191
};
180192
}
181193

0 commit comments

Comments
 (0)