void gdipp_setting::load_gdimm_process(const xpath_node_set &process_nodes) { // backward iterate so that first-coming process settings overwrites last-coming ones xpath_node_set::const_iterator node_iter = process_nodes.end(); node_iter--; for (size_t i = 0; i < process_nodes.size(); i++, node_iter--) { // only store the setting items which match the current process name const xml_node curr_proc = node_iter->node(); const xml_attribute name_attr = curr_proc.attribute(L"name"); bool process_matched = name_attr.empty(); if (!process_matched) { const wregex name_ex(name_attr.value(), regex_flags); process_matched = regex_match(_process_name, name_ex); } if (process_matched) { for (xml_node::iterator set_iter = node_iter->node().begin(); set_iter != node_iter->node().end(); set_iter++) parse_gdimm_setting_node(*set_iter, _process_setting); } } }
const ImageMetadata* ObjectType::deserializeImageMetadata(const xml_node node) { const xml_attribute pathAttribute = node.attribute("path"); const string path(pathAttribute.as_string()); if (path.empty()) { #ifdef ENABLE_LOGGING LOGGER->error("The \"path\" attribute is a required field for %s", node.path('/').c_str()); #endif exit(XML_SCHEMA_MISMATCH); } const xml_attribute widthAttribute = node.attribute("width"); const int width = widthAttribute.as_int(-1); const xml_attribute heightAttribute = node.attribute("height"); const int height = heightAttribute.as_int(-1); // if width or height is below zero, we assume this is a single image if (width < 0 || height < 0) { return new ImageMetadata(path); } const xml_attribute rowCountAttribute = node.attribute("rows"); const int rowCount = rowCountAttribute.as_int(1); const xml_attribute columnCountAttribute = node.attribute("columns"); const int columnCount = columnCountAttribute.as_int(1); return new ImageMetadata(path, width, height, rowCount, columnCount); }
const ImageReference* ObjectType::deserializeImageReference(const xml_node node) { const xml_attribute idAttribute = node.attribute("id"); const int id = idAttribute.as_int(0); const xml_attribute alphaAttribute = node.attribute("alpha"); const int alpha = alphaAttribute.as_int(255); return new ImageReference(id, alpha); }
const Frame* ObjectType::deserializeFrame(const xml_node node) { const xml_attribute waitAttribute = node.attribute("wait"); const int wait = waitAttribute.as_int(0); const xml_node imageReferenceNode = node.child("pic"); const ImageReference* imageReference = deserializeImageReference(imageReferenceNode); return new Frame(wait, imageReference); }
const Sequence* ObjectType::deserializeSequence(const xml_node node) { const xml_attribute idAttribute = node.attribute("id"); const int id = idAttribute.as_int(); const xml_attribute nextAttribute = node.attribute("next"); const int next = nextAttribute.as_int(0); auto const frames = new vector<const Frame*>(); const auto frameNodes = node.children("frame"); for (const xml_node frameNode : frameNodes) { auto const frame = deserializeFrame(frameNode); frames->push_back(frame); } return new Sequence(id, next, frames); }
static void xml_read_float_array(T& value, xml_attribute attr) { vector<string> tokens; string_split(tokens, attr.value()); if(tokens.size() % VECTOR_SIZE != 0) { return; } value.resize(tokens.size() / VECTOR_SIZE); for(size_t i = 0; i < value.size(); i++) { float *value_float = (float*)&value[i]; for(size_t j = 0; j < VECTOR_SIZE; j++) value_float[j] = (float)atof(tokens[i * VECTOR_SIZE + j].c_str()); } }
for ( sprite_init_param_group_with_size& the_sprite_ipgws : the_sublevel.sprite_ipgws_vec_for_xml ) { the_sublevel.sprite_ipgws_vec_2d .at(the_sprite_ipgws.initial_block_grid_y_coord) .at(the_sprite_ipgws.initial_block_grid_x_coord) = the_sprite_ipgws; } }; auto parse_sublevel_node = [&]( xml_node& sublevel_node, u32 sublevel_index ) -> void { for ( xml_attribute attr=sublevel_node.first_attribute(); attr; attr=attr.next_attribute() ) { if ( attr.name() == string("width") ) { temp_level.sublevel_vec.at(sublevel_index).real_size_2d.x = attr.as_uint(); } else if ( attr.name() == string("height") ) { temp_level.sublevel_vec.at(sublevel_index).real_size_2d.y = attr.as_uint(); } }
void gdipp_setting::load_gdimm_font(const xpath_node_set &font_node) { for (xpath_node_set::const_iterator node_iter = font_node.begin(); node_iter != font_node.end(); node_iter++) { setting_map curr_settings; for (xml_node::iterator set_iter = node_iter->node().begin(); set_iter != node_iter->node().end(); set_iter++) parse_gdimm_setting_node(*set_iter, curr_settings); const xml_node curr_font = node_iter->node(); const xml_attribute name_attr = curr_font.attribute(L"name"); const xml_attribute bold_attr = curr_font.attribute(L"bold"); const xml_attribute italic_attr = curr_font.attribute(L"italic"); const xml_attribute max_height_attr = curr_font.attribute(L"max_height"); // negative indicates such optional attribute is not specified const gdimm_font_node new_font = {(name_attr.empty() ? wstring() : name_attr.value()), (bold_attr.empty() ? -1 : bold_attr.as_uint()), (italic_attr.empty() ? -1 : italic_attr.as_uint()), (max_height_attr.empty() ? -1 : max_height_attr.as_uint()), curr_settings}; _gdimm_font.push_back(new_font); } }