mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-10 03:39:55 +00:00
added save stage for globals
This commit is contained in:
parent
874ce26bef
commit
bf0fba68af
@ -2058,9 +2058,9 @@ void CSMDoc::Document::addOptionalGlobals()
|
||||
{
|
||||
static const char *sGlobals[] =
|
||||
{
|
||||
"dayspassed",
|
||||
"pcwerewolf",
|
||||
"pcyear",
|
||||
"DaysPassed",
|
||||
"PCWerewolf",
|
||||
"PCYear",
|
||||
0
|
||||
};
|
||||
|
||||
|
@ -1,9 +1,14 @@
|
||||
|
||||
#include "saving.hpp"
|
||||
|
||||
#include "state.hpp"
|
||||
#include <components/esm/defs.hpp>
|
||||
|
||||
#include "../world/data.hpp"
|
||||
#include "../world/idcollection.hpp"
|
||||
|
||||
#include "state.hpp"
|
||||
#include "savingstages.hpp"
|
||||
#include "document.hpp"
|
||||
|
||||
CSMDoc::Saving::Saving (Document& document)
|
||||
: Operation (State_Saving, true, true), mDocument (document), mState (*this)
|
||||
@ -12,6 +17,8 @@ CSMDoc::Saving::Saving (Document& document)
|
||||
|
||||
appendStage (new WriteHeaderStage (mDocument, mState));
|
||||
|
||||
appendStage (new WriteCollectionStage<CSMWorld::IdCollection<ESM::Global> >
|
||||
(mDocument.getData().getGlobals(), mState, ESM::REC_GLOB));
|
||||
|
||||
|
||||
appendStage (new CloseSaveStage (mState));
|
||||
|
@ -1,8 +1,14 @@
|
||||
#ifndef CSM_DOC_SAVINGSTAGES_H
|
||||
#define CSM_DOC_SAVINGSTAGES_H
|
||||
|
||||
#include <components/esm/defs.hpp>
|
||||
|
||||
#include "stage.hpp"
|
||||
|
||||
#include "savingstate.hpp"
|
||||
|
||||
#include "../world/record.hpp"
|
||||
|
||||
namespace CSMDoc
|
||||
{
|
||||
class Document;
|
||||
@ -40,6 +46,62 @@ namespace CSMDoc
|
||||
///< Messages resulting from this stage will be appended to \a messages.
|
||||
};
|
||||
|
||||
|
||||
template<class CollectionT>
|
||||
class WriteCollectionStage : public Stage
|
||||
{
|
||||
const CollectionT& mCollection;
|
||||
SavingState& mState;
|
||||
ESM::RecNameInts mRecordType;
|
||||
|
||||
public:
|
||||
|
||||
WriteCollectionStage (const CollectionT& collection, SavingState& state,
|
||||
ESM::RecNameInts recordType);
|
||||
|
||||
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.
|
||||
};
|
||||
|
||||
template<class CollectionT>
|
||||
WriteCollectionStage<CollectionT>::WriteCollectionStage (const CollectionT& collection,
|
||||
SavingState& state, ESM::RecNameInts recordType)
|
||||
: mCollection (collection), mState (state), mRecordType (recordType)
|
||||
{}
|
||||
|
||||
template<class CollectionT>
|
||||
int WriteCollectionStage<CollectionT>::setup()
|
||||
{
|
||||
return mCollection.getSize();
|
||||
}
|
||||
|
||||
template<class CollectionT>
|
||||
void WriteCollectionStage<CollectionT>::perform (int stage, std::vector<std::string>& messages)
|
||||
{
|
||||
CSMWorld::RecordBase::State state = mCollection.getRecord (stage).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 *> (&mRecordType)[i];
|
||||
|
||||
mState.getWriter().startRecord (type);
|
||||
mCollection.getRecord (stage).mModified.save (mState.getWriter());
|
||||
mState.getWriter().endRecord (type);
|
||||
}
|
||||
else if (state==CSMWorld::RecordBase::State_Deleted)
|
||||
{
|
||||
/// \todo write record with delete flag
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class CloseSaveStage : public Stage
|
||||
{
|
||||
SavingState& mState;
|
||||
|
@ -90,7 +90,7 @@ class ESMWriter
|
||||
write((char*)&data, size);
|
||||
}
|
||||
|
||||
void startRecord(const std::string& name, uint32_t flags);
|
||||
void startRecord(const std::string& name, uint32_t flags = 0);
|
||||
void startSubRecord(const std::string& name);
|
||||
void endRecord(const std::string& name);
|
||||
void writeHString(const std::string& data);
|
||||
|
Loading…
x
Reference in New Issue
Block a user