int Module_SOW_Car::load(const XMLReader& xmldata) { /* //See comment below if (ModuleG2D::load(xmldata) != 0) { //Some error happened return -1; }*/ //xmldata.getXMLGroupHandle("")->dump(); //Load from xml xmldata.for_all("object", [=](const XMLGroup* g) { XMLReader r(*g); SFG::Pointer<SOW_Car> c(new SOW_Car(this)); int loadableret = c.cast<Loadable>()->Loadable::load(r); int gobjret = c.cast<GObjectBase>()->GObjectBase::load(XMLReader(*r.getXMLGroupHandle("GObjectBase/"))); int carret = c->load(XMLReader(*r.getXMLGroupHandle("Car"))); SFG::Util::printLog(SFG::Util::Information, __FILE__, __LINE__, "Loading car module has return values %d - %d -%d", loadableret, gobjret, carret); this->addObject(c); }); return 0; }
int SOW_Car::load(const XMLReader& data) { data.for_all("blinker", [=](const XMLGroup* g){ XMLReader(*g).for_all("Light",[=](const XMLGroup* g2){ //Add lights and stuff }); }); return 0; }
int SSG_Planet::load(const XMLReader& reader) { //SFG::Util::printLog(SFG::Util::Development, __FILE__, __LINE__, "Still to do"); //Load values accordingly this->m_name = reader.getValue("name."); bool real = false; this->setMass(PE::Mass(reader.asDouble("mass/", real))); if(!real) { //Failed to load mass SFG::Util::printLog(SFG::Util::Error, __FILE__, __LINE__, "Failed to load Mass"); } sf::FloatRect r = reader.asFloatRect("PosAndVel/", real); if(!real) { //Failed to load pos and Velocity SFG::Util::printLog(SFG::Util::Error, __FILE__, __LINE__, "Failed to load PosAndVel"); } //this->setPosition(r.left, r.top); this->setPosition(mpf_class(r.left), mpf_class(r.top)); this->setVelocity(PE::Velocity(r.width, r.height)); auto radius = reader.asDouble("radius/", real); if(!real) { SFG::Util::printLog(SFG::Util::Error, __FILE__, __LINE__, "Failed to get radius for planet %s", this->m_name.toAnsiString().c_str()); } this->getShape().setRadius(radius); SFG::FloatRect rect(this->getShape().getLocalBounds()); this->getShape().setOrigin(rect.center()); m_planet_surface.reset(new SSG_PlanetSurface(radius)); m_planet_surface->load(); //Get Moons reader.for_all("Moon", [=](const XMLGroup* g){ SFG::Pointer<SSG_Planet> ptr(new SSG_Planet()); ptr->m_parentSys = this->m_parentSys; ptr->setGuiDesktop(this->desktop()); int ret = ptr->load(XMLReader(*g)); if(ret != 0) { SFG::Util::printLog(SFG::Util::Error, __FILE__, __LINE__, "Failed to load moon"); return; } printf("Position: %f + %f | %f + %f\n", getShape().getPosition().x , ptr->getShape().getPosition().x, getShape().getPosition().y, ptr->getShape().getPosition().y); //Correct relative values //ptr->setPosition(getShape().getPosition().x + ptr->getShape().getPosition().x, // getShape().getPosition().y + ptr->getShape().getPosition().y); ptr->setPosition(x() + ptr->x(), y() + ptr->y()); ptr->setVelocity(getVelocity() + ptr->getVelocity()); //Add to system this->m_parentSys->addSpecificToSystem(ptr); SFG::Util::printLog(SFG::Util::Information, __FILE__, __LINE__, "Moon \"%s\" has been added", ptr->getName().toAnsiString().c_str()); }); //TESTING this->getShape().setFillColor(sf::Color(255, 255, 255)); //!TESTING return 0; }