static bool decode(const Node& node, OpenXcom::DeploymentData& rhs) { if (!node.IsMap()) return false; rhs.alienRank = node["alienRank"].as<int>(rhs.alienRank); rhs.lowQty = node["lowQty"].as<int>(rhs.lowQty); rhs.highQty = node["highQty"].as<int>(rhs.highQty); rhs.dQty = node["dQty"].as<int>(rhs.dQty); rhs.extraQty = node["extraQty"].as<int>(0); // give this a default, as it's not 100% needed, unlike the others. rhs.percentageOutsideUfo = node["percentageOutsideUfo"].as<int>(rhs.percentageOutsideUfo); rhs.itemSets = node["itemSets"].as< std::vector<OpenXcom::ItemSet> >(rhs.itemSets); return true; }
bool convert<csapex::connection_types::KeyValueMessage>::decode(const Node& node, csapex::connection_types::KeyValueMessage& rhs) { if (!node.IsMap()) { return false; } convert<csapex::connection_types::Message>::decode(node, rhs); std::string name = node["name"].as<std::string>(); TokenData::ConstPtr data_ptr = node["value"].as<TokenDataConstPtr>(); rhs.value = std::make_pair(name, data_ptr); return true; }
static bool decode(const Node& node, OpenXcom::BriefingData& rhs) { if (!node.IsMap()) return false; rhs.palette = node["palette"].as<int>(rhs.palette); rhs.textOffset = node["textOffset"].as<int>(rhs.textOffset); rhs.title = node["title"].as<std::string>(rhs.title); rhs.desc = node["desc"].as<std::string>(rhs.desc); rhs.music = node["music"].as<std::string>(rhs.music); rhs.cutscene = node["cutscene"].as<std::string>(rhs.cutscene); rhs.background = node["background"].as<std::string>(rhs.background); rhs.showCraft = node["showCraft"].as<bool>(rhs.showCraft); rhs.showTarget = node["showTarget"].as<bool>(rhs.showTarget); return true; }
static bool decode(const Node& node, florb::cfg_gpsd& rhs) { if((!node.IsMap()) || (node.size() == 0)) return true; if (node["enabled"]) rhs.enabled(node["enabled"].as<bool>()); if (node["host"]) rhs.host(node["host"].as<std::string>()); if (node["port"]) rhs.port(node["port"].as<std::string>()); return true; }
static bool decode(const Node& node, florb::cfg_units& rhs) { if((!node.IsMap()) || (node.size() == 0)) return true; if (node["system_length"]) { std::string sm(node["system_length"].as<std::string>()); if (sm == "imperial") rhs.system_length(florb::cfg_units::system::IMPERIAL); else if (sm == "nautical") rhs.system_length(florb::cfg_units::system::NAUTICAL); else rhs.system_length(florb::cfg_units::system::METRIC); } return true; }
static bool decode(const Node& node, Attachment& rhs) { if (!node.IsMap()) { return false; } if (!node["frame"]) { return false; } if (!node["urdf"]) { return false; } rhs.attach_to_frame = node["frame"].as<std::string>(); rhs.urdf_filename = node["urdf"].as<std::string>(); if (node["joint_type"]) { rhs.joint_type = node["joint_type"].as<FloatingBaseType>(); } else { rhs.joint_type = kFixed; } return true; }
static bool decode(const Node& node, florb::cfg_viewport& rhs) { if((!node.IsMap()) || (node.size() == 0)) { return true; } if (node["lat"]) rhs.lat(node["lat"].as<double>()); if (node["lon"]) rhs.lon(node["lon"].as<double>()); if (node["z"]) rhs.z(node["z"].as<unsigned int>()); return true; }
void StyleMixer::mergeMapFieldTakingLast(const std::string& key, Node target, const std::vector<Node>& sources) { Node map = target[key]; if (map && !map.IsMap()) { return; } for (auto it = sources.rbegin(); it != sources.rend(); ++it) { const auto& source = (*it)[key]; if (!source.IsMap()) { continue; } for (const auto& entry : source) { const auto& subkey = entry.first.Scalar(); if (!map[subkey]) { map[subkey] = entry.second; } } } }
std::vector<std::string> StyleMixer::getMixingOrder(const Node& _styles) { // Input must be a map of names to style configuration nodes. if (!_styles.IsMap()) { return {}; } // Dependencies are pairs of strings that form a DAG. // If style 'a' mixes style 'b', the dependency would be {'b', 'a'}. std::vector<std::pair<std::string, std::string>> dependencies; for (const auto& entry : _styles) { const auto& name = entry.first; const auto& config = entry.second; for (const auto& mix : getStylesToMix(config)) { dependencies.push_back({ mix, name.Scalar() }); } } return topologicalSort(dependencies); }
void Importer::resolveSceneUrls(Node& root, const Url& baseUrl) { auto base = baseUrl; if (isZipArchiveUrl(baseUrl)) { base = getBaseUrlForZipArchive(baseUrl); } // Resolve global texture URLs. Node textures = root["textures"]; if (textures.IsDefined()) { for (auto texture : textures) { if (Node textureUrlNode = texture.second["url"]) { if (nodeIsPotentialUrl(textureUrlNode)) { textureUrlNode = Url(textureUrlNode.Scalar()).resolved(base).string(); } } } } // Resolve inline texture URLs. if (Node styles = root["styles"]) { for (auto entry : styles) { Node style = entry.second; if (!style.IsMap()) { continue; } //style->texture if (Node texture = style["texture"]) { if (nodeIsTextureUrl(texture, textures)) { texture = Url(texture.Scalar()).resolved(base).string(); } } //style->material->texture if (Node material = style["material"]) { if (!material.IsMap()) { continue; } for (auto& prop : {"emission", "ambient", "diffuse", "specular", "normal"}) { if (Node propNode = material[prop]) { if (!propNode.IsMap()) { continue; } if (Node matTexture = propNode["texture"]) { if (nodeIsTextureUrl(matTexture, textures)) { matTexture = Url(matTexture.Scalar()).resolved(base).string(); } } } } } //style->shader->uniforms->texture if (Node shaders = style["shaders"]) { if (!shaders.IsMap()) { continue; } if (Node uniforms = shaders["uniforms"]) { for (auto uniformEntry : uniforms) { Node uniformValue = uniformEntry.second; if (nodeIsTextureUrl(uniformValue, textures)) { uniformValue = Url(uniformValue.Scalar()).resolved(base).string(); } else if (uniformValue.IsSequence()) { for (Node u : uniformValue) { if (nodeIsTextureUrl(u, textures)) { u = Url(u.Scalar()).resolved(base).string(); } } } } } } } } // Resolve data source URLs. if (Node sources = root["sources"]) { for (auto source : sources) { if (!source.second.IsMap()) { continue; } if (Node sourceUrl = source.second["url"]) { if (nodeIsPotentialUrl(sourceUrl)) { sourceUrl = Url(sourceUrl.Scalar()).resolved(base).string(); } } } } // Resolve font URLs. if (Node fonts = root["fonts"]) { if (fonts.IsMap()) { for (const auto& font : fonts) { if (font.second.IsMap()) { auto urlNode = font.second["url"]; if (nodeIsPotentialUrl(urlNode)) { urlNode = Url(urlNode.Scalar()).resolved(base).string(); } } else if (font.second.IsSequence()) { for (auto& fontNode : font.second) { auto urlNode = fontNode["url"]; if (nodeIsPotentialUrl(urlNode)) { urlNode = Url(urlNode.Scalar()).resolved(base).string(); } } } } } } }