MCPcopy Create free account
hub / github.com/MaaXYZ/MaaFramework / parse_and_param

Method parse_and_param

source/MaaFramework/Resource/PipelineParser.cpp:1850–1904  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1848}
1849
1850bool PipelineParser::parse_and_param(
1851 const json::value& input,
1852 std::shared_ptr<Recognition::AndParam>& output,
1853 const std::shared_ptr<Recognition::AndParam>& default_value,
1854 const DefaultPipelineMgr& default_mgr)
1855{
1856 if (!output) {
1857 output = std::make_shared<Recognition::AndParam>();
1858 }
1859
1860 if (!default_value) {
1861 LogError << "default_value is null" << VAR(input);
1862 return false;
1863 }
1864
1865 const auto& defaults = *default_value;
1866
1867 auto all_opt = input.find("all_of");
1868 if (!all_opt) {
1869 if (!defaults.all_of.empty()) {
1870 output->all_of = defaults.all_of;
1871 }
1872 else {
1873 LogError << "And recognition requires non-empty 'all_of' array field" << VAR(input);
1874 return false;
1875 }
1876 }
1877 else if (!all_opt->is_array() || all_opt->as_array().empty()) {
1878 LogError << "And recognition requires non-empty 'all_of' array field" << VAR(input);
1879 return false;
1880 }
1881 else {
1882 output->all_of.clear();
1883 for (const auto& sub_input : all_opt->as_array()) {
1884 Recognition::SubRecognition sub_reco;
1885 if (!parse_sub_recognition(sub_input, sub_reco, default_mgr)) {
1886 LogError << "failed to parse sub recognition in 'all_of'" << VAR(sub_input);
1887 return false;
1888 }
1889 output->all_of.emplace_back(std::move(sub_reco));
1890 }
1891 }
1892
1893 if (!get_and_check_value(input, "box_index", output->box_index, defaults.box_index)) {
1894 LogError << "failed to get_and_check_value box_index" << VAR(input);
1895 return false;
1896 }
1897
1898 if (output->box_index < 0 || output->box_index >= static_cast<int>(output->all_of.size())) {
1899 LogError << "box_index out of range" << VAR(output->box_index) << VAR(output->all_of.size());
1900 return false;
1901 }
1902
1903 return true;
1904}
1905
1906bool PipelineParser::parse_or_param(
1907 const json::value& input,

Callers

nothing calls this directly

Calls 5

moveFunction · 0.85
findMethod · 0.45
emptyMethod · 0.45
clearMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected