mirror of
https://github.com/OpenMW/openmw.git
synced 2025-05-11 00:41:27 +00:00
added saving for referenceable records
This commit is contained in:
parent
c42e74dadf
commit
e4fdebc85b
7 changed files with 91 additions and 0 deletions
|
@ -48,6 +48,8 @@ CSMDoc::Saving::Saving (Document& document)
|
||||||
appendStage (new WriteCollectionStage<CSMWorld::IdCollection<ESM::Spell> >
|
appendStage (new WriteCollectionStage<CSMWorld::IdCollection<ESM::Spell> >
|
||||||
(mDocument.getData().getSpells(), mState));
|
(mDocument.getData().getSpells(), mState));
|
||||||
|
|
||||||
|
appendStage (new WriteRefIdCollectionStage (mDocument, mState));
|
||||||
|
|
||||||
|
|
||||||
appendStage (new CloseSaveStage (mState));
|
appendStage (new CloseSaveStage (mState));
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,21 @@ void CSMDoc::WriteHeaderStage::perform (int stage, std::vector<std::string>& mes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CSMDoc::WriteRefIdCollectionStage::WriteRefIdCollectionStage (Document& document, SavingState& state)
|
||||||
|
: mDocument (document), mState (state)
|
||||||
|
{}
|
||||||
|
|
||||||
|
int CSMDoc::WriteRefIdCollectionStage::setup()
|
||||||
|
{
|
||||||
|
return mDocument.getData().getReferenceables().getSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSMDoc::WriteRefIdCollectionStage::perform (int stage, std::vector<std::string>& messages)
|
||||||
|
{
|
||||||
|
mDocument.getData().getReferenceables().save (stage, mState.getWriter());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
CSMDoc::CloseSaveStage::CloseSaveStage (SavingState& state)
|
CSMDoc::CloseSaveStage::CloseSaveStage (SavingState& state)
|
||||||
: mState (state)
|
: mState (state)
|
||||||
{}
|
{}
|
||||||
|
|
|
@ -99,6 +99,23 @@ namespace CSMDoc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class WriteRefIdCollectionStage : public Stage
|
||||||
|
{
|
||||||
|
Document& mDocument;
|
||||||
|
SavingState& mState;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
WriteRefIdCollectionStage (Document& document, SavingState& state);
|
||||||
|
|
||||||
|
virtual int setup();
|
||||||
|
///< \return number of steps
|
||||||
|
|
||||||
|
virtual void perform (int stage, std::vector<std::string>& messages);
|
||||||
|
///< Messages resulting from this stage will be appended to \a messages.
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class CloseSaveStage : public Stage
|
class CloseSaveStage : public Stage
|
||||||
{
|
{
|
||||||
SavingState& mState;
|
SavingState& mState;
|
||||||
|
|
|
@ -539,3 +539,8 @@ std::vector<std::string> CSMWorld::RefIdCollection::getIds (bool listDeleted) co
|
||||||
{
|
{
|
||||||
return mData.getIds (listDeleted);
|
return mData.getIds (listDeleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSMWorld::RefIdCollection::save (int index, ESM::ESMWriter& writer) const
|
||||||
|
{
|
||||||
|
mData.save (index, writer);
|
||||||
|
}
|
|
@ -9,6 +9,11 @@
|
||||||
#include "collectionbase.hpp"
|
#include "collectionbase.hpp"
|
||||||
#include "refiddata.hpp"
|
#include "refiddata.hpp"
|
||||||
|
|
||||||
|
namespace ESM
|
||||||
|
{
|
||||||
|
class ESMWriter;
|
||||||
|
}
|
||||||
|
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
class RefIdAdapter;
|
class RefIdAdapter;
|
||||||
|
@ -94,6 +99,8 @@ namespace CSMWorld
|
||||||
///< Return a sorted collection of all IDs
|
///< Return a sorted collection of all IDs
|
||||||
///
|
///
|
||||||
/// \param listDeleted include deleted record in the list
|
/// \param listDeleted include deleted record in the list
|
||||||
|
|
||||||
|
void save (int index, ESM::ESMWriter& writer) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -218,3 +218,16 @@ std::vector<std::string> CSMWorld::RefIdData::getIds (bool listDeleted) const
|
||||||
|
|
||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSMWorld::RefIdData::save (int index, ESM::ESMWriter& writer) const
|
||||||
|
{
|
||||||
|
LocalIndex localIndex = globalToLocalIndex (index);
|
||||||
|
|
||||||
|
std::map<UniversalId::Type, RefIdDataContainerBase *>::const_iterator iter =
|
||||||
|
mRecordContainers.find (localIndex.second);
|
||||||
|
|
||||||
|
if (iter==mRecordContainers.end())
|
||||||
|
throw std::logic_error ("invalid local index type");
|
||||||
|
|
||||||
|
iter->second->save (localIndex.first, writer);
|
||||||
|
}
|
|
@ -23,6 +23,7 @@
|
||||||
#include <components/esm/loadweap.hpp>
|
#include <components/esm/loadweap.hpp>
|
||||||
#include <components/esm/loadnpc.hpp>
|
#include <components/esm/loadnpc.hpp>
|
||||||
#include <components/esm/loadmisc.hpp>
|
#include <components/esm/loadmisc.hpp>
|
||||||
|
#include <components/esm/esmwriter.hpp>
|
||||||
|
|
||||||
#include "record.hpp"
|
#include "record.hpp"
|
||||||
#include "universalid.hpp"
|
#include "universalid.hpp"
|
||||||
|
@ -51,6 +52,8 @@ namespace CSMWorld
|
||||||
virtual void erase (int index, int count) = 0;
|
virtual void erase (int index, int count) = 0;
|
||||||
|
|
||||||
virtual std::string getId (int index) const = 0;
|
virtual std::string getId (int index) const = 0;
|
||||||
|
|
||||||
|
virtual void save (int index, ESM::ESMWriter& writer) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename RecordT>
|
template<typename RecordT>
|
||||||
|
@ -71,6 +74,8 @@ namespace CSMWorld
|
||||||
virtual void erase (int index, int count);
|
virtual void erase (int index, int count);
|
||||||
|
|
||||||
virtual std::string getId (int index) const;
|
virtual std::string getId (int index) const;
|
||||||
|
|
||||||
|
virtual void save (int index, ESM::ESMWriter& writer) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename RecordT>
|
template<typename RecordT>
|
||||||
|
@ -123,6 +128,31 @@ namespace CSMWorld
|
||||||
return mContainer.at (index).get().mId;
|
return mContainer.at (index).get().mId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename RecordT>
|
||||||
|
void RefIdDataContainer<RecordT>::save (int index, ESM::ESMWriter& writer) const
|
||||||
|
{
|
||||||
|
CSMWorld::RecordBase::State state = mContainer.at (index).mState;
|
||||||
|
|
||||||
|
if (state==CSMWorld::RecordBase::State_Modified ||
|
||||||
|
state==CSMWorld::RecordBase::State_ModifiedOnly)
|
||||||
|
{
|
||||||
|
std::string type;
|
||||||
|
for (int i=0; i<4; ++i)
|
||||||
|
/// \todo make endianess agnostic (change ESMWriter interface?)
|
||||||
|
type += reinterpret_cast<const char *> (&mContainer.at (index).mModified.sRecordId)[i];
|
||||||
|
|
||||||
|
writer.startRecord (type);
|
||||||
|
writer.writeHNCString ("NAME", getId (index));
|
||||||
|
mContainer.at (index).mModified.save (writer);
|
||||||
|
writer.endRecord (type);
|
||||||
|
}
|
||||||
|
else if (state==CSMWorld::RecordBase::State_Deleted)
|
||||||
|
{
|
||||||
|
/// \todo write record with delete flag
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class RefIdData
|
class RefIdData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -187,6 +217,8 @@ namespace CSMWorld
|
||||||
///< Return a sorted collection of all IDs
|
///< Return a sorted collection of all IDs
|
||||||
///
|
///
|
||||||
/// \param listDeleted include deleted record in the list
|
/// \param listDeleted include deleted record in the list
|
||||||
|
|
||||||
|
void save (int index, ESM::ESMWriter& writer) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue