1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-30 19:45:40 +00:00
openmw/components/esm3/savedgame.cpp

57 lines
1.7 KiB
C++
Raw Normal View History

#include "savedgame.hpp"
#include "esmreader.hpp"
#include "esmwriter.hpp"
namespace ESM
{
2022-09-22 18:26:05 +00:00
void SavedGame::load(ESMReader& esm)
{
mPlayerName = esm.getHNString("PLNA");
esm.getHNOT(mPlayerLevel, "PLLE");
mPlayerClassId = esm.getHNORefId("PLCL");
2022-09-22 18:26:05 +00:00
mPlayerClassName = esm.getHNOString("PLCN");
2023-03-26 11:23:19 +00:00
if (esm.getFormatVersion() <= ESM::MaxSavedGameCellNameAsRefIdFormatVersion)
mPlayerCellName = esm.getHNRefId("PLCE").toString();
else
mPlayerCellName = esm.getHNString("PLCE");
2022-09-22 18:26:05 +00:00
esm.getHNTSized<16>(mInGameTime, "TSTM");
esm.getHNT(mTimePlayed, "TIME");
mDescription = esm.getHNString("DESC");
while (esm.isNextSub("DEPE"))
mContentFiles.push_back(esm.getHString());
esm.getSubNameIs("SCRN");
esm.getSubHeader();
mScreenshot.resize(esm.getSubSize());
esm.getExact(mScreenshot.data(), mScreenshot.size());
}
void SavedGame::save(ESMWriter& esm) const
{
esm.writeHNString("PLNA", mPlayerName);
esm.writeHNT("PLLE", mPlayerLevel);
if (!mPlayerClassId.empty())
esm.writeHNRefId("PLCL", mPlayerClassId);
2022-09-22 18:26:05 +00:00
else
esm.writeHNString("PLCN", mPlayerClassName);
esm.writeHNString("PLCE", mPlayerCellName);
2022-09-22 18:26:05 +00:00
esm.writeHNT("TSTM", mInGameTime, 16);
esm.writeHNT("TIME", mTimePlayed);
esm.writeHNString("DESC", mDescription);
for (std::vector<std::string>::const_iterator iter(mContentFiles.begin()); iter != mContentFiles.end(); ++iter)
esm.writeHNString("DEPE", *iter);
esm.startSubRecord("SCRN");
esm.write(mScreenshot.data(), mScreenshot.size());
esm.endRecord("SCRN");
}
}