+
+ size_t origsize = m_nodenames.size();
+ if (!deserializeFromMts(&is, &m_nodenames))
+ return false;
+
+ m_nnlistsizes.push_back(m_nodenames.size() - origsize);
+
+ name = filename;
+
+ if (replace_names) {
+ for (size_t i = origsize; i < m_nodenames.size(); i++) {
+ std::string &node_name = m_nodenames[i];
+ StringMap::iterator it = replace_names->find(node_name);
+ if (it != replace_names->end())
+ node_name = it->second;
+ }
+ }
+
+ if (ndef)
+ ndef->pendNodeResolve(this);
+
+ return true;
+}
+
+
+bool Schematic::saveSchematicToFile(const std::string &filename,
+ INodeDefManager *ndef)
+{
+ MapNode *orig_schemdata = schemdata;
+ std::vector<std::string> ndef_nodenames;
+ std::vector<std::string> *names;
+
+ if (m_resolve_done && ndef == NULL)
+ ndef = m_ndef;
+
+ if (ndef) {
+ names = &ndef_nodenames;
+
+ u32 volume = size.X * size.Y * size.Z;
+ schemdata = new MapNode[volume];
+ for (u32 i = 0; i != volume; i++)
+ schemdata[i] = orig_schemdata[i];
+
+ generate_nodelist_and_update_ids(schemdata, volume, names, ndef);
+ } else { // otherwise, use the names we have on hand in the list
+ names = &m_nodenames;
+ }
+
+ std::ostringstream os(std::ios_base::binary);
+ bool status = serializeToMts(&os, *names);
+
+ if (ndef) {
+ delete []schemdata;
+ schemdata = orig_schemdata;
+ }
+
+ if (!status)
+ return false;
+
+ return fs::safeWriteToFile(filename, os.str());