| 322 | } |
| 323 | |
| 324 | void ReadScriptParametersFromXML(ScriptParamMap &spm, const TiXmlElement *params) { |
| 325 | LOG_ASSERT(params); |
| 326 | const TiXmlElement *param = params->FirstChildElement("parameter"); |
| 327 | while (param) { |
| 328 | std::string name = param->Attribute("name"); |
| 329 | std::string type_str = param->Attribute("type"); |
| 330 | ScriptParam sp; |
| 331 | if (type_str == "int") { |
| 332 | int val; |
| 333 | param->QueryIntAttribute("val", &val); |
| 334 | sp.SetInt(val); |
| 335 | } else if (type_str == "float") { |
| 336 | float val = 0.0f; |
| 337 | param->QueryFloatAttribute("val", &val); |
| 338 | sp.SetFloat(val); |
| 339 | } else if (type_str == "string") { |
| 340 | sp.SetString(param->Attribute("val")); |
| 341 | } else if (type_str == "json") { |
| 342 | sp.SetJSONFromString(param->Attribute("val")); |
| 343 | } |
| 344 | spm[name] = sp; |
| 345 | param = param->NextSiblingElement(); |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | void WriteScriptParamsToXML(const ScriptParamMap &pm, TiXmlElement *params) { |
| 350 | for (const auto &iter : pm) { |
no test coverage detected