bool TMXMapImporter::loadWorld(Game *game, wstring initDir, wstring mapLevelFileName)
{
	dir = initDir;
	mapLevelFilePath = dir + mapLevelFileName;
	bool success = loadMapInfo();
	if (!success) return false;
	success = buildWorldFromInfo(game);
	if (!success) return false;
	return true;
}
Beispiel #2
0
	bool Map::loadMap(const std::string &filename)
	{
	    std::string file = resourceManager->getDataPath(filename);
        logger->logDebug("Loading map " + file);

        TiXmlDocument doc(file.c_str());
        bool loaded = doc.LoadFile();
        if (!loaded)
        {
            logger->logError("Error loading map");
            return false;
        }

        TiXmlHandle hDoc(&doc);
        TiXmlElement *e;
        TiXmlHandle map = hDoc.FirstChild("map");

        if (!loadMapInfo(map.ToElement()))
        {
            return false;
        }

        int numTilesets = 0;

        while(1)
        {
            e = map.Child("tileset", numTilesets).ToElement();

            if (!loadTileset(e))
            {
                break;
            }
            ++numTilesets;
        }

        if (numTilesets == 0)
        {
            logger->logError("No tilesets found.");
            return false;
        }

        int numLayers = 0;
        while(1)
        {
            e = map.Child("layer", numLayers).ToElement();

            if (!loadLayer(e))
            {
                break;
            }
            ++numLayers;
        }
        if (numLayers == 0)
        {
            logger->logError("No layers found!");
            return false;
        }

        logger->logDebug("Finished loading map");

        mLoaded = true;

        return true;
    }