예제 #1
0
	void ConfigValues::Load(const std::string &filename)
	{
		TiXmlDocument doc;
		doc.LoadFile(Assets::GetContentPath() + filename);
		TiXmlElement *xmlValues = doc.FirstChildElement("config"); 
		if (xmlValues)
		{
			TiXmlElement *xmlValue = xmlValues->FirstChildElement("value");
			while (xmlValue)
			{
				std::string name = XMLReadString(xmlValue, "name");

				if (xmlValue->Attribute("float"))
					instance->floats[name] = XMLReadFloat(xmlValue, "float");

				if (xmlValue->Attribute("string"))
					instance->strings[name] = XMLReadString(xmlValue, "string");

				if (xmlValue->Attribute("int"))
					instance->ints[name] = XMLReadInt(xmlValue, "int");

				if (xmlValue->Attribute("bool"))
					instance->bools[name] = XMLReadBool(xmlValue, "bool");

				if (xmlValue->Attribute("vector2"))
					instance->vector2s[name] = XMLReadVector2(xmlValue, "vector2");

				xmlValue = xmlValue->NextSiblingElement("value");
			}
		}
	}
예제 #2
0
	void TestScene::LoadTextureSheet(const std::string &filename)
	{
		// load the xml file
		TiXmlDocument xml(filename);
		bool isLoaded = xml.LoadFile();

		if (isLoaded)
		{
			TiXmlElement* eTextures = xml.FirstChildElement("Textures");
			if (eTextures)
			{
				TiXmlElement* eTextureSheet = eTextures->FirstChildElement("TextureSheet");
				while (eTextureSheet)
				{
					textureSheet.name = XMLReadString(eTextureSheet, "name");

					TiXmlElement* eTexture = eTextureSheet->FirstChildElement("Texture");
					while (eTexture)
					{
						Texture texture;
						texture.name = eTexture->Attribute("name");
						texture.width = XMLReadInt(eTexture, "width");
						texture.height = XMLReadInt(eTexture, "height");
						texture.registrationPoint.x = XMLReadFloat(eTexture, "registrationPointX");
						texture.registrationPoint.y = XMLReadFloat(eTexture, "registrationPointY");

						textureSheet.textures.push_back(texture);

						eTexture = eTexture->NextSiblingElement("Texture");
					}

					eTextureSheet = eTextureSheet->NextSiblingElement("TextureSheet");
				}
			}
		}
		else
		{
			Debug::Log("Error: could not load textureSheet from: " + filename + " - " + xml.ErrorDesc());
		}
	}
예제 #3
0
	void Level::LoadProject(const std::string &filename)
	{
		Debug::Log("Loading Level...");
		// load the project data from an xml file
		instance->tilesets.clear();

		TiXmlDocument xml(Assets::GetContentPath() + filename);
		bool isLoaded = xml.LoadFile();
		if (isLoaded)
		{
			TiXmlElement* eProject = xml.FirstChildElement("Project");
			if (eProject)
			{
				// Load Tileset data (for tiles on a grid)
				TiXmlElement* eTilesets = eProject->FirstChildElement("Tilesets");
				if (eTilesets)
				{
					TiXmlElement* eTileset = eTilesets->FirstChildElement("Tileset");
					while (eTileset)
					{
						instance->tilesets.push_back(Tileset(XMLReadString(eTileset, "name"), XMLReadString(eTileset, "image"), XMLReadInt(eTileset, "tileWidth"), XMLReadInt(eTileset, "tileHeight")));

						eTileset = eTilesets->NextSiblingElement("Tileset");
					}
				}

				// Load FringeTileset data (for abitrarily sized 'n placed tiles)
				TiXmlElement* eFringeTilesets = eProject->FirstChildElement("FringeTilesets");
				if (eFringeTilesets)
				{
					TiXmlElement* eFringeTileset = eFringeTilesets->FirstChildElement("FringeTileset");
					while (eFringeTileset)
					{
						FringeTileset fringeTileset = FringeTileset(XMLReadString(eFringeTileset, "name"));
						
						TiXmlElement* eFringeTile = eFringeTileset->FirstChildElement("FringeTile");
						while (eFringeTile)
						{
							if (eFringeTile->Attribute("id") && eFringeTile->Attribute("image"))
							{
								int tileID = XMLReadInt(eFringeTile, "id");
								std::string image = XMLReadString(eFringeTile, "image");
								int width = -1;
								int height = -1;
								if (eFringeTile->Attribute("width") && eFringeTile->Attribute("height"))
								{
									width = XMLReadInt(eFringeTile, "width");
									height = XMLReadInt(eFringeTile, "height");
								}

								FilterType filter = FILTER_LINEAR;

								bool repeatX = XMLReadBool(eFringeTile, "repeatX");
								bool repeatY = XMLReadBool(eFringeTile, "repeatY");

								if (image != "")
								{
									fringeTileset.SetFringeTileData(tileID, new FringeTileData(image, width, height, filter, repeatX, repeatY));
								}
							}
							eFringeTile = eFringeTile->NextSiblingElement("FringeTile");
						}
						
						instance->fringeTilesets.push_back(fringeTileset);

						eFringeTileset = eFringeTileset->NextSiblingElement("FringeTileset");
					}
				}
			}
		}
		Debug::Log("...done");
	}
예제 #4
0
	void TestScene::LoadAnimation(const std::string &filename)
	{
		// load the xml file
		TiXmlDocument xml(filename);
		bool isLoaded = xml.LoadFile();

		if (isLoaded)
		{
			TiXmlElement* eAnimations = xml.FirstChildElement("Animations");
			if (eAnimations)
			{
				TiXmlElement* eAnimation = eAnimations->FirstChildElement("Animation");
				while (eAnimation)
				{
					Animation animation(XMLReadString(eAnimation, "name"), XMLReadInt(eAnimation, "frameCount"));
					
					TiXmlElement* ePart = eAnimation->FirstChildElement("Part");
					while (ePart)
					{
						Part part(ePart->Attribute("name"));
						
						TiXmlElement* eFrame = ePart->FirstChildElement("Frame");
						while (eFrame)
						{
							Frame frame;
							frame.pos = Vector2(XMLReadFloat(eFrame, "x"), XMLReadFloat(eFrame, "y"));
							
							if (eFrame->Attribute("scaleX"))
							{
								frame.scale.x = XMLReadFloat(eFrame, "scaleX");
							}

							if (eFrame->Attribute("scaleY"))
							{
								frame.scale.y = XMLReadFloat(eFrame, "scaleY");
							}

							if (eFrame->Attribute("alpha") != NULL)
							{
								frame.alpha = atof(eFrame->Attribute("alpha"));
							}

							part.frames.push_back(frame);

							eFrame = eFrame->NextSiblingElement("Frame");
						}
						
						animation.parts.push_back(part);

						ePart = ePart->NextSiblingElement("Part");
					}

					animations.push_back(animation);

					eAnimation = eAnimation->NextSiblingElement("Animation");
				}
			}
		}
		else
		{
			Debug::Log("Error: could not load animations from: " + filename + " - " + xml.ErrorDesc());
		}
	}
예제 #5
0
	void Level::Load(const std::string &filename, Scene* scene)
	{
		// load from an xml file, into the scene

		if (scene != NULL)
		{
			instance->scene = scene;
		}

		if (instance->scene)
		{
			// unload tilemaps... (need to destroy them?)
			instance->tilemaps.clear();
			//clearfringeTileset

			TiXmlDocument xml(Assets::GetContentPath() + filename);
			instance->filename = filename;
			bool isLoaded = xml.LoadFile();

			if (isLoaded)
			{
				TiXmlElement* eLevel = xml.FirstChildElement("Level");
				if (eLevel)
				{
					instance->width = XMLReadInt(eLevel, "width");
					instance->height = XMLReadInt(eLevel, "height");

					TiXmlElement *eTilemap = eLevel->FirstChildElement("Tilemap");
					while (eTilemap)
					{
						Entity *entity = new Entity();
						Tilemap *tilemap = new Tilemap(instance->GetTilesetByName(XMLReadString(eTilemap, "set")), instance->width, instance->height, XMLReadInt(eTilemap, "tileWidth"), XMLReadInt(eTilemap, "tileHeight"));
						instance->tilemaps.push_back(tilemap);
						entity->SetGraphic(tilemap);
						instance->scene->Add(entity);

						TiXmlElement *eTile = eTilemap->FirstChildElement("Tile");
						while (eTile)
						{
							tilemap->SetTile(XMLReadInt(eTile, "x"), XMLReadInt(eTile, "y"), XMLReadInt(eTile, "tileID"));
							eTile = eTile->NextSiblingElement("Tile");
						}
						eTilemap = eTilemap->NextSiblingElement("Tilemap");
					}

					TiXmlElement *eFringeTiles = eLevel->FirstChildElement("FringeTiles");
					while (eFringeTiles)
					{
						FringeTileset *fringeTileset = instance->GetFringeTilesetByName(XMLReadString(eFringeTiles, "set"));

						/*
						Entity *entity = new Entity();
						Tilemap *tilemap = new Tilemap(instance->GetTileset(XMLString(eTilemap, "set")), instance->width, instance->height, XMLInt(eTilemap, "tileWidth"), XMLInt(eTilemap, "tileHeight"));
						instance->tilemaps.push_back(tilemap);
						entity->SetGraphic(tilemap);
						instance->scene->Add(entity);
						*/

						if (fringeTileset)
						{
							TiXmlElement *eFringeTile = eFringeTiles->FirstChildElement("FringeTile");
							while (eFringeTile)
							{
								int tileID = XMLReadInt(eFringeTile, "id");

								int layer = XMLReadInt(eFringeTile, "layer");

								Vector2 position = Vector2(XMLReadFloat(eFringeTile, "x"), XMLReadFloat(eFringeTile, "y"));

								Vector2 scale = Vector2::one;

								if (eFringeTile->Attribute("scaleX") != NULL && eFringeTile->Attribute("scaleY") != NULL)
									scale = Vector2(XMLReadFloat(eFringeTile, "scaleX"), XMLReadFloat(eFringeTile, "scaleY"));

								int rotation = XMLReadFloat(eFringeTile, "rotation");

								Color color = Color::white;
								if (eFringeTile->Attribute("ca"))
								{
									color.a = XMLReadFloat(eFringeTile, "ca");
								}

								AddFringeTile(fringeTileset, tileID, layer, position, scale, rotation, color);

								eFringeTile = eFringeTile->NextSiblingElement("FringeTile");
							}
						}

						eFringeTiles = eFringeTiles->NextSiblingElement("FringeTiles");
					}
				}
			}
					
		}
	}