Ejemplo n.º 1
0
void Bundle::loadFromDisk() {
	std::ifstream file;
	GetBundleFileHandleForReading(this->bundleName, file);

	if (file.good()) {
		XmlParser* parser = new XmlParser();
		parser->ParseXmlFile(file);

		XmlTree* tree = parser->GetXmlTree();
		VERIFY(tree != nullptr, "Got xml tree for bundle data in bundle %s", this->bundleName.c_str());

		XmlNode* rootNode = tree->GetRootNode();
		VERIFY(rootNode != nullptr, "Got root node for bundle data in bundle %s", this->bundleName.c_str());
		VERIFY(rootNode->GetName() == BUNDLE_TAG, "Got bundle node for bundle data in bundle %s", this->bundleName.c_str());

		XmlNode* dataNode = rootNode->GetFirstChildByNodeName(DATA_TAG);
		while(dataNode != nullptr) {
			std::string key   = dataNode->GetAttributeValueS(KEY_ATTRIBUTE);
			std::string value = dataNode->GetAttributeValueS(VALUE_ATTRIBUTE);
			this->PutString(key, value);
			//
			dataNode = dataNode->GetNextSiblingByNodeName(DATA_TAG);
		}

		delete parser;
	}
}
Ejemplo n.º 2
0
void LevelLoader::LoadTutorialLevelNames(std::vector<std::string>* levelsWithTutorials) {
	FRAMEWORK->GetLogger()->dbglog("\nLoading tutorials from file: %s", tutorialXmlPath);

	XmlParser* parser = new XmlParser();
	parser->ParseXmlFile(FRAMEWORK->GetFileSystemUtils()->GetDeviceBaseResourcesPath() + tutorialXmlPath);

	XmlTree* xmlTree = parser->GetXmlTree();
	ASSERT(xmlTree != nullptr, "Got valid xmlTree from parser for level file %s", tutorialXmlPath);
	
	XmlNode* rootTutorialsNode = xmlTree->GetRootNode();
	ASSERT(rootTutorialsNode != nullptr, "Got valid tutoral node from xml tree for tutorial file %s", tutorialXmlPath);

	for(XmlNode* tutorialNode : rootTutorialsNode->GetChildren()) {
		FRAMEWORK->GetLogger()->dbglog("\n Loaded tutorial data for level: %s", tutorialNode->GetAttributeValueS(NAME_ATTRIBUTE).c_str());
		levelsWithTutorials->push_back(tutorialNode->GetAttributeValueS(NAME_ATTRIBUTE));
	}
	delete parser;

}
Ejemplo n.º 3
0
void LevelLoader::LoadLevelFromFile(std::string levelFilename) {
	FRAMEWORK->GetLogger()->dbglog("\nLoading level from level file: %s", levelFilename.c_str());

	XmlParser* parser = new XmlParser();
	parser->ParseXmlFile(FRAMEWORK->GetFileSystemUtils()->GetDeviceBaseResourcesPath() + "levels/" + levelFilename);

#ifdef DEBUG
	parser->Print();
#endif // DEBUG

	XmlTree* xmlTree = parser->GetXmlTree();
	ASSERT(xmlTree != nullptr, "Got valid xmlTree from parser for level file %s", levelFilename.c_str());
	XmlNode* levelNode = xmlTree->GetRootNode();
	ASSERT(levelNode != nullptr && levelNode->GetName() == LEVEL_TAG, "Got valid level node from xml tree for level file %s", levelFilename.c_str());
	
	std::string bgm = levelNode->GetAttributeValueS(BGM_ATTRIBUTE);
	if (bgm != "") {
		AudioSource* bgmSource = SINGLETONS->GetMenuManager()->GetBGMSource();
		bgmSource->LoadAudioClip(LEVEL_BGM, "audio/" + bgm);
	}

	XmlNode* gridNode = levelNode->GetFirstChildByNodeName(GRID_TAG);
	VERIFY(gridNode != nullptr, "Level definition contains <%s> node", GRID_TAG);
	SINGLETONS->GetGridManager()->loadGridDataFromXml(gridNode);

	// Create the shady camera before we load any objects because their AudioSource components will need it
	createCamera();

	XmlNode* staticNode = levelNode->GetFirstChildByNodeName(STATIC_TAG);
	// The level doesn't need to have a STATIC_TAG node
	if (staticNode != nullptr) {
		loadStaticDataFromXml(staticNode);
	}

	XmlNode* otherDataNode = levelNode->GetFirstChildByNodeName(OTHER_TAG);
	// The level doesn't need to have an OTHER_TAG node
	if (otherDataNode != nullptr) {
		loadOtherDataFromXml(otherDataNode);
	}

	XmlNode* unitBaseNode = levelNode->GetFirstChildByNodeName(UNITS_TAG);
	VERIFY(unitBaseNode != nullptr, "Level definition contains <%s> node", UNITS_TAG);
	loadUnitDataFromXml(unitBaseNode);

	XmlNode* linkBaseNode = levelNode->GetFirstChildByNodeName(LINKS_TAG);
	VERIFY(linkBaseNode != nullptr, "Level definition contains <%s> node", LINKS_TAG);
	if (linkBaseNode != nullptr) {
		loadLinkDataFromXml(linkBaseNode);
		loadParentConnectionsFromXml(linkBaseNode);
		loadEndConditionsFromXml(linkBaseNode);
	}

	XmlNode* cameraNode = levelNode->GetFirstChildByNodeName(CAMERA_TAG);
	VERIFY(cameraNode != nullptr, "Level definition contains <%s> node", CAMERA_TAG);
	loadCameraDataFromXml(cameraNode);

	delete parser;

	SINGLETONS->GetMenuManager()->PlayBGM(LEVEL_BGM);

	idsFromXml.clear();
	
	LevelLoader::adjustLighting();

	LevelLoader::postLoadLevel();
}
Ejemplo n.º 4
0
void LevelLoader::LoadLevelData(std::vector<ContractData*>* contractData) {
	// Load the tutorials
	std::vector<std::string> levelsWithTutorials;
	LevelLoader::LoadTutorialLevelNames(&levelsWithTutorials);

	FRAMEWORK->GetLogger()->dbglog("\nLoading levelData from file: %s", levelListXmlPath);

	XmlParser* parser = new XmlParser();
	parser->ParseXmlFile(FRAMEWORK->GetFileSystemUtils()->GetDeviceBaseResourcesPath() + levelListXmlPath);

	XmlTree* xmlTree = parser->GetXmlTree();
	ASSERT(xmlTree != nullptr, "Got valid xmlTree from parser for level file %s", levelListXmlPath);
	
	XmlNode* rootLevelListNode = xmlTree->GetRootNode();
	ASSERT(rootLevelListNode != nullptr, "Got valid tutoral node from xml tree for tutorial file %s", levelListXmlPath);

	// Get the saved data
	VERIFY(FRAMEWORK->GetSavedDataManager()->HasBundle(PLAYER_BUNDLE_NAME), "The game has saved data");
	Bundle* bundle = FRAMEWORK->GetSavedDataManager()->GetSavedBundle(PLAYER_BUNDLE_NAME);
	ASSERT(bundle->HasKey(LEVEL_COMPLETION), "The saved data has level completion");
	std::string levelCompletionData = bundle->GetString(LEVEL_COMPLETION);

	int missionNum = 0;
	int levelNum = 0;
	for(XmlNode* contractNode : rootLevelListNode->GetChildren()) {
		ContractData* cData = new ContractData();
		cData->name = StringUtilities::ReplaceCharInString(contractNode->GetAttributeValueS("title"), '_', ' ');
		for(XmlNode* missionNode : contractNode->GetChildren()) {
			FRAMEWORK->GetLogger()->dbglog("\n Loaded mission data for game");
			MissionData* mData = new MissionData();
			mData->name = StringUtilities::ReplaceCharInString(missionNode->GetAttributeValueS("title"), '_', ' ');
			for(XmlNode* levelDataNode : missionNode->GetChildren()) {
				LevelData* lData = new LevelData();
				lData->name = levelDataNode->GetAttributeValueS(NAME_PROPERTY);
				lData->name = StringUtilities::ReplaceCharInString(lData->name, '_', ' ');
				lData->path = levelDataNode->GetAttributeValueS(PATH_PROPERTY);
				lData->type = LevelLoader::stringToLevelType(levelDataNode->GetAttributeValueS(TYPE_PROPERTY));
				lData->bounty = StringUtilities::ConvertStringToInt(levelDataNode->GetAttributeValueS("bounty"));
				lData->description = StringUtilities::StringToUpper(levelDataNode->GetAttributeValueS(TYPE_PROPERTY));
				lData->completion = LevelLoader::charToCompletionData(levelCompletionData[levelNum]);
				lData->hasTutorial = std::find(levelsWithTutorials.begin(), levelsWithTutorials.end(), lData->path) != levelsWithTutorials.end();
				lData->levelNum = levelNum;
				lData->bonus = LevelBonus::None;
				for(XmlNode* child : levelDataNode->GetChildren()) {
					if(child->GetName() == "missionScreen") {
						lData->pinX = child->GetAttributeValueF("x");
						lData->pinY = child->GetAttributeValueF("y");
						lData->parallaxScreen = child->GetAttributeValueF("parallaxScreen");
					} else if(child->GetName() == "bonus") {
						lData->bonus = StringToLevelBonus(child->GetAttributeValueS("type"));
						lData->bonusValue = child->GetAttributeValueI("value");
					}
				}
				mData->levels.push_back(lData);
				levelNum++;
			}
			cData->missions.push_back(mData);
			missionNum++;
		}
		contractData->push_back(cData);
	}
	delete parser;
}