Exemple #1
0
/*!
 * \brief Loads signe BGO configuration
 * \param sbgo Target BGO structure
 * \param section Name of INI-section where look for a BGO
 * \param merge_with Source of already loaded BGO structure to provide default settings per every BGO
 * \param iniFile INI-file where look for a BGO
 * \param setup loaded INI-file descriptor to load from global nested INI-file
 * \return true on success loading, false if error has occouped
 */
bool dataconfigs::loadLevelBGO(obj_bgo &sbgo, QString section, obj_bgo *merge_with, QString iniFile, QSettings *setup)
{
    bool valid=true;
    bool internal=!setup;
    QString errStr;
    if(internal)
    {
        setup=new QSettings(iniFile, QSettings::IniFormat);
        setup->setIniCodec("UTF-8");
    }

    if(!openSection(setup, section))
        return false;

    if(sbgo.setup.parse(setup, bgoPath, defaultGrid.bgo, merge_with ? &merge_with->setup : nullptr, &errStr))
    {
        sbgo.isValid = true;
    }
    else
    {
        addError(errStr);
        sbgo.isValid = false;
    }

    closeSection(setup);
    if(internal)
        delete setup;
    return valid;
}
/*!
 * \brief Loads signe BGO configuration
 * \param sbgo Target BGO structure
 * \param section Name of INI-section where look for a BGO
 * \param merge_with Source of already loaded BGO structure to provide default settings per every BGO
 * \param iniFile INI-file where look for a BGO
 * \param setup loaded INI-file descriptor to load from global nested INI-file
 * \return true on success loading, false if error has occouped
 */
bool dataconfigs::loadLevelBGO(obj_bgo &sbgo, QString section, obj_bgo *merge_with, QString iniFile, IniProcessing *setup)
{
    bool valid = true;
    bool internal = !setup;
    QString errStr;
    if(internal)
        setup = new IniProcessing(iniFile);

    m_errOut = merge_with ? ERR_CUSTOM : ERR_GLOBAL;

    if(!openSection(setup, section.toStdString(), internal))
        return false;

    if(sbgo.setup.parse(setup, folderLvlBgo.graphics, defaultGrid.bgo, merge_with ? &merge_with->setup : nullptr, &errStr))
        sbgo.isValid = true;
    else
    {
        addError(errStr);
        sbgo.isValid = false;
    }

    closeSection(setup);
    if(internal)
        delete setup;
    return valid;
}
void MultipleFilePrinter::print(config::StateConfigPtr state_ptr) {
  openSection('[');
  state_ptr->accept(ModelConfigSerializer(
        Self::make(false, root_dir_, os_, depth_, ": ", ",\n")));
  closeSection(']');
}
Exemple #4
0
void dataconfigs::loadLevelBGO()
{
    unsigned long i;

    obj_bgo sbgo;
    unsigned long bgo_total=0;
    bool useDirectory=false;

    QString bgo_ini = getFullIniPath("lvl_bgo.ini");
    if(bgo_ini.isEmpty())
        return;

    QString nestDir = "";

    QSettings setup(bgo_ini, QSettings::IniFormat);
    setup.setIniCodec("UTF-8");

    main_bgo.clear();   //Clear old

    if(!openSection( &setup, "background-main")) return;
        bgo_total = setup.value("total", 0).toUInt();
        defaultGrid.bgo = setup.value("grid", defaultGrid.bgo).toUInt();
        total_data +=bgo_total;
        nestDir =   setup.value("config-dir", "").toString();
        if(!nestDir.isEmpty())
        {
            nestDir = config_dir + nestDir;
            useDirectory = true;
        }
    closeSection(&setup);

    emit progressPartNumber(1);
    emit progressMax(static_cast<int>(bgo_total));
    emit progressValue(0);
    emit progressTitle(QObject::tr("Loading BGOs..."));

    ConfStatus::total_bgo = static_cast<long>(bgo_total);

    main_bgo.allocateSlots(static_cast<int>(bgo_total));

    if(ConfStatus::total_bgo==0)
    {
        addError(QString("ERROR LOADING lvl_bgo.ini: number of items not define, or empty config"), PGE_LogLevel::Critical);
        return;
    }

    for(i=1; i<=bgo_total; i++)
    {
        emit progressValue(static_cast<int>(i));
        bool valid=false;

        if(useDirectory)
        {
            valid = loadLevelBGO(sbgo, "background", nullptr, QString("%1/background-%2.ini").arg(nestDir).arg(i));
        }
        else
        {
            valid = loadLevelBGO(sbgo, QString("background-%1").arg(i), 0, "", &setup);
        }

        /***************Load image*******************/
        if(valid)
        {
            QString errStr;
            GraphicsHelps::loadMaskedImage(bgoPath,
               sbgo.setup.image_n, sbgo.setup.mask_n,
               sbgo.image,
               errStr);

            if(!errStr.isEmpty())
            {
                valid=false;
                addError(QString("BGO-%1 %2").arg(i).arg(errStr));
            }
        }
        /***************Load image*end***************/
        sbgo.setup.id = i;
        main_bgo.storeElement(static_cast<int>(i), sbgo, valid);

        if( setup.status() != QSettings::NoError )
        {
            addError(QString("ERROR LOADING lvl_bgo.ini N:%1 (bgo-%2)").arg(setup.status()).arg(i), PGE_LogLevel::Critical);
        }
    }

    if(static_cast<unsigned long>(main_bgo.stored()) < bgo_total)
    {
        addError(QString("Not all BGOs loaded! Total: %1, Loaded: %2").arg(bgo_total).arg(main_bgo.stored()));
    }
}
Exemple #5
0
void dataconfigs::loadPlayers()
{
    main_characters.clear();

    uint64_t i;
    uint64_t players_total = 0;

    QString player_ini = getFullIniPath("lvl_characters.ini");
    if(player_ini.isEmpty())
        return;

    IniProcessing setup(player_ini);

    if(!openSection(&setup, "main-characters"))
        return;
    {
        setup.read("total", players_total, 0u);
    }
    closeSection(&setup);

    ConfStatus::total_characters = static_cast<long>(players_total);

    if(players_total == 0)
    {
        return;
    }

    main_characters.reserve(static_cast<int>(players_total));
    for(i = 1; i <= players_total; i++)
    {
        obj_player splayer;
        splayer.wld_offset_y = 0;

        //Default size of frame is 100x100, but re-calculates from matrix size and size of target sprite
        splayer.frame_width  = 100;
        splayer.frame_height = 100;
        splayer.statesCount  = 0;

        if(!openSection(&setup, QString("character-%1").arg(i).toStdString()))
            return;
        {
            splayer.id = i;
            setup.read("name", splayer.name, QString("player %1").arg(i));
            if(splayer.name.isEmpty())
            {
                addError(QString("Player-%1 Item name isn't defined").arg(i));
                closeSection(&setup);
                continue;
            }
            setup.read("sprite-folder", splayer.sprite_folder, QString("player-%1").arg(i));
            setup.read("sprite-folder", splayer.state_type, 0);
            setup.read("matrix-width",  splayer.matrix_width, 10);
            setup.read("matrix-height", splayer.matrix_height, 10);
            setup.read("script-file",   splayer.script, "");
            setup.read("states-number", splayer.statesCount, 0);
            if(splayer.statesCount == 0)
            {
                addError(QString("player-%1 has no states!").arg(i));
                closeSection(&setup);
                continue;
            }
        }
        closeSection(&setup);

        for(int j=1; j<=splayer.statesCount; j++)
        {
            obj_player_state pstate;
            openSection(&setup, QString("character-%1-state-%2").arg(i).arg(j).toStdString() );
            {
                setup.read("name", pstate.name, QString("State %1").arg(j));
            }
            closeSection(&setup);

            splayer.states.push_back(pstate);
        }

        main_characters.push_back(splayer);
    }

}
Exemple #6
0
bool dataconfigs::loadLevelBackground(obj_BG &sbg, QString section, obj_BG *merge_with, QString iniFile, QSettings *setup)
{
    bool valid=true;
    bool internal=!setup;
    QString errStr, tmpstr, imgFile;
    if(internal)
    {
        setup=new QSettings(iniFile, QSettings::IniFormat);
        setup->setIniCodec("UTF-8");
    }

    if(!openSection(setup, section))
        return false;

        sbg.name = setup->value("name", (merge_with? merge_with->name : "") ).toString();
        if(sbg.name.isEmpty())
        {
            addError(QString("%1 Item name isn't defined").arg(section.toUpper()));
            valid=false;
            goto abort;
        }
        tmpstr = setup->value("type", "-1").toString();
            if(tmpstr=="single-row")
               sbg.type = 0;
            else if(tmpstr=="double-row")
               sbg.type = 1;
            else if(tmpstr=="tiled")
               sbg.type = 2;
            else if(tmpstr=="-1")
               sbg.type = (merge_with ? merge_with->type : 0);
            else sbg.type = 0;


        sbg.repeat_h = float(qFabs(setup->value("repeat-h", (merge_with ? merge_with->repeat_h : 2.0f)).toFloat()));

        tmpstr = setup->value("repeat-v", "-1").toString();
            if(tmpstr=="NR")
                sbg.repead_v = 0;
            else if(tmpstr=="ZR")
                sbg.repead_v = 1;
            else if(tmpstr=="RP")
                sbg.repead_v = 2;
            else if(tmpstr=="RZ")
                sbg.repead_v = 3;
            else if(tmpstr=="-1")
                sbg.repead_v = (merge_with ? merge_with->repead_v : 0);
            else sbg.repead_v = 0;

        sbg.image_n = setup->value("image", (merge_with ? merge_with->image_n : "") ).toString();
        if(!merge_with)
        {
            if( (sbg.image_n !="") )
            {
                GraphicsHelps::loadMaskedImage(BGPath,
                    sbg.image_n, imgFile,
                    sbg.image,
                    errStr);
                if(!errStr.isEmpty())
                {
                    addError(QString("%1 %2").arg(section).arg(errStr));
                    valid=false;
                    //goto abort;
                }
            } else {
                addError(QString("%1 Image filename isn't defined").arg(section));
                valid=false;
                //goto abort;
            }
        }

        sbg.attached =     uint(setup->value("attached",
                                             (merge_with?(merge_with->attached==1?"top":"bottom"):"bottom") ).toString()=="top");

        sbg.editing_tiled =    setup->value("tiled-in-editor", merge_with?merge_with->editing_tiled:false ).toBool();

        sbg.magic =             setup->value("magic", (merge_with?merge_with->magic:false)).toBool();
        sbg.magic_strips =      setup->value("magic-strips", (merge_with? merge_with->magic_strips: 1 )).toUInt();
        sbg.magic_splits =      setup->value("magic-splits", (merge_with? merge_with->magic_splits:"0")).toString();
        sbg.magic_speeds =      setup->value("magic-speeds", (merge_with? merge_with->magic_speeds:"0")).toString();

        sbg.animated =          setup->value("animated", (merge_with?merge_with->animated:false)).toBool();//animated
        sbg.frames =            setup->value("frames", (merge_with?merge_with->frames:1)).toUInt();
        sbg.framespeed =        setup->value("framespeed", (merge_with?merge_with->framespeed : 128)).toUInt();
        sbg.display_frame =     setup->value("display-frame", (merge_with?merge_with->display_frame : 0)).toUInt();
        //frames

        if(sbg.type==1)
        {
            sbg.second_image_n = setup->value("second-image", (merge_with ? merge_with->second_image_n : "")).toString();
            if(!merge_with)
            {
                if( (sbg.second_image_n !="") )
                {
                    GraphicsHelps::loadMaskedImage(BGPath,
                       sbg.second_image_n, imgFile,
                       sbg.second_image,
                       errStr);
                } else {
                    sbg.second_image = Themes::Image(Themes::dummy_bg);
                }
            }

            sbg.second_repeat_h = float(qFabs(setup->value("second-repeat-h", (merge_with ? merge_with->second_repeat_h : 2.0f)).toFloat()));

            tmpstr = setup->value("second-repeat-v", "-1").toString();
                if(tmpstr=="NR")
                    sbg.second_repeat_v = 0;
                else if(tmpstr=="ZR")
                    sbg.second_repeat_v = 1;
                else if(tmpstr=="RP")
                    sbg.second_repeat_v = 2;
                else if(tmpstr=="RZ")
                    sbg.second_repeat_v = 3;
                else if(tmpstr=="-1")
                    sbg.second_repeat_v = (merge_with ? merge_with->second_repeat_v : 0);
                else sbg.second_repeat_v = 0;

            tmpstr = setup->value("second-attached", "-1").toString();
                if(tmpstr=="overfirst")
                    sbg.second_attached = 0;
                else if(tmpstr=="bottom")
                    sbg.second_attached = 1;
                else if(tmpstr=="top")
                    sbg.second_attached = 2;
                else if(tmpstr=="-1")
                    sbg.second_attached = (merge_with ? merge_with->second_attached : 0);
                else sbg.second_repeat_v = 0;
        }

        if(sbg.animated)
        {
            int fHeight = sbg.image.height() / int(sbg.frames);
            sbg.image = sbg.image.copy(0, 0, sbg.image.width(), fHeight );
        }

        sbg.isValid = true;

    abort:
        closeSection(setup);
        if(internal) delete setup;
    return valid;
}
Exemple #7
0
void dataconfigs::loadLevelBackgrounds()
{
    unsigned int i;
    obj_BG sbg;
    unsigned long bg_total=0;
    bool useDirectory=false;

    QString bg_ini = getFullIniPath("lvl_bkgrd.ini");
    if( bg_ini.isEmpty() )
        return;

    QString nestDir = "";

    QSettings setup(bg_ini, QSettings::IniFormat);
    setup.setIniCodec("UTF-8");

    main_bg.clear();   //Clear old

    if(!openSection(&setup, "background2-main")) return;
        bg_total = setup.value("total", 0).toUInt();
        total_data += bg_total;
        nestDir = setup.value("config-dir", "").toString();
        if(!nestDir.isEmpty())
        {
            nestDir = config_dir + nestDir;
            useDirectory = true;
        }
    closeSection(&setup);

    emit progressPartNumber(0);
    emit progressMax(int(bg_total));
    emit progressValue(0);
    emit progressTitle(QObject::tr("Loading Backgrounds..."));

    ConfStatus::total_bg = long(bg_total);
    main_bg.allocateSlots(int(bg_total));

    if(ConfStatus::total_bg==0)
    {
        addError(QString("ERROR LOADING lvl_bkgrd.ini: number of items not define, or empty config"), PGE_LogLevel::Critical);
        return;
    }

    for(i=1; i<=bg_total; i++)
    {
        emit progressValue(int(i));

        bool valid = false;
        if(useDirectory)
        {
            valid = loadLevelBackground(sbg, "background2", nullptr, QString("%1/background2-%2.ini").arg(nestDir).arg(i));
        }
        else
        {
            valid = loadLevelBackground(sbg, QString("background2-%1").arg(i), 0, "", &setup);
        }

        sbg.id = i;
        main_bg.storeElement(int(i), sbg, valid);

        if( setup.status() != QSettings::NoError )
        {
            addError(QString("ERROR LOADING lvl_bgrnd.ini N:%1 (background2-%2)").arg(setup.status()).arg(i), PGE_LogLevel::Critical);
        }
    }
}
void dataconfigs::loadLevelBGO()
{
    unsigned long i;

    obj_bgo sbgo;
    unsigned long bgo_total = 0;
    bool useDirectory = false;

    QString bgo_ini = getFullIniPath("lvl_bgo.ini");
    if(bgo_ini.isEmpty())
        return;

    IniProcessing setup(bgo_ini);

    folderLvlBgo.items.clear();
    main_bgo.clear();   //Clear old

    if(!openSection(&setup, "background-main"))
        return;
    {
        setup.read("total", bgo_total, 0);
        setup.read("grid",  defaultGrid.bgo, defaultGrid.bgo);
        total_data += bgo_total;
        setup.read("config-dir", folderLvlBgo.items, "");
        setup.read("extra-settings", folderLvlBgo.extraSettings, folderLvlBgo.items);
        if(!folderLvlBgo.items.isEmpty())
        {
            folderLvlBgo.items = config_dir + folderLvlBgo.items;
            useDirectory = true;
        }
    }
    closeSection(&setup);

    emit progressPartNumber(1);
    emit progressMax(static_cast<int>(bgo_total));
    emit progressValue(0);
    emit progressTitle(QObject::tr("Loading BGOs..."));

    ConfStatus::total_bgo = static_cast<long>(bgo_total);

    main_bgo.allocateSlots(static_cast<int>(bgo_total));

    if(ConfStatus::total_bgo == 0)
    {
        addError(QString("ERROR LOADING lvl_bgo.ini: number of items not define, or empty config"), PGE_LogLevel::Critical);
        return;
    }

    for(i = 1; i <= bgo_total; i++)
    {
        emit progressValue(static_cast<int>(i));
        bool valid = false;

        if(useDirectory)
            valid = loadLevelBGO(sbgo, "background", nullptr, QString("%1/background-%2.ini").arg(folderLvlBgo.items).arg(i));
        else
            valid = loadLevelBGO(sbgo, QString("background-%1").arg(i), 0, "", &setup);

        /***************Load image*******************/
        if(valid)
        {
            QString errStr;
            GraphicsHelps::loadMaskedImage(folderLvlBgo.graphics,
                                           sbgo.setup.image_n, sbgo.setup.mask_n,
                                           sbgo.image,
                                           errStr);

            if(!errStr.isEmpty())
            {
                valid = false;
                addError(QString("BGO-%1 %2").arg(i).arg(errStr));
            }
        }
        /***************Load image*end***************/
        sbgo.setup.id = i;
        main_bgo.storeElement(static_cast<int>(i), sbgo, valid);

        if(setup.lastError() != IniProcessing::ERR_OK)
            addError(QString("ERROR LOADING lvl_bgo.ini N:%1 (bgo-%2)").arg(setup.lastError()).arg(i), PGE_LogLevel::Critical);
    }

    if(static_cast<unsigned long>(main_bgo.stored()) < bgo_total)
        addError(QString("Not all BGOs loaded! Total: %1, Loaded: %2").arg(bgo_total).arg(main_bgo.stored()));
}