Skip to content
Merged
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
2 changes: 1 addition & 1 deletion SerialPrograms/Source/CommonFramework/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace PokemonAutomation{
#endif

#ifndef PA_VERSION_PATCH
#define PA_VERSION_PATCH 4
#define PA_VERSION_PATCH 5
#endif

const bool IS_BETA_VERSION = PA_IS_BETA;
Expand Down
6 changes: 3 additions & 3 deletions SerialPrograms/Source/ComputerPrograms/ComputerProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*
*/

#include "Common/Cpp/Json/JsonObject.h"
#include "Common/Cpp/Json/JsonValue.h"
#include "ComputerProgram.h"
#include "ComputerPrograms/Framework/ComputerProgramOption.h"
#include "ComputerPrograms/Framework/ComputerProgramSession.h"

namespace PokemonAutomation{

Expand All @@ -26,7 +26,7 @@ ComputerProgramDescriptor::ComputerProgramDescriptor(
)
{}
std::unique_ptr<PanelSession> ComputerProgramDescriptor::make_panel() const{
return std::unique_ptr<PanelSession>(new ComputerProgramOption(*this));
return std::unique_ptr<PanelSession>(new ComputerProgramSession(*this));
}


Expand Down
2 changes: 1 addition & 1 deletion SerialPrograms/Source/ComputerPrograms/ComputerProgram.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ComputerProgramInstance{


protected:
friend class ComputerProgramOption;
friend class ComputerProgramSession;

BatchOption m_options;
void add_option(ConfigOption& option, std::string serialization_string);
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
*/

#include "Common/Cpp/Exceptions.h"
#include "Common/Cpp/Json/JsonValue.h"
#include "Common/Cpp/CancellableScope.h"
#include "CommonFramework/Exceptions/FatalProgramException.h"
#include "CommonFramework/Exceptions/ProgramFinishedException.h"
#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h"
#include "CommonFramework/Notifications/ProgramInfo.h"
#include "CommonFramework/Notifications/ProgramNotifications.h"
#include "CommonFramework/Options/Environment/PerformanceOptions.h"
#include "ComputerProgramOption.h"
#include "ComputerProgramSession.h"
#include "ComputerProgramWidget.h"

//#include <iostream>
//using std::cout;
Expand All @@ -22,9 +22,11 @@
namespace PokemonAutomation{


ComputerProgramSession::ComputerProgramSession(ComputerProgramOption& option)
: ProgramSession(option.descriptor())
, m_option(option)
ComputerProgramSession::ComputerProgramSession(const ComputerProgramDescriptor& descriptor)
: PanelSession(descriptor)
, ProgramSession(descriptor)
, m_descriptor(descriptor)
, m_instance(descriptor.make_instance())
{}

ComputerProgramSession::~ComputerProgramSession(){
Expand All @@ -40,15 +42,28 @@ void ComputerProgramSession::restore_defaults(){
return;
}
logger().log("Restoring settings to defaults...");
m_option.restore_defaults();
m_instance->restore_defaults();
}
ConfigOption& ComputerProgramSession::options(){
return m_instance->m_options;
}
std::string ComputerProgramSession::check_validity() const{
return m_option.check_validity();
return m_instance->check_validity();
}




JsonValue ComputerProgramSession::to_json() const{
return m_instance->to_json();
}
void ComputerProgramSession::load_json(const JsonValue& json){
m_instance->load_json(json);
}
QWidget* ComputerProgramSession::make_widget(QWidget& parent){
return new ComputerProgramWidget(parent, *this);
}


void ComputerProgramSession::run_program_instance(ProgramEnvironment& env, CancellableScope& scope){
{
Expand All @@ -65,7 +80,7 @@ void ComputerProgramSession::run_program_instance(ProgramEnvironment& env, Cance
}

try{
m_option.instance().program(env, scope);
m_instance->program(env, scope);
}catch (...){
WriteSpinLock lg(m_lock, PA_CURRENT_FUNCTION);
m_scope = nullptr;
Expand Down Expand Up @@ -95,12 +110,12 @@ void ComputerProgramSession::internal_run_program(){
return;
}

m_option.options().reset_state();
options().reset_state();

ProgramInfo program_info(
identifier(),
m_option.descriptor().category(),
m_option.descriptor().display_name(),
m_descriptor.category(),
m_descriptor.display_name(),
timestamp()
);
CancellableHolder<CancellableScope> scope;
Expand All @@ -119,7 +134,7 @@ void ComputerProgramSession::internal_run_program(){
}catch (ProgramCancelledException&){
}catch (ProgramFinishedException& e){
logger().log("Program finished early!", COLOR_BLUE);
send_program_finished_notification(env, m_option.instance().NOTIFICATION_PROGRAM_FINISH, e.message(), *e.screenshot());
send_program_finished_notification(env, m_instance->NOTIFICATION_PROGRAM_FINISH, e.message(), *e.screenshot());
}catch (InvalidConnectionStateException&){
}catch (OperationFailedExceptionWithScreenshot& e){
logger().log("Program stopped with an exception!", COLOR_RED);
Expand All @@ -128,23 +143,23 @@ void ComputerProgramSession::internal_run_program(){
message = e.name();
}
report_error(message);
e.send_fatal_error_notif_and_telemetry_report(env, m_option.instance().NOTIFICATION_ERROR_FATAL);
e.send_fatal_error_notif_and_telemetry_report(env, m_instance->NOTIFICATION_ERROR_FATAL);
}catch (OperationFailedException& e){ // no screenshot
logger().log("Program stopped with an exception!", COLOR_RED);
std::string message = e.message();
if (message.empty()){
message = e.name();
}
report_error(message);
e.send_fatal_error_notif_and_telemetry_report(env, m_option.instance().NOTIFICATION_ERROR_FATAL);
e.send_fatal_error_notif_and_telemetry_report(env, m_instance->NOTIFICATION_ERROR_FATAL);
}catch (FatalProgramException& e){
logger().log("Program stopped with an exception!", COLOR_RED);
std::string message = e.message();
if (message.empty()){
message = e.name();
}
report_error(message);
e.send_fatal_error_notif_and_telemetry_report(env, m_option.instance().NOTIFICATION_ERROR_FATAL);
e.send_fatal_error_notif_and_telemetry_report(env, m_instance->NOTIFICATION_ERROR_FATAL);
}catch (Exception& e){
logger().log("Program stopped with an exception!", COLOR_RED);
std::string message = e.message();
Expand All @@ -153,7 +168,7 @@ void ComputerProgramSession::internal_run_program(){
}
report_error(message);
send_program_fatal_error_notification(
env, m_option.instance().NOTIFICATION_ERROR_FATAL,
env, m_instance->NOTIFICATION_ERROR_FATAL,
message
);
}catch (std::exception& e){
Expand All @@ -164,14 +179,14 @@ void ComputerProgramSession::internal_run_program(){
}
report_error(message);
send_program_fatal_error_notification(
env, m_option.instance().NOTIFICATION_ERROR_FATAL,
env, m_instance->NOTIFICATION_ERROR_FATAL,
message
);
}catch (...){
logger().log("Program stopped with an exception!", COLOR_RED);
report_error("Unknown error.");
send_program_fatal_error_notification(
env, m_option.instance().NOTIFICATION_ERROR_FATAL,
env, m_instance->NOTIFICATION_ERROR_FATAL,
"Unknown error."
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define PokemonAutomation_ComputerPrograms_ComputerProgramSession_H

#include "Common/Cpp/Concurrency/SpinLock.h"
#include "CommonFramework/Panels/PanelSession.h"
#include "CommonFramework/ProgramSession.h"
#include "ComputerPrograms/ComputerProgram.h"

Expand All @@ -26,25 +27,39 @@ class ComputerProgramOption;
class ProgramEnvironment;


class ComputerProgramSession final : public ProgramSession{
class ComputerProgramSession final : public PanelSession, public ProgramSession{
public:
virtual ~ComputerProgramSession();
ComputerProgramSession(ComputerProgramOption& option);
ComputerProgramSession(const ComputerProgramDescriptor& descriptor);

void restore_defaults();


public:
const ComputerProgramDescriptor& descriptor() const{ return m_descriptor; }
ConfigOption& options();


private:
virtual std::string check_validity() const override;

virtual void internal_run_program() override;
virtual void internal_stop_program() override;


private:
virtual JsonValue to_json() const override;
virtual void load_json(const JsonValue& json) override;
virtual QWidget* make_widget(QWidget& parent) override;


private:
void run_program_instance(ProgramEnvironment& env, CancellableScope& scope);


private:
ComputerProgramOption& m_option;
const ComputerProgramDescriptor& m_descriptor;
std::unique_ptr<ComputerProgramInstance> m_instance;

SpinLock m_lock;
CancellableScope* m_scope = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "CommonFramework/ProgramStats/StatsTracking.h"
#include "CommonFramework/ResourceDownload/ProgramResourceDownloadWidget.h"
#include "ComputerPrograms/ComputerProgram.h"
#include "ComputerPrograms/Framework/ComputerProgramOption.h"
#include "ComputerProgramWidget.h"

// #include <iostream>
Expand All @@ -33,15 +32,15 @@ ComputerProgramWidget::~ComputerProgramWidget(){
}
ComputerProgramWidget::ComputerProgramWidget(
QWidget& parent,
ComputerProgramOption& option
ComputerProgramSession& session
)
: QWidget(&parent)
, m_session(option)
, m_session(session)
{
m_layout = new QVBoxLayout(this);
m_layout->setContentsMargins(0, 0, 0, 0);

const ComputerProgramDescriptor& descriptor = option.descriptor();
const ComputerProgramDescriptor& descriptor = m_session.descriptor();

CollapsibleGroupBox* header = make_panel_header(
*this,
Expand All @@ -62,7 +61,7 @@ ComputerProgramWidget::ComputerProgramWidget(
QVBoxLayout* scroll_layout = new QVBoxLayout(scroll_inner);
scroll_layout->setAlignment(Qt::AlignTop);

m_options = ConfigWidget::make_from_option(option.options(), this);
m_options = ConfigWidget::make_from_option(m_session.options(), this);
scroll_layout->addWidget(&m_options->widget());

scroll_layout->addStretch(1);
Expand Down Expand Up @@ -98,7 +97,7 @@ ComputerProgramWidget::ComputerProgramWidget(
m_actions_bar, &RunnablePanelActionBar::defaults_clicked,
this, [&]{
std::lock_guard<Mutex> lg(m_session.program_lock());
option.restore_defaults();
m_session.restore_defaults();
m_options->update_all(false);
}
);
Expand Down
Loading