/// Save account information to a file void GameEconomicGameClient::SaveConfiguration(Configuration &configuration) { /// Get Resource ResourceCache * cache = GetSubsystem<ResourceCache>(); FileSystem * fileSystem = GetSubsystem<FileSystem>(); String configFileName; /// Set directory and path for network file configFileName.Append(fileSystem->GetProgramDir().CString()); configFileName.Append(""); configFileName.Append("Configuration.xml"); /// Check if the account file information exist if(fileSystem->FileExists(configFileName.CString())) { fileSystem->Delete(configFileName.CString()); } cout << "It got here "<<endl; File saveFile(context_, configFileName.CString(), FILE_WRITE); XMLFile * preferencefileconfig = new XMLFile(context_); XMLElement configElem = preferencefileconfig -> CreateRoot("Configuration"); XMLElement GameModeConfigurationElement = configElem.CreateChild("GameModeConfiguration"); XMLElement VideoConfigurationElement= configElem.CreateChild("VideoConfiguration"); /// Set true false if(configuration.GameModeForceTablet==true) { GameModeConfigurationElement.SetAttribute("GameModeForceTablet", "true"); } else { GameModeConfigurationElement.SetAttribute("GameModeForceTablet", "false"); } /// Convert video bloom to float String VideoBloomParamValue1String(configuration.VideoBloomParam1); String VideoBloomParamValue2String(configuration.VideoBloomParam2); /// Copy values testing VideoConfigurationElement.SetAttribute("BloomParam1",VideoBloomParamValue1String); VideoConfigurationElement.SetAttribute("BloomParam2",VideoBloomParamValue2String); preferencefileconfig->Save(saveFile); return; }
bool XMLFile::BeginLoad(Deserializer& source) { unsigned dataSize = source.GetSize(); if (!dataSize && !source.GetName().Empty()) { URHO3D_LOGERROR("Zero sized XML data in " + source.GetName()); return false; } SharedArrayPtr<char> buffer(new char[dataSize]); if (source.Read(buffer.Get(), dataSize) != dataSize) return false; if (!document_->load_buffer(buffer.Get(), dataSize)) { URHO3D_LOGERROR("Could not parse XML data from " + source.GetName()); document_->reset(); return false; } XMLElement rootElem = GetRoot(); String inherit = rootElem.GetAttribute("inherit"); if (!inherit.Empty()) { // The existence of this attribute indicates this is an RFC 5261 patch file ResourceCache* cache = GetSubsystem<ResourceCache>(); // If being async loaded, GetResource() is not safe, so use GetTempResource() instead XMLFile* inheritedXMLFile = GetAsyncLoadState() == ASYNC_DONE ? cache->GetResource<XMLFile>(inherit) : cache->GetTempResource<XMLFile>(inherit); if (!inheritedXMLFile) { URHO3D_LOGERRORF("Could not find inherited XML file: %s", inherit.CString()); return false; } // Patch this XMLFile and leave the original inherited XMLFile as it is UniquePtr<pugi::xml_document> patchDocument(document_.Detach()); document_ = new pugi::xml_document(); document_->reset(*inheritedXMLFile->document_); Patch(rootElem); // Store resource dependencies so we know when to reload/repatch when the inherited resource changes cache->StoreResourceDependency(this, inherit); // Approximate patched data size dataSize += inheritedXMLFile->GetMemoryUse(); } // Note: this probably does not reflect internal data structure size accurately SetMemoryUse(dataSize); return true; }
void RogueSkill4::Start() { skillSprite_ = (Sprite*)(main_->mySceneNode_->GetComponent<HUD>()-> hud_->GetChild("skill4", false)->GetChild(0)->GetChild(0)); SubscribeToEvent(E_HUDBUTT, HANDLER(RogueSkill4, HandleHudButt)); SetUpdateEventMask(USE_UPDATE); XMLFile* xmlFile = main_->cache_->GetResource<XMLFile>("Objects/terriesDagger1.xml"); arrow_ = node_->GetScene()->InstantiateXML(xmlFile->GetRoot(), Vector3::ZERO, Quaternion::IDENTITY, LOCAL); arrow_->SetEnabled(false); }
void WizardSkill0::Start() { skillSprite_ = (Sprite*)(main_->mySceneNode_->GetComponent<HUD>()-> hud_->GetChild("skill0", false)->GetChild(0)->GetChild(0)); SubscribeToEvent(E_HUDBUTT, HANDLER(WizardSkill0, HandleHudButt)); SetUpdateEventMask(USE_UPDATE); XMLFile* xmlFile = main_->cache_->GetResource<XMLFile>("Objects/terriesMeteor.xml"); meteor_ = node_->GetScene()->InstantiateXML(xmlFile->GetRoot(), Vector3::ZERO, Quaternion::IDENTITY, LOCAL); meteor_->SetEnabled(false); SubscribeToEvent(E_NODEREMOVED, HANDLER(WizardSkill0, HandleNodeRemoved)); }
void WizardSkill4::Start() { skillSprite_ = (Sprite*)(main_->mySceneNode_->GetComponent<HUD>()-> hud_->GetChild("skill4", false)->GetChild(0)->GetChild(0)); SubscribeToEvent(E_HUDBUTT, HANDLER(WizardSkill4, HandleHudButt)); SetUpdateEventMask(USE_UPDATE); XMLFile* xmlFile = main_->cache_->GetResource<XMLFile>("Objects/terriesOrb.xml"); orb_ = node_->GetScene()->InstantiateXML(xmlFile->GetRoot(), Vector3::ZERO, Quaternion::IDENTITY, LOCAL); orb_->SetPosition(node_->GetScene()->GetChild("tent")->GetPosition() + (Vector3::UP * 2.0f)); SubscribeToEvent(orb_, E_NODECOLLISIONSTART, HANDLER(WizardSkill4, HandleNodeCollisionStart)); //orb_->SetEnabled(false); }
//------------------------------------------------------------------------------------------------------------------------------------------------------ void BaseApplication::InitTouchInput() { touchEnabled_ = true; ResourceCache* cache = GetSubsystem<ResourceCache>(); Input* input = GetSubsystem<Input>(); XMLFile* layout = cache->GetResource<XMLFile>("UI/ScreenJoystick_Samples.xml"); const String& patchString = GetScreenJoystickPatchString(); if (!patchString.Empty()) { // Patch the screen joystick layout further on demand SharedPtr<XMLFile> patchFile(new XMLFile(context_)); if (patchFile->FromString(patchString)) layout->Patch(patchFile); } screenJoystickIndex_ = input->AddScreenJoystick(layout, cache->GetResource<XMLFile>("UI/DefaultStyle.xml")); input->SetScreenJoystickVisible(screenJoystickSettingsIndex_, true); }
bool assemblegffexolocstr(XMLFile &xml, GFFFile &gff, uint32 n) { int pr, lang=0; std::string lbl; ExoLocString exo; uint64 tmp; while((pr = xml.parse()) >= 0) { switch(pr) { case 0: if(rsubstr(xml.section, 6) == ".label") lbl = xml.value; if(rsubstr(xml.section, 7) == ".strref") { sscanf(xml.value.c_str(), S_UINT64, &tmp); exo.stringref = (uint32) tmp; } if(rsubstr(xml.section, 16) == ".substr.language") { if((lang = getpos(langs, LANGS, xml.value)) == -1) return printxmlerr(xml, "Invalid language"); } if(rsubstr(xml.section, 7) == ".substr") exo.str[lang] = unquotestr(xml.value); break; case 1: if(rsubstr(xml.section, 7) != ".substr") return printxmlerr(xml, "Invalid tag"); break; case 2: if(rsubstr(xml.value, 10) == ".exolocstr") { if(gff.writeExoLocString(n, lbl, exo)) return printxmlerr(xml, gff.getStrError()); return true; } break; } } if(pr != -6) return printxmlerr(xml, xml.getStrError()); printxmlerr(xml, "Unexpected end of file"); return false; }
void GameMenu::QueryMasterServer() { if (!masterServerConnected_) { XMLFile* xmlFile = main_->cache_->GetResource<XMLFile>("Objects/serverInfo.xml"); Node* serverInfo = main_->scene_->InstantiateXML(xmlFile->GetRoot(), Vector3::ZERO, Quaternion(), LOCAL); masterServerIP_ = serverInfo->GetVar("masterServerIP").GetString(); main_->scene_->RemoveChild(serverInfo); if (masterServerIP_ == "127.0.0.1") { return; } masterServerConnected_ = network_->Connect(masterServerIP_, 9001, 0); } }
void Sound::LoadParameters() { ResourceCache* cache = GetSubsystem<ResourceCache>(); String xmlName = ReplaceExtension(GetName(), ".xml"); if (!cache->Exists(xmlName)) return; XMLFile* file = cache->GetResource<XMLFile>(xmlName); if (!file) return; XMLElement rootElem = file->GetRoot(); XMLElement paramElem = rootElem.GetChild(); while (paramElem) { String name = paramElem.GetName(); if (name == "format" && !compressed_) { if (paramElem.HasAttribute("frequency")) frequency_ = paramElem.GetInt("frequency"); if (paramElem.HasAttribute("sixteenbit")) sixteenBit_ = paramElem.GetBool("sixteenbit"); if (paramElem.HasAttribute("16bit")) sixteenBit_ = paramElem.GetBool("16bit"); if (paramElem.HasAttribute("stereo")) stereo_ = paramElem.GetBool("stereo"); } if (name == "loop") { if (paramElem.HasAttribute("enable")) SetLooped(paramElem.GetBool("enable")); if (paramElem.HasAttribute("start") && paramElem.HasAttribute("end")) SetLoop(paramElem.GetInt("start"), paramElem.GetInt("end")); } paramElem = paramElem.GetNext(); } }
bool assembleerfdesc(XMLFile &xml, ERFFile &erf) { int pr, lang=0; ExoLocString exo; uint64 tmp; while((pr = xml.parse()) >= 0) { switch(pr) { case 0: if(rsubstr(xml.section, 7) == ".strref") { sscanf(xml.value.c_str(), S_UINT64, &tmp); exo.stringref = (uint32) tmp; } if(rsubstr(xml.section, 16) == ".substr.language") { if((lang = getpos(langs, LANGS, xml.value)) == -1) return printxmlerr(xml, "Invalid language"); } if(rsubstr(xml.section, 7) == ".substr") exo.str[lang] = unquotestr(xml.value); break; case 1: if(rsubstr(xml.section, 7) != ".substr") return printxmlerr(xml, "Invalid tag"); break; case 2: if(rsubstr(xml.value, 12) == ".description") { erf.desc = exo; return true; } break; } } if(pr != -6) return printxmlerr(xml, xml.getStrError()); printxmlerr(xml, "Unexpected end of file"); return false; }
void SceneView3D::HandleUpdate(StringHash eventType, VariantMap& eventData) { // Timestep parameter is same no matter what event is being listened to float timeStep = eventData[Update::P_TIMESTEP].GetFloat(); if (MouseInView()) MoveCamera(timeStep); QueueUpdate(); if (preloadResourceScene_.NotNull()) { if (preloadResourceScene_->GetAsyncProgress() == 1.0f) { ResourceCache* cache = GetSubsystem<ResourceCache>(); XMLFile* xml = cache->GetResource<XMLFile>(dragAssetGUID_); if (dragNode_.NotNull()) { dragNode_->LoadXML(xml->GetRoot()); UpdateDragNode(0, 0); AnimationController* controller = dragNode_->GetComponent<AnimationController>(); if (controller) { controller->PlayExclusive("Idle", 0, true); dragNode_->GetScene()->SetUpdateEnabled(true); } } preloadResourceScene_ = 0; dragAssetGUID_ = ""; } } }
void Costume::save(string dirPath) { Log::write(LOG_INFO, "Costume\n"); Log::indent(); if (!IO::createDirectory(dirPath)) Log::write(LOG_ERROR, "Could not create directory \"%s\" !\n", dirPath.c_str()); XMLFile xmlFile; XMLNode *rootNode = new XMLNode("costume"); xmlFile.setRootNode(rootNode); rootNode->addChild(new XMLNode("name", _name)); Log::write(LOG_INFO, "name: %s\n", _name.c_str()); rootNode->addChild(new XMLNode("mirror", _mirror)); Log::write(LOG_INFO, "mirror: %d\n", _mirror); for (int i = 0; i < _anims.size(); i++) { XMLNode *child = new XMLNode("anim"); rootNode->addChild(child); _anims[i]->save(child); } for (int i = 0; i < _frames.size(); i++) { XMLNode *child = new XMLNode("frame"); rootNode->addChild(child); _frames[i]->save(child, dirPath); } _paletteData->save(dirPath); if (!xmlFile.save(dirPath + XML_FILE_NAME)) Log::write(LOG_ERROR, "Couldn't save costume to the specified directory !\n"); Log::unIndent(); }
void Costume::load(string dirPath) { Log::write(LOG_INFO, "Costume\n"); Log::indent(); XMLFile xmlFile; xmlFile.open(dirPath + XML_FILE_NAME); XMLNode *rootNode = xmlFile.getRootNode(); _name = rootNode->getChild("name")->getStringContent(); Log::write(LOG_INFO, "name: %s\n", _name.c_str()); _mirror = rootNode->getChild("mirror")->getBooleanContent(); Log::write(LOG_INFO, "mirror: %d\n", _mirror); int i = 0; XMLNode *child; while ((child = rootNode->getChild("anim", i++)) != NULL) { Anim *anim = new Anim(); anim->load(child); _anims.push_back(anim); } i = 0; while ((child = rootNode->getChild("frame", i++)) != NULL) { Frame *frame = new Frame(); frame->load(child, dirPath); _frames.push_back(frame); } _paletteData = new PaletteData(); _paletteData->load(dirPath); Log::unIndent(); }
void ResourceManager::loadBodyParts(const std::string &filename) { XMLFile file; int size; char *data = loadFile(filename, size); if (data && file.parse(data)) { // set size file.setElement("size"); mBodyWidth = file.readInt("size", "width"); mBodyHeight = file.readInt("size", "height"); // set defaults file.setElement("default"); mDefaultBody = file.readInt("default", "body"); mDefaultFemale = file.readInt("default", "female"); mDefaultHair = file.readInt("default", "hair"); mDefaultChest = file.readInt("default", "chest"); mDefaultLegs = file.readInt("default", "legs"); mDefaultFeet = file.readInt("default", "feet"); // add all the body parts file.setElement("body"); do { file.setSubElement("image"); int id = file.readInt("body", "id"); std::string icon = file.readString("body", "icon"); int part = file.readInt("body", "part"); std::string colour = file.readString("body", "colour"); Texture *iconTex = NULL; if (icon != "") { if (getDataPath(icon).find(".zip") == std::string::npos) { iconTex = graphicsEngine->loadTexture(getDataPath(icon)); } else { int iconBufSize = 0; char *buffer = loadFile(icon, iconBufSize); iconTex = graphicsEngine->loadTexture(icon, buffer, iconBufSize); free(buffer); } if (iconTex == NULL) { logger->logError("Unable to load icon: " + icon); } } BodyPart *body = new BodyPart(id, part, iconTex); do { int dir = -1; // check if img is in a content update std::string img = file.readString("image", "file"); std::string dirstr = file.readString("image", "dir"); if (dirstr == "SE") dir = DIRECTION_SOUTHEAST; else if (dirstr == "SW") dir = DIRECTION_SOUTHWEST; else if (dirstr == "NE") dir = DIRECTION_NORTHEAST; else if (dirstr == "NW") dir = DIRECTION_NORTHWEST; std::string path = getDataPath(img); size_t found = path.find(".zip"); if (found == std::string::npos) { body->addTexture(dir, path); } else { int imgBufSize = 0; char *buffer = loadFile(img, imgBufSize); body->addTexture(dir, img, buffer, imgBufSize); free(buffer); } } while (file.nextSubElement("image")); mBodyParts.push_back(body); file.clear("image"); } while (file.nextElement("body")); } }
void ResourceManager::loadAnimations(const std::string &filename) { XMLFile file; int size; bool loaded = false; char *data = loadFile(filename, size); if (data && file.parse(data)) { // add all the animations file.setElement("animation"); do { file.setSubElement("body"); int id = file.readInt("animation", "id"); std::string name = file.readString("animation", "name"); int frames = file.readInt("animation", "frames"); int width = file.readInt("animation", "width"); int height = file.readInt("animation", "height"); // get list of animations for each body part std::list<BeingAnimation*> animList; do { std::string img = file.readString("body", "file"); int part = file.readInt("body", "part"); std::stringstream texName; texName << part << name; // check if animation is in content update if (getDataPath(img).find(".zip") == std::string::npos) { img = getDataPath(img); loaded = graphicsEngine->loadTextureSet(texName.str(), img, width, height); } else { int imgBufSize = 0; char *buffer = loadFile(img, imgBufSize); loaded = graphicsEngine->loadTextureSet(texName.str(), buffer, imgBufSize, width, height); free(buffer); } // load in all the frames of animation if (loaded) { BeingAnimation *anim = new BeingAnimation(id, part); for (int i = 1; i <= frames; ++i) { std::stringstream str; str << texName.str() << i; anim->addTexture(graphicsEngine->getTexture(str.str())); } animList.push_back(anim); } } while (file.nextSubElement("body")); mAnimations.insert(std::pair<std::string, std::list<BeingAnimation*> >(name, animList)); file.clear("body"); } while (file.nextElement("animation")); } }
Node* TerrySpawner::LoadSprite(String name) { //Vector3 startPos = terrySpawns_->GetChild(Random(0,terrySpawns_->GetNumChildren()))->GetPosition(); Vector3 startPos = spawnPoint_; XMLFile* xmlFile = main_->cache_->GetResource<XMLFile>("Objects/terriesNode.xml"); Node* spriteNode = scene_->InstantiateXML(xmlFile->GetRoot(), startPos, Quaternion::IDENTITY, LOCAL); spriteNode->RemoveChild(spriteNode->GetChild("camera")); spriteNode->SetName(name); spriteNode->AddComponent(new Gravity(context_, main_), 0, LOCAL); spriteNode->AddComponent(new Speed(context_, main_), 0, LOCAL); //spriteNode->AddComponent(new RotateTo(context_, main_), 0, LOCAL); spriteNode->AddComponent(new MoveByTouch(context_, main_), 0, LOCAL); spriteNode->AddComponent(new Health(context_, main_), 0, LOCAL); spriteNode->GetComponent<MoveByTouch>()->UnsubscribeFromEvent(E_HUDBUTT); StaticSprite2D* sprite = spriteNode->CreateComponent<StaticSprite2D>(); sprite->SetCustomMaterial(SharedPtr<Material>(main_->cache_->GetResource<Material>("Materials/" + name + "Mat.xml"))); AnimatedSpriteSheet* animatedSpriteSheet = new AnimatedSpriteSheet(); animatedSpriteSheet->sheet_ = main_->cache_->GetResource<SpriteSheet2D>("Urho2D/" + name + "/" + name + "Sheet.xml"); animatedSpriteSheet->staticSprite_ = sprite; animatedSpriteSheet->playing_ = false; animatedSpriteSheet->spriteID_ = spriteIDCount_; animatedSpriteSheet->noed_ = spriteNode; animatedSpriteSheet->flipX_ = false; sprites_.Push(animatedSpriteSheet); spriteIDCount_++; Vector<String> files; files.Push("attackF.xml"); files.Push("attackM.xml"); files.Push("dieF.xml"); files.Push("dieM.xml"); files.Push("gestureF.xml"); files.Push("gestureM.xml"); files.Push("idleF.xml"); files.Push("idleM.xml"); files.Push("runF.xml"); files.Push("runM.xml"); /*main_->filesystem_->ScanDir(files, main_->filesystem_->GetProgramDir() + "Data/Urho2D/" + name + "/animations/", "*.xml", SCAN_FILES, false);*/ for (int x = 0; x < files.Size(); x++) { XMLElement ani = main_->cache_->GetResource<XMLFile>("Urho2D/" + name + "/animations/" + files[x])->GetRoot(); SpriteSheetAnimation* spriteSheetAni = new SpriteSheetAnimation(); animatedSpriteSheet->animations_.Push(spriteSheetAni); spriteSheetAni->name_ = ani.GetChild("Name").GetAttribute("name"); spriteSheetAni->loop_ = ani.GetChild("Loop").GetBool("loop"); int frameCount = ani.GetChild("FrameCount").GetInt("frameCount"); for (int x = 0; x < frameCount; x++) { SpriteSheetAnimationFrame* frame = new SpriteSheetAnimationFrame(); spriteSheetAni->frames_.Push(frame); String child = "Frame" + String(x); frame->duration_ = ani.GetChild(child).GetFloat("duration"); frame->sprite_ = ani.GetChild(child).GetAttribute("sprite"); } } bool sex = Random(0,2); animatedSpriteSheet->noed_->SetVar("sex",sex); VariantMap vm; vm[AnimateSpriteSheet::P_NODE] = node_; vm[AnimateSpriteSheet::P_SPRITEID] = animatedSpriteSheet->spriteID_; if (sex) { vm[AnimateSpriteSheet::P_ANIMATION] = "idleF"; } else { vm[AnimateSpriteSheet::P_ANIMATION] = "idleM"; } vm[AnimateSpriteSheet::P_FLIPX] = 0; SendEvent(E_ANIMATESPRITESHEET, vm); animatedSpriteSheet->noed_->SetVar("collisionCount",0); animatedSpriteSheet->noed_->SetVar("attack",1); animatedSpriteSheet->noed_->SetVar("attackInterval",1.0f); animatedSpriteSheet->noed_->SetVar("attackElapsedTime",0.0f); animatedSpriteSheet->noed_->SetVar("canAttack",false); animatedSpriteSheet->noed_->SetVar("npcType",1);//0 = hero, 1 = terry return spriteNode; }
bool Animation::Load(Deserializer& source) { PROFILE(LoadAnimation); unsigned memoryUse = sizeof(Animation); // Check ID if (source.ReadFileID() != "UANI") { LOGERROR(source.GetName() + " is not a valid animation file"); return false; } // Read name and length animationName_ = source.ReadString(); animationNameHash_ = animationName_; length_ = source.ReadFloat(); tracks_.Clear(); unsigned tracks = source.ReadUInt(); tracks_.Resize(tracks); memoryUse += tracks * sizeof(AnimationTrack); // Read tracks for (unsigned i = 0; i < tracks; ++i) { AnimationTrack& newTrack = tracks_[i]; newTrack.name_ = source.ReadString(); newTrack.nameHash_ = newTrack.name_; newTrack.channelMask_ = source.ReadUByte(); unsigned keyFrames = source.ReadUInt(); newTrack.keyFrames_.Resize(keyFrames); memoryUse += keyFrames * sizeof(AnimationKeyFrame); // Read keyframes of the track for (unsigned j = 0; j < keyFrames; ++j) { AnimationKeyFrame& newKeyFrame = newTrack.keyFrames_[j]; newKeyFrame.time_ = source.ReadFloat(); if (newTrack.channelMask_ & CHANNEL_POSITION) newKeyFrame.position_ = source.ReadVector3(); if (newTrack.channelMask_ & CHANNEL_ROTATION) newKeyFrame.rotation_ = source.ReadQuaternion(); if (newTrack.channelMask_ & CHANNEL_SCALE) newKeyFrame.scale_ = source.ReadVector3(); } } // Optionally read triggers from an XML file ResourceCache* cache = GetSubsystem<ResourceCache>(); String xmlName = ReplaceExtension(GetName(), ".xml"); if (cache->Exists(xmlName)) { XMLFile* file = cache->GetResource<XMLFile>(xmlName); if (file) { XMLElement rootElem = file->GetRoot(); XMLElement triggerElem = rootElem.GetChild("trigger"); while (triggerElem) { if (triggerElem.HasAttribute("normalizedtime")) AddTrigger(triggerElem.GetFloat("normalizedtime"), true, triggerElem.GetVariant()); else if (triggerElem.HasAttribute("time")) AddTrigger(triggerElem.GetFloat("time"), false, triggerElem.GetVariant()); triggerElem = triggerElem.GetNext("trigger"); } memoryUse += triggers_.Size() * sizeof(AnimationTriggerPoint); } } SetMemoryUse(memoryUse); return true; }
void Object::load(string dirPath) { Log::write(LOG_INFO, "Object\n"); Log::indent(); XMLFile xmlFile; xmlFile.open(dirPath + XML_FILE_NAME); XMLNode *rootNode = xmlFile.getRootNode(); _name = rootNode->getChild("name")->getStringContent(); Log::write(LOG_INFO, "name: %s\n", _name.c_str()); _displayName = rootNode->getChild("displayName")->getStringContent(); Log::write(LOG_INFO, "displayName: %s\n", _displayName.c_str()); _hotspotX = rootNode->getChild("hotspotX")->getIntegerContent(); Log::write(LOG_INFO, "hotspotX: %u\n", _hotspotX); _hotspotY = rootNode->getChild("hotspotY")->getIntegerContent(); Log::write(LOG_INFO, "hotspotY: %u\n", _hotspotY); _x = rootNode->getChild("x")->getIntegerContent(); Log::write(LOG_INFO, "x: %u\n", _x); _y = rootNode->getChild("y")->getIntegerContent(); Log::write(LOG_INFO, "y: %u\n", _y); _width = rootNode->getChild("width")->getIntegerContent(); Log::write(LOG_INFO, "width: %u\n", _width); _height = rootNode->getChild("height")->getIntegerContent(); Log::write(LOG_INFO, "height: %u\n", _height); string actorDir = rootNode->getChild("actorDir")->getStringContent(); if (actorDir == "west") _actorDir = ACTOR_DIR_WEST; else if (actorDir == "east") _actorDir = ACTOR_DIR_EAST; else if (actorDir == "south") _actorDir = ACTOR_DIR_SOUTH; else if (actorDir == "north") _actorDir = ACTOR_DIR_NORTH; else Log::write(LOG_ERROR, "Unable to convert actorDir \"%s\" !\n", actorDir.c_str()); Log::write(LOG_INFO, "actorDir: %s (%u)\n", actorDir.c_str(), _actorDir); int i = 0; XMLNode *child; while ((child = rootNode->getChild("image", i++)) != NULL) { Image *image = new Image(); image->load(dirPath + child->getStringContent() + "/"); _images.push_back(image); } if (!_images.empty()) { _paletteData = new PaletteData(); _paletteData->load(dirPath); } // Change hotspots from absolute to relative positions _hotspotX -= _x; _hotspotY -= _y; Log::unIndent(); }
void Object::save(string dirPath) { Log::write(LOG_INFO, "Object\n"); Log::indent(); if (!IO::createDirectory(dirPath)) Log::write(LOG_ERROR, "Could not create directory \"%s\" !\n", dirPath.c_str()); XMLFile xmlFile; XMLNode *rootNode = new XMLNode("object"); xmlFile.setRootNode(rootNode); rootNode->addChild(new XMLNode("name", _name)); Log::write(LOG_INFO, "name: %s\n", _name.c_str()); rootNode->addChild(new XMLNode("displayName", _displayName)); Log::write(LOG_INFO, "displayName: %s\n", _displayName.c_str()); // Change hotspots from relative to absolute positions when saving them rootNode->addChild(new XMLNode("hotspotX", _hotspotX + _x)); Log::write(LOG_INFO, "hotspotX: %d\n", _hotspotX + _y); rootNode->addChild(new XMLNode("hotspotY", _hotspotY)); Log::write(LOG_INFO, "hotspotY: %d\n", _hotspotY); rootNode->addChild(new XMLNode("x", _x)); Log::write(LOG_INFO, "x: %u\n", _x); rootNode->addChild(new XMLNode("y", _y)); Log::write(LOG_INFO, "y: %u\n", _y); rootNode->addChild(new XMLNode("width", _width)); Log::write(LOG_INFO, "width: %u\n", _width); rootNode->addChild(new XMLNode("height", _height)); Log::write(LOG_INFO, "height: %u\n", _height); string actorDir; switch (_actorDir) { case ACTOR_DIR_WEST: actorDir = "west"; break; case ACTOR_DIR_EAST: actorDir = "east"; break; case ACTOR_DIR_SOUTH: actorDir = "south"; break; case ACTOR_DIR_NORTH: actorDir = "north"; break; } rootNode->addChild(new XMLNode("actorDir", actorDir)); Log::write(LOG_INFO, "actorDir: %s (%u)\n", actorDir.c_str(), _actorDir); for (int i = 0; i < _images.size(); i++) { _images[i]->save(dirPath + _images[i]->getName() + '/'); rootNode->addChild(new XMLNode("image", _images[i]->getName())); } if (!_images.empty()) _paletteData->save(dirPath); if (!xmlFile.save(dirPath + XML_FILE_NAME)) Log::write(LOG_ERROR, "Couldn't save object to the specified directory !\n"); Log::unIndent(); }
/** * handle get value case */ void XMLCALL getvalue(void *userData, const XML_Char *s, int len) { XMLFile *pObj = (XMLFile*)(userData); pObj->GetXMLValue(s, len); }
bool assemblessf(char *fname, uint8 **mem, uint32 *size) { int pr; uint32 stringref=0xFFFFFFFF; uint64 tmp; std::string resref; XMLFile xml; SSFFile ssf; if(xml.open(fname)) { std::cerr << "Error opening file \"" << fname << "\": "; std::cerr << xml.getStrError() << "\n"; return false; } while((pr = xml.parse()) >= 0) { switch(pr) { case 0: if(!mem && (xml.section == ".ssf.filename")) ssf.filename = xml.value; else if(xml.section == ".ssf.filetype") { if((ssf.type = ssf.getFileResTypeByExt(xml.value)) == -1) return printxmlerr(xml, "Unknown filetype"); if(!ssf.typeIsCorrect()) return printxmlerr(xml, "No SSF type"); } else if(xml.section == ".ssf.sound.resref") resref = xml.value; else if(xml.section == ".ssf.sound.stringref") { sscanf(xml.value.c_str(), S_UINT64, &tmp); stringref = (uint32) tmp; } break; case 1: if((xml.section != ".?xml") && (xml.section != ".ssf") && (getpos(validssftags, SSFTAGS, xml.section) == -1)) return printxmlerr(xml, "Invalid tag"); break; case 2: if(xml.value == ".ssf.sound") { if(ssf.add(resref, stringref)) return printxmlerr(xml, ssf.getStrError()); resref.clear(); stringref = 0xFFFFFFFF; } break; } } if(pr != -6) return printxmlerr(xml, xml.getStrError()); xml.close(); if(!mem) { if(ssf.filename.empty()) return printxmlerr(xml, "Missing filename"); else if(ssf.write(ssf.filename)) return printnwnerr(ssf); } else if(ssf.write(mem, size)) return printnwnerr(ssf); return true; }
void GameEconomicGameClient::LoadConfiguration(Configuration &configuration) { /// Grab resources FileSystem * fileSystem = GetSubsystem<FileSystem>(); /// Set all defaults bool success=false; configuration.GameModeForceTablet=false; configuration.VideoBloomParam1=0.9f; configuration.VideoBloomParam2=0.6f; /// Create String String configFileName; /// Set directory and path for network file configFileName.Append(fileSystem->GetProgramDir().CString()); configFileName.Append(""); configFileName.Append("Configuration.xml"); /// If file does not exist exit function with null structure if (!fileSystem->FileExists(configFileName)) { cout << "Configuration file not found.. Using defaults.. " << endl; return; } /// Flag file for loading and load File loadFile(context_, configFileName, FILE_READ); XMLFile * configurationXML = new XMLFile(context_); configurationXML -> Load(loadFile); XMLElement configElem = configurationXML->GetRoot(); /// If no configuration is set or no root if (configElem.IsNull()) { cout << "Configuration file not found.. Using defaults.. " << endl; return; } /// Basic Config XMLElement GameModeConfigurationElem = configElem.GetChild("GameModeConfiguration"); /// If no network server element return false; if (!GameModeConfigurationElem.IsNull()) { if (GameModeConfigurationElem.HasAttribute("GameModeForceTablet")) configuration.GameModeForceTablet = GameModeConfigurationElem.GetBool("GameModeForceTablet"); } /// Basic Config XMLElement VideoConfigurationElem = configElem.GetChild("VideoConfiguration"); /// If no network server element return false; if (!VideoConfigurationElem.IsNull()) { if (VideoConfigurationElem.HasAttribute("BloomParam1")) configuration.VideoBloomParam1= VideoConfigurationElem.GetFloat("BloomParam1"); if (VideoConfigurationElem.HasAttribute("BloomParam2")) configuration.VideoBloomParam2= VideoConfigurationElem.GetFloat("BloomParam2"); } return; }
bool options(int count, char **arg) { int i; bool result = true; if (count == 1) { PrintHelp(); exit(0); } cout.setf(ios_base::fixed); for (i=1; i<count; i++) { string argument = string(arg[i]); string keyword(argument); string value(""); string::size_type n=argument.find("="); if (n != string::npos && n > 0) { keyword = argument.substr(0, n); value = argument.substr(n+1); } if (keyword == "--help") { PrintHelp(); exit(0); } else if (keyword == "--version") { cout << endl << " JSBSim Version: " << FDMExec->GetVersion() << endl << endl; exit (0); } else if (keyword == "--realtime") { realtime = true; } else if (keyword == "--nice") { play_nice = true; } else if (keyword == "--suspend") { suspend = true; } else if (keyword == "--nohighlight") { nohighlight = true; } else if (keyword == "--outputlogfile") { if (n != string::npos) { LogOutputName = value; } else { LogOutputName = "JSBout.csv"; cerr << " Output log file name must be specified with an = sign. Using JSBout.csv as default"; } } else if (keyword == "--logdirectivefile") { if (n != string::npos) { LogDirectiveName.push_back(value); } else { gripe; exit(1); } } else if (keyword == "--root") { if (n != string::npos) { RootDir = value; if (RootDir[RootDir.length()-1] != '/') { RootDir += '/'; } } else { gripe; exit(1); } } else if (keyword == "--aircraft") { if (n != string::npos) { AircraftName = value; } else { gripe; exit(1); } } else if (keyword == "--script") { if (n != string::npos) { ScriptName = value; } else { gripe; exit(1); } } else if (keyword == "--initfile") { if (n != string::npos) { ResetName = value; } else { gripe; exit(1); } } else if (keyword == "--property") { if (n != string::npos) { string propName = value.substr(0,value.find("=")); string propValueString = value.substr(value.find("=")+1); double propValue = atof(propValueString.c_str()); CommandLineProperties.push_back(propName); CommandLinePropertyValues.push_back(propValue); } else { gripe; exit(1); } } else if (keyword == "--end-time") { if (n != string::npos) { try { end_time = atof( value.c_str() ); } catch (...) { cerr << endl << " Invalid end time given!" << endl << endl; result = false; } } else { gripe; exit(1); } } else if (keyword == "--simulation-rate") { if (n != string::npos) { try { simulation_rate = atof( value.c_str() ); override_sim_rate = true; } catch (...) { cerr << endl << " Invalid simulation rate given!" << endl << endl; result = false; } } else { gripe; exit(1); } } else if (keyword == "--catalog") { catalog = true; if (value.size() > 0) AircraftName=value; } else if (keyword.substr(0,2) != "--" && value.empty() ) { // See what kind of files we are specifying on the command line XMLFile xmlFile; if (xmlFile.IsScriptFile(keyword)) ScriptName = keyword; else if (xmlFile.IsLogDirectiveFile(keyword)) LogDirectiveName.push_back(keyword); //else if (xmlFile.IsAircraftFile(keyword)) AircraftName = keyword; //else if (xmlFile.IsInitFile(keyword)) ResetName = keyword; else { cerr << "The argument \"" << keyword << "\" cannot be interpreted as a file name or option." << endl; exit(1); } } else //Unknown keyword so print the help file, the bad keyword and abort { PrintHelp(); cerr << "The argument \"" << keyword << "\" cannot be interpreted as a file name or option." << endl; exit(1); } } // Post-processing for script options. check for incompatible options. if (catalog && !ScriptName.empty()) { cerr << "Cannot specify catalog with script option" << endl << endl; result = false; } if (AircraftName.size() > 0 && ResetName.size() == 0 && !catalog) { cerr << "You must specify an initialization file with the aircraft name." << endl << endl; result = false; } if ((ScriptName.size() > 0 && AircraftName.size() > 0) || (ScriptName.size() > 0 && ResetName.size() > 0)) { cerr << "You cannot specify an aircraft or initialization file with a script." << endl; result = false; } return result; }
/// Load Communication Logs bool GameEconomicGameClient::LoadCommunicationLogs(LogFormatType LogType, Vector<CommunicationLog> * TargetLogs) { /// Grab resources FileSystem * fileSystem = GetSubsystem<FileSystem>(); bool success=false; /// Create String String configFileName; /// Set directory and path for network file configFileName.Append(fileSystem->GetProgramDir().CString()); configFileName.Append("CommunicationLogs/DefaultLogs.xml"); /// If file does not exist exit function with null structure if (!fileSystem->FileExists(configFileName)) { cout << "No file found communication log" << endl; return false; } /// Flag file for loading and load File loadFile(context_, configFileName, FILE_READ); XMLFile * communicationXML = new XMLFile(context_); communicationXML -> Load(loadFile); XMLElement communicationRootElement = communicationXML->GetRoot(); /// If no configuration is set or no root if (communicationRootElement.IsNull()) { return false; } /// Setupload data XMLElement TempLogElement; String FormatText; /// Log log format Personal if(LogType == LogFormat_Personal) { FormatText.Append(String("PersonalLog")); TempLogElement = communicationRootElement.GetChild(FormatText); } else { return false; } /// If no network server element return false; while(!TempLogElement.IsNull()) { /// Create a temporary log CommunicationLog TempLog; if (TempLogElement.HasAttribute("LogCreation")) TempLog.Creation= TempLogElement.GetInt("LogCreation"); if (TempLogElement.HasAttribute("LogTitle")) TempLog.Title = TempLogElement.GetAttribute("LogTitle"); if (TempLogElement.HasAttribute("LogText")) TempLog.Text = TempLogElement.GetAttribute("LogText"); TargetLogs->Push(TempLog); cout << "Adding" << TempLog.Title.CString()<<endl; /// Get next TempLogElement=communicationRootElement.GetNext(FormatText); } return success; }
bool assemblegff(char *fname, uint8 **mem, uint32 *size) { int pr; uint32 n=0; XMLFile xml; GFFFile gff; if(xml.open(fname)) { std::cerr << "Error opening file \"" << fname << "\": "; std::cerr << xml.getStrError() << "\n"; return false; } while((pr = xml.parse()) >= 0) { switch(pr) { // std::cout << pr << ": " << xml.section << " = \"" << xml.value << "\"\n"; case 0: if(!mem && (xml.section == ".gff.filename")) { if(gff.beginWrite(xml.value)) return printxmlerr(xml, gff.getStrError()); } else if(xml.section == ".gff.filetype") { if((gff.type = gff.getFileResTypeByExt(xml.value)) == -1) return printxmlerr(xml, "Unknown filetype"); if(!gff.typeIsCorrect()) return printxmlerr(xml, "No GFF type"); } break; case 1: if(xml.section == ".gff.struct") { if(n) return printxmlerr(xml, "Must have exactly one top level struct"); if(!mem) { if(gff.filename.empty()) return printxmlerr(xml, "Missing filename"); } else { if(gff.beginWrite()) return printxmlerr(xml, gff.getStrError()); } if(gff.writeStruct(n, "", 0)) return printxmlerr(xml, gff.getStrError()); if(!assemblegffstruct(xml, gff, n++, NULL)) return false; } else if((xml.section != ".?xml") && (xml.section != ".gff")) { if(getpos(validgfftags, GFFTAGS, xml.section) == -1) return printxmlerr(xml, "Invalid tag"); else return printxmlerr(xml, "Element outside the top level struct"); } break; } } if(pr != -6) return printxmlerr(xml, xml.getStrError()); xml.close(); if(gff.endwrite(mem, size)) return printxmlerr(xml, gff.getStrError()); return true; }
bool assemblekeybif(char *fname, uint8 **mem, uint32 *size) { int pr; std::string bfname, rfname, resref; std::vector<uint8 *> datas; uint16 drives=0; uint32 asize; uint64 tmp; NWNFileType restype=NWN_FILE_UNDEFINED; bool newbif=true, withCd=false, exploded=false; XMLFile xml; KEYFile key; BIFFile bif; if(xml.open(fname)) { std::cerr << "Error opening file \"" << fname << "\": "; std::cerr << xml.getStrError() << "\n"; return false; } while((pr = xml.parse()) >= 0) { switch(pr) { case 0: if(!mem && (xml.section == ".key.filename")) key.filename = xml.value; else if(xml.section == ".key.filetype") { if((key.type = key.getFileResTypeByExt(xml.value)) == -1) return printxmlerr(xml, "Unknown filetype"); if(!key.typeIsCorrect()) return printxmlerr(xml, "No KEY type"); } else if(xml.section == ".key.buildyear") { sscanf(xml.value.c_str(), S_UINT64, &tmp); key.buildyear = (uint32) (tmp - 1900); } else if(xml.section == ".key.buildday") { sscanf(xml.value.c_str(), S_UINT64, &tmp); key.buildday = (uint32) tmp; } else if(xml.section == ".key.bif.filename") bfname = xml.value; else if(xml.section == ".key.bif.drives") { sscanf(xml.value.c_str(), S_UINT64, &tmp); drives = (uint16) tmp; } else if(xml.section == ".key.bif.variable.resource.resref") resref = xml.value; else if(xml.section == ".key.bif.variable.resource.filename") rfname = xml.value; else if(xml.section == ".key.bif.variable.resource.restype") { if((restype = key.getFileResTypeByExt(xml.value)) == -1) return printxmlerr(xml, "Unknown filetype"); } else if(xml.section == ".key.bif.variable.resource.withCd") { sscanf(xml.value.c_str(), S_UINT64, &tmp); withCd = (bool) tmp; } else if(xml.section == ".key.bif.variable.resource.exploded") { sscanf(xml.value.c_str(), S_UINT64, &tmp); exploded = (bool) tmp; } break; case 1: if(xml.section == ".bif.fixed") return printxmlerr(xml, "Fixed resources aren't supported"); else if((xml.section != ".?xml") && (xml.section != ".key") && (getpos(validkeybiftags, KEYBIFTAGS, xml.section) == -1)) return printxmlerr(xml, "Invalid tag"); break; case 2: if(xml.value == ".key.bif") { bfname = bif.filename; if(bif.endwrite()) return printxmlerr(xml, bif.getStrError()); if(bif.open(bfname)) return printxmlerr(xml, bif.getStrError()); key.fsizes[key.bifcount-1] = bif.getFileSize(); bif.deInit(); newbif = true; bfname.clear(); drives = 0; } else if(xml.value == ".key.bif.variable.resource") { if(newbif) { if(bfname.empty()) return printxmlerr(xml, "Missing filename"); if(key.addBif(bfname, drives, 0)) return printxmlerr(xml, key.getStrError()); if(bif.beginWrite(getbasename((char*)bfname.c_str()))) return printxmlerr(xml, bif.getStrError()); bif.type = NWN_FILE_BIF; newbif = false; } if(resref.empty()) return printxmlerr(xml, "Missing resref"); if(rfname.empty()) return printxmlerr(xml, "Missing filename"); if(restype == NWN_FILE_UNDEFINED) return printxmlerr(xml, "Missing restype"); if(exploded) { datas.resize((tmp=datas.size())+1); if(!(datas[tmp] = expd(xml, bif.getBaseType(restype), rfname, asize))) return false; if(bif.writeData(restype, withCd, true, datas[tmp], asize, false)) return printxmlerr(xml, bif.getStrError()); } else if(bif.writeData(restype, withCd, true, rfname)) return printxmlerr(xml, bif.getStrError()); if(key.addResource(key.bifcount-1, resref, restype, bif.vrescount-1)) return printxmlerr(xml, key.getStrError()); resref.clear(); rfname.clear(); restype = NWN_FILE_UNDEFINED; withCd = exploded = false; } break; } } if(pr != -6) return printxmlerr(xml, xml.getStrError()); xml.close(); if(!mem) { if(key.filename.empty()) return printxmlerr(xml, "Missing filename"); else if(key.write(key.filename)) return printnwnerr(key); } else if(key.write(mem, size)) return printnwnerr(key); for(uint32 i=0;i<datas.size();i++) free(datas[i]); return true; }
bool assembletlk(char *fname, uint8 **mem, uint32 *size) { int pr; uint32 flags=0; uint64 tmp; float32 sndlength=0; std::string sndresref, str; XMLFile xml; TLKFile tlk; if(xml.open(fname)) { std::cerr << "Error opening file \"" << fname << "\": "; std::cerr << xml.getStrError() << "\n"; return false; } while((pr = xml.parse()) >= 0) { switch(pr) { case 0: if(!mem && (xml.section == ".tlk.filename")) tlk.filename = xml.value; else if(xml.section == ".tlk.filetype") { if((tlk.type = tlk.getFileResTypeByExt(xml.value)) == -1) return printxmlerr(xml, "Unknown filetype"); if(!tlk.typeIsCorrect()) return printxmlerr(xml, "No TLK type"); } else if(xml.section == ".tlk.language") { if((tlk.language = (NWNLang) getpos(langs, LANGS, xml.value)) == -1) return printxmlerr(xml, "Invalid language"); } else if(xml.section == ".tlk.std::string.sndresref") sndresref = xml.value; else if(xml.section == ".tlk.std::string.flags") { sscanf(xml.value.c_str(), S_UINT64, &tmp); flags = (uint32) tmp; } else if(xml.section == ".tlk.std::string.sndlength") sscanf(xml.value.c_str(), S_FLOAT32, &sndlength); else if(xml.section == ".tlk.std::string") str = xml.value; break; case 1: if((xml.section != ".?xml") && (xml.section != ".tlk") && (getpos(validtlktags, TLKTAGS, xml.section) == -1)) return printxmlerr(xml, "Invalid tag"); break; case 2: if(xml.value == ".tlk.std::string") { if(tlk.add(flags, sndresref, sndlength, unquotestr(str))) return printxmlerr(xml, tlk.getStrError()); sndlength = flags = 0; str.clear(); sndresref.clear(); } break; } } if(pr != -6) return printxmlerr(xml, xml.getStrError()); xml.close(); if(!mem) { if(tlk.filename.empty()) return printxmlerr(xml, "Missing filename"); else if(tlk.write(tlk.filename)) return printnwnerr(tlk); } else if(tlk.write(mem, size)) return printnwnerr(tlk); return true; }
/** * handle element start case */ void XMLCALL startElement(void *userData, const char *name, const char **atts) { XMLFile *pObj = (XMLFile*)(userData); pObj->StartXMLElement(name, atts); }
void apply_options(AG_Event *event) { int opengl = *static_cast<int*>(AG_PTR(1)); int fs = *static_cast<int*>(AG_PTR(2)); int lang = *static_cast<int*>(AG_PTR(3)); std::stringstream str; str << "Fullscreen: " << fs; logger->logDebug(str.str()); if (lang == -1) return; switch (lang) { case 0: game->setLanguage("en"); break; case 1: game->setLanguage("pt"); break; case 2: game->setLanguage("es"); break; } interfaceManager->removeAllWindows(); game->restart(opengl, fs, width, height); XMLFile file; if (file.load(resourceManager->getDataPath("townslife.cfg"))) { file.setElement("graphics"); file.changeInt("graphics", "opengl", opengl); if (fs) file.changeString("graphics", "fullscreen", "true"); else file.changeString("graphics", "fullscreen", "false"); file.changeInt("graphics", "width", width); file.changeInt("graphics", "height", height); file.setElement("language"); file.changeString("language", "value", game->getLanguage()); file.save(); } GameState *state = new LoginState; game->changeState(state); }
/** * handle element end case */ void XMLCALL endElement(void *userData, const char *name) { XMLFile *pObj = (XMLFile*)(userData); pObj->EndXMLElement(name); }