store global script state in saved game files
parent
2a35c7d33a
commit
3590fa40bd
@ -0,0 +1,25 @@
|
||||
|
||||
#include "globalscript.hpp"
|
||||
|
||||
#include "esmreader.hpp"
|
||||
#include "esmwriter.hpp"
|
||||
|
||||
void ESM::GlobalScript::load (ESMReader &esm)
|
||||
{
|
||||
mId = esm.getHNString ("NAME");
|
||||
|
||||
mLocals.load (esm);
|
||||
|
||||
mRunning = 0;
|
||||
esm.getHNOT (mRunning, "RUN_");
|
||||
}
|
||||
|
||||
void ESM::GlobalScript::save (ESMWriter &esm) const
|
||||
{
|
||||
esm.writeHNString ("NAME", mId);
|
||||
|
||||
mLocals.save (esm);
|
||||
|
||||
if (mRunning)
|
||||
esm.writeHNT ("RUN_", mRunning);
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
#ifndef OPENMW_ESM_GLOBALSCRIPT_H
|
||||
#define OPENMW_ESM_GLOBALSCRIPT_H
|
||||
|
||||
#include "locals.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
class ESMReader;
|
||||
class ESMWriter;
|
||||
|
||||
/// \brief Storage structure for global script state (only used in saved games)
|
||||
|
||||
struct GlobalScript
|
||||
{
|
||||
std::string mId;
|
||||
Locals mLocals;
|
||||
int mRunning;
|
||||
|
||||
void load (ESMReader &esm);
|
||||
void save (ESMWriter &esm) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,28 @@
|
||||
|
||||
#include "locals.hpp"
|
||||
|
||||
#include "esmreader.hpp"
|
||||
#include "esmwriter.hpp"
|
||||
|
||||
void ESM::Locals::load (ESMReader &esm)
|
||||
{
|
||||
while (esm.isNextSub ("LOCA"))
|
||||
{
|
||||
std::string id = esm.getHString();
|
||||
|
||||
Variant value;
|
||||
value.read (esm, Variant::Format_Info);
|
||||
|
||||
mVariables.push_back (std::make_pair (id, value));
|
||||
}
|
||||
}
|
||||
|
||||
void ESM::Locals::save (ESMWriter &esm) const
|
||||
{
|
||||
for (std::vector<std::pair<std::string, Variant> >::const_iterator iter (mVariables.begin());
|
||||
iter!=mVariables.end(); ++iter)
|
||||
{
|
||||
esm.writeHNString ("LOCA", iter->first);
|
||||
iter->second.write (esm, Variant::Format_Info);
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
#ifndef OPENMW_ESM_LOCALS_H
|
||||
#define OPENMW_ESM_LOCALS_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "variant.hpp"
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
class ESMReader;
|
||||
class ESMWriter;
|
||||
|
||||
/// \brief Storage structure for local variables (only used in saved games)
|
||||
///
|
||||
/// \note This is not a top-level record.
|
||||
|
||||
struct Locals
|
||||
{
|
||||
std::vector<std::pair<std::string, Variant> > mVariables;
|
||||
|
||||
void load (ESMReader &esm);
|
||||
void save (ESMWriter &esm) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue