コード例 #1
0
ファイル: item_group.cpp プロジェクト: Bubbadoo/Cataclysm-DDA
Group_tag item_group::load_item_group( JsonIn& stream, const std::string& default_subtype )
{
    if( stream.test_string() ) {
        return stream.get_string();
    } else if( stream.test_object() ) {
        const Group_tag group = get_unique_group_id();

        JsonObject jo = stream.get_object();
        const std::string subtype = jo.get_string( "subtype", default_subtype );
        item_controller->load_item_group( jo, group, subtype );

        return group;
    } else if( stream.test_array() ) {
        const Group_tag group = get_unique_group_id();

        JsonArray jarr = stream.get_array();
        // load_item_group needs a bool, invalid subtypes are unexpected and most likely errors
        // from the caller of this function.
        if( default_subtype != "collection" && default_subtype != "distribution" ) {
            debugmsg( "invalid subtype for item group: %s", default_subtype.c_str() );
        }
        item_controller->load_item_group( jarr, group, default_subtype == "collection" );

        return group;
    } else {
        stream.error( "invalid item group, must be string (group id) or object/array (the group data)" );
        // stream.error always throws, this is here to prevent a warning
        return Group_tag{};
    }
}
コード例 #2
0
ファイル: format.cpp プロジェクト: CleverRaven/Cataclysm-DDA
static void write_object( JsonIn &jsin, JsonOut &jsout, int depth, bool force_wrap )
{
    jsout.start_object( force_wrap );
    jsin.start_object();
    while( !jsin.end_object() ) {
        std::string name = jsin.get_member_name();
        jsout.member( name );
        bool override_wrap = false;
        if( name == "rows" || name == "blueprint" ) {
            // Introspect into the row, if it has more than one element, force it to wrap.
            int in_start_pos = jsin.tell();
            bool ate_seperator = jsin.get_ate_separator();
            {
                JsonArray arr = jsin.get_array();
                if( arr.size() > 1 ) {
                    override_wrap = true;
                }
            }
            jsin.seek( in_start_pos );
            jsin.set_ate_separator( ate_seperator );
        }
        format( jsin, jsout, depth, override_wrap );
    }
    jsout.end_object();
}
コード例 #3
0
Trait_group_tag trait_group::load_trait_group( JsonIn &stream, const std::string &default_subtype )
{
    if( stream.test_string() ) {
        return Trait_group_tag( stream.get_string() );
    } else if( stream.test_object() ) {
        const Trait_group_tag group = get_unique_trait_group_id();

        JsonObject jo = stream.get_object();
        const std::string subtype = jo.get_string( "subtype", default_subtype );

        mutation_branch::load_trait_group( jo, group, subtype );

        return group;
    } else if( stream.test_array() ) {
        const Trait_group_tag group = get_unique_trait_group_id();

        JsonArray jarr = stream.get_array();
        if( default_subtype != "collection" && default_subtype != "distribution" ) {
            jarr.throw_error( "invalid subtype for trait group" );
        }

        mutation_branch::load_trait_group( jarr, group, default_subtype == "collection" );
        return group;
    } else {
        stream.error( "invalid trait group, must be string (group id) or object/array (the group data)" );
        return Trait_group_tag{};
    }
}
コード例 #4
0
 profession::itypedec get_next( JsonIn &jin ) const {
     // either a plain item type id string, or an array with item type id
     // and as second entry the item description.
     if( jin.test_string() ) {
         return profession::itypedec( jin.get_string(), "" );
     }
     JsonArray jarr = jin.get_array();
     const auto id = jarr.get_string( 0 );
     const auto s = jarr.get_string( 1 );
     const auto snippet = _( s.c_str() );
     return profession::itypedec( id, snippet );
 }
コード例 #5
0
void inventory::json_load_items(JsonIn &jsin)
{
    try {
        JsonArray ja = jsin.get_array();
        while ( ja.has_more() ) {
            JsonObject jo = ja.next_object();
            add_item(item( jo ), false, false);
        }
    } catch (std::string& jsonerr) {
         debugmsg("bad inventory json:\n%s", jsonerr.c_str() );
    }
}
コード例 #6
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() );
    }
}