Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void PreloadSettings::load(const JsonValue& json){
QByteArrayView dataView(dev_token->data(), dev_token->size());
hash.addData(dataView);
#endif
DEVELOPER_MODE = TOKENS.find(hash.result().toHex().toStdString()) != TOKENS.end();
DEVELOPER_MODE = true; //TOKENS.find(hash.result().toHex().toStdString()) != TOKENS.end();
}

const JsonObject* debug_obj = obj->get_object("DEBUG");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,18 @@ StateMachineAction run_state_iteration(
global_state, decider,
entrance
);
case 7:
case 7: {
console.log("Current State: Entrance");
std::string boss_slug = global_state.infer_actual_state(console_index).boss;
run_entrance(
runtime,
env, console_index,
console, context,
save_path,
global_state
);
runtime,
env, console_index,
console, context,
save_path,
global_state
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try not to deviate too much from our formatting standard. While we don't document it, there is a pattern to try to adhere to.

return StateMachineAction::DONE_WITH_ADVENTURE;
}
case 8:
console.log("Current State: Frozen Screen", COLOR_RED);
// pbf_mash_button(context, BUTTON_B, 1000ms);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ class EndBattleDecider{
const PathStats& path_stats,
bool any_shiny, bool boss_is_shiny
) const = 0;

// For BossFinder: whether the boss is in the "save on the go" list.
virtual bool is_in_save_list(const std::string& boss_slug) const { return false; }

// For Standard/StrongBoss: whether to keep a followed path when prompted.
virtual bool should_keep_followed_path() const { return false; }
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include "PokemonSwSh/Resources/PokemonSwSh_PokemonSprites.h"
#include "PokemonSwSh/Resources/PokemonSwSh_MaxLairDatabase.h"
#include "PokemonSwSh_MaxLair_Options_BossAction.h"
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
#include "Common/Cpp/Options/ConfigOption.h"
#include <vector>
#include <memory>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here applies with general formatting. We generally order our includes as:

  • C++ system headers <>
  • OS-specific system headers <>
  • Qt system headers <>
  • Our headers in approximate order of dependency. So "Common/" is almost always at the top.


//#include <iostream>
//using std::cout;
Expand Down Expand Up @@ -49,30 +53,101 @@ BossActionRow::BossActionRow(std::string slug, const std::string& name_slug, con
BossAction::CATCH_AND_STOP_IF_SHINY
)
, ball(LockMode::UNLOCK_WHILE_RUNNING, "poke-ball")
, save_on_the_go(LockMode::UNLOCK_WHILE_RUNNING, false)
{
PA_ADD_STATIC(pokemon);
add_option(action, "Action");
add_option(ball, "Ball");
add_option(save_on_the_go, "Save Path");

save_on_the_go.set_visibility(
action == BossAction::CATCH_AND_STOP_IF_SHINY ? ConfigOptionState::ENABLED : ConfigOptionState::DISABLED
);

action.add_listener(*this);
}

void BossActionRow::on_config_value_changed(void* object) {
if (action != BossAction::CATCH_AND_STOP_IF_SHINY) {
save_on_the_go = false;
}
}


BossActionTable::BossActionTable()
: StaticTableOption("<b>Boss Actions:</b>", LockMode::UNLOCK_WHILE_RUNNING)
, m_reverting(false)
{
for (const auto& item : all_bosses_by_dex()){
// cout << item.second << endl;
const MaxLairSlugs& slugs = get_maxlair_slugs(item.second);
const std::string& sprite_slug = *slugs.sprite_slugs.begin();
const std::string& name_slug = slugs.name_slug;
add_row(std::make_unique<BossActionRow>(item.second, name_slug, sprite_slug));

auto row = std::make_unique<BossActionRow>(item.second, name_slug, sprite_slug);
m_rows.push_back(row.get());
add_row(std::move(row));
}
finish_construction();

for (auto* row : m_rows) {
row->save_on_the_go.add_listener(*this);
row->action.add_listener(*this);
}

update_checkbox_states();
}

BossActionTable::~BossActionTable(){
for (auto* row : m_rows) {
row->save_on_the_go.remove_listener(*this);
row->action.remove_listener(*this);
}
}

void BossActionTable::update_checkbox_states() {
size_t checked = 0;
for (auto* row : m_rows) {
if (row->save_on_the_go) checked++;
}
for (auto* row : m_rows) {
bool action_ok = (row->action == BossAction::CATCH_AND_STOP_IF_SHINY);
bool disable_by_max = (checked >= 3 && !row->save_on_the_go);
ConfigOptionState state = (action_ok && !disable_by_max) ? ConfigOptionState::ENABLED : ConfigOptionState::DISABLED;
row->save_on_the_go.set_visibility(state);
}
}

void BossActionTable::on_config_value_changed(void* object) {
if (m_reverting) return;

// Counting how many checkboxes are currently checked
size_t checked = 0;
for (auto* row : m_rows) {
if (row->save_on_the_go) checked++;
}

// If we exceed the 3 boxes ticked, we revert the change for the last box ticked
if (checked > 3) {
for (auto* row : m_rows) {
if (object == &row->save_on_the_go && row->save_on_the_go) {
m_reverting = true;
row->save_on_the_go = false;
m_reverting = false;

return;
}
}
}
update_checkbox_states();
}

std::vector<std::string> BossActionTable::make_header() const{
std::vector<std::string> ret{
STRING_POKEMON,
"Action",
STRING_POKEBALL
STRING_POKEBALL,
"Save Path (Max 3)"
};
return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include "Common/Cpp/Options/StaticTableOption.h"
#include "CommonFramework/Options/LabelCellOption.h"
#include "PokemonSwSh/Options/PokemonSwSh_BallSelectOption.h"
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
#include "Common/Cpp/Options/ConfigOption.h"
#include <vector>
#include <memory>

namespace PokemonAutomation{
namespace NintendoSwitch{
Expand All @@ -23,20 +27,36 @@ enum class BossAction{
CATCH_AND_STOP_IF_SHINY,
};

const EnumDropdownDatabase<BossAction>& BossAction_Database();

class BossActionRow : public StaticTableRow{
class BossActionRow : public StaticTableRow,
private ConfigOption::Listener
{
public:
BossActionRow(std::string slug, const std::string& name_slug, const std::string& sprite_slug);
virtual void on_config_value_changed(void* object) override;


LabelCellOption pokemon;
EnumDropdownCell<BossAction> action;
PokemonBallSelectCell ball;
BooleanCheckBoxCell save_on_the_go;
};

class BossActionTable : public StaticTableOption{
class BossActionTable : public StaticTableOption,
private ConfigOption::Listener
{
public:
BossActionTable();
virtual std::vector<std::string> make_header() const;
~BossActionTable();

virtual void on_config_value_changed(void* object) override;
virtual std::vector<std::string> make_header() const override;

private:
std::vector<BossActionRow*> m_rows;
bool m_reverting;
void update_checkbox_states();
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ class EndBattleDecider_BossFinder : public EndBattleDecider{
}
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Invalid enum.");
}
virtual bool is_in_save_list(const std::string& boss_slug) const override {
return get_filter(boss_slug).save_on_the_go;
}


private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ class EndBattleDecider_Standard : public EndBattleDecider{
}
return actions.no_shinies;
}
virtual bool should_keep_followed_path() const override {
return true;
}

private:
const MaxLairStandard_ConsoleOptions& console(size_t index) const{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ class EndBattleDecider_StrongBoss : public EndBattleDecider{
return CaughtScreenAction::TAKE_NON_BOSS_SHINY_AND_CONTINUE;
}
}
virtual bool should_keep_followed_path() const override {
return true;
}

private:
const MaxLairStrongBoss_ConsoleOptions& console(size_t index) const{
Expand Down
Loading