void ItemDefinition::deSerialize(std::istream &is) { // Reset everything reset(); // Deserialize int version = readU8(is); if(version != 1) throw SerializationError("unsupported ItemDefinition version"); type = (enum ItemType)readU8(is); name = deSerializeString(is); description = deSerializeString(is); inventory_image = deSerializeString(is); wield_image = deSerializeString(is); wield_scale = readV3F1000(is); stack_max = readS16(is); usable = readU8(is); liquids_pointable = readU8(is); eatable = readU8(is); std::string tool_capabilities_s = deSerializeString(is); if(!tool_capabilities_s.empty()) { std::istringstream tmp_is(tool_capabilities_s, std::ios::binary); tool_capabilities = new ToolCapabilities; tool_capabilities->deSerialize(tmp_is); } groups.clear(); u32 groups_size = readU16(is); for(u32 i=0; i<groups_size; i++){ std::string name = deSerializeString(is); int value = readS16(is); groups[name] = value; } }
void deSerialize(std::istream &is) { // Clear everything clear(); // Deserialize int version = readU8(is); if(version != 0) throw SerializationError("unsupported ItemDefManager version"); u16 count = readU16(is); for(u16 i=0; i<count; i++) { // Deserialize a string and grab an ItemDefinition from it std::istringstream tmp_is(deSerializeString(is), std::ios::binary); ItemDefinition def; def.deSerialize(tmp_is); // Register registerItem(def); } u16 num_aliases = readU16(is); for(u16 i=0; i<num_aliases; i++) { std::string name = deSerializeString(is); std::string convert_to = deSerializeString(is); registerAlias(name, convert_to); } }
void ItemDefinition::deSerialize(std::istream &is) { // Reset everything reset(); // Deserialize int version = readU8(is); if(version < 1 || version > 3) throw SerializationError("unsupported ItemDefinition version"); type = (enum ItemType)readU8(is); name = deSerializeString(is); description = deSerializeString(is); inventory_image = deSerializeString(is); wield_image = deSerializeString(is); wield_scale = readV3F1000(is); stack_max = readS16(is); usable = readU8(is); liquids_pointable = readU8(is); std::string tool_capabilities_s = deSerializeString(is); if(!tool_capabilities_s.empty()) { std::istringstream tmp_is(tool_capabilities_s, std::ios::binary); tool_capabilities = new ToolCapabilities; tool_capabilities->deSerialize(tmp_is); } groups.clear(); u32 groups_size = readU16(is); for(u32 i=0; i<groups_size; i++){ std::string name = deSerializeString(is); int value = readS16(is); groups[name] = value; } if(version == 1){ // We cant be sure that node_placement_prediction is send in version 1 try{ node_placement_prediction = deSerializeString(is); }catch(SerializationError &e) {}; // Set the old default sound sound_place.name = "default_place_node"; sound_place.gain = 0.5; } else if(version >= 2) { node_placement_prediction = deSerializeString(is); //deserializeSimpleSoundSpec(sound_place, is); sound_place.name = deSerializeString(is); sound_place.gain = readF1000(is); } if(version == 3) { range = readF1000(is); } // If you add anything here, insert it primarily inside the try-catch // block to not need to increase the version. try { sound_place_failed.name = deSerializeString(is); sound_place_failed.gain = readF1000(is); } catch(SerializationError &e) {}; }
void ItemDefinition::deSerialize(std::istream &is) { // Reset everything reset(); // Deserialize int version = readU8(is); if (version < 5) throw SerializationError("unsupported ItemDefinition version"); type = (enum ItemType)readU8(is); name = deSerializeString(is); description = deSerializeString(is); inventory_image = deSerializeString(is); wield_image = deSerializeString(is); wield_scale = readV3F1000(is); stack_max = readS16(is); usable = readU8(is); liquids_pointable = readU8(is); std::string tool_capabilities_s = deSerializeString(is); if(!tool_capabilities_s.empty()) { std::istringstream tmp_is(tool_capabilities_s, std::ios::binary); tool_capabilities = new ToolCapabilities; tool_capabilities->deSerialize(tmp_is); } groups.clear(); u32 groups_size = readU16(is); for(u32 i=0; i<groups_size; i++){ std::string name = deSerializeString(is); int value = readS16(is); groups[name] = value; } node_placement_prediction = deSerializeString(is); //deserializeSimpleSoundSpec(sound_place, is); sound_place.name = deSerializeString(is); sound_place.gain = readF1000(is); range = readF1000(is); sound_place_failed.name = deSerializeString(is); sound_place_failed.gain = readF1000(is); palette_image = deSerializeString(is); color = readARGB8(is); sound_place.pitch = readF1000(is); sound_place_failed.pitch = readF1000(is); inventory_overlay = deSerializeString(is); wield_overlay = deSerializeString(is); // If you add anything here, insert it primarily inside the try-catch // block to not need to increase the version. //try { //} catch(SerializationError &e) {}; }
// Parses a string serialized by serializeJsonStringIfNeeded. static std::string deSerializeJsonStringIfNeeded(std::istream &is) { std::ostringstream tmp_os; bool expect_initial_quote = true; bool is_json = false; bool was_backslash = false; for(;;) { char c = is.get(); if(is.eof()) break; if(expect_initial_quote && c == '"') { tmp_os << c; is_json = true; } else if(is_json) { tmp_os << c; if(was_backslash) was_backslash = false; else if(c == '\\') was_backslash = true; else if(c == '"') break; // Found end of string } else { if(c == ' ') { // Found end of word is.unget(); break; } else { tmp_os << c; } } expect_initial_quote = false; } if(is_json) { std::istringstream tmp_is(tmp_os.str(), std::ios::binary); return deSerializeJsonString(tmp_is); } else return tmp_os.str(); }
virtual void deSerialize(std::istream &is) { // Clear everything clear(); // Deserialize int version = readU8(is); if(version != 0) throw SerializationError( "unsupported CraftDefManager version"); u16 count = readU16(is); for(u16 i=0; i<count; i++){ // Deserialize a string and grab a CraftDefinition from it std::istringstream tmp_is(deSerializeString(is), std::ios::binary); CraftDefinition *def = CraftDefinition::deSerialize(tmp_is); // Register registerCraft(def); } }
void deSerialize(std::istream &is) { clear(); u16 count = readU16(is); std::istringstream tmp_is(deSerializeLongString(is), std::ios::binary); for(u16 n=0; n<count; n++){ u16 i = readU16(tmp_is); if(i > MAX_CONTENT){ errorstream<<"ContentFeatures::deSerialize(): " <<"Too large content id: "<<i<<std::endl; continue; } /*// Do not deserialize special types if(i == CONTENT_IGNORE || i == CONTENT_AIR) continue;*/ ContentFeatures *f = &m_content_features[i]; f->deSerialize(tmp_is); if(f->name != "") addNameIdMapping(i, f->name); } }