bool QDomNamedNodeMapProto:: isEmpty() const { QDomNamedNodeMap *item = qscriptvalue_cast<QDomNamedNodeMap*>(thisObject()); if (item) return item->isEmpty(); return false; }
bool DefinitionParser::createMultiFrameSprite (QDomNode& frame, const Content::Class clazz) { QDomNode parent = frame.parentNode(); QDomNamedNodeMap attributes = parent.attributes(); const QString childName = clazz == Content::MOVIECLIP ? ::NODE_FRAME : ::NODE_OBJECT; const QString className = attributes.namedItem(ATTR_CLASS).nodeValue(); const QString basePath = attributes.namedItem(ATTR_PATH).nodeValue(); const QString absBasePath = _targetDir.absoluteFilePath(basePath); struct SpriteAsset* sprite = NULL; if (!QFile::exists(absBasePath)) { info("base path \'" + absBasePath + "\' does not exist"); return false; } while (!frame.isNull()) { QDomElement e = frame.toElement(); QDomNamedNodeMap attr = frame.attributes(); checkAttributes(frame); frame = frame.nextSibling(); if (e.isNull()) { continue; } const QString tn = e.tagName(); if (tn != childName) { warnInvalidTag(tn, frame.parentNode().nodeName()); continue; } const QString relpath = attr.namedItem(ATTR_PATH).nodeValue(); if (attr.isEmpty() || relpath.isEmpty()) { warnMissingAttr(ATTR_PATH, tn); continue; } const QString path = _targetDir.absoluteFilePath(basePath + relpath); if (!checkPathExists(path)) { continue; } struct AssetBit asset; asset.name = attr.namedItem(ATTR_NAME).nodeValue(); asset.path = _tempDir.relativeFilePath(path); copyAttributes(&asset, attr); if (!sprite) { sprite = new SpriteAsset(); } sprite->assets.push_back(asset); } if (sprite) { sprite->clazz = clazz; sprite->name = className; copyAttributes(sprite, attributes); _assets[className] = sprite; } return true; }
void DefinitionParser::parseAssetNodes (QDomNode& node, const Content::Class clazz) { bool sprite = false; QString nodeName; switch (clazz) { case Content::MOVIECLIP: nodeName = NODE_MOVIECLIP; sprite = true; break; case Content::SPRITE: sprite = true; nodeName = NODE_SPRITE; break; case Content::BITMAPDATA: nodeName = NODE_BITMAP; break; case Content::SOUND: nodeName = NODE_SOUND; break; case Content::BYTEARRAY: nodeName = NODE_BINARY; break; default: error("invalid class type " + QString::number(clazz)); return; } while (!node.isNull()) { QDomElement elem = node.toElement(); QDomNode parseNode = node; QDomNamedNodeMap attributes = node.attributes(); QDomNode frame = node.firstChild(); checkAttributes(node); node = node.nextSibling(); if (elem.isNull()) { continue; } const QString tag = elem.tagName(); if (nodeName != tag) { warnInvalidTag(tag, parseNode.parentNode().nodeName()); continue; } if (attributes.isEmpty() || attributes.namedItem(ATTR_CLASS).nodeValue().isEmpty()) { warnMissingAttr(ATTR_CLASS, tag); continue; } if (frame.isNull() || !sprite) { createSingleFrameAsset(parseNode, clazz, nodeName); } else { createMultiFrameSprite(frame, clazz); } } }
bool CAnm2DXml::load(const QDomDocument &xml) { if ( xml.doctype().name() != kAnmXML_ID_Anm2D ) { return false ; } QDomElement root = xml.documentElement() ; if ( root.isNull() ) { return false ; } if ( root.nodeName() != kAnmXML_ID_Root ) { return false ; } QDomNamedNodeMap nodeMap = root.attributes() ; if ( nodeMap.isEmpty() ) { return false ; } if ( nodeMap.namedItem(kAnmXML_Attr_Version).isNull() ) { return false ; } int version = nodeMap.namedItem(kAnmXML_Attr_Version).toAttr().value().toInt() ; if ( version != kAnmXML_Version ) { return false ; } if ( nodeMap.namedItem(kAnmXML_Attr_ObjNum).isNull() ) { return false ; } if ( nodeMap.namedItem(kAnmXML_Attr_ImageNum).isNull() ) { return false ; } int objNum = nodeMap.namedItem(kAnmXML_Attr_ObjNum).toAttr().value().toInt() ; int imageNum = nodeMap.namedItem(kAnmXML_Attr_ImageNum).toAttr().value().toInt() ; QDomNode n = root.firstChild() ; return loadElement(n, objNum, imageNum) ; }