Exemplo n.º 1
0
/*
 * Invlet cache: player specific, thus not wrapped in inventory::json_load/save
 */
void inventory::json_load_invcache(JsonIn &jsin)
{
    try {
        JsonArray ja = jsin.get_array();
        while ( ja.has_more() ) {
            JsonObject jo = ja.next_object();
            std::set<std::string> members = jo.get_member_names();
            for (std::set<std::string>::iterator it = members.begin();
                    it != members.end(); ++it) {
                std::vector<char> vect;
                JsonArray pvect = jo.get_array(*it);
                while ( pvect.has_more() ) {
                    vect.push_back( pvect.next_int() );
                }
                invlet_cache[*it] = vect;
            }
        }
    } catch (std::string jsonerr) {
        debugmsg("bad invcache json:\n%s", jsonerr.c_str() );
    }
}
Exemplo n.º 2
0
void item::deserialize(JsonObject &data)
{
    init();
    clear();

    std::string idtmp="";
    std::string ammotmp="null";
    int lettmp = 0;
    std::string corptmp = "null";
    int damtmp = 0;

    if ( ! data.read( "typeid", idtmp) ) {
        debugmsg("Invalid item type: %s ", data.str().c_str() );
        idtmp = "null";
    }

    data.read( "charges", charges );
    data.read( "burnt", burnt );
    data.read( "poison", poison );
    data.read( "owned", owned );

    data.read( "bday", bday );

    data.read( "mode", mode );
    data.read( "mission_id", mission_id );
    data.read( "player_id", player_id );

    if (!data.read( "corpse", corptmp )) {
        int ctmp = -1;
        data.read( "corpse", ctmp );
        if (ctmp != -1) {
            corptmp = legacy_mon_id[ctmp];
        } else {
            corptmp = "null";
        }
    }
    if (corptmp != "null") {
        corpse = GetMType(corptmp);
    } else {
        corpse = NULL;
    }

    JsonObject pvars = data.get_object("item_vars");
    std::set<std::string> members = pvars.get_member_names();
    for ( std::set<std::string>::iterator pvarsit = members.begin();
            pvarsit != members.end(); ++pvarsit ) {
        if ( pvars.has_string( *pvarsit ) ) {
            item_vars[ *pvarsit ] = pvars.get_string( *pvarsit );
        }
    }

    bool old_itype = false;

    if ( idtmp == "null" ) {
        std::map<std::string, std::string>::const_iterator oldity = item_vars.find("_invalid_itype_");
        if ( oldity != item_vars.end() ) {
            old_itype = true;
            idtmp = oldity->second;
        }
    }

    std::map<std::string, itype*>::const_iterator ity = itypes.find(idtmp);
    if ( ity == itypes.end() ) {
        item_vars["_invalid_itype_"] = idtmp;
        make(NULL);
    } else {
        if ( old_itype ) {
            item_vars.erase( "_invalid_itype_" );
        }
        make(ity->second);
    }

    if ( ! data.read( "name", name ) ) {
        name=type->name;
    }

    data.read( "invlet", lettmp );
    invlet = char(lettmp);

    data.read( "damage", damtmp );
    damage = damtmp; // todo: check why this is done after make(), using a tmp variable
    data.read( "active", active );
    data.read( "item_counter" , item_counter );
    data.read( "fridge", fridge );
    data.read( "rot", rot );
    data.read( "last_rot_check", last_rot_check );

    data.read( "curammo", ammotmp );
    if ( ammotmp != "null" ) {
        curammo = dynamic_cast<it_ammo*>(itypes[ammotmp]);
    } else {
        curammo = NULL;
    }

    data.read("item_tags", item_tags);


    int tmplum=0;
    if ( data.read("light",tmplum) ) {

        light=nolight;
        int tmpwidth=0;
        int tmpdir=0;

        data.read("light_width",tmpwidth);
        data.read("light_dir",tmpdir);
        light.luminance = tmplum;
        light.width = (short)tmpwidth;
        light.direction = (short)tmpdir;
    }

    data.read("contents", contents);
    data.read("components", components);
}