EntityArchetype::EntityArchetype(xmlpp::Document* doc, ImageLoader& loader, Database* db) { const xmlpp::Element* root = dynamic_cast<const xmlpp::Element*>(doc->get_root_node()); name = dynamic_cast<const xmlpp::Element*>(root->find("name")[0])->get_child_text()->get_content(); width = atoi(dynamic_cast<const xmlpp::Element*>(root->find("width")[0])->get_child_text()->get_content().c_str()); height = atoi(dynamic_cast<const xmlpp::Element*>(root->find("height")[0])->get_child_text()->get_content().c_str()); frames = atoi(dynamic_cast<const xmlpp::Element*>(root->find("frames")[0])->get_child_text()->get_content().c_str()); std::string imgName = dynamic_cast<const xmlpp::Element*>(root->find("image")[0])->get_child_text()->get_content(); if (!root->find("scripts").empty()) { const xmlpp::Element* scripts = dynamic_cast<const xmlpp::Element*>(root->find("scripts")[0]); if (!scripts->find("idle").empty()) idleScript = dynamic_cast<const xmlpp::Element*>(scripts->find("idle")[0])->get_child_text()->get_content(); if (!scripts->find("timer").empty()) timerScript = dynamic_cast<const xmlpp::Element*>(scripts->find("timer")[0])->get_child_text()->get_content(); if (!scripts->find("init").empty()) initScript = dynamic_cast<const xmlpp::Element*>(scripts->find("init")[0])->get_child_text()->get_content(); } std::vector<xmlpp::Node*> modeNodes = root->find("modes"); for (unsigned int i = 0; i < modeNodes.size(); ++i) { modes.push_back(dynamic_cast<const xmlpp::Element*>(modeNodes[i])->get_child_text()->get_content()); } image = loader.loadFromFile("gfx/entities/" + imgName); }