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
58 changes: 29 additions & 29 deletions SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,35 @@ GlobalSettings::GlobalSettings()
OPEN_BASE_FOLDER_BUTTON.add_listener(static_cast<ButtonListener&>(*this));
}

JsonValue GlobalSettings::to_json() const{
JsonObject obj = std::move(*BatchOption::to_json().to_object());
obj["NAUGHTY_MODE"] = STATIC_GLOBALS.NAUGHTY_MODE;

JsonObject command_line_test_obj;
command_line_test_obj["RUN"] = COMMAND_LINE_TEST_MODE;
command_line_test_obj["FOLDER"] = COMMAND_LINE_TEST_FOLDER;

{
JsonArray test_list;
for (const auto& name : COMMAND_LINE_TEST_LIST){
test_list.push_back(name);
}
command_line_test_obj["TEST_LIST"] = std::move(test_list);
}

{
JsonArray ignore_list;
for (const auto& name : COMMAND_LINE_IGNORE_LIST){
ignore_list.push_back(name);
}
command_line_test_obj["IGNORE_LIST"] = std::move(ignore_list);
}

obj["COMMAND_LINE_TESTS"] = std::move(command_line_test_obj);
obj["DEBUG"] = STATIC_GLOBALS.to_json_debug();

return obj;
}
void GlobalSettings::load_json(const JsonValue& json){
const JsonObject* obj = json.to_object();
if (obj == nullptr){
Expand Down Expand Up @@ -343,35 +372,6 @@ void GlobalSettings::load_json(const JsonValue& json){
}


JsonValue GlobalSettings::to_json() const{
JsonObject obj = std::move(*BatchOption::to_json().to_object());
obj["NAUGHTY_MODE"] = STATIC_GLOBALS.NAUGHTY_MODE;

JsonObject command_line_test_obj;
command_line_test_obj["RUN"] = COMMAND_LINE_TEST_MODE;
command_line_test_obj["FOLDER"] = COMMAND_LINE_TEST_FOLDER;

{
JsonArray test_list;
for (const auto& name : COMMAND_LINE_TEST_LIST){
test_list.push_back(name);
}
command_line_test_obj["TEST_LIST"] = std::move(test_list);
}

{
JsonArray ignore_list;
for (const auto& name : COMMAND_LINE_IGNORE_LIST){
ignore_list.push_back(name);
}
command_line_test_obj["IGNORE_LIST"] = std::move(ignore_list);
}

obj["COMMAND_LINE_TESTS"] = std::move(command_line_test_obj);
obj["DEBUG"] = STATIC_GLOBALS.to_json_debug();

return obj;
}

void GlobalSettings::on_config_value_changed(void* object){
bool enabled = ENABLE_LIFETIME_SANITIZER0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class GlobalSettings : public BatchOption, private ConfigOption::Listener, priva
public:
static GlobalSettings& instance();

virtual void load_json(const JsonValue& json) override;
virtual JsonValue to_json() const override;
virtual void load_json(const JsonValue& json) override;

void connect_row_with_download(const std::string& resource_slug, std::shared_ptr<ResourceDownload>& download_ptr);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "Common/Cpp/Json/JsonValue.h"
#include "Common/Cpp/Json/JsonObject.h"
#include "Common/Cpp/CpuId/CpuId.h"
#include "Common/Cpp/Hardware/Hardware.h"
#include "CommonFramework/Logging/Logger.h"
#include "ProcessorLevelOption.h"
Expand Down Expand Up @@ -45,6 +46,12 @@ bool ProcessorLevelOption::set_value(size_t value){
set_global(value);
return true;
}
JsonValue ProcessorLevelOption::to_json() const{
JsonObject obj;
obj["Level"] = IntegerEnumDropdownOption::to_json();
obj["ProcessorString"] = get_processor_name();
return obj;
}
void ProcessorLevelOption::load_json(const JsonValue& json){
const JsonObject* obj = json.to_object();
if (obj == nullptr){
Expand All @@ -70,12 +77,6 @@ void ProcessorLevelOption::load_json(const JsonValue& json){
global_logger_tagged().log("Mismatched processor string. Will not load saved processor level.", COLOR_RED);
}
}
JsonValue ProcessorLevelOption::to_json() const{
JsonObject obj;
obj["Level"] = IntegerEnumDropdownOption::to_json();
obj["ProcessorString"] = get_processor_name();
return obj;
}
void ProcessorLevelOption::set_global(){
set_global(current_value());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#ifndef PokemonAutomation_ProcessorLevelOption_H
#define PokemonAutomation_ProcessorLevelOption_H

#include "Common/Cpp/CpuId/CpuId.h"
#include "Common/Cpp/Options/EnumDropdownOption.h"

namespace PokemonAutomation{
Expand All @@ -19,8 +18,8 @@ class ProcessorLevelOption : public IntegerEnumDropdownOption{

virtual bool set_value(size_t value) override;

virtual void load_json(const JsonValue& json) override;
virtual JsonValue to_json() const override;
virtual void load_json(const JsonValue& json) override;

void set_global();
void set_global(size_t value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ const ImageViewRGB32& LabelCellOption::icon() const{
Resolution LabelCellOption::resolution() const{
return m_data->m_resolution;
}
void LabelCellOption::load_json(const JsonValue&){
}
JsonValue LabelCellOption::to_json() const{
return JsonValue();
}
void LabelCellOption::load_json(const JsonValue&){
}

void LabelCellOption::set_text(std::string x){
// sanitize(x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class LabelCellOption : public UiState<LabelCellOption, ConfigOption>{

void set_text(std::string x);

virtual void load_json(const JsonValue& json) override;
virtual JsonValue to_json() const override;
virtual void load_json(const JsonValue& json) override;

virtual void restore_defaults() override{}

Expand Down
10 changes: 5 additions & 5 deletions SerialPrograms/Source/CommonFramework/Panels/PanelSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ PanelSession::PanelSession(const PanelDescriptor& descriptor)
}
}

void PanelSession::from_json(){
void PanelSession::load_json(){
JsonValue* node = PERSISTENT_SETTINGS().panels.get_value(m_descriptor.identifier());
if (node == nullptr){
return;
}
from_json(*node);
load_json(*node);
}

void PanelSession::from_json(const JsonValue& json){

}
JsonValue PanelSession::to_json() const{
return JsonValue();
}
void PanelSession::load_json(const JsonValue& json){

}
void PanelSession::save_settings() const{
const std::string& identifier = m_descriptor.identifier();
Expand Down
4 changes: 2 additions & 2 deletions SerialPrograms/Source/CommonFramework/Panels/PanelSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class PanelSession{

public:
// Serialization
void from_json();
virtual void from_json(const JsonValue& json);
void load_json();
virtual JsonValue to_json() const;
virtual void load_json(const JsonValue& json);


protected:
Expand Down
2 changes: 1 addition & 1 deletion SerialPrograms/Source/CommonFramework/Panels/PanelTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ std::unique_ptr<PanelDescriptor> make_panel(){
template <typename Descriptor, typename Instance>
std::unique_ptr<PanelDescriptor> make_settings(){
auto ret = std::make_unique<PanelDescriptorWrapper<Descriptor, Instance>>();
ret->make_panel()->from_json();
ret->make_panel()->load_json();
return ret;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ SettingsPanelInstance::SettingsPanelInstance(const PanelDescriptor& descriptor)
, m_options(LockMode::LOCK_WHILE_RUNNING)
{}

void SettingsPanelInstance::from_json(const JsonValue& json){
m_options.load_json(json);
}
JsonValue SettingsPanelInstance::to_json() const{
return m_options.to_json();
}
void SettingsPanelInstance::load_json(const JsonValue& json){
m_options.load_json(json);
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class SettingsPanelInstance : public PanelSession{

public:
// Serialization
virtual void from_json(const JsonValue& json) override;
virtual JsonValue to_json() const override;
virtual void load_json(const JsonValue& json) override;

protected:
friend class SettingsPanelWidget;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void PanelListWidget::handle_panel_clicked(const std::string& text){
try{
std::unique_ptr<PanelSession> panel = descriptor->make_panel();
// try{
panel->from_json(PERSISTENT_SETTINGS().panels[descriptor->identifier()]);
panel->load_json(PERSISTENT_SETTINGS().panels[descriptor->identifier()]);
// }catch (ParseException&){}
m_panel_holder.load_panel(descriptor, std::move(panel));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class VideoSourceDescriptor{
// do some optional additional stuff, e.g. open a file selection dialog
// box to continue user interaction.
virtual void run_post_select(){};
virtual void load_json(const JsonValue& json) = 0;
virtual JsonValue to_json() const = 0;
virtual void load_json(const JsonValue& json) = 0;

public:
virtual std::unique_ptr<VideoSource> make_VideoSource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ std::string VideoSourceDescriptor_Camera::display_name() const{
return get_camera_name(m_info);
}

JsonValue VideoSourceDescriptor_Camera::to_json() const{
return m_info.device_name();
}
void VideoSourceDescriptor_Camera::load_json(const JsonValue& json){
const std::string* name = json.to_string();
if (name != nullptr){
m_info = CameraInfo(*name);
}
}
JsonValue VideoSourceDescriptor_Camera::to_json() const{
return m_info.device_name();
}

std::unique_ptr<VideoSource> VideoSourceDescriptor_Camera::make_VideoSource(
Logger& logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class VideoSourceDescriptor_Camera : public VideoSourceDescriptor{
virtual bool operator==(const VideoSourceDescriptor& x) const override;
virtual std::string display_name() const override;

virtual void load_json(const JsonValue& json) override;
virtual JsonValue to_json() const override;
virtual void load_json(const JsonValue& json) override;

virtual std::unique_ptr<VideoSource> make_VideoSource(
Logger& logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ std::string VideoSourceDescriptor_Null::display_name() const{
return "(none)";
}

void VideoSourceDescriptor_Null::load_json(const JsonValue& json){

}
JsonValue VideoSourceDescriptor_Null::to_json() const{
return JsonValue();
}
void VideoSourceDescriptor_Null::load_json(const JsonValue& json){

}

std::unique_ptr<VideoSource> VideoSourceDescriptor_Null::make_VideoSource(
Logger& logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class VideoSourceDescriptor_Null : public VideoSourceDescriptor{
virtual bool operator==(const VideoSourceDescriptor& x) const override;
virtual std::string display_name() const override;

virtual void load_json(const JsonValue& json) override;
virtual JsonValue to_json() const override;
virtual void load_json(const JsonValue& json) override;

virtual std::unique_ptr<VideoSource> make_VideoSource(
Logger& logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ void VideoSourceDescriptor_StillImage::run_post_select(){
).toStdString();
set_path(std::move(path));
}
JsonValue VideoSourceDescriptor_StillImage::to_json() const{
ReadSpinLock lg(m_lock, PA_CURRENT_FUNCTION);
return m_path;
}
void VideoSourceDescriptor_StillImage::load_json(const JsonValue& json){
// cout << "load_json: " << m_path << endl;
const std::string* name = json.to_string();
Expand All @@ -55,10 +59,6 @@ void VideoSourceDescriptor_StillImage::load_json(const JsonValue& json){
m_path = *name;
}
}
JsonValue VideoSourceDescriptor_StillImage::to_json() const{
ReadSpinLock lg(m_lock, PA_CURRENT_FUNCTION);
return m_path;
}

std::unique_ptr<VideoSource> VideoSourceDescriptor_StillImage::make_VideoSource(
Logger& logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ class VideoSourceDescriptor_StillImage : public VideoSourceDescriptor{
}

virtual void run_post_select() override;
virtual void load_json(const JsonValue& json) override;

virtual JsonValue to_json() const override;
virtual void load_json(const JsonValue& json) override;

virtual std::unique_ptr<VideoSource> make_VideoSource(
Logger& logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ void LanguageOCRCell::set(Language language){
}


JsonValue LanguageOCRCell::to_json() const{
return language_data((Language)*this).code;
}
void LanguageOCRCell::load_json(const JsonValue& json){
const std::string* str = json.to_string();
if (str == nullptr){
Expand All @@ -92,9 +95,6 @@ void LanguageOCRCell::load_json(const JsonValue& json){
m_current.store(iter->second, std::memory_order_relaxed);
report_value_changed(this);
}
JsonValue LanguageOCRCell::to_json() const{
return language_data((Language)*this).code;
}

std::string LanguageOCRCell::check_validity() const{
return m_case_list[m_current.load(std::memory_order_relaxed)].second ? std::string() : "Language data is not available.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class LanguageOCRCell : public UiState<LanguageOCRCell, ConfigOption>{
operator Language() const{ return m_case_list[m_current.load(std::memory_order_relaxed)].first; }
void set(Language language);

virtual void load_json(const JsonValue& json) override;
virtual JsonValue to_json() const override;
virtual void load_json(const JsonValue& json) override;

virtual std::string check_validity() const override;
virtual void restore_defaults() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class ScreenWatchOption : public GroupOption{
double default_width = 1, double default_height = 1
);

// virtual void load_json(const JsonValue& json) override;
// virtual JsonValue to_json() const override;
// virtual void load_json(const JsonValue& json) override;

// virtual void restore_defaults() override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,14 @@ const StringSelectDatabase& StringSelectCell::database() const{
return m_data->m_database;
}

JsonValue StringSelectCell::to_json() const{
return m_data->to_json();
}
void StringSelectCell::load_json(const JsonValue& json){
if (m_data->load_json(json)){
report_value_changed(this);
}
}
JsonValue StringSelectCell::to_json() const{
return m_data->to_json();
}
void StringSelectCell::restore_defaults(){
m_data->restore_defaults();
report_value_changed(this);
Expand Down
Loading