mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 18:35:20 +00:00
Fix some issues with content file numbers in the editor.
1. Change content numbers to be relative to the plugin when saving. 2. Initialize the indices in the MasterData part of a plugin header.
This commit is contained in:
parent
2fef8948f1
commit
3ae2fc17c6
@ -321,6 +321,10 @@ void CSMDoc::WriteCellCollectionStage::perform (int stage, Messages& messages)
|
|||||||
{
|
{
|
||||||
CSMWorld::CellRef refRecord = ref.get();
|
CSMWorld::CellRef refRecord = ref.get();
|
||||||
|
|
||||||
|
// Correct content file number to be relative to plugin
|
||||||
|
refRecord.mRefNum.mContentFile = mDocument.getData().getPluginContentFile(
|
||||||
|
refRecord.mRefNum.mContentFile);
|
||||||
|
|
||||||
// recalculate the ref's cell location
|
// recalculate the ref's cell location
|
||||||
std::ostringstream stream;
|
std::ostringstream stream;
|
||||||
if (!interior)
|
if (!interior)
|
||||||
|
@ -902,6 +902,8 @@ int CSMWorld::Data::startLoading (const boost::filesystem::path& path, bool base
|
|||||||
mReader->setIndex(mReaderIndex++);
|
mReader->setIndex(mReaderIndex++);
|
||||||
mReader->open (path.string());
|
mReader->open (path.string());
|
||||||
|
|
||||||
|
mContentFileNames.insert(std::make_pair(path.filename().string(), mReader->getIndex()));
|
||||||
|
|
||||||
mBase = base;
|
mBase = base;
|
||||||
mProject = project;
|
mProject = project;
|
||||||
|
|
||||||
@ -914,6 +916,35 @@ int CSMWorld::Data::startLoading (const boost::filesystem::path& path, bool base
|
|||||||
mMetaData.setRecord (0, Record<MetaData> (RecordBase::State_ModifiedOnly, 0, &metaData));
|
mMetaData.setRecord (0, Record<MetaData> (RecordBase::State_ModifiedOnly, 0, &metaData));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fix uninitialized master data index
|
||||||
|
for (std::vector<ESM::Header::MasterData>::const_iterator masterData = mReader->getGameFiles().begin();
|
||||||
|
masterData != mReader->getGameFiles().end(); ++masterData)
|
||||||
|
{
|
||||||
|
std::map<std::string, int>::iterator nameResult = mContentFileNames.find(masterData->name);
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return mReader->getRecordCount();
|
return mReader->getRecordCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1171,6 +1202,16 @@ int CSMWorld::Data::count (RecordBase::State state) const
|
|||||||
count (state, mPathgrids);
|
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> CSMWorld::Data::getIds (bool listDeleted) const
|
||||||
{
|
{
|
||||||
std::vector<std::string> ids;
|
std::vector<std::string> ids;
|
||||||
|
@ -123,6 +123,10 @@ namespace CSMWorld
|
|||||||
|
|
||||||
std::vector<boost::shared_ptr<ESM::ESMReader> > mReaders;
|
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
|
// not implemented
|
||||||
Data (const Data&);
|
Data (const Data&);
|
||||||
Data& operator= (const Data&);
|
Data& operator= (const Data&);
|
||||||
@ -298,6 +302,9 @@ namespace CSMWorld
|
|||||||
int count (RecordBase::State state) const;
|
int count (RecordBase::State state) const;
|
||||||
///< Return number of top-level records with the given \a state.
|
///< 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:
|
signals:
|
||||||
|
|
||||||
void idListChanged();
|
void idListChanged();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user