Exemplo n.º 1
0
int main(int argc, char *argv[])
{
    // Avoid performance issues with X11 engine when rendering objects
#ifdef Q_WS_X11
    QApplication::setGraphicsSystem(QLatin1String("raster"));
#endif
    QString help="The arguement to open it: [map.tmx]";

    QApplication a(argc, argv);

    a.setOrganizationDomain(QLatin1String("catchchallenger"));
    a.setApplicationName(QLatin1String("map2png"));
    a.setApplicationVersion(QLatin1String("1.0"));

    CommandLineOptions options;
    parseCommandLineArguments(options);

    if (options.fileToOpen.isEmpty())
    {
        qDebug() << help;
        return 0;
    }

    Map2Png w;
    w.viewMap(options.fileToOpen);

    return a.exec();
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
    // Avoid performance issues with X11 engine when rendering objects
#ifdef Q_WS_X11
    QApplication::setGraphicsSystem(QStringLiteral("raster"));
#endif

    QApplication a(argc, argv);

    a.setOrganizationDomain(QStringLiteral("catchchallenger"));
    a.setApplicationName(QStringLiteral("map2png"));
    a.setApplicationVersion(QStringLiteral("1.0"));

    QStringList arguments=QCoreApplication::arguments();
    bool renderAll=false;
    if(arguments.size()==1)
        renderAll=true;
    QString renderAllString=QStringLiteral("--renderAll");
    if(arguments.contains(renderAllString))
    {
        arguments.removeAll(renderAllString);
        renderAll=true;
    }
    QString fileToOpen,destination;
    QFileInfo dir;
    if(arguments.size()>1)
        dir=QFileInfo(arguments.last());
    if(arguments.size()>1 && dir.isDir())
    {
        QString baseDatapack;
        {
            QString previousFolder;
            bool found=true;
            QFileInfo dirDatapack(QFileInfo(dir.absoluteFilePath()+Map2Png::text_slash).absolutePath());
            while(!QFileInfo(dirDatapack.absoluteFilePath()+QStringLiteral("/informations.xml")).exists())
            {
                previousFolder=dirDatapack.absoluteFilePath();
                dirDatapack=QFileInfo(dirDatapack.absolutePath());
                if(previousFolder==dirDatapack.absoluteFilePath())
                {
                    found=false;
                    break;
                }
            }
            if(found)
                baseDatapack=dirDatapack.absoluteFilePath();
        }
        QTime time;
        time.restart();
        QStringList files=Map2Png::listFolder(dir.absoluteFilePath()+Map2Png::text_slash);
        int index=0;
        while(index<files.size())
        {
            if(files.at(index).endsWith(Map2Png::text_dottmx))
            {
                fileToOpen=files.at(index);
                destination=files.at(index);
                destination.replace(Map2Png::text_dottmx,Map2Png::text_dotpng);
                Map2Png w;
                if(!baseDatapack.isEmpty())
                    w.baseDatapack=baseDatapack;
                w.viewMap(false,dir.absoluteFilePath()+Map2Png::text_slash+fileToOpen,destination);
            }
            index++;
        }
        qDebug() << QString("Done into: %1s").arg(time.elapsed()/1000);
        return 0;
    }
    else
    {
        {
            int index=0;
            while(index<arguments.size())
            {
                if(arguments.at(index).endsWith(Map2Png::text_dottmx))
                {
                    fileToOpen=arguments.at(index);
                    break;
                }
                index++;
            }
            {
                int index=0;
                while(index<arguments.size())
                {
                    if(arguments.at(index).endsWith(Map2Png::text_dotpng))
                    {
                        destination=arguments.at(index);
                        break;
                    }
                    index++;
                }
            }
        }
        Map2Png w;
        if (fileToOpen.isEmpty())
        {
            QString source = QFileDialog::getOpenFileName(NULL,QStringLiteral("Select map"));
            if(source.isEmpty() || source.isNull())
                return 0;
            fileToOpen=source;
        }
        if(destination.isEmpty())
        {
            destination = QFileDialog::getSaveFileName(NULL,QStringLiteral("Save the render"),QString(),QStringLiteral("Png Images (*.png)"));
            if(destination.isEmpty())
            {
            }
            else
            {
                if(!destination.endsWith(Map2Png::text_dotpng))
                    destination+=Map2Png::text_dotpng;
            }
        }
        {
            QString previousFolder;
            bool found=true;
            QFileInfo dir(QFileInfo(fileToOpen).absolutePath());
            while(!QFileInfo(dir.absoluteFilePath()+QStringLiteral("/informations.xml")).exists())
            {
                previousFolder=dir.absoluteFilePath();
                dir=QFileInfo(dir.absolutePath());
                if(previousFolder==dir.absoluteFilePath())
                {
                    found=false;
                    break;
                }
            }
            if(found)
                w.baseDatapack=dir.absoluteFilePath();
        }

        if(arguments.size()==1)
        {
            w.viewMap(renderAll,fileToOpen,destination);
            w.show();
            w.setWindowIcon(QIcon(QStringLiteral(":/icon.png")));
            return a.exec();
        }
        else
        {
            w.viewMap(renderAll,fileToOpen,destination);
            return 0;
        }
    }
}