1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 06:35:30 +00:00

basic globals record loading

This commit is contained in:
Marc Zinnschlag 2013-02-07 12:52:01 +01:00
parent 7d112e4d5c
commit adcaea464b
4 changed files with 69 additions and 22 deletions

View File

@ -15,7 +15,7 @@ CS::Editor::Editor() : mViewManager (mDocumentManager), mNewDocumentIndex (0)
connect (&mStartup, SIGNAL (createDocument()), this, SLOT (createDocument ()));
connect (&mStartup, SIGNAL (loadDocument()), this, SLOT (loadDocument ()));
connect (&mOpenDialog, SIGNAL(accepted()), this, SLOT(openFiles()));
}
@ -50,23 +50,7 @@ void CS::Editor::openFiles()
std::vector<boost::filesystem::path> paths;
mOpenDialog.getFileList(paths);
CSMDoc::Document *document = mDocumentManager.addDocument(paths, false);
static const char *sGlobals[] =
{
"Day", "DaysPassed", "GameHour", "Month", "PCRace", "PCVampire", "PCWerewolf", "PCYear", 0
};
for (int i=0; sGlobals[i]; ++i)
{
ESM::Global record;
record.mId = sGlobals[i];
record.mValue = i==0 ? 1 : 0;
record.mType = ESM::VT_Float;
document->getData().getGlobals().add (record);
}
document->getData().merge(); /// \todo remove once proper ESX loading is implemented
mViewManager.addView (document);
}

View File

@ -5,6 +5,7 @@
#include <QAbstractTableModel>
#include <components/esm/esmreader.hpp>
#include <components/esm/loadglob.hpp>
#include "idtable.hpp"
@ -63,5 +64,26 @@ void CSMWorld::Data::merge()
void CSMWorld::Data::loadFile (const boost::filesystem::path& path, bool base)
{
std::cout << "pretending to load " << path.string() << std::endl;
ESM::ESMReader reader;
/// \todo set encoder
reader.open (path.string());
// Note: We do not need to send update signals here, because at this point the model is not connected
// to any view.
while (reader.hasMoreRecs())
{
ESM::NAME n = reader.getRecName();
reader.getRecHeader();
switch (n.val)
{
case ESM::REC_GLOB: mGlobals.load (reader, base); break;
default:
/// \todo throw an exception instead, once all records are implemented
reader.skipRecord();
}
}
}

View File

@ -3,4 +3,4 @@
CSMWorld::IdCollectionBase::IdCollectionBase() {}
CSMWorld::IdCollectionBase::~IdCollectionBase() {}
CSMWorld::IdCollectionBase::~IdCollectionBase() {}

View File

@ -11,9 +11,12 @@
#include <QVariant>
#include "columnbase.hpp"
#include <components/esm/esmreader.hpp>
#include <components/misc/stringops.hpp>
#include "columnbase.hpp"
namespace CSMWorld
{
class IdCollectionBase
@ -67,9 +70,11 @@ namespace CSMWorld
virtual std::string getId (const RecordBase& record) const = 0;
///< Return ID for \a record.
///
/// \attention Throw san exception, if the type of \a record does not match.
/// \attention Throws an exception, if the type of \a record does not match.
virtual const RecordBase& getRecord (const std::string& id) const = 0;
virtual void load (ESM::ESMReader& reader, bool base) = 0;
};
///< \brief Collection of ID-based records
@ -136,6 +141,8 @@ namespace CSMWorld
virtual const RecordBase& getRecord (const std::string& id) const;
virtual void load (ESM::ESMReader& reader, bool base);
void addColumn (Column<ESXRecordT> *column);
};
@ -309,6 +316,40 @@ namespace CSMWorld
return (record2.isModified() ? record2.mModified : record2.mBase).mId;
}
template<typename ESXRecordT>
void IdCollection<ESXRecordT>::load (ESM::ESMReader& reader, bool base)
{
std::string id = reader.getHNOString ("NAME");
/// \todo deal with deleted flag
ESXRecordT record;
record.mId = id;
record.load (reader);
int index = searchId (id);
if (index==-1)
{
// new record
Record<ESXRecordT> record2;
record2.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly;
(base ? record2.mBase : record2.mModified) = record;
appendRecord (record2);
}
else
{
// old record
Record<ESXRecordT>& record2 = mRecords[index];
if (base)
record2.mBase = record;
else
record2.setModified (record);
}
}
template<typename ESXRecordT>
const RecordBase& IdCollection<ESXRecordT>::getRecord (const std::string& id) const
{