void CLanguages::LoadStringTable() { //parse language xml and load strings to table //clear old table m_LanguageStringTable.clear(); m_ObjectStringTable.clear(); stringc file = m_Language->value + stringc("_strings.xml"); IXMLReader* xml = m_FS->createXMLReader(file); if (xml) { //get language name and value from file while(xml->read()) { switch(xml->getNodeType()) { case io::EXN_ELEMENT: { if (stringw("string").equals_ignore_case(xml->getNodeName())) { TLanguageString lang; lang.id = xml->getAttributeValueAsInt(L"id"); lang.value = xml->getAttributeValue(L"value"); m_LanguageStringTable.push_back(lang); } } } } xml->drop(); // don't forget to delete the xml reader } file = m_Language->value + stringc("_go_strings.xml"); xml = m_FS->createXMLReader(file); if (xml) { //get language name and value from file while(xml->read()) { switch(xml->getNodeType()) { case io::EXN_ELEMENT: { if (stringw("string").equals_ignore_case(xml->getNodeName())) { TLanguageString lang; lang.id = xml->getAttributeValueAsInt(L"id"); lang.value = xml->getAttributeValue(L"value"); m_ObjectStringTable.push_back(lang); } } } } xml->drop(); // don't forget to delete the xml reader } }
void IXMLWriterTest::writeText() { IWriteFile* fWrite = IFileSystem::createWriteFile( "assets/io/fileXMLEmpty.xml"); IXMLWriter* fxml = IFileSystem::createXMLWriter(fWrite); if (fWrite) fWrite->drop(); fxml->writeElement("fff", false); fxml->writeText("text text text"); fxml->writeClosingTag("fff"); if (fxml) fxml->drop(); IReadFile* fRead = IFileSystem::createReadFile( "assets/io/fileXMLEmpty.xml"); IXMLReader* fxmlR = IFileSystem::createXMLReader(fRead); fxmlR->read(); fxmlR->read(); if (fxmlR->getNodeType() != EXNT_TEXT) mes.append("\n writeText: element text is not created"); core::stringc strND = core::stringc("text text text"); if (!strND.equalsn(fxmlR->getNodeData(), 14)) mes.append( "\n writeText: correctly writes text content of the"); if (fxmlR) fxmlR->drop(); }
void IXMLWriterTest::writeXMLHeader() { IWriteFile* fWrite = IFileSystem::createWriteFile( "assets/io/fileXMLEmpty.xml"); IXMLWriter* fxml = IFileSystem::createXMLWriter(fWrite); if (fWrite) fWrite->drop(); fxml->writeXMLHeader(); if (fxml) fxml->drop(); IReadFile* fRead = IFileSystem::createReadFile( "assets/io/fileXMLEmpty.xml"); IXMLReader* fxmlR = IFileSystem::createXMLReader(fRead); fxmlR->read(); if (fxmlR->getNodeType() != EXNT_UNKNOWN) mes.append( "\n writeXMLHeader: does not write the XMLHeader"); if (fxmlR) fxmlR->drop(); if (fRead) fRead->drop(); }
void IXMLWriterTest::writeClosingTag() { IWriteFile* fWrite = IFileSystem::createWriteFile( "assets/io/fileXMLEmpty.xml"); IXMLWriter* fxml = IFileSystem::createXMLWriter(fWrite); if (fWrite) fWrite->drop(); fxml->writeClosingTag("fff"); if (fxml) fxml->drop(); IReadFile* fRead = IFileSystem::createReadFile( "assets/io/fileXMLEmpty.xml"); IXMLReader* fxmlR = IFileSystem::createXMLReader(fRead); fxmlR->read(); if (fxmlR->getNodeType() != EXNT_ELEMENT_END) mes.append( "\n writeClosingTag: Closing tag is not created"); if (fxmlR) fxmlR->drop(); // TODO create empty closing teg IWriteFile* fWrite1 = IFileSystem::createWriteFile( "assets/io/fileXMLEmpty.xml"); IXMLWriter* fxml1 = IFileSystem::createXMLWriter(fWrite1); if (fWrite1) fWrite1->drop(); fxml1->writeClosingTag(""); if (fxml1) fxml1->drop(); IReadFile* fRead1 = IFileSystem::createReadFile( "assets/io/fileXMLEmpty.xml"); IXMLReader* fxmlR1 = IFileSystem::createXMLReader(fRead1); fxmlR1->read(); if (fxmlR1->getNodeType() != EXNT_ELEMENT_END) mes.append( "\n writeClosingTag: emty closing tag is not created"); if (fxmlR1) fxmlR1->drop(); }
void IXMLWriterTest::writeComment() { IWriteFile* fWrite = IFileSystem::createWriteFile( "assets/io/fileXMLEmpty.xml"); IXMLWriter* fxml = IFileSystem::createXMLWriter(fWrite); if (fWrite) fWrite->drop(); fxml->writeComment(static_cast<const c8*>("bla bla bla")); if (fxml) fxml->drop(); IReadFile* fRead = IFileSystem::createReadFile( "assets/io/fileXMLEmpty.xml"); IXMLReader* fxmlR = IFileSystem::createXMLReader(fRead); fxmlR->read(); if (fxmlR->getNodeType() != EXNT_COMMENT) mes.append("\n writeComment: comment is not created"); if (fxmlR) fxmlR->drop(); //TODO creates an empty comment IWriteFile* fWrite1 = IFileSystem::createWriteFile( "assets/io/fileXMLEmpty.xml"); IXMLWriter* fxml1 = IFileSystem::createXMLWriter(fWrite1); if (fWrite1) fWrite1->drop(); fxml1->writeComment(static_cast<const c8*>("")); if (fxml1) fxml1->drop(); IReadFile* fRead1 = IFileSystem::createReadFile( "assets/io/fileXMLEmpty.xml"); IXMLReader* fxmlR1 = IFileSystem::createXMLReader(fRead1); fxmlR1->read(); if (fxmlR1->getNodeType() != EXNT_COMMENT) mes.append("\n writeComment: empty comment is not created"); if (fxmlR1) fxmlR1->drop(); }
bool CGWIC_Cell::LoadObjectStates() { path filenm = GWIC_CELLSTORE_DIR; filenm += GetCellFileSuffix(); filenm += ".xml"; IXMLReader* xml = graphics->getFileSystem()->createXMLReader(filenm); if (!xml) { std::cerr << "LoadObjectStates(): can't create xml reader for " << filenm.c_str() << std::endl; return false; } const stringw tg_obj(L"object"); const stringw tg_pos(L"position"); const stringw tg_opt(L"options"); stringw cur_tag; path cfile; CIrrStrParser pos,rot,scl; CGWIC_GameObject* optr = NULL; while (xml->read()) { switch (xml->getNodeType()) { case EXN_ELEMENT: if ((cur_tag.empty()) && (tg_obj.equals_ignore_case(xml->getNodeName()))) { cur_tag = tg_obj; cfile = xml->getAttributeValueSafe(L"file"); optr = new CGWIC_GameObject(cfile,GetCoord(),graphics,physics); if (!optr) std::cerr << "Failed to create object from " << cfile.c_str() << std::endl; else objects.push_back(optr); } else if ((cur_tag == tg_obj) && (optr)) { if (tg_pos.equals_ignore_case(xml->getNodeName())) { pos = xml->getAttributeValueSafe(L"pos"); rot = xml->getAttributeValueSafe(L"rot"); scl = xml->getAttributeValueSafe(L"scale"); optr->SetPos(pos.ToVector3f()); optr->SetScale(scl.ToVector3f()); optr->SetRot(rot.ToVector3f()); } else if (tg_pos.equals_ignore_case(xml->getNodeName())) { optr->SetPhysical(xml->getAttributeValueAsInt(L"physical")); optr->SetEnabled(xml->getAttributeValueAsInt(L"enabled")); } } break; case EXN_ELEMENT_END: cur_tag = L""; optr = NULL; break; default: break; } } xml->drop(); return false; }
int CSLevel::loadPrefab(stringc filename) { CS_LOG(CSLOGTYPE::CSL_DEBUG, "Loading prefab %s", filename.c_str()); int id = 0; stringc dir(getApplication()->getDirectory("PrefabDirectory")); dir += filename; IXMLReader* reader = getDevice()->getFileSystem()->createXMLReader(filename); if (!reader) { CS_LOG(CSLOGTYPE::CSL_WARNING, "Warning! unable to open prefab file %s", filename.c_str()); return -1; } // read file while (reader->read()) { switch (reader->getNodeType()) { case io::EXN_ELEMENT: stringw name = reader->getNodeName(); if (stringw("CSOBJECT") == name) { stringw type = reader->getAttributeValueSafe(L"TYPE"); CSObject* obj = getObjectFactory()->createObjectByType(stringc(type)); if (obj) { id = obj->getId(); IAttributes* attr = getDevice()->getFileSystem()->createEmptyAttributes(getDriver()); attr->read(reader, false); obj->deserializeAttributes(attr); obj->setId(id); obj->reCreate(); attr->drop(); } } } } reader->drop(); return id; }
/** * \brief Init loads list of available languages and sets default language from preferences. * \author Petar Bajic * \date January, 21 2012. */ bool CLanguages::Init() { u32 index = 0; IFileList* fileList = m_FS->createFileList(); u32 count = fileList->getFileCount(); for (u32 i=0; i<count; i++) { stringc file = fileList->getFileName(i); IXMLReader* xml = m_FS->createXMLReader(file); if (xml) { //get language name and value from file while(xml->read()) { switch(xml->getNodeType()) { case io::EXN_ELEMENT: { if (stringw("Language").equals_ignore_case(xml->getNodeName())) { TLanguage* lang = new TLanguage(); lang->name = xml->getAttributeValue(L"name"); lang->value = xml->getAttributeValue(L"value"); lang->index = index; m_ListOfAvailableLanguages.push_back(lang); index++; } } } } xml->drop(); // don't forget to delete the xml reader } } return true; }
int CSObject::loadFromPreFab(stringc filename) { int id = 0; stringc dir(getLevel()->getApplication()->getDirectory("PrefabDirectory")); dir += filename; CS_LOG(CSLOGTYPE::CSL_DEBUG, "Loading from prefab directory %s", dir.c_str()); IXMLReader* reader = getDevice()->getFileSystem()->createXMLReader(dir); CS_CHECK_BOOL(reader, CSLOGTYPE::CSL_DEBUG, "Warning! unable to open prefab file"); // read file while (reader->read()) { switch (reader->getNodeType()) { case io::EXN_ELEMENT: { stringw name = reader->getNodeName(); if (stringw("CSOBJECT") == name) { stringw type = reader->getAttributeValueSafe(L"TYPE"); IAttributes* attr = getDevice()->getFileSystem()->createEmptyAttributes(getDriver()); attr->read(reader, false); deserializeAttributes(attr); setId(getLevel()->getObjectFactory()->getObjectManager()->getUniqueId()); attr->drop(); } } } } reader->drop(); return id; }
// load the level objects from disk file bool CSLevel::loadFromDisk(stringc filename, bool destroyOld) { CS_LOG(CSLOGTYPE::CSL_DEBUG, "*************************** Loading level from file %s ***************************", filename.c_str()); if (destroyOld) clear(); // attempt to open the file IXMLReader* reader = getDevice()->getFileSystem()->createXMLReader(filename); if (!reader) { CS_LOG(CSLOGTYPE::CSL_WARNING, "Warning! unable to open file %s", filename.c_str()); return false; } // read file while (reader->read()) { // based on the node type switch (reader->getNodeType()) { case io::EXN_ELEMENT: { // get the node name stringw name = reader->getNodeName(); // if this is an object definition if (stringw("CAMERA") == name) { stringw pos = reader->getAttributeValueSafe(L"POSITION"); stringw tar = reader->getAttributeValueSafe(L"TARGET"); if (getCamera()) { getCamera()->setPosition(stringcToVector3df(stringc(pos))); getCamera()->setTarget(stringcToVector3df(stringc(tar))); } else CS_LOG(CSLOGTYPE::CSL_WARNING, "no camera in game save file"); } // if this is an object definition if (stringw("CSOBJECT") == name) { // get the object type stringw type = reader->getAttributeValueSafe(L"TYPE"); // attempt to create the object CSObject* obj = getObjectFactory()->createObjectByType(stringc(type)); if (obj) { // load the attributes from the file IAttributes* attr = getDevice()->getFileSystem()->createEmptyAttributes(getDriver()); attr->read(reader, false); // let the object deserialize from the attributes obj->deserializeAttributes(attr); // recreate the object using the new attribtues obj->reCreate(); // drop the pointer attr->drop(); } } } } } // drop the reader reader->drop(); CS_LOG(CSLOGTYPE::CSL_DEBUG, "*************************** finished Loading level from file %s ***************************", filename.c_str()); // everything went fine return true; }
void IXMLWriterTest::writeElement() { IWriteFile* fWrite = IFileSystem::createWriteFile( "assets/io/fileXMLEmpty.xml"); IXMLWriter* fxml = IFileSystem::createXMLWriter(fWrite); if (fWrite) fWrite->drop(); fxml->writeElement("fff", true, "attr1", "attrValue1"); if (fxml) fxml->drop(); IReadFile* fRead = IFileSystem::createReadFile( "assets/io/fileXMLEmpty.xml"); IXMLReader* fxmlR = IFileSystem::createXMLReader(fRead); fxmlR->read(); if (fxmlR->getNodeType() != EXNT_ELEMENT) mes.append( "\n writeElement: incorrectly indicates the type of node"); if (fxmlR->getAttributeCount() != 1) mes.append( "\n writeElement: correctly returns the number of attributes"); core::stringc strA = core::stringc("attr1"); if (!strA.equalsn(fxmlR->getAttributeName(0), 4)) mes.append( "\n writeElement: correctly returns the name of attributes"); core::stringc strV = core::stringc("attrValue1"); if (!strV.equalsn(fxmlR->getAttributeValue(0), 10)) mes.append( "\n writeElement: correctly returns the value of attributes"); if (fxmlR) fxmlR->drop(); if (fRead) fRead->drop(); //TODO should not create an element with no name IWriteFile* fWrite1 = IFileSystem::createWriteFile( "assets/io/fileXMLEmpty.xml"); IXMLWriter* fxml1 = IFileSystem::createXMLWriter(fWrite1); if (fWrite1) fWrite1->drop(); fxml1->writeElement("", true); if (fxml1) fxml1->drop(); IReadFile* fRead1 = IFileSystem::createReadFile( "assets/io/fileXMLEmpty.xml"); IXMLReader* fxmlR1 = IFileSystem::createXMLReader(fRead1); fxmlR1->read(); core::stringc strN = core::stringc(""); if (strN.equalsn(fxmlR1->getNodeName(), 1)) mes.append("\n writeElement: node name can not be empty"); if (fxmlR1->getAttributeCount() != 0) mes.append("\n writeElement: sees non-existent attributes"); if (fxmlR1) fxmlR1->drop(); if (fRead1) fRead1->drop(); core::array<core::stringc> atr; atr.insert(core::stringc("atr1")); atr.insert(core::stringc("atr2")); atr.insert(core::stringc("7")); atr.insert(core::stringc(0)); atr.insert(core::stringc("art5")); atr.insert(core::stringc("</>")); atr.insert(core::stringc("art7")); core::array<core::stringc> atrValue; atrValue.insert(core::stringc("atrValue1")); atrValue.insert(core::stringc("atrValue2")); atrValue.insert(core::stringc("atrValue3")); atrValue.insert(core::stringc("atrValue4")); atrValue.insert(core::stringc("atrValue5")); atrValue.insert(core::stringc("6")); atrValue.insert(core::stringc("")); IWriteFile* fWrite3 = IFileSystem::createWriteFile( "assets/io/fileXMLEmpty.xml"); IXMLWriter* fxml3 = IFileSystem::createXMLWriter(fWrite3); if (fWrite3) fWrite3->drop(); fxml3->writeElement("fff", true, atr, atrValue); if (fxml3) fxml3->drop(); IReadFile* fRead3 = IFileSystem::createReadFile( "assets/io/fileXMLEmpty.xml"); IXMLReader* fxmlR3 = IFileSystem::createXMLReader(fRead3); fxmlR3->read(); if (fxmlR3->getAttributeCount() != 7) mes.append( "\n writeElement: correctly returns the number of attributes"); //TODO attribute name can not be a 0 if (fxmlR3->getAttributeName(3) == 0) mes.append( "\n writeElement: attribute name can not be a 0"); //TODO attribute value can not be empty core::stringc strAV = core::stringc(""); if (strAV.equalsn(fxmlR3->getAttributeValue(6), 1)) mes.append( "\n writeElement: attribute value can not be empty"); if (fxmlR3) { fxmlR3->drop(); } }