TEST(TestTinyXML, read_part) { tinyxml2::XMLDocument doc; EXPECT_EQ(doc.LoadFile("..\\autumn leaves.xml"), tinyxml2::XMLError::XML_SUCCESS); const auto part = doc.FirstChildElement("chord-score")->FirstChildElement("score")->FirstChildElement("part"); EXPECT_EQ(part->IntAttribute("repeat"), 2); const auto next = part->NextSiblingElement("part"); EXPECT_EQ(next->IntAttribute("repeat"), 0); }
void UnitData::init(const tinyxml2::XMLElement * xmlElement) { assert(xmlElement && "UnitData::init() the xml element is nullptr."); pimpl->m_Type = xmlElement->Attribute("Type"); //Load movement data. auto movementElement = xmlElement->FirstChildElement("Movement"); pimpl->m_Movement = movementElement->IntAttribute("Range"); pimpl->m_MovementType = movementElement->Attribute("Type"); //Load animations. pimpl->m_Animation.loadAnimation(xmlElement->FirstChildElement("Animation")); //Load other animation data. pimpl->m_MovingSpeedGridsPerSec = xmlElement->FirstChildElement("MovingSpeed")->FloatAttribute("Value"); }
void DialogSystem::receive(const MouseClickEvent &mce) { game::entities.each<Position, Solid, Dialog, Name>( [&](entityx::Entity e, Position &pos, Solid &dim, Dialog &d, Name &name) { static std::atomic_bool dialogRun; (void)e; (void)d; if (((mce.position.x > pos.x) & (mce.position.x < pos.x + dim.width)) && ((mce.position.y > pos.y) & (mce.position.y < pos.y + dim.height))) { if (!dialogRun.load()) { std::thread([&] { std::string questAssignedText; int newIndex; auto exml = game::engine.getSystem<WorldSystem>()->getXML()->FirstChildElement("Dialog"); dialogRun.store(true); if (e.has_component<Direction>()) d.talking = true; if (d.index == 9999) { ui::dialogBox(name.name, "", false, randomDialog[d.rindex % randomDialog.size()]); ui::waitForDialog(); } else if (exml != nullptr) { while (exml->StrAttribute("name") != name.name) exml = exml->NextSiblingElement(); exml = exml->FirstChildElement("text"); while (exml->IntAttribute("id") != d.index) exml = exml->NextSiblingElement(); auto oxml = exml->FirstChildElement("set"); if (oxml != nullptr) { do game::setValue(oxml->StrAttribute("id"), oxml->StrAttribute("value")); while ((oxml = oxml->NextSiblingElement())); game::briceUpdate(); } auto qxml = exml->FirstChildElement("quest"); if (qxml != nullptr) { const char *qname; auto qsys = game::engine.getSystem<QuestSystem>(); do { // assign quest qname = qxml->Attribute("assign"); if (qname != nullptr) { questAssignedText = qname; auto req = qxml->GetText(); qsys->assign(qname, qxml->StrAttribute("desc"), req ? req : ""); } // check / finish quest else { qname = qxml->Attribute("check"); if (qname != nullptr) { if (qname != nullptr && qsys->hasQuest(qname) && qsys->finish(qname) == 0) { d.index = 9999; } else { ui::dialogBox(name.name, "", false, "Finish my quest u nug"); ui::waitForDialog(); return; } // oldidx = d.index; // d.index = qxml->UnsignedAttribute("fail"); // goto COMMONAIFUNC; } } } while((qxml = qxml->NextSiblingElement())); } auto cxml = exml->FirstChildElement("content"); const char *content; if (cxml == nullptr) { content = randomDialog[d.rindex % randomDialog.size()].c_str(); } else { content = cxml->GetText() - 1; while (*++content && isspace(*content)); } ui::dialogBox(name.name, "", false, content); ui::waitForDialog(); if (!questAssignedText.empty()) ui::passiveImportantText(5000, ("Quest assigned:\n\"" + questAssignedText + "\"").c_str()); if (exml->QueryIntAttribute("nextid", &newIndex) == XML_NO_ERROR) d.index = newIndex; } d.talking = false; dialogRun.store(false); }).detach(); } } }); }