Initialize with correct content file number instead of correcting at save stage.

pull/55/head
Aesylwinn 8 years ago
parent 3ae2fc17c6
commit b2ddd3c259

@ -321,9 +321,9 @@ void CSMDoc::WriteCellCollectionStage::perform (int stage, Messages& messages)
{
CSMWorld::CellRef refRecord = ref.get();
// Correct content file number to be relative to plugin
refRecord.mRefNum.mContentFile = mDocument.getData().getPluginContentFile(
refRecord.mRefNum.mContentFile);
// Check for uninitialized content file
if (!refRecord.mRefNum.hasContentFile())
refRecord.mRefNum.mContentFile = 0;
// recalculate the ref's cell location
std::ostringstream stream;

@ -64,7 +64,7 @@ int CSMWorld::Data::count (RecordBase::State state, const CollectionBase& collec
CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourcesManager, const Fallback::Map* fallback, const boost::filesystem::path& resDir)
: mEncoder (encoding), mPathgrids (mCells), mRefs (mCells),
mResourcesManager (resourcesManager), mFallbackMap(fallback),
mReader (0), mDialogue (0), mReaderIndex(0), mResourceSystem(new Resource::ResourceSystem(resourcesManager.getVFS()))
mReader (0), mDialogue (0), mReaderIndex(1), mResourceSystem(new Resource::ResourceSystem(resourcesManager.getVFS()))
{
mResourceSystem->getSceneManager()->setShaderPath((resDir / "shaders").string());
@ -899,7 +899,7 @@ int CSMWorld::Data::startLoading (const boost::filesystem::path& path, bool base
mReader = new ESM::ESMReader;
mReader->setEncoder (&mEncoder);
mReader->setIndex(mReaderIndex++);
mReader->setIndex((project || !base) ? 0 : mReaderIndex++);
mReader->open (path.string());
mContentFileNames.insert(std::make_pair(path.filename().string(), mReader->getIndex()));
@ -924,24 +924,9 @@ int CSMWorld::Data::startLoading (const boost::filesystem::path& path, bool base
if (nameResult != mContentFileNames.end())
{
ESM::Header::MasterData& hackedMasterData = const_cast<ESM::Header::MasterData&>(*masterData);
hackedMasterData.index = nameResult->second;
}
}
// Needed for saving
if (!mBase)
{
mReverseContentFiles.insert(std::make_pair(mReader->getIndex(), 0));
}
if (mProject)
{
mReverseContentFiles.insert(std::make_pair(mReader->getIndex(), 0));
// A new project has no header, so extrapolate the content files from the reader index
// The base/project index of 0 will not be overwritten
for (int i = 0; i < mReader->getIndex(); ++i)
{
mReverseContentFiles.insert(std::make_pair(i, i+1));
hackedMasterData.index = nameResult->second;
}
}
@ -1202,16 +1187,6 @@ int CSMWorld::Data::count (RecordBase::State state) const
count (state, mPathgrids);
}
int CSMWorld::Data::getPluginContentFile(int currentContentFile)
{
std::map<int, int>::iterator searchResult = mReverseContentFiles.find(currentContentFile);
if (searchResult != mReverseContentFiles.end())
return searchResult->second;
else
return 0; // Assume faulty plugin with original content
}
std::vector<std::string> CSMWorld::Data::getIds (bool listDeleted) const
{
std::vector<std::string> ids;

@ -124,8 +124,6 @@ namespace CSMWorld
std::vector<boost::shared_ptr<ESM::ESMReader> > mReaders;
std::map<std::string, int> mContentFileNames;
// current index, plugin index
std::map<int, int> mReverseContentFiles;
// not implemented
Data (const Data&);
@ -302,9 +300,6 @@ namespace CSMWorld
int count (RecordBase::State state) const;
///< Return number of top-level records with the given \a state.
/// Returns the content file number relative to the plugin being edited, 0 by default
int getPluginContentFile(int currentContentFile);
signals:
void idListChanged();

Loading…
Cancel
Save