diff --git a/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp b/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp index a2debabc17..29f53bb28a 100644 --- a/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp +++ b/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp @@ -255,6 +255,35 @@ GlobalSettings::GlobalSettings() OPEN_BASE_FOLDER_BUTTON.add_listener(static_cast(*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){ @@ -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; diff --git a/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.h b/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.h index be883b2994..458404e388 100644 --- a/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.h +++ b/SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.h @@ -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& download_ptr); diff --git a/SerialPrograms/Source/CommonFramework/Options/Environment/ProcessorLevelOption.cpp b/SerialPrograms/Source/CommonFramework/Options/Environment/ProcessorLevelOption.cpp index a86ed422fc..527874397f 100644 --- a/SerialPrograms/Source/CommonFramework/Options/Environment/ProcessorLevelOption.cpp +++ b/SerialPrograms/Source/CommonFramework/Options/Environment/ProcessorLevelOption.cpp @@ -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" @@ -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){ @@ -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()); } diff --git a/SerialPrograms/Source/CommonFramework/Options/Environment/ProcessorLevelOption.h b/SerialPrograms/Source/CommonFramework/Options/Environment/ProcessorLevelOption.h index 28df1ee6bd..9dc3e2495d 100644 --- a/SerialPrograms/Source/CommonFramework/Options/Environment/ProcessorLevelOption.h +++ b/SerialPrograms/Source/CommonFramework/Options/Environment/ProcessorLevelOption.h @@ -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{ @@ -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); diff --git a/SerialPrograms/Source/CommonFramework/Options/LabelCellOption.cpp b/SerialPrograms/Source/CommonFramework/Options/LabelCellOption.cpp index 6c4af4c757..749e7fa06f 100644 --- a/SerialPrograms/Source/CommonFramework/Options/LabelCellOption.cpp +++ b/SerialPrograms/Source/CommonFramework/Options/LabelCellOption.cpp @@ -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); diff --git a/SerialPrograms/Source/CommonFramework/Options/LabelCellOption.h b/SerialPrograms/Source/CommonFramework/Options/LabelCellOption.h index c8026efd62..d3cc72c8d8 100644 --- a/SerialPrograms/Source/CommonFramework/Options/LabelCellOption.h +++ b/SerialPrograms/Source/CommonFramework/Options/LabelCellOption.h @@ -47,8 +47,8 @@ class LabelCellOption : public UiState{ 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{} diff --git a/SerialPrograms/Source/CommonFramework/Panels/PanelSession.cpp b/SerialPrograms/Source/CommonFramework/Panels/PanelSession.cpp index a58449adf9..9121269916 100644 --- a/SerialPrograms/Source/CommonFramework/Panels/PanelSession.cpp +++ b/SerialPrograms/Source/CommonFramework/Panels/PanelSession.cpp @@ -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(); diff --git a/SerialPrograms/Source/CommonFramework/Panels/PanelSession.h b/SerialPrograms/Source/CommonFramework/Panels/PanelSession.h index 94274c226a..3065bf0dfb 100644 --- a/SerialPrograms/Source/CommonFramework/Panels/PanelSession.h +++ b/SerialPrograms/Source/CommonFramework/Panels/PanelSession.h @@ -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: diff --git a/SerialPrograms/Source/CommonFramework/Panels/PanelTools.h b/SerialPrograms/Source/CommonFramework/Panels/PanelTools.h index 4736318b25..bde50ad252 100644 --- a/SerialPrograms/Source/CommonFramework/Panels/PanelTools.h +++ b/SerialPrograms/Source/CommonFramework/Panels/PanelTools.h @@ -98,7 +98,7 @@ std::unique_ptr make_panel(){ template std::unique_ptr make_settings(){ auto ret = std::make_unique>(); - ret->make_panel()->from_json(); + ret->make_panel()->load_json(); return ret; } diff --git a/SerialPrograms/Source/CommonFramework/Panels/SettingsPanel.cpp b/SerialPrograms/Source/CommonFramework/Panels/SettingsPanel.cpp index 1c95292b15..d6c3d39658 100644 --- a/SerialPrograms/Source/CommonFramework/Panels/SettingsPanel.cpp +++ b/SerialPrograms/Source/CommonFramework/Panels/SettingsPanel.cpp @@ -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); +} diff --git a/SerialPrograms/Source/CommonFramework/Panels/SettingsPanel.h b/SerialPrograms/Source/CommonFramework/Panels/SettingsPanel.h index bc03c21317..df33b9633e 100644 --- a/SerialPrograms/Source/CommonFramework/Panels/SettingsPanel.h +++ b/SerialPrograms/Source/CommonFramework/Panels/SettingsPanel.h @@ -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; diff --git a/SerialPrograms/Source/CommonFramework/Panels/UI/PanelListWidget.cpp b/SerialPrograms/Source/CommonFramework/Panels/UI/PanelListWidget.cpp index 2a717addbb..568e1e42ee 100644 --- a/SerialPrograms/Source/CommonFramework/Panels/UI/PanelListWidget.cpp +++ b/SerialPrograms/Source/CommonFramework/Panels/UI/PanelListWidget.cpp @@ -99,7 +99,7 @@ void PanelListWidget::handle_panel_clicked(const std::string& text){ try{ std::unique_ptr 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)); diff --git a/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSourceDescriptor.h b/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSourceDescriptor.h index 214e047275..c3eaa38555 100644 --- a/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSourceDescriptor.h +++ b/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSourceDescriptor.h @@ -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 make_VideoSource( diff --git a/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_Camera.cpp b/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_Camera.cpp index 80650debb7..a7750ba6f0 100644 --- a/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_Camera.cpp +++ b/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_Camera.cpp @@ -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 VideoSourceDescriptor_Camera::make_VideoSource( Logger& logger, diff --git a/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_Camera.h b/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_Camera.h index 7d407cb721..9e8aa70fcc 100644 --- a/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_Camera.h +++ b/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_Camera.h @@ -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 make_VideoSource( Logger& logger, diff --git a/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_Null.cpp b/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_Null.cpp index 561b5fba71..4649cf2fc0 100644 --- a/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_Null.cpp +++ b/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_Null.cpp @@ -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 VideoSourceDescriptor_Null::make_VideoSource( Logger& logger, diff --git a/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_Null.h b/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_Null.h index 76a85d2906..02553c21e1 100644 --- a/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_Null.h +++ b/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_Null.h @@ -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 make_VideoSource( Logger& logger, diff --git a/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_StillImage.cpp b/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_StillImage.cpp index a34fc7527f..3cf22bde94 100644 --- a/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_StillImage.cpp +++ b/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_StillImage.cpp @@ -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(); @@ -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 VideoSourceDescriptor_StillImage::make_VideoSource( Logger& logger, diff --git a/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_StillImage.h b/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_StillImage.h index 7131543c07..f12cb60d56 100644 --- a/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_StillImage.h +++ b/SerialPrograms/Source/CommonFramework/VideoPipeline/VideoSources/VideoSource_StillImage.h @@ -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 make_VideoSource( Logger& logger, diff --git a/SerialPrograms/Source/CommonTools/Options/LanguageOCROption.cpp b/SerialPrograms/Source/CommonTools/Options/LanguageOCROption.cpp index 57a9da9d57..922041a0aa 100644 --- a/SerialPrograms/Source/CommonTools/Options/LanguageOCROption.cpp +++ b/SerialPrograms/Source/CommonTools/Options/LanguageOCROption.cpp @@ -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){ @@ -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."; diff --git a/SerialPrograms/Source/CommonTools/Options/LanguageOCROption.h b/SerialPrograms/Source/CommonTools/Options/LanguageOCROption.h index e149effcca..4d0bd6ebb6 100644 --- a/SerialPrograms/Source/CommonTools/Options/LanguageOCROption.h +++ b/SerialPrograms/Source/CommonTools/Options/LanguageOCROption.h @@ -31,8 +31,8 @@ class LanguageOCRCell : public UiState{ 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; diff --git a/SerialPrograms/Source/CommonTools/Options/ScreenWatchOption.h b/SerialPrograms/Source/CommonTools/Options/ScreenWatchOption.h index 9d4c1c7a8b..e4af6edc6d 100644 --- a/SerialPrograms/Source/CommonTools/Options/ScreenWatchOption.h +++ b/SerialPrograms/Source/CommonTools/Options/ScreenWatchOption.h @@ -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; diff --git a/SerialPrograms/Source/CommonTools/Options/StringSelectOption.cpp b/SerialPrograms/Source/CommonTools/Options/StringSelectOption.cpp index 0311183094..46fd89b623 100644 --- a/SerialPrograms/Source/CommonTools/Options/StringSelectOption.cpp +++ b/SerialPrograms/Source/CommonTools/Options/StringSelectOption.cpp @@ -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); diff --git a/SerialPrograms/Source/CommonTools/Options/StringSelectOption.h b/SerialPrograms/Source/CommonTools/Options/StringSelectOption.h index 1cb9dce843..da791cdde2 100644 --- a/SerialPrograms/Source/CommonTools/Options/StringSelectOption.h +++ b/SerialPrograms/Source/CommonTools/Options/StringSelectOption.h @@ -118,8 +118,8 @@ class StringSelectCell : public UiState{ const StringSelectDatabase& database() const; - 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; diff --git a/SerialPrograms/Source/ComputerPrograms/ComputerProgram.cpp b/SerialPrograms/Source/ComputerPrograms/ComputerProgram.cpp index c186ed7bae..35e618283c 100644 --- a/SerialPrograms/Source/ComputerPrograms/ComputerProgram.cpp +++ b/SerialPrograms/Source/ComputerPrograms/ComputerProgram.cpp @@ -57,12 +57,12 @@ ComputerProgramInstance::ComputerProgramInstance() void ComputerProgramInstance::add_option(ConfigOption& option, std::string serialization_string){ m_options.add_option(option, std::move(serialization_string)); } -void ComputerProgramInstance::from_json(const JsonValue& json){ - m_options.load_json(json); -} JsonValue ComputerProgramInstance::to_json() const{ return m_options.to_json(); } +void ComputerProgramInstance::load_json(const JsonValue& json){ + m_options.load_json(json); +} std::string ComputerProgramInstance::check_validity() const{ return m_options.check_validity(); } diff --git a/SerialPrograms/Source/ComputerPrograms/ComputerProgram.h b/SerialPrograms/Source/ComputerPrograms/ComputerProgram.h index 60aefb2ce8..f2951772ed 100644 --- a/SerialPrograms/Source/ComputerPrograms/ComputerProgram.h +++ b/SerialPrograms/Source/ComputerPrograms/ComputerProgram.h @@ -68,8 +68,8 @@ class ComputerProgramInstance{ public: // Settings - virtual void from_json(const JsonValue& json); virtual JsonValue to_json() const; + virtual void load_json(const JsonValue& json); virtual std::string check_validity() const; virtual void restore_defaults(); diff --git a/SerialPrograms/Source/ComputerPrograms/Framework/ComputerProgramOption.cpp b/SerialPrograms/Source/ComputerPrograms/Framework/ComputerProgramOption.cpp index 2354942e61..8a9d64711f 100644 --- a/SerialPrograms/Source/ComputerPrograms/Framework/ComputerProgramOption.cpp +++ b/SerialPrograms/Source/ComputerPrograms/Framework/ComputerProgramOption.cpp @@ -5,7 +5,6 @@ */ #include "Common/Cpp/Json/JsonValue.h" -#include "Common/Cpp/Json/JsonObject.h" #include "ComputerProgramOption.h" #include "ComputerProgramWidget.h" @@ -20,12 +19,12 @@ ComputerProgramOption::ComputerProgramOption(const ComputerProgramDescriptor& de , m_instance(descriptor.make_instance()) {} -void ComputerProgramOption::from_json(const JsonValue& json){ - m_instance->from_json(json); -} JsonValue ComputerProgramOption::to_json() const{ return m_instance->to_json(); } +void ComputerProgramOption::load_json(const JsonValue& json){ + m_instance->load_json(json); +} ConfigOption& ComputerProgramOption::options(){ return m_instance->m_options; diff --git a/SerialPrograms/Source/ComputerPrograms/Framework/ComputerProgramOption.h b/SerialPrograms/Source/ComputerPrograms/Framework/ComputerProgramOption.h index 63acef469e..7a603c695d 100644 --- a/SerialPrograms/Source/ComputerPrograms/Framework/ComputerProgramOption.h +++ b/SerialPrograms/Source/ComputerPrograms/Framework/ComputerProgramOption.h @@ -29,8 +29,8 @@ class ComputerProgramOption final : public PanelSession{ public: ComputerProgramOption(const ComputerProgramDescriptor& descriptor); - virtual void from_json(const JsonValue& json) override; virtual JsonValue to_json() const override; + virtual void load_json(const JsonValue& json) override; public: const ComputerProgramDescriptor& descriptor() const{ return m_descriptor; } diff --git a/SerialPrograms/Source/ConsoleInfra/CommandRowWidget.cpp b/SerialPrograms/Source/ConsoleInfra/CommandRowWidget.cpp index ce6b45e303..48aed399c8 100644 --- a/SerialPrograms/Source/ConsoleInfra/CommandRowWidget.cpp +++ b/SerialPrograms/Source/ConsoleInfra/CommandRowWidget.cpp @@ -148,10 +148,7 @@ CommandRowWidget::CommandRowWidget( m_session.allow_commands_while_locked() ); - // Deserialize into this local option instance. - option.load_json(load_json_file(path)); - - m_session.load(option); + m_session.load_json(load_json_file(path)); } ); connect( @@ -173,9 +170,7 @@ CommandRowWidget::CommandRowWidget( m_session.allow_commands_while_locked() ); - m_session.save(option); - - option.to_json().dump(path); + m_session.to_json().dump(path); } ); connect( diff --git a/SerialPrograms/Source/ConsoleInfra/ConsoleSystemOption.cpp b/SerialPrograms/Source/ConsoleInfra/ConsoleSystemOption.cpp index 72b0e7f378..182d99216c 100644 --- a/SerialPrograms/Source/ConsoleInfra/ConsoleSystemOption.cpp +++ b/SerialPrograms/Source/ConsoleInfra/ConsoleSystemOption.cpp @@ -49,6 +49,23 @@ ConsoleSystemOption::ConsoleSystemOption( { ConsoleSystemOption::load_json(json); } +JsonValue ConsoleSystemOption::to_json() const{ + JsonObject root; + root[JSON_VIDEO] = m_video.to_json(); + root[JSON_AUDIO] = m_audio.to_json(); + root[JSON_OVERLAY] = m_overlay.to_json(); + if (m_controllers.size() == 1){ + root[JSON_CONTROLLER] = m_controllers[0].to_json(); + }else{ + JsonArray list; + for (const ControllerOption& controller : m_controllers){ + list.push_back(controller.to_json()); + } + root[JSON_CONTROLLERS] = std::move(list); + } + + return root; +} void ConsoleSystemOption::load_json(const JsonValue& json){ const JsonObject* obj = json.to_object(); if (obj == nullptr){ @@ -78,28 +95,11 @@ void ConsoleSystemOption::load_json(const JsonValue& json){ for (; c < stop; c++){ m_controllers[c].load_json((*array)[c]); } - stop = m_controllers.size(); - for (; c < stop; c++){ - m_controllers[c].set_descriptor(null_controller_descriptor()); - } - } -} -JsonValue ConsoleSystemOption::to_json() const{ - JsonObject root; - root[JSON_VIDEO] = m_video.to_json(); - root[JSON_AUDIO] = m_audio.to_json(); - root[JSON_OVERLAY] = m_overlay.to_json(); - if (m_controllers.size() == 1){ - root[JSON_CONTROLLER] = m_controllers[0].to_json(); - }else{ - JsonArray list; - for (const ControllerOption& controller : m_controllers){ - list.push_back(controller.to_json()); - } - root[JSON_CONTROLLERS] = std::move(list); +// stop = m_controllers.size(); +// for (; c < stop; c++){ +// m_controllers[c].set_descriptor(null_controller_descriptor()); +// } } - - return root; } diff --git a/SerialPrograms/Source/ConsoleInfra/ConsoleSystemOption.h b/SerialPrograms/Source/ConsoleInfra/ConsoleSystemOption.h index d0d1311f67..2e2a562784 100644 --- a/SerialPrograms/Source/ConsoleInfra/ConsoleSystemOption.h +++ b/SerialPrograms/Source/ConsoleInfra/ConsoleSystemOption.h @@ -42,8 +42,8 @@ class ConsoleSystemOption{ const JsonValue& json ); - virtual void load_json(const JsonValue& json); virtual JsonValue to_json() const; + virtual void load_json(const JsonValue& json); public: diff --git a/SerialPrograms/Source/ConsoleInfra/ConsoleSystemSession.cpp b/SerialPrograms/Source/ConsoleInfra/ConsoleSystemSession.cpp index 8ded5eb4e3..d8d2b92889 100644 --- a/SerialPrograms/Source/ConsoleInfra/ConsoleSystemSession.cpp +++ b/SerialPrograms/Source/ConsoleInfra/ConsoleSystemSession.cpp @@ -104,34 +104,23 @@ std::string ConsoleSystemSession::status() const{ return m_status_text; } -void ConsoleSystemSession::save(ConsoleSystemOption& option) const{ +JsonValue ConsoleSystemSession::to_json() const{ std::lock_guard lg(m_lock); - - m_video.save(option.m_video); - m_audio.save(option.m_audio); - m_overlay.save(option.m_overlay); - - option.m_controllers = m_option.m_controllers; + return m_option.to_json(); } -void ConsoleSystemSession::load(const ConsoleSystemOption& option){ +void ConsoleSystemSession::load_json(const JsonValue& json){ std::lock_guard lg(m_lock); - m_video.load(option.m_video); - m_audio.load(option.m_audio); - m_overlay.load(option.m_overlay); + m_option.load_json(json); + m_video.load(m_option.m_video); + m_audio.load(m_option.m_audio); + m_overlay.load(m_option.m_overlay); size_t c = 0; - size_t stop = std::min(m_option.m_controllers.size(), option.m_controllers.size()); - for (; c < stop; c++){ - m_option.m_controllers[c] = option.m_controllers[c]; - m_controllers[c].session.load(option.m_controllers[c]); - } - - stop = m_option.m_controllers.size(); + size_t stop = m_option.m_controllers.size(); for (; c < stop; c++){ - m_option.m_controllers[c].set_descriptor(null_controller_descriptor()); - m_controllers[c].session.set_device(m_option.m_controllers[c].descriptor()); + m_controllers[c].session.load(m_option.m_controllers[c]); } } diff --git a/SerialPrograms/Source/ConsoleInfra/ConsoleSystemSession.h b/SerialPrograms/Source/ConsoleInfra/ConsoleSystemSession.h index d9f42923b9..e534240bec 100644 --- a/SerialPrograms/Source/ConsoleInfra/ConsoleSystemSession.h +++ b/SerialPrograms/Source/ConsoleInfra/ConsoleSystemSession.h @@ -91,8 +91,8 @@ class ConsoleSystemSession virtual AudioFeed& audio_feed() override{ return audio(); } virtual ControllerSession& controller() override{ return ConsoleSystemSession::controller(0); }; - virtual void save(ConsoleSystemOption& option) const; - virtual void load(const ConsoleSystemOption& option); + virtual JsonValue to_json() const; + virtual void load_json(const JsonValue& json); public: diff --git a/SerialPrograms/Source/ConsoleInfra/VirtualConsole.cpp b/SerialPrograms/Source/ConsoleInfra/VirtualConsole.cpp index b663a8931b..dfbf4dc79d 100644 --- a/SerialPrograms/Source/ConsoleInfra/VirtualConsole.cpp +++ b/SerialPrograms/Source/ConsoleInfra/VirtualConsole.cpp @@ -37,12 +37,12 @@ VirtualConsole::VirtualConsole(const VirtualConsole_Descriptor& descriptor) : PanelSession(descriptor) , m_console_options(descriptor.m_controllers, true) {} -void VirtualConsole::from_json(const JsonValue& json){ - m_console_options.load_json(json); -} JsonValue VirtualConsole::to_json() const{ return m_console_options.to_json(); } +void VirtualConsole::load_json(const JsonValue& json){ + m_console_options.load_json(json); +} QWidget* VirtualConsole::make_widget(QWidget& parent){ return VirtualConsole_Widget::make(parent, *this); } diff --git a/SerialPrograms/Source/ConsoleInfra/VirtualConsole.h b/SerialPrograms/Source/ConsoleInfra/VirtualConsole.h index 18f1b2ccf3..3af106ab63 100644 --- a/SerialPrograms/Source/ConsoleInfra/VirtualConsole.h +++ b/SerialPrograms/Source/ConsoleInfra/VirtualConsole.h @@ -47,8 +47,8 @@ class VirtualConsole : 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; private: friend class VirtualConsole_Widget; diff --git a/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingOption.cpp b/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingOption.cpp index 5d61fd966d..52232aae65 100644 --- a/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingOption.cpp +++ b/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingOption.cpp @@ -59,13 +59,13 @@ void KeyboardHidBindingCell::set(std::string text){ -void KeyboardHidBindingCell::load_json(const JsonValue& json){ - set((KeyboardKey)json.to_integer_default(0)); -} JsonValue KeyboardHidBindingCell::to_json() const{ ReadSpinLock lg(m_data->m_lock); return (uint64_t)m_data->m_current; } +void KeyboardHidBindingCell::load_json(const JsonValue& json){ + set((KeyboardKey)json.to_integer_default(0)); +} void KeyboardHidBindingCell::restore_defaults(){ set(m_data->m_default); diff --git a/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingOption.h b/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingOption.h index 02721d0fc8..91c35e08f4 100644 --- a/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingOption.h +++ b/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingOption.h @@ -25,8 +25,8 @@ class KeyboardHidBindingCell : public UiState{ virtual std::string display_name() const = 0; public: - 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 open_connection(Logger& logger) const = 0; diff --git a/SerialPrograms/Source/Controllers/ControllerStateTable.cpp b/SerialPrograms/Source/Controllers/ControllerStateTable.cpp index 0a3092c2bc..023a772ba2 100644 --- a/SerialPrograms/Source/Controllers/ControllerStateTable.cpp +++ b/SerialPrograms/Source/Controllers/ControllerStateTable.cpp @@ -232,6 +232,17 @@ void ControllerCommandTable::load_json_NS_TurboMacro(const JsonValue& json){ load_json(value); } +JsonValue ControllerCommandTable::to_json() const{ + JsonObject obj; + obj["ControllerClass"] = CONTROLLER_CLASS_STRINGS().get_string(m_type); + JsonArray history; + run_on_all_rows([&](const ControllerStateRow& row){ + history.push_back(row.to_json()); + return false; + }); + obj["Schedule"] = std::move(history); + return obj; +} void ControllerCommandTable::load_json(const JsonValue& json){ clear(); @@ -262,17 +273,6 @@ void ControllerCommandTable::load_json(const JsonValue& json){ EditableTableOption::load_json(*value); } -JsonValue ControllerCommandTable::to_json() const{ - JsonObject obj; - obj["ControllerClass"] = CONTROLLER_CLASS_STRINGS().get_string(m_type); - JsonArray history; - run_on_all_rows([&](const ControllerStateRow& row){ - history.push_back(row.to_json()); - return false; - }); - obj["Schedule"] = std::move(history); - return obj; -} std::vector ControllerCommandTable::make_header() const{ auto& map = get_controller_map(); diff --git a/SerialPrograms/Source/Controllers/ControllerStateTable.h b/SerialPrograms/Source/Controllers/ControllerStateTable.h index aaeb8ab7b8..2aea579c47 100644 --- a/SerialPrograms/Source/Controllers/ControllerStateTable.h +++ b/SerialPrograms/Source/Controllers/ControllerStateTable.h @@ -76,8 +76,8 @@ class ControllerCommandTable : public EditableTableOption{ } } - virtual void load_json(const JsonValue& json) override; virtual JsonValue to_json() const override; + virtual void load_json(const JsonValue& json) override; virtual std::vector make_header() const override; virtual std::unique_ptr make_row() override; diff --git a/SerialPrograms/Source/Controllers/NullController.cpp b/SerialPrograms/Source/Controllers/NullController.cpp index e4b733db0e..f02047d20e 100644 --- a/SerialPrograms/Source/Controllers/NullController.cpp +++ b/SerialPrograms/Source/Controllers/NullController.cpp @@ -33,12 +33,12 @@ bool NullControllerDescriptor::operator==(const ControllerDescriptor& x) const{ } std::string NullControllerDescriptor::display_name() const{ return "(none)"; -} -void NullControllerDescriptor::load_json(const JsonValue& json){ - } JsonValue NullControllerDescriptor::to_json() const{ return JsonValue(); +} +void NullControllerDescriptor::load_json(const JsonValue& json){ + } std::unique_ptr NullControllerDescriptor::open_connection(Logger& logger) const{ return nullptr; diff --git a/SerialPrograms/Source/Controllers/NullController.h b/SerialPrograms/Source/Controllers/NullController.h index 03578861d8..e802b328d0 100644 --- a/SerialPrograms/Source/Controllers/NullController.h +++ b/SerialPrograms/Source/Controllers/NullController.h @@ -29,8 +29,8 @@ class NullControllerDescriptor : public UiState open_connection(Logger& logger) const override; virtual std::unique_ptr make_controller( diff --git a/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_Descriptor.cpp b/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_Descriptor.cpp index 9d67dc6296..07003251fe 100644 --- a/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_Descriptor.cpp +++ b/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_Descriptor.cpp @@ -44,6 +44,9 @@ std::string SerialPABotBase2_Descriptor::display_name() const{ } return m_name; } +JsonValue SerialPABotBase2_Descriptor::to_json() const{ + return m_name; +} void SerialPABotBase2_Descriptor::load_json(const JsonValue& json){ const std::string* name = json.to_string(); if (name == nullptr || name->empty()){ @@ -51,9 +54,6 @@ void SerialPABotBase2_Descriptor::load_json(const JsonValue& json){ } m_name = *name; } -JsonValue SerialPABotBase2_Descriptor::to_json() const{ - return m_name; -} std::unique_ptr SerialPABotBase2_Descriptor::open_connection(Logger& logger) const{ #ifdef QT_CORE_LIB diff --git a/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_Descriptor.h b/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_Descriptor.h index 272a1522b6..f87c63c83c 100644 --- a/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_Descriptor.h +++ b/SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_Descriptor.h @@ -35,8 +35,8 @@ class SerialPABotBase2_Descriptor : public UiState open_connection(Logger& logger) const override; virtual std::unique_ptr make_controller( diff --git a/SerialPrograms/Source/ML/DataLabeling/ML_AnnotationIO.cpp b/SerialPrograms/Source/ML/DataLabeling/ML_AnnotationIO.cpp index 4c683b720b..5e81b37521 100644 --- a/SerialPrograms/Source/ML/DataLabeling/ML_AnnotationIO.cpp +++ b/SerialPrograms/Source/ML/DataLabeling/ML_AnnotationIO.cpp @@ -248,7 +248,7 @@ void export_image_annotations_to_yolo_dataset( const int64_t image_height = json_obj->get_integer_throw("IMAGE_HEIGHT"); const JsonArray& json_array = json_obj->get_array_throw("ANNOTATION"); for (size_t j = 0; j < json_array.size(); j++){ - const ObjectAnnotation anno_obj = ObjectAnnotation::from_json((json_array)[j]); + const ObjectAnnotation anno_obj = ObjectAnnotation::load_json((json_array)[j]); const std::string& label = anno_obj.label; auto it = label_indices.find(label); diff --git a/SerialPrograms/Source/ML/DataLabeling/ML_ObjectAnnotation.cpp b/SerialPrograms/Source/ML/DataLabeling/ML_ObjectAnnotation.cpp index 70a0661ee4..f721b1c444 100644 --- a/SerialPrograms/Source/ML/DataLabeling/ML_ObjectAnnotation.cpp +++ b/SerialPrograms/Source/ML/DataLabeling/ML_ObjectAnnotation.cpp @@ -22,7 +22,7 @@ ObjectAnnotation::ObjectAnnotation() {} // if failed to pass, will throw JsonParseException -ObjectAnnotation ObjectAnnotation::from_json(const JsonValue& json){ +ObjectAnnotation ObjectAnnotation::load_json(const JsonValue& json){ ObjectAnnotation anno_obj; const JsonObject& json_obj = json.to_object_throw(); diff --git a/SerialPrograms/Source/ML/DataLabeling/ML_ObjectAnnotation.h b/SerialPrograms/Source/ML/DataLabeling/ML_ObjectAnnotation.h index 3f96827953..1ffae5c15c 100644 --- a/SerialPrograms/Source/ML/DataLabeling/ML_ObjectAnnotation.h +++ b/SerialPrograms/Source/ML/DataLabeling/ML_ObjectAnnotation.h @@ -41,7 +41,7 @@ struct ObjectAnnotation{ ObjectAnnotation(); // if failed to pass, will throw JsonParseException - static ObjectAnnotation from_json(const JsonValue& json); + static ObjectAnnotation load_json(const JsonValue& json); JsonValue to_json() const; }; diff --git a/SerialPrograms/Source/ML/Programs/ML_LabelImages.cpp b/SerialPrograms/Source/ML/Programs/ML_LabelImages.cpp index 72e3071601..31d721d334 100644 --- a/SerialPrograms/Source/ML/Programs/ML_LabelImages.cpp +++ b/SerialPrograms/Source/ML/Programs/ML_LabelImages.cpp @@ -150,7 +150,16 @@ LabelImages::~LabelImages(){ FORM_LABEL.remove_listener(*this); } -void LabelImages::from_json(const JsonValue& json){ +JsonValue LabelImages::to_json() const{ + JsonObject obj = std::move(*m_options.to_json().to_object()); + obj["ImageSetup"] = m_display_option.to_json(); + obj["CUSTOM_LABEL_SET_FILE_PATH"] = m_custom_label_set_file_path; + obj["YOLO_CONFIG_FILE_PATH"] = m_yolo_config_file_path; + + save_annotation_to_file(); + return obj; +} +void LabelImages::load_json(const JsonValue& json){ const JsonObject* obj = json.to_object(); if (obj == nullptr){ return; @@ -170,15 +179,6 @@ void LabelImages::from_json(const JsonValue& json){ m_yolo_config_file_path = *file_path; } } -JsonValue LabelImages::to_json() const{ - JsonObject obj = std::move(*m_options.to_json().to_object()); - obj["ImageSetup"] = m_display_option.to_json(); - obj["CUSTOM_LABEL_SET_FILE_PATH"] = m_custom_label_set_file_path; - obj["YOLO_CONFIG_FILE_PATH"] = m_yolo_config_file_path; - - save_annotation_to_file(); - return obj; -} void LabelImages::init_sam_session(bool use_gpu){ // , m_sam_session{RESOURCE_PATH() + "ML/sam_cpu.onnx"} @@ -278,7 +278,7 @@ void LabelImages::load_image_related_data(const std::string& image_path, size_t for (size_t i = 0; i < json_array->size(); i++){ try{ - ObjectAnnotation anno_obj = ObjectAnnotation::from_json((*json_array)[i]); + ObjectAnnotation anno_obj = ObjectAnnotation::load_json((*json_array)[i]); m_annotations.emplace_back(std::move(anno_obj)); }catch (JsonParseException&){ m_fail_to_load_annotation_file = true; diff --git a/SerialPrograms/Source/ML/Programs/ML_LabelImages.h b/SerialPrograms/Source/ML/Programs/ML_LabelImages.h index 5fc80044f4..5793caeeb6 100644 --- a/SerialPrograms/Source/ML/Programs/ML_LabelImages.h +++ b/SerialPrograms/Source/ML/Programs/ML_LabelImages.h @@ -70,8 +70,8 @@ class LabelImages : public PanelSession, public ConfigOption::Listener { public: // Serialization - virtual void from_json(const JsonValue& json) override; virtual JsonValue to_json() const override; + virtual void load_json(const JsonValue& json) override; void init_sam_session(bool use_gpu); diff --git a/SerialPrograms/Source/NintendoSwitch/Controllers/Joycon/NintendoSwitch_JoyconTable.cpp b/SerialPrograms/Source/NintendoSwitch/Controllers/Joycon/NintendoSwitch_JoyconTable.cpp index 239b9c84d9..92d699bdec 100644 --- a/SerialPrograms/Source/NintendoSwitch/Controllers/Joycon/NintendoSwitch_JoyconTable.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Controllers/Joycon/NintendoSwitch_JoyconTable.cpp @@ -119,6 +119,14 @@ std::unique_ptr JoyconStateRow::clone() const{ return ret; } +JsonValue JoyconStateRow::to_json() const{ + JoyconState state; + get_state(state); + + JsonObject json = state.to_json(); + json["ms"] = DURATION.to_json(); + return json; +} void JoyconStateRow::load_json(const JsonValue& json){ const JsonObject& obj = json.to_object_throw(); @@ -138,14 +146,6 @@ void JoyconStateRow::load_json(const JsonValue& json){ JOYSTICK_X.set(state.joystick.x); JOYSTICK_Y.set(state.joystick.y); } -JsonValue JoyconStateRow::to_json() const{ - JoyconState state; - get_state(state); - - JsonObject json = state.to_json(); - json["ms"] = DURATION.to_json(); - return json; -} void JoyconStateRow::get_state(JoyconState& state) const{ state.buttons = BUTTONS; diff --git a/SerialPrograms/Source/NintendoSwitch/Controllers/Joycon/NintendoSwitch_JoyconTable.h b/SerialPrograms/Source/NintendoSwitch/Controllers/Joycon/NintendoSwitch_JoyconTable.h index 0e1b400678..98f4e0eb03 100644 --- a/SerialPrograms/Source/NintendoSwitch/Controllers/Joycon/NintendoSwitch_JoyconTable.h +++ b/SerialPrograms/Source/NintendoSwitch/Controllers/Joycon/NintendoSwitch_JoyconTable.h @@ -27,8 +27,8 @@ class JoyconStateRow : public ControllerStateRow, public ConfigOption::Listener{ virtual std::unique_ptr clone() const override; - virtual void load_json(const JsonValue& json) override; virtual JsonValue to_json() const override; + virtual void load_json(const JsonValue& json) override; void get_state(JoyconState& state) const; virtual std::unique_ptr get_state(Milliseconds& duration) const override; diff --git a/SerialPrograms/Source/NintendoSwitch/Controllers/Procon/NintendoSwitch_ProControllerTable.h b/SerialPrograms/Source/NintendoSwitch/Controllers/Procon/NintendoSwitch_ProControllerTable.h index dca6626c3f..2b1e659cb3 100644 --- a/SerialPrograms/Source/NintendoSwitch/Controllers/Procon/NintendoSwitch_ProControllerTable.h +++ b/SerialPrograms/Source/NintendoSwitch/Controllers/Procon/NintendoSwitch_ProControllerTable.h @@ -27,8 +27,8 @@ class ProControllerStateRow : public ControllerStateRow, public ConfigOption::Li virtual std::unique_ptr clone() const override; - virtual void load_json(const JsonValue& json) override; virtual JsonValue to_json() const override; + virtual void load_json(const JsonValue& json) override; void get_state(ProControllerState& state) const; virtual std::unique_ptr get_state(Milliseconds& duration) const override; diff --git a/SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Descriptor.cpp b/SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Descriptor.cpp index ab1bb79fdd..f22f10fa1f 100644 --- a/SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Descriptor.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Descriptor.cpp @@ -32,6 +32,9 @@ std::string TcpSysbotBase_Descriptor::display_name() const{ return m_url; } +JsonValue TcpSysbotBase_Descriptor::to_json() const{ + return m_url; +} void TcpSysbotBase_Descriptor::load_json(const JsonValue& json){ const std::string* url = json.to_string(); if (url == nullptr || url->empty()){ @@ -39,9 +42,6 @@ void TcpSysbotBase_Descriptor::load_json(const JsonValue& json){ } m_url = *url; } -JsonValue TcpSysbotBase_Descriptor::to_json() const{ - return m_url; -} diff --git a/SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Descriptor.h b/SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Descriptor.h index f9017c9e4f..683eb38056 100644 --- a/SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Descriptor.h +++ b/SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Descriptor.h @@ -35,8 +35,8 @@ class TcpSysbotBase_Descriptor : public UiState open_connection(Logger& logger) const override; virtual std::unique_ptr make_controller( diff --git a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_MultiSwitchProgramSession.cpp b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_MultiSwitchProgramSession.cpp index 846ba1debc..c551c76294 100644 --- a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_MultiSwitchProgramSession.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_MultiSwitchProgramSession.cpp @@ -100,7 +100,12 @@ ConfigOption& MultiSwitchProgramSession::options(){ } -void MultiSwitchProgramSession::from_json(const JsonValue& json){ +JsonValue MultiSwitchProgramSession::to_json() const{ + JsonObject obj = std::move(*m_instance->to_json().to_object()); + obj["SwitchSetup"] = m_system_option.to_json(); + return obj; +} +void MultiSwitchProgramSession::load_json(const JsonValue& json){ const JsonObject* obj = json.to_object(); if (obj == nullptr){ return; @@ -109,12 +114,7 @@ void MultiSwitchProgramSession::from_json(const JsonValue& json){ if (value){ m_system.load_json(*value); } - m_instance->from_json(json); -} -JsonValue MultiSwitchProgramSession::to_json() const{ - JsonObject obj = std::move(*m_instance->to_json().to_object()); - obj["SwitchSetup"] = m_system_option.to_json(); - return obj; + m_instance->load_json(json); } QWidget* MultiSwitchProgramSession::make_widget(QWidget& parent){ return new MultiSwitchProgramWidget2(parent, *this); diff --git a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_MultiSwitchProgramSession.h b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_MultiSwitchProgramSession.h index 0b9e5b809c..e4fafb1dea 100644 --- a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_MultiSwitchProgramSession.h +++ b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_MultiSwitchProgramSession.h @@ -63,8 +63,8 @@ class MultiSwitchProgramSession final virtual void shutdown() override; virtual void startup(size_t switch_count) override; - virtual void from_json(const JsonValue& json) override; virtual JsonValue to_json() const override; + virtual void load_json(const JsonValue& json) override; virtual QWidget* make_widget(QWidget& parent) override; diff --git a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SingleSwitchProgramSession.cpp b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SingleSwitchProgramSession.cpp index dca4733549..b3cc85bde4 100644 --- a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SingleSwitchProgramSession.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SingleSwitchProgramSession.cpp @@ -272,22 +272,21 @@ void SingleSwitchProgramSession::internal_run_program(){ } -void SingleSwitchProgramSession::from_json(const JsonValue& json){ +JsonValue SingleSwitchProgramSession::to_json() const{ + JsonObject obj = std::move(*m_instance->to_json().to_object()); + obj["SwitchSetup"] = m_system_option.to_json(); + return obj; +} +void SingleSwitchProgramSession::load_json(const JsonValue& json){ const JsonObject* obj = json.to_object(); if (obj == nullptr){ return; } const JsonValue* value = obj->get_value("SwitchSetup"); if (value){ - SwitchSystemOption option(m_system_option.m_allow_commands_while_locked, *value); - m_system.load(option); + m_system.load_json(*value); } - m_instance->from_json(json); -} -JsonValue SingleSwitchProgramSession::to_json() const{ - JsonObject obj = std::move(*m_instance->to_json().to_object()); - obj["SwitchSetup"] = m_system_option.to_json(); - return obj; + m_instance->load_json(json); } QWidget* SingleSwitchProgramSession::make_widget(QWidget& parent){ return new SingleSwitchProgramWidget2(parent, *this); diff --git a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SingleSwitchProgramSession.h b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SingleSwitchProgramSession.h index df45abef3a..261e03d466 100644 --- a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SingleSwitchProgramSession.h +++ b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SingleSwitchProgramSession.h @@ -49,8 +49,8 @@ class SingleSwitchProgramSession final : public PanelSession, public ProgramSess private: - virtual void from_json(const JsonValue& json) override; virtual JsonValue to_json() const override; + virtual void load_json(const JsonValue& json) override; virtual QWidget* make_widget(QWidget& parent) override; diff --git a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SwitchSystemOption.cpp b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SwitchSystemOption.cpp index 8d5e43136f..b61ba2f59c 100644 --- a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SwitchSystemOption.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SwitchSystemOption.cpp @@ -47,9 +47,17 @@ SwitchSystemOption::SwitchSystemOption( { load_json(json); } +JsonValue SwitchSystemOption::to_json() const{ + JsonValue ret = ConsoleSystemOption::to_json(); + JsonObject& root = ret.to_object_throw(); + root[JSON_CONSOLE_TYPE] = m_console_type.to_json(); + return ret; +} void SwitchSystemOption::load_json(const JsonValue& json){ ConsoleSystemOption::load_json(json); - + load_json_self(json); +} +void SwitchSystemOption::load_json_self(const JsonValue& json){ const JsonObject* obj = json.to_object(); if (obj == nullptr){ return; @@ -61,12 +69,6 @@ void SwitchSystemOption::load_json(const JsonValue& json){ m_console_type.load_json(*value); } } -JsonValue SwitchSystemOption::to_json() const{ - JsonValue ret = ConsoleSystemOption::to_json(); - JsonObject& root = ret.to_object_throw(); - root[JSON_CONSOLE_TYPE] = m_console_type.to_json(); - return ret; -} diff --git a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SwitchSystemOption.h b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SwitchSystemOption.h index 39f88c66c9..61223d2a1b 100644 --- a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SwitchSystemOption.h +++ b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SwitchSystemOption.h @@ -41,8 +41,10 @@ class SwitchSystemOption : public ConsoleInfra::ConsoleSystemOption{ const JsonValue& json ); - virtual void load_json(const JsonValue& json) override; virtual JsonValue to_json() const override; + virtual void load_json(const JsonValue& json) override; + + void load_json_self(const JsonValue& json); public: diff --git a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SwitchSystemSession.cpp b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SwitchSystemSession.cpp index 3e7ae65540..ffdd2a39c8 100644 --- a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SwitchSystemSession.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SwitchSystemSession.cpp @@ -48,6 +48,15 @@ SwitchSystemSession::SwitchSystemSession( +JsonValue SwitchSystemSession::to_json() const{ + return m_option.to_json(); +} +void SwitchSystemSession::load_json(const JsonValue& json){ + ConsoleSystemSession::load_json(json); + m_option.load_json_self(json); +} + + } diff --git a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SwitchSystemSession.h b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SwitchSystemSession.h index 4e961b42e4..0b1ce1946a 100644 --- a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SwitchSystemSession.h +++ b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SwitchSystemSession.h @@ -46,6 +46,11 @@ class SwitchSystemSession final : public UiState m_console_id; diff --git a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.cpp b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.cpp index 8f815e9f11..3bf5b488eb 100644 --- a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.cpp +++ b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.cpp @@ -198,12 +198,12 @@ void MultiSwitchProgramInstance::start_program_border_check( void MultiSwitchProgramInstance::add_option(ConfigOption& option, std::string serialization_string){ m_options.add_option(option, std::move(serialization_string)); } -void MultiSwitchProgramInstance::from_json(const JsonValue& json){ - m_options.load_json(json); -} JsonValue MultiSwitchProgramInstance::to_json() const{ return m_options.to_json(); } +void MultiSwitchProgramInstance::load_json(const JsonValue& json){ + m_options.load_json(json); +} std::string MultiSwitchProgramInstance::check_validity() const{ return m_options.check_validity(); } diff --git a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.h b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.h index 8d5cdcc5be..af7d8249a9 100644 --- a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.h +++ b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.h @@ -164,8 +164,8 @@ class MultiSwitchProgramInstance{ public: // Settings - virtual void from_json(const JsonValue& json); virtual JsonValue to_json() const; + virtual void load_json(const JsonValue& json); virtual std::string check_validity() const; virtual void restore_defaults(); diff --git a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.cpp b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.cpp index 343a09d8fc..f15c4355b1 100644 --- a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.cpp +++ b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.cpp @@ -141,12 +141,12 @@ void SingleSwitchProgramInstance::start_program_border_check( void SingleSwitchProgramInstance::add_option(ConfigOption& option, std::string serialization_string){ m_options.add_option(option, std::move(serialization_string)); } -void SingleSwitchProgramInstance::from_json(const JsonValue& json){ - m_options.load_json(json); -} JsonValue SingleSwitchProgramInstance::to_json() const{ return m_options.to_json(); } +void SingleSwitchProgramInstance::load_json(const JsonValue& json){ + m_options.load_json(json); +} std::string SingleSwitchProgramInstance::check_validity() const{ return m_options.check_validity(); } diff --git a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h index c8247999e7..65f0cf221d 100644 --- a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h +++ b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h @@ -143,8 +143,8 @@ class SingleSwitchProgramInstance{ public: // Settings - virtual void from_json(const JsonValue& json); virtual JsonValue to_json() const; + virtual void load_json(const JsonValue& json); virtual std::string check_validity() const; virtual void restore_defaults(); diff --git a/SerialPrograms/Source/NintendoSwitch/Options/NintendoSwitch_FriendCodeListOption.cpp b/SerialPrograms/Source/NintendoSwitch/Options/NintendoSwitch_FriendCodeListOption.cpp index 065134cd5f..6fa96d1a42 100644 --- a/SerialPrograms/Source/NintendoSwitch/Options/NintendoSwitch_FriendCodeListOption.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Options/NintendoSwitch_FriendCodeListOption.cpp @@ -19,6 +19,14 @@ FriendCodeListOption::FriendCodeListOption(std::string label, std::vector{ std::vector lines() const; std::vector list() const; - 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; diff --git a/SerialPrograms/Source/NintendoSwitch/Options/TurboMacroTable.cpp b/SerialPrograms/Source/NintendoSwitch/Options/TurboMacroTable.cpp index ccb10a1a27..0a0746febc 100644 --- a/SerialPrograms/Source/NintendoSwitch/Options/TurboMacroTable.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Options/TurboMacroTable.cpp @@ -158,6 +158,44 @@ std::unique_ptr TurboMacroRow::clone() const{ return ret; } +JsonValue TurboMacroRow::to_json() const{ + JsonObject obj; + obj["Action"] = action.to_json(); + switch (action){ + case TurboMacroAction::LEFT_JOY_CLICK: + case TurboMacroAction::RIGHT_JOY_CLICK: + case TurboMacroAction::B: + case TurboMacroAction::A: + case TurboMacroAction::Y: + case TurboMacroAction::X: + case TurboMacroAction::R: + case TurboMacroAction::L: + case TurboMacroAction::ZR: + case TurboMacroAction::ZL: + case TurboMacroAction::PLUS: + case TurboMacroAction::MINUS: + case TurboMacroAction::DPADLEFT: + case TurboMacroAction::DPADRIGHT: + case TurboMacroAction::DPADUP: + case TurboMacroAction::DPADDOWN: + obj["HoldMs"] = parameters.button_hold.to_json(); + obj["ReleaseMs"] = parameters.button_release.to_json(); + break; + case TurboMacroAction::LEFT_JOYSTICK: + case TurboMacroAction::RIGHT_JOYSTICK: + obj["MoveDirectionX"] = parameters.x_axis.to_json(); + obj["MoveDirectionY"] = parameters.y_axis.to_json(); + obj["HoldMs"] = parameters.button_hold.to_json(); + obj["ReleaseMs"] = parameters.button_release.to_json(); + break; + case TurboMacroAction::WAIT: + obj["WaitMs"] = parameters.wait.to_json(); + break; + default: + break; + } + return obj; +} void TurboMacroRow::load_json(const JsonValue& json){ const JsonObject* obj = json.to_object(); if (obj == nullptr){ @@ -245,44 +283,6 @@ void TurboMacroRow::load_json(const JsonValue& json){ break; } } -JsonValue TurboMacroRow::to_json() const{ - JsonObject obj; - obj["Action"] = action.to_json(); - switch (action){ - case TurboMacroAction::LEFT_JOY_CLICK: - case TurboMacroAction::RIGHT_JOY_CLICK: - case TurboMacroAction::B: - case TurboMacroAction::A: - case TurboMacroAction::Y: - case TurboMacroAction::X: - case TurboMacroAction::R: - case TurboMacroAction::L: - case TurboMacroAction::ZR: - case TurboMacroAction::ZL: - case TurboMacroAction::PLUS: - case TurboMacroAction::MINUS: - case TurboMacroAction::DPADLEFT: - case TurboMacroAction::DPADRIGHT: - case TurboMacroAction::DPADUP: - case TurboMacroAction::DPADDOWN: - obj["HoldMs"] = parameters.button_hold.to_json(); - obj["ReleaseMs"] = parameters.button_release.to_json(); - break; - case TurboMacroAction::LEFT_JOYSTICK: - case TurboMacroAction::RIGHT_JOYSTICK: - obj["MoveDirectionX"] = parameters.x_axis.to_json(); - obj["MoveDirectionY"] = parameters.y_axis.to_json(); - obj["HoldMs"] = parameters.button_hold.to_json(); - obj["ReleaseMs"] = parameters.button_release.to_json(); - break; - case TurboMacroAction::WAIT: - obj["WaitMs"] = parameters.wait.to_json(); - break; - default: - break; - } - return obj; -} TurboMacroTable::TurboMacroTable() diff --git a/SerialPrograms/Source/NintendoSwitch/Options/TurboMacroTable.h b/SerialPrograms/Source/NintendoSwitch/Options/TurboMacroTable.h index 66026b77a5..e7a0d5e843 100644 --- a/SerialPrograms/Source/NintendoSwitch/Options/TurboMacroTable.h +++ b/SerialPrograms/Source/NintendoSwitch/Options/TurboMacroTable.h @@ -71,8 +71,8 @@ class TurboMacroRow : public EditableTableRow{ TurboMacroRow(EditableTableOption& parent_table); virtual std::unique_ptr clone() const override; - virtual void load_json(const JsonValue& json) override; virtual JsonValue to_json() const override; + virtual void load_json(const JsonValue& json) override; public: EnumDropdownCell action; diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_SwitchViewer.cpp b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_SwitchViewer.cpp index d366010f97..26913c0645 100644 --- a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_SwitchViewer.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_SwitchViewer.cpp @@ -34,12 +34,12 @@ SwitchViewer::SwitchViewer(const SwitchViewer_Descriptor& descriptor) 1, 4, 1 ) {} -void SwitchViewer::from_json(const JsonValue& json){ - m_switches.load_json(json); -} JsonValue SwitchViewer::to_json() const{ return m_switches.to_json(); } +void SwitchViewer::load_json(const JsonValue& json){ + m_switches.load_json(json); +} QWidget* SwitchViewer::make_widget(QWidget& parent){ return SwitchViewer_Widget::make(parent, *this); } diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_SwitchViewer.h b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_SwitchViewer.h index 22c987e23a..f670e1edde 100644 --- a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_SwitchViewer.h +++ b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_SwitchViewer.h @@ -30,8 +30,8 @@ class SwitchViewer : 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; private: friend class SwitchViewer_Widget; diff --git a/SerialPrograms/Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterOption.cpp b/SerialPrograms/Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterOption.cpp index 10571c70fc..76b81a195d 100644 --- a/SerialPrograms/Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterOption.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterOption.cpp @@ -25,6 +25,16 @@ EncounterFilterOption::EncounterFilterOption(bool enable_overrides) , m_shiny_filter_default(ShinyFilter::SHINY) , m_shiny_filter_current(m_shiny_filter_default) {} +JsonValue EncounterFilterOption::to_json() const{ + JsonObject obj; + obj["ShinyFilter"] = ShinyFilter_NAMES[(size_t)m_shiny_filter_current.load(std::memory_order_acquire)]; + + if (m_enable_overrides){ + obj["Overrides"] = m_table.to_json(); + } + + return obj; +} void EncounterFilterOption::load_json(const JsonValue& json){ using namespace Pokemon; @@ -48,16 +58,6 @@ void EncounterFilterOption::load_json(const JsonValue& json){ } } } -JsonValue EncounterFilterOption::to_json() const{ - JsonObject obj; - obj["ShinyFilter"] = ShinyFilter_NAMES[(size_t)m_shiny_filter_current.load(std::memory_order_acquire)]; - - if (m_enable_overrides){ - obj["Overrides"] = m_table.to_json(); - } - - return obj; -} void EncounterFilterOption::restore_defaults(){ m_shiny_filter_current.store(m_shiny_filter_default, std::memory_order_release); m_table.restore_defaults(); diff --git a/SerialPrograms/Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterOption.h b/SerialPrograms/Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterOption.h index 6926bbea9b..f716f45d4d 100644 --- a/SerialPrograms/Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterOption.h +++ b/SerialPrograms/Source/PokemonBDSP/Options/EncounterFilter/PokemonBDSP_EncounterFilterOption.h @@ -26,8 +26,8 @@ class EncounterFilterOption : public ConfigOption{ return m_table.copy_snapshot(); } - 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; diff --git a/SerialPrograms/Source/PokemonLA/Options/PokemonLA_CustomPathTable.cpp b/SerialPrograms/Source/PokemonLA/Options/PokemonLA_CustomPathTable.cpp index 7cdd0cf9e4..7fd0548333 100644 --- a/SerialPrograms/Source/PokemonLA/Options/PokemonLA_CustomPathTable.cpp +++ b/SerialPrograms/Source/PokemonLA/Options/PokemonLA_CustomPathTable.cpp @@ -190,6 +190,34 @@ std::unique_ptr CustomPathTableRow::clone() const{ ret->parameters = parameters; return ret; } +JsonValue CustomPathTableRow::to_json() const{ + JsonObject obj; + obj["Action"] = action.to_json(); + switch (action){ + case PathAction::CHANGE_MOUNT: + obj["Mount"] = parameters.mount.to_json(); + break; + case PathAction::MOVE_FORWARD: + obj["MoveForwardMs"] = parameters.move_forward.to_json(); + obj["Speed"] = parameters.move_speed.to_json(); + break; + case PathAction::MOVE_IN_DIRECTION: + obj["MoveForwardMs"] = parameters.move_forward.to_json(); +// obj["Speed"] = parameters.move_speed.to_json(); + obj["MoveDirectionX"] = parameters.left_x.to_json(); + obj["MoveDirectionY"] = parameters.left_y.to_json(); + break; + case PathAction::JUMP: + obj["JumpWaitMs"] = parameters.jump_wait.to_json(); + break; + case PathAction::WAIT: + obj["WaitMs"] = parameters.wait.to_json(); + break; + default: + break; + } + return obj; +} void CustomPathTableRow::load_json(const JsonValue& json){ const JsonObject* obj = json.to_object(); if (obj == nullptr){ @@ -269,34 +297,6 @@ void CustomPathTableRow::load_json(const JsonValue& json){ break; } } -JsonValue CustomPathTableRow::to_json() const{ - JsonObject obj; - obj["Action"] = action.to_json(); - switch (action){ - case PathAction::CHANGE_MOUNT: - obj["Mount"] = parameters.mount.to_json(); - break; - case PathAction::MOVE_FORWARD: - obj["MoveForwardMs"] = parameters.move_forward.to_json(); - obj["Speed"] = parameters.move_speed.to_json(); - break; - case PathAction::MOVE_IN_DIRECTION: - obj["MoveForwardMs"] = parameters.move_forward.to_json(); -// obj["Speed"] = parameters.move_speed.to_json(); - obj["MoveDirectionX"] = parameters.left_x.to_json(); - obj["MoveDirectionY"] = parameters.left_y.to_json(); - break; - case PathAction::JUMP: - obj["JumpWaitMs"] = parameters.jump_wait.to_json(); - break; - case PathAction::WAIT: - obj["WaitMs"] = parameters.wait.to_json(); - break; - default: - break; - } - return obj; -} CustomPathTable::CustomPathTable() : EditableTableOption_t( diff --git a/SerialPrograms/Source/PokemonLA/Options/PokemonLA_CustomPathTable.h b/SerialPrograms/Source/PokemonLA/Options/PokemonLA_CustomPathTable.h index 4c13dbb82a..1c3aea0d4c 100644 --- a/SerialPrograms/Source/PokemonLA/Options/PokemonLA_CustomPathTable.h +++ b/SerialPrograms/Source/PokemonLA/Options/PokemonLA_CustomPathTable.h @@ -86,8 +86,8 @@ class CustomPathTableRow : public EditableTableRow{ CustomPathTableRow(EditableTableOption& parent_table); virtual std::unique_ptr clone() const override; - virtual void load_json(const JsonValue& json) override; virtual JsonValue to_json() const override; + virtual void load_json(const JsonValue& json) override; public: EnumDropdownCell action; diff --git a/SerialPrograms/Source/PokemonSwSh/Options/EncounterFilter/PokemonSwSh_EncounterFilterOption.cpp b/SerialPrograms/Source/PokemonSwSh/Options/EncounterFilter/PokemonSwSh_EncounterFilterOption.cpp index b5b46c9dbb..4d5375c6e7 100644 --- a/SerialPrograms/Source/PokemonSwSh/Options/EncounterFilter/PokemonSwSh_EncounterFilterOption.cpp +++ b/SerialPrograms/Source/PokemonSwSh/Options/EncounterFilter/PokemonSwSh_EncounterFilterOption.cpp @@ -27,6 +27,14 @@ EncounterFilterOption::EncounterFilterOption(bool rare_stars, bool enable_overri , m_shiny_filter_current(m_shiny_filter_default) , m_table(rare_stars) {} +JsonValue EncounterFilterOption::to_json() const{ + JsonObject obj; + obj["ShinyFilter"] = ShinyFilter_NAMES[(size_t)m_shiny_filter_current.load(std::memory_order_relaxed)]; + if (m_enable_overrides){ + obj["Overrides"] = m_table.to_json(); + } + return obj; +} void EncounterFilterOption::load_json(const JsonValue& json){ using namespace Pokemon; @@ -47,14 +55,6 @@ void EncounterFilterOption::load_json(const JsonValue& json){ } } } -JsonValue EncounterFilterOption::to_json() const{ - JsonObject obj; - obj["ShinyFilter"] = ShinyFilter_NAMES[(size_t)m_shiny_filter_current.load(std::memory_order_relaxed)]; - if (m_enable_overrides){ - obj["Overrides"] = m_table.to_json(); - } - return obj; -} void EncounterFilterOption::restore_defaults(){ m_shiny_filter_current = m_shiny_filter_default; m_table.restore_defaults(); diff --git a/SerialPrograms/Source/PokemonSwSh/Options/EncounterFilter/PokemonSwSh_EncounterFilterOption.h b/SerialPrograms/Source/PokemonSwSh/Options/EncounterFilter/PokemonSwSh_EncounterFilterOption.h index 482de20643..8c16f5facd 100644 --- a/SerialPrograms/Source/PokemonSwSh/Options/EncounterFilter/PokemonSwSh_EncounterFilterOption.h +++ b/SerialPrograms/Source/PokemonSwSh/Options/EncounterFilter/PokemonSwSh_EncounterFilterOption.h @@ -25,9 +25,9 @@ class EncounterFilterOption : public ConfigOption{ return m_table.copy_snapshot(); } - 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; virtual ConfigWidget* make_QtWidget(QWidget& parent) override;