Example #1
0
Map* Map::CreateFromXml(std::string xmlPath)
{
	XmlReader mapReader;
	mapReader.LoadFile(PathLoader::GetPath(xmlPath));

	// Get the size properties to create a Map instance
	int mapWidth;
	int mapHeight;

	auto sizeElement = mapReader.FindNode("map_size");
	mapWidth = atoi(sizeElement->GetAttribute("width").AttributeValue);
	mapHeight = atoi(sizeElement->GetAttribute("height").AttributeValue);

	Map* ret = new Map(mapWidth, mapHeight);

	// Then read the xml to generate the layout of the map tiles

	auto mapDataElement = mapReader.FindNode("map_data");

	// No map data, create a random layout
	if (mapDataElement == NULL)
	{
        ret->InitializeDefaultMap();
	}
	else
	{
		// Woah, you're asking a lot here.
	}

	return ret;
}
Example #2
0
World* World::CreateWorldFromXml(std::string xmlPath)
{
	XmlReader worldFileReader = XmlReader();
	World* ret = new World();

	worldFileReader.LoadFile(PathLoader::GetPath(xmlPath));

	// Read the <tiles> node
	auto mapNodes = worldFileReader.GetNode("maps")->GetNodes("map");

	auto it = ITBEGIN(mapNodes);
	while (it != ITEND(mapNodes))
	{
		XmlNode* element = *it;

		std::string mapName = element->GetAttribute("name").AttributeValue;
		std::string mapFilepath = element->GetAttribute("source").AttributeValue;

		Map* newMap = Map::CreateFromXml(mapFilepath);

		ret->Maps->Add(newMap);

		it++;
	}

	// Read the <tile_description> node
	auto descriptionNode = worldFileReader.FindNode("tile_description")->GetNodes("tile");
	TileDescriptionList* descList = new TileDescriptionList();
	ret->TileMapping = descList;

	descList->Entries = new PointerList<TileDescriptionEntry*>();

	auto descIt = ITBEGIN(descriptionNode);
	while (descIt != ITEND(descriptionNode))
	{
		XmlNode* element = *descIt;

		TileDescriptionEntry* newEntry = new TileDescriptionEntry();
		newEntry->id = atoi(element->GetAttribute("id").AttributeValue);
		newEntry->TextureName = element->GetAttribute("texture").AttributeValue;

		descList->Entries->Add(newEntry);

		descIt++;
	}

	return ret;
}
Spritesheet::Spritesheet(std::string configFilePath, BaseGraphicEngine* engine)
{
    assert(configFilePath != "");
    assert(engine != NULL);
    
    // Open config file to get the spritesheet image location
    XmlReader configReader = XmlReader();
    configReader.LoadFile(configFilePath);

    XmlNode* node = configReader.FindNode("TextureAtlas");

    std::string path = node->GetAttribute("imagePath").AttributeValue;

    this->spritesheetHeight = std::atoi(node->GetAttribute("height").AttributeValue);
    this->spritesheetWidth = std::atoi(node->GetAttribute("width").AttributeValue);

    this->spritesheetTexture = engine->TextureRepo->LoadFromDisk("assets//" + path); // TODO : Asset root is not prepended in the texture packed config file

    this->Graphics = engine;
    this->SpritesheetFilePath = path;
    this->ConfigFilePath = configFilePath;
}