本文整理汇总了C++中CL_DomElement::get_attribute_int方法的典型用法代码示例。如果您正苦于以下问题:C++ CL_DomElement::get_attribute_int方法的具体用法?C++ CL_DomElement::get_attribute_int怎么用?C++ CL_DomElement::get_attribute_int使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CL_DomElement
的用法示例。
在下文中一共展示了CL_DomElement::get_attribute_int方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CL_Exception
TileMap::TileMap(CL_GraphicContext& gc, CL_ResourceManager& resmgr, const CL_String& tileset)
: map_width(0), map_height(0), cur_map_x(0), cur_map_y(0) {
CL_Resource res = resmgr.get_resource(tileset);
if (res.get_type() != "tilemap")
throw CL_Exception(cl_format("Resource %1 is not a tilemap", tileset));
CL_DomElement element = res.get_element();
levelname = element.get_attribute("name");
CL_String resource_name = element.get_attribute("resource");
map_width = element.get_attribute_int("width");
map_height = element.get_attribute_int("height");
tiles = CL_Sprite(gc, resource_name, &resmgr);
float scalex, scaley;
tiles.get_scale(scalex, scaley);
tile_width = tiles.get_width() * scalex;
tile_height = tiles.get_height() * scaley;
auto layer_nodes = element.select_nodes("layer");
for (CL_DomNode& idx : layer_nodes) {
CL_DomElement layer_element = idx.to_element();
CL_String layer_tiles = layer_element.get_first_child().get_node_value();
std::vector<CL_String> tile_indices = CL_StringHelp::split_text(layer_tiles, ",");
MapLayer layer;
layer.map.reserve(tile_indices.size());
for (auto& tile : tile_indices)
layer.map.push_back(CL_StringHelp::text_to_int(tile));
layers.push_back(layer);
}
}
示例2: load
void TileMap::load(CL_GraphicContext &gc, const CL_String &level, CL_ResourceManager &resources)
{
CL_Resource resource = resources.get_resource(level);
if (resource.get_type() != "tilemap")
throw CL_Exception(cl_format("Resource %1 is not of type tilemap!", level));
CL_DomElement element = resource.get_element();
CL_String level_name = element.get_attribute("name");
CL_String resource_name = element.get_attribute("resource");
map_width = element.get_attribute_int("width");
map_height = element.get_attribute_int("height");
cl_log_event("Debug", "Loading level %1 (%2x%3)", level_name, map_width, map_height);
sprite_tiles = CL_Sprite(gc, resource_name, &resources);
tile_width = sprite_tiles.get_width();
tile_height = sprite_tiles.get_height();
cl_log_event("Debug", "Loaded resource %1 with %2 tiles", resource_name, sprite_tiles.get_frame_count());
std::vector<CL_DomNode> layer_nodes = element.select_nodes("layer");
for (size_t layer_index = 0; layer_index < layer_nodes.size(); layer_index++)
{
CL_DomElement layer_element = layer_nodes[layer_index].to_element();
CL_String layer_name = layer_element.get_attribute("name");
CL_String layer_tiles = layer_element.get_first_child().get_node_value();
std::vector<CL_String> tile_indices = CL_StringHelp::split_text(layer_tiles, ",");
TileMapLayer layer;
layer.map.reserve(tile_indices.size());
for(size_t i = 0; i < tile_indices.size(); ++i)
layer.map.push_back(CL_StringHelp::text_to_int(tile_indices[i]));
layers.push_back(layer);
cl_log_event("Debug", "Loaded layer %1 with %2 tiles", layer_name, layer.map.size());
}
current_map_position_x = 0;
current_map_position_y = 0;
}
示例3: load_polylist
void CL_Collada_Triangles_Impl::load_polylist(CL_DomElement &polylist_element, bool contains_vcount, std::vector<CL_Collada_Source> &sources, CL_Collada_Vertices &vertices, std::vector<CL_Collada_Material> &library_materials)
{
name = polylist_element.get_attribute("name");
// Find material
if (polylist_element.has_attribute("material"))
{
CL_String material_name = polylist_element.get_attribute("material");
std::vector<CL_Collada_Material>::size_type size, cnt;
size = library_materials.size();
for (cnt=0; cnt< size; cnt++)
{
if (library_materials[cnt].get_id() == material_name)
{
material = library_materials[cnt];
break;
}
}
if (material.is_null())
throw CL_Exception("Unable to find material");
}
triangle_count = polylist_element.get_attribute_int("count", 0);
load_inputs(polylist_element, sources, vertices);
if (contains_vcount)
{
CL_DomElement vcount_element = polylist_element.named_item("vcount").to_element();
if (!vcount_element.is_null())
validate_vcount(vcount_element);
}
CL_DomElement primitive_element = polylist_element.named_item("p").to_element();
if (!primitive_element.is_null())
load_primitive(primitive_element);
}
示例4: main
int ConsoleProgram::main(const std::vector<CL_String> &args)
{
// Setup clanCore:
CL_SetupCore setup_core;
// Initialize the ClanLib display component
CL_SetupDisplay setup_display;
// Create a console Window if one does not exist:
CL_ConsoleWindow console_window("Console", 80, 600);
try
{
//получение параметра запуска
for (std::vector<CL_String>::const_iterator iter_args = args.begin(); iter_args != args.end(); ++iter_args)
CL_Console::write_line( *iter_args );
//получение имени директории для сохранения
CL_String workDirectoryName;
if (args.size() > 1)
{
//полное имя рабочей директории
workDirectoryName = args[1];
//конвертирование из CP-1251 в UTF-8 имени рабочей директории
workDirectoryName = decode(workDirectoryName);
}
else
{
//получение полного пути к текущему каталогу
workDirectoryName = CL_Directory::get_current();
}
CL_Console::write_line("workDirectoryName: %1", workDirectoryName);
//получение имени последней директории
CL_String locationName = CL_PathHelp::remove_trailing_slash(workDirectoryName);
locationName = CL_PathHelp::get_filename(locationName);
CL_Console::write_line("locationName: %1", locationName);
CL_String tempDir = CL_PathHelp::add_trailing_slash(workDirectoryName) + "temp\\";
CL_DirectoryScanner directoryScanner;
directoryScanner.scan(tempDir, "*.export");
while (directoryScanner.next())
{
//имя обрабатываемого файла
CL_String fileName;
if (directoryScanner.is_directory())
continue;
//получение полного имени файла экспорта
fileName = directoryScanner.get_pathname();
//конвертирование из CP-1251 в UTF-8
fileName = decode(fileName);
CL_Console::write_line("find: %1", fileName);
//открытие XML файла
CL_File fileXML;
bool is_opened = fileXML.open(fileName);
if( !is_opened )
return PrintError( CL_String("Can't open file: ") + fileName );
//Создание объекта DOM парсера
CL_DomDocument document(fileXML);
//получение root узла
CL_DomElement root = document.get_document_element();
if( root.get_local_name() != "resources")
{
CL_Console::write_line("Root name can't be: %1", root.get_local_name().c_str());
return PrintError("");
}
//цикл по потомкам "resources"
for (CL_DomNode cur = root.get_first_child(); !cur.is_null(); cur = cur.get_next_sibling())
{
//загрузка только спрайтов
if (cur.get_node_name() != "sprite")
continue;
CL_DomElement element = cur.to_element();
//проверка на обязательные параметры
if (!element.has_attribute("name"))
return PrintError("Error: can't find parametr \"name\"");
CL_DomString name = element.get_attribute("name");
int x = element.get_attribute_int("x");
int y = element.get_attribute_int("y");
//добавление спрайта
sprites.push_back( S_Sprite(name, CL_Vec2i(x, y) ) );
//цикл по "image" (формирование списка имен файлов)
for (CL_DomNode cur_image = cur.get_first_child(); !cur_image.is_null(); cur_image = cur_image.get_next_sibling())
{
//загрузка только image
if (cur_image.get_node_name() != "image")
continue;
CL_DomElement element_image = cur_image.to_element();
CL_DomString file = element_image.get_attribute("file");
//конвертирование из CP-1251 в UTF-8 имени файла изображения
//.........这里部分代码省略.........