本文整理汇总了C++中XmlNode::GetFirstChildByNodeName方法的典型用法代码示例。如果您正苦于以下问题:C++ XmlNode::GetFirstChildByNodeName方法的具体用法?C++ XmlNode::GetFirstChildByNodeName怎么用?C++ XmlNode::GetFirstChildByNodeName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlNode
的用法示例。
在下文中一共展示了XmlNode::GetFirstChildByNodeName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadFromDisk
void Bundle::loadFromDisk() {
std::ifstream file;
GetBundleFileHandleForReading(this->bundleName, file);
if (file.good()) {
XmlParser* parser = new XmlParser();
parser->ParseXmlFile(file);
XmlTree* tree = parser->GetXmlTree();
VERIFY(tree != nullptr, "Got xml tree for bundle data in bundle %s", this->bundleName.c_str());
XmlNode* rootNode = tree->GetRootNode();
VERIFY(rootNode != nullptr, "Got root node for bundle data in bundle %s", this->bundleName.c_str());
VERIFY(rootNode->GetName() == BUNDLE_TAG, "Got bundle node for bundle data in bundle %s", this->bundleName.c_str());
XmlNode* dataNode = rootNode->GetFirstChildByNodeName(DATA_TAG);
while(dataNode != nullptr) {
std::string key = dataNode->GetAttributeValueS(KEY_ATTRIBUTE);
std::string value = dataNode->GetAttributeValueS(VALUE_ATTRIBUTE);
this->PutString(key, value);
//
dataNode = dataNode->GetNextSiblingByNodeName(DATA_TAG);
}
delete parser;
}
}
示例2: loadLinkDataFromXml
void LevelLoader::loadLinkDataFromXml (XmlNode* linkBaseNode) {
XmlNode* triggerLinkNode = linkBaseNode->GetFirstChildByNodeName(TRIGGER_LINK_TAG);
while (triggerLinkNode != nullptr) {
int triggerXmlId = triggerLinkNode->GetAttributeValueI(ID_ATTRIBUTE);
ObjectIdType triggerId = idsFromXml[triggerXmlId];
GameObject* triggerObj = ENGINE->GetSceneGraph3D()->GetGameObjectById(triggerId);
ASSERT(triggerObj != nullptr, "Trigger object with id %d exists in level", triggerId);
if (triggerObj != nullptr) {
Triggerable* triggerComp = triggerObj->GetComponent<Triggerable>();
ASSERT((triggerComp != nullptr), "Object with id %d has Triggerable component", triggerId);
if (triggerComp != nullptr) {
XmlNode* switchNode = triggerLinkNode->GetFirstChildByNodeName(SWITCH_TAG);
while (switchNode != nullptr) {
int switchXmlId = switchNode->GetAttributeValueI(ID_ATTRIBUTE);
ObjectIdType switchId = idsFromXml[switchXmlId];
triggerComp->SubscribeToSwitchObject(switchId);
switchNode = switchNode->GetNextSiblingByNodeName(SWITCH_TAG);
}
}
}
triggerLinkNode = triggerLinkNode->GetNextSiblingByNodeName(TRIGGER_LINK_TAG);
}
}
示例3: loadOtherDataFromXml
void LevelLoader::loadOtherDataFromXml(XmlNode* otherDataNode) {
XmlNode* dynamicObjNode = otherDataNode->GetFirstChildByNodeName(DYNAMIC_OBJECT_TAG);
while (dynamicObjNode != nullptr) {
int objXmlId = dynamicObjNode->GetAttributeValueI(ID_ATTRIBUTE);
std::string prefab = dynamicObjNode->GetAttributeValueS(PREFAB_ATTRIBUTE);
int xGridPosition = dynamicObjNode->GetAttributeValueI(X_ATTRIBUTE);
float yPosition = dynamicObjNode->GetAttributeValueF(Y_ATTRIBUTE);
int zGridPosition = dynamicObjNode->GetAttributeValueI(Z_ATTRIBUTE);
float rotation = dynamicObjNode->GetAttributeValueF(ROTATION_ATTRIBUTE) inRadians;
GameObject* dynamicObj = PrefabLoader::InstantiateGameObjectFromPrefab(FRAMEWORK->GetFileSystemUtils()->GetDevicePrefabsResourcesPath() + prefab + PREFAB_EXTENSION, ENGINE->GetSceneGraph3D());
idsFromXml[objXmlId] = dynamicObj->GetId();
// Position and orient the object
dynamicObj->GetTransform()->SetPosition(xGridPosition, yPosition, -zGridPosition);
dynamicObj->GetTransform()->SetOrientation(rotation, YAXIS);
// Check for overloaded components
XmlNode* compNode = dynamicObjNode->GetFirstChildByNodeName(COMPONENT_TAG);
while (compNode != nullptr) {
PrefabLoader::LoadComponentFromComponentNodeInPrefab(dynamicObj, compNode);
compNode = compNode->GetNextSiblingByNodeName(COMPONENT_TAG);
}
GridZone* zone = dynamicObj->GetComponent<GridZone>();
if (zone != nullptr) {
SINGLETONS->GetGridManager()->placeZoneOnGrid(dynamicObj->GetId());//GetGrid()->AddGridZone(dynamicObj->GetId());
}
dynamicObjNode = dynamicObjNode->GetNextSiblingByNodeName(DYNAMIC_OBJECT_TAG);
}
// TODO [Implement] Other things such as triggerables
}
示例4: loadUnitDataFromXml
void LevelLoader::loadUnitDataFromXml(XmlNode* unitBaseNode) {
// Start with player units
XmlNode* unitNode = unitBaseNode->GetFirstChildByNodeName("");
while (unitNode != nullptr) {
int unitXmlId = unitNode->GetAttributeValueI(ID_ATTRIBUTE);
std::string unitPrefab = unitNode->GetAttributeValueS(PREFAB_ATTRIBUTE);
GameObject* unitObj = PrefabLoader::InstantiateGameObjectFromPrefab(FRAMEWORK->GetFileSystemUtils()->GetDevicePrefabsResourcesPath() + unitPrefab + PREFAB_EXTENSION, ENGINE->GetSceneGraph3D());
idsFromXml[unitXmlId] = unitObj->GetId();
// Units require a GridNavigator component
GridNavigator* gNav = unitObj->GetComponent<GridNavigator>();
ASSERT(gNav != nullptr, "Unit with id %d has GridNavigator component", unitObj->GetId());
// Read the initial position of the unit
int gX = unitNode->GetAttributeValueI(X_ATTRIBUTE);
int gZ = unitNode->GetAttributeValueI(Z_ATTRIBUTE);
float rotation = unitNode->GetAttributeValueF(ROTATION_ATTRIBUTE) inRadians;
// Add the unit to the grid
SINGLETONS->GetGridManager()->placeUnitOnGrid(unitObj->GetId(), gX, gZ);
// Orient the unit.
unitObj->GetTransform()->SetOrientation(rotation, YAXIS);
// Check unit type
if (unitNode->GetName() == ENEMY_UNIT_TAG) {
EnemyUnit* enemyUnit = unitObj->GetComponent<EnemyUnit>();
ASSERT(enemyUnit != nullptr, "Enemy unit with id %d has EnemyUnit component", unitObj->GetId());
enemyUnit->Activate();
AiPerception* aiPerception = unitObj->GetComponent<AiPerception>();
ASSERT(aiPerception != nullptr, "Enemy unit with id %d has AiPerception component", unitObj->GetId());
aiPerception->Activate();
AiRoutine* aiRoutine = unitObj->GetComponent<AiRoutine>();
ASSERT(aiRoutine != nullptr, "Enemy unit with id %d has AiRoutine component", unitObj->GetId());
// Load the AI routine.
XmlNode* aiCommandNode = unitNode->GetFirstChildByNodeName(AI_COMMAND_TAG);
std::vector<std::string> commands;
while (aiCommandNode != nullptr) {
std::string command = aiCommandNode->GetValue();
commands.push_back(command);
aiCommandNode = aiCommandNode->GetNextSiblingByNodeName(AI_COMMAND_TAG);
}
aiRoutine->SetBehavior(commands);
}
GridZone* zone = unitObj->GetComponent<GridZone>();
if (zone != nullptr) {
SINGLETONS->GetGridManager()->placeZoneOnGrid(unitObj->GetId());//GetGrid()->AddGridZone(dynamicObj->GetId());
}
unitNode = unitNode->GetNextSiblingByNodeName("");
}
}
示例5: loadParentConnectionsFromXml
void LevelLoader::loadParentConnectionsFromXml(XmlNode* linkBaseNode) {
XmlNode* parentNode = linkBaseNode->GetFirstChildByNodeName(PARENT_LINK_TAG);
while (parentNode != nullptr) {
int parentXmlId = parentNode->GetAttributeValueI(ID_ATTRIBUTE);
GameObject* parentObj = ENGINE->GetSceneGraph3D()->GetGameObjectById(idsFromXml[parentXmlId]);
if (parentObj != nullptr) {
XmlNode* childNode = parentNode->GetFirstChildByNodeName(CHILD_TAG);
while (childNode != nullptr) {
int childXmlId = childNode->GetAttributeValueI(ID_ATTRIBUTE);
parentObj->AddChild_maintainTransform(idsFromXml[childXmlId]);
childNode = childNode->GetNextSiblingByNodeName(CHILD_TAG);
}
}
parentNode = parentNode->GetNextSiblingByNodeName(PARENT_LINK_TAG);
}
}
示例6: LoadLevelFromFile
void LevelLoader::LoadLevelFromFile(std::string levelFilename) {
FRAMEWORK->GetLogger()->dbglog("\nLoading level from level file: %s", levelFilename.c_str());
XmlParser* parser = new XmlParser();
parser->ParseXmlFile(FRAMEWORK->GetFileSystemUtils()->GetDeviceBaseResourcesPath() + "levels/" + levelFilename);
#ifdef DEBUG
parser->Print();
#endif // DEBUG
XmlTree* xmlTree = parser->GetXmlTree();
ASSERT(xmlTree != nullptr, "Got valid xmlTree from parser for level file %s", levelFilename.c_str());
XmlNode* levelNode = xmlTree->GetRootNode();
ASSERT(levelNode != nullptr && levelNode->GetName() == LEVEL_TAG, "Got valid level node from xml tree for level file %s", levelFilename.c_str());
std::string bgm = levelNode->GetAttributeValueS(BGM_ATTRIBUTE);
if (bgm != "") {
AudioSource* bgmSource = SINGLETONS->GetMenuManager()->GetBGMSource();
bgmSource->LoadAudioClip(LEVEL_BGM, "audio/" + bgm);
}
XmlNode* gridNode = levelNode->GetFirstChildByNodeName(GRID_TAG);
VERIFY(gridNode != nullptr, "Level definition contains <%s> node", GRID_TAG);
SINGLETONS->GetGridManager()->loadGridDataFromXml(gridNode);
// Create the shady camera before we load any objects because their AudioSource components will need it
createCamera();
XmlNode* staticNode = levelNode->GetFirstChildByNodeName(STATIC_TAG);
// The level doesn't need to have a STATIC_TAG node
if (staticNode != nullptr) {
loadStaticDataFromXml(staticNode);
}
XmlNode* otherDataNode = levelNode->GetFirstChildByNodeName(OTHER_TAG);
// The level doesn't need to have an OTHER_TAG node
if (otherDataNode != nullptr) {
loadOtherDataFromXml(otherDataNode);
}
XmlNode* unitBaseNode = levelNode->GetFirstChildByNodeName(UNITS_TAG);
VERIFY(unitBaseNode != nullptr, "Level definition contains <%s> node", UNITS_TAG);
loadUnitDataFromXml(unitBaseNode);
XmlNode* linkBaseNode = levelNode->GetFirstChildByNodeName(LINKS_TAG);
VERIFY(linkBaseNode != nullptr, "Level definition contains <%s> node", LINKS_TAG);
if (linkBaseNode != nullptr) {
loadLinkDataFromXml(linkBaseNode);
loadParentConnectionsFromXml(linkBaseNode);
loadEndConditionsFromXml(linkBaseNode);
}
XmlNode* cameraNode = levelNode->GetFirstChildByNodeName(CAMERA_TAG);
VERIFY(cameraNode != nullptr, "Level definition contains <%s> node", CAMERA_TAG);
loadCameraDataFromXml(cameraNode);
delete parser;
SINGLETONS->GetMenuManager()->PlayBGM(LEVEL_BGM);
idsFromXml.clear();
LevelLoader::adjustLighting();
LevelLoader::postLoadLevel();
}