Exemplo n.º 1
0
bool TiledMap::load()
{
    Tiled::Map *tiledMap;
    Tiled::MapReader reader;

    tiledMap = reader.readMap(m_mapSource);

    if (!tiledMap) {
        qCritical() << "Fail to read map " << m_mapSource;
        return false;
    }

    if (tiledMap->orientation() == Tiled::Map::Isometric) {
        setRenderer(new TiledRenderer(new Tiled::IsometricRenderer(tiledMap), this));
    } else if (tiledMap->orientation() == Tiled::Map::Orthogonal) {
        setRenderer(new TiledRenderer(new Tiled::OrthogonalRenderer(tiledMap), this));
    } else {
        qWarning() << "Map type not supported.";
        return false;
    }

    setTiledMap(tiledMap);

    loadLayers(tiledMap);

    emit loaded();

    return true;
}
Exemplo n.º 2
0
void TMXLoader::loadMap(std::string mapName, std::string filePath)
{
    // String to hold file contents
    std::string fileContents = "";
    
    // Attempt to load file using provided file path
    bool fileLoaded = loadFile(filePath, fileContents);
    
    if (fileLoaded == true)
    {
        // Create new RapidXML document instance to use to parse map data
        rapidxml::xml_document<char> m_currentMap;
        m_currentMap.parse<0>((char*)fileContents.c_str());
        rapidxml::xml_node<> *parentNode = m_currentMap.first_node("map");
        
        // Add new TMXMap to m_mapContainer
        m_mapContainer[mapName] = std::unique_ptr<TMXMap>(new TMXMap());
        
        // Load the map settings, tilesets and layers
        loadMapSettings(m_mapContainer[mapName], parentNode);
        loadTileSets(m_mapContainer[mapName], parentNode);
        loadLayers(m_mapContainer[mapName], parentNode);
        loadObjectLayers(m_mapContainer[mapName], parentNode);

        
        std::cout << "TMXLoader: loaded map '" << mapName << "' from: '" << filePath << "' successfully" << std::endl;
    }
    else
    {
        std::cout << "TMXLoader: map '" << mapName << "' at '" << filePath << "' could not be loaded." << std::endl;
    }
}
Exemplo n.º 3
0
bool CAnm2DXml::loadLayers(QDomNode node, AnmLayer *pParent)
{
	while ( !node.isNull() ) {
		if ( node.nodeName() == kAnmXML_ID_Layer ) {
			QDomNamedNodeMap nodeMap = node.attributes() ;
			if ( nodeMap.namedItem(kAnmXML_Attr_Name).isNull()
			  || nodeMap.namedItem(kAnmXML_Attr_FrameNum).isNull()
			  || nodeMap.namedItem(kAnmXML_Attr_ChildNum).isNull() ) {
				return false ;
			}
			QString name ;
			int frameDataNum = 0 ;
			int childNum = 0 ;

			name = nodeMap.namedItem(kAnmXML_Attr_Name).toAttr().value() ;
			frameDataNum = nodeMap.namedItem(kAnmXML_Attr_FrameNum).toAttr().value().toInt() ;
			childNum = nodeMap.namedItem(kAnmXML_Attr_ChildNum).toAttr().value().toInt() ;

			AnmLayer *pLayer = new AnmLayer ;
			pLayer->pParentLayer = pParent ;
			pParent->childPtrs.append(pLayer) ;

			QDomNode child = node.firstChild() ;
			if ( !loadFrameData(child, pLayer, frameDataNum) ) {
				return false ;
			}
			QDomNode layers = node.firstChild() ;
			if ( !loadLayers(layers, pLayer) ) {
				return false ;
			}
		}
		node = node.nextSibling() ;
	}
	return true ;
}
Exemplo n.º 4
0
void GameScene::loadResources()
{
	// Create the Box2D world
	world = new b2World(b2Vec2(0, -30));

	// Load stuff
	loadLevelData();
	loadLayers();
}
Exemplo n.º 5
0
/**
 * If the load fails, you can get the (translateable) error message using \a error().
 * @return true on success
 */
bool Reader::load(const QString &filename)
{
	QFile orafile(filename);
	if(!orafile.open(QIODevice::ReadOnly)) {
		_error = orafile.errorString();
		return false;
	}

	ZipReader zip(&orafile);

	if(!zip.isReadable()) {
		_error = QApplication::tr("ORA file is unreadable!");
		return false;
	}

	// Make sure this is an OpenRaster file
	{
		QByteArray mimetype(zip.fileData("mimetype"));
		qDebug() << "read mimetype:" << mimetype;
		if(mimetype != "image/openraster") {
			_error = QApplication::tr("File is not an OpenRaster file");
			return false;
		}
	}

	// Read the stack
	QDomDocument doc;
	if(doc.setContent(zip.fileData("stack.xml"), true, &_error) == false)
		return false;

	const QDomElement stackroot = doc.documentElement().firstChildElement("stack");

	// Get the size of the image
	// These attributes are required by ORA standard.
	QSize imagesize(
			doc.documentElement().attribute("w").toInt(),
			doc.documentElement().attribute("h").toInt()
			);

	if(imagesize.isEmpty()) {
		_error = QApplication::tr("Image has zero size!");
		return false;
	}

	// Initialize the layer stack now that we know the size
	_commands.append(MessagePtr(new protocol::CanvasResize(imagesize.width(), imagesize.height())));

	_layerid = 0;
	_annotationid = 0;
	// Load the layer images
	if(loadLayers(zip, stackroot, QPoint()) == false)
		return false;

	return true;
}
Exemplo n.º 6
0
bool CAnm2DXml::loadElement(QDomNode node, const int objNum, const int imageNum)
{
	while ( !node.isNull() ) {
		if ( node.nodeName() == kAnmXML_ID_Object ) {	// オブジェクト
			QString name ;
			int layerNum = 0 ;
			int no = 0 ;
			QDomNamedNodeMap nodeMap = node.attributes() ;
			if ( nodeMap.namedItem(kAnmXML_Attr_Name).isNull()
			  || nodeMap.namedItem(kAnmXML_Attr_LayerNum).isNull()
			  || nodeMap.namedItem(kAnmXML_Attr_No).isNull()
			  || nodeMap.namedItem(kAnmXML_Attr_LoopNum).isNull() ) {
				return false ;
			}
			name = nodeMap.namedItem(kAnmXML_Attr_Name).toAttr().value() ;
			layerNum = nodeMap.namedItem(kAnmXML_Attr_LayerNum).toAttr().value().toInt() ;
			no = nodeMap.namedItem(kAnmXML_Attr_No).toAttr().value().toInt() ;
			int loopNum = nodeMap.namedItem(kAnmXML_Attr_LoopNum).toAttr().value().toInt() ;
			int fps = 60 ;
			if ( !nodeMap.namedItem(kAnmXML_Attr_FpsNum).isNull() ) {
				fps = nodeMap.namedItem(kAnmXML_Attr_FpsNum).toAttr().value().toInt() ;
			}
			AnmObject *pObj = new AnmObject ;
			pObj->nLoop = loopNum ;
			pObj->nFps = fps ;

			QDomNode child = node.firstChild() ;
			if ( !loadLayers(child, pObj) ) { return false ; }
			m_objPtrs.append(pObj) ;
		}
		else if ( node.nodeName() == kAnmXML_ID_Image ) {	// イメージ
			QDomNamedNodeMap nodeMap = node.attributes() ;
			if ( nodeMap.namedItem(kAnmXML_Attr_No).isNull() ) {
				return false ;
			}
			int no = nodeMap.namedItem(kAnmXML_Attr_No).toAttr().value().toInt() ;

			AnmImage data ;
			QDomNode child = node.firstChild() ;
			if ( !loadImage(child, data) ) {
				return false ;
			}
			data.no = no ;
			m_images.append(data) ;
		}
		node = node.nextSibling() ;
	}
	return true ;
}
	void TiledMapLoader::loadInternalMap(Map &map, char *xml) {
		rapidxml::xml_document<> document;
		rapidxml::xml_node<> *rootNode = nullptr;
		document.parse<rapidxml::parse_no_data_nodes>(xml);
		rootNode = document.first_node("map");
		if (!rootNode) {
			throw std::logic_error("Invalid tiled map: no map tag");
		}
		auto &rootNodeRef = *rootNode;
		XMLElement mapElement(*rootNode);
		map.setVersion(mapElement.getString("version"));
		map.setWidth(mapElement.getInt("width"));
		map.setHeight(mapElement.getInt("height"));
		map.setTileWidth(mapElement.getInt("tilewidth"));
		map.setTileHeight(mapElement.getInt("tileheight"));
		map.parseProperties(*rootNode);

		loadTilesets(map, rootNodeRef);
		loadLayers(map, rootNodeRef);
		loadObjectGroups(map, rootNodeRef);
	}
Exemplo n.º 8
0
//--------------------------------------------------------------
void ofApp::setup(){
    loadLayers("chinesechardream1");
    loadShaders();
    getMaxAbsDiff();
//    ofBackground(0);
}
Exemplo n.º 9
0
bool Reader::loadLayers(ZipReader &zip, const QDomElement& stack, QPoint offset)
{
	// TODO are layer coordinates relative to stack coordinates?
	// The spec, as of this writing, is not clear on this.
	offset += QPoint(
			stack.attribute("x", "0").toInt(),
			stack.attribute("y", "0").toInt()
			);

	QDomNodeList nodes = stack.childNodes();
	// Iterate backwards to get the layers in the right order (layers are always added to the top of the stack)
	for(int n=nodes.count()-1;n>=0;--n) {
		QDomElement e = nodes.at(n).toElement();
		if(e.isNull())
			continue;

		if(e.tagName()=="layer") {
			// Check for unknown attributes
			const char *layerattrs[] = {
					"x", "y", "name", "src", "opacity", "visibility", "composite-op", 0
			};
			if(!isKnown(e.attributes(), layerattrs))
				_warnings |= ORA_EXTENDED;

			// Load content image from the file
			const QString src = e.attribute("src");
			QImage content;
			{
				QByteArray image = zip.fileData(src);
				if(image.isNull()) {
					_error = QApplication::tr("Couldn't get layer %1").arg(src);
					return false;
				}
				if(content.loadFromData(image, "png")==false) {
					_error = QApplication::tr("Couldn't load layer %1").arg(src);
					return false;
				}
			}

			// Create layer
			QString name = e.attribute("name", QApplication::tr("Unnamed layer"));
			_commands.append(MessagePtr(new protocol::LayerCreate(
				1,
				++_layerid,
				0,
				name
			)));

			QPoint layerPos = offset + QPoint(
				e.attribute("x", "0").toInt(),
				e.attribute("y", "0").toInt()
				);
			_commands.append(net::putQImage(_layerid, layerPos.x(), layerPos.y(), content, false));

			QString compositeOp = e.attribute("composite-op", "src-over");
			int blendmode = dpcore::blendModeSvg(compositeOp);
			if(blendmode<0) {
				_warnings |= ORA_EXTENDED;
				blendmode = 1;
			}

			_commands.append(MessagePtr(new protocol::LayerAttributes(
				_layerid,
				qRound(255 * e.attribute("opacity", "1.0").toDouble()),
				blendmode
			)));

			// TODO visibility flag
			//layer->setHidden(e.attribute("visibility", "visible") != "visible");
		} else if(e.tagName()=="stack") {
			// Nested stacks are not fully supported
			_warnings |= ORA_NESTED;
			if(loadLayers(zip, e, offset)==false)
				return false;
		} else if(e.namespaceURI()==DP_NAMESPACE && e.localName()=="annotations") {
			loadAnnotations(e);
		} else if(e.namespaceURI()==DP_NAMESPACE) {
			qWarning() << "Unhandled drawpile extension in stack:" << e.tagName();
			_warnings |= ORA_EXTENDED;
		} else if(e.prefix()=="") {
			qWarning() << "Unhandled stack element:" << e.tagName();
			_warnings |= ORA_EXTENDED;
		}
	}
	return true;
}