Skip to content

Commit

Permalink
Update windbot handling for generic executor
Browse files Browse the repository at this point in the history
Don't display it among the available decks, but keep it only as deck engine that is also always shown regardless of the duel options
  • Loading branch information
edo9300 committed Jun 13, 2021
1 parent 49109f5 commit 37a0d15
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
17 changes: 10 additions & 7 deletions gframe/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2020,30 +2020,33 @@ void Game::RefreshAiDecks() {
}
}
#endif
int genericEngineIdx = -1;
WindBot generic_engine_bot;
for(auto& obj : j) {
try {
WindBot bot;
bot.name = BufferIO::DecodeUTF8(obj.at("name").get_ref<std::string&>());
bot.deck = BufferIO::DecodeUTF8(obj.at("deck").get_ref<std::string&>());
bot.deckfile = fmt::format(L"AI_{}", bot.deck);
if(bot.deck == L"Lucky" ) {
genericEngineIdx = (int)gBot.bots.size();
}
bot.difficulty = obj.at("difficulty").get<int>();
for(auto& masterRule : obj.at("masterRules")) {
if(masterRule.is_number()) {
bot.masterRules.insert(masterRule.get<int>());
}
}
gBot.bots.push_back(std::move(bot));
bool is_generic_engine = bot.deck == L"Lucky";
if(is_generic_engine)
generic_engine_bot = bot;
else
gBot.bots.push_back(std::move(bot));
}
catch(const std::exception& e) {
ErrorLog(fmt::format("Failed to parse WindBot Ignite config json entry: {}", e.what()));
}
}
if(genericEngineIdx != -1)
gBot.genericEngine = &gBot.bots[genericEngineIdx];
if(generic_engine_bot.deck.size()) {
gBot.bots.push_back(std::move(generic_engine_bot));
gBot.genericEngine = &gBot.bots.back();
}
}
} else {
ErrorLog("Failed to open WindBot Ignite config json!");
Expand Down
13 changes: 8 additions & 5 deletions gframe/windbot_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,21 @@ void WindBotPanel::Refresh(int filterMasterRule, int lastIndex) {
cbBotEngine->clear();
genericEngineIdx = -1;
size_t i = 0;
for (; i < bots.size(); i++) {
const auto& bot = bots[i];
for (const auto& bot : bots) {
if(genericEngine == &bot)
continue;
if (filterMasterRule == 0 || bot.masterRules.find(filterMasterRule) != bot.masterRules.end()) {
int newIndex = cbBotDeck->addItem(bot.name.data(), i);
cbBotEngine->addItem(bot.name.data(), i);
if(genericEngine == &bot)
genericEngineIdx = newIndex;
if(i == lastBot) {
cbBotDeck->setSelected(newIndex);
cbBotEngine->setSelected(newIndex);
}
}
i++;
}
if(genericEngine) {
genericEngineIdx = cbBotEngine->addItem(genericEngine->name.data(), i);
}
for(auto& file : Utils::FindFiles(EPRO_TEXT("./deck/"), { EPRO_TEXT("ydk") })) {
file.erase(file.size() - 4);
Expand All @@ -54,7 +57,7 @@ void WindBotPanel::UpdateDescription() {
deckProperties->setText(L"");
return;
}
if (index >= (int)bots.size() || index != CurrentEngine()) {
if (index >= (int)(bots.size() - (genericEngine != nullptr)) || index != CurrentEngine()) {
deckProperties->setText(L"???");
return;
}
Expand Down

0 comments on commit 37a0d15

Please sign in to comment.