spTmxMap TmxMap::loadMap(const char* name, Resources& resStore, const PropCallback& pc) { Resource* res = resStore.get(name); if(res == nullptr) { log::error("resource %s not found", name); return nullptr; } ResBuffer* rb = dynamic_cast<ResBuffer*>(res); if(rb == nullptr) { log::error("resource %s not buffer", name); return nullptr; } const file::buffer& buf = rb->getBuffer(); pugi::xml_document doc; pugi::xml_parse_result pr = doc.load_buffer(buf.getData(), buf.getSize()); if(pr.status != pugi::status_ok) { log::error("resource %s not xml", name); return nullptr; } pugi::xml_node xm = doc.child("map"); spTmxMap map = new TmxMap; map->_width = xm.attribute("width").as_int(); map->_height = xm.attribute("height").as_int(); map->_tileWidth = xm.attribute("tile_width").as_int(); map->_tileHeight = xm.attribute("tile_height").as_int(); pugi::xml_node ts = xm.child("tileset"); map->_tileset.init(ts, resStore); int order = 0; for (auto item = xm.first_child(); item; item = item.next_sibling()) { if(strcmp(item.name(), "layer") == 0) { spTmxLayer layer = TmxLayer::loadLayer(item, resStore, &map->_tileset, pc); if(layer.get() != nullptr) { layer->setPriority(order); layer->attachTo(map); ++order; } } } return map; }
Resource *ResBuffer::create(CreateResourceContext &context) { ResBuffer *rs = new ResBuffer(); string file = context.node.attribute("file").value(); rs->setName(Resource::extractID(context.node, file, "")); rs->init((*context.folder + file).c_str()); setNode(rs, context.node); return rs; }
Resource *ResBuffer::create(CreateResourceContext &context) { ResBuffer *rs = new ResBuffer(); pugi::xml_node node = context.walker.getNode(); string file = node.attribute("file").value(); rs->setName(Resource::extractID(node, file, "")); rs->init(context.walker.getPath("file").c_str()); setNode(rs, node); return rs; }