diff --git a/apps/opencs/editor.cpp b/apps/opencs/editor.cpp index 02b494d3db..9161072f80 100644 --- a/apps/opencs/editor.cpp +++ b/apps/opencs/editor.cpp @@ -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 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); } diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 5d4e63b277..9b89533a64 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -5,6 +5,7 @@ #include +#include #include #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(); + } + } } \ No newline at end of file diff --git a/apps/opencs/model/world/idcollection.cpp b/apps/opencs/model/world/idcollection.cpp index fc4bb1ef65..5ea9532790 100644 --- a/apps/opencs/model/world/idcollection.cpp +++ b/apps/opencs/model/world/idcollection.cpp @@ -3,4 +3,4 @@ CSMWorld::IdCollectionBase::IdCollectionBase() {} -CSMWorld::IdCollectionBase::~IdCollectionBase() {} \ No newline at end of file +CSMWorld::IdCollectionBase::~IdCollectionBase() {} diff --git a/apps/opencs/model/world/idcollection.hpp b/apps/opencs/model/world/idcollection.hpp index 963997924a..dd8fbcb382 100644 --- a/apps/opencs/model/world/idcollection.hpp +++ b/apps/opencs/model/world/idcollection.hpp @@ -11,9 +11,12 @@ #include -#include "columnbase.hpp" +#include + #include +#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 *column); }; @@ -309,6 +316,40 @@ namespace CSMWorld return (record2.isModified() ? record2.mModified : record2.mBase).mId; } + template + void IdCollection::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 record2; + record2.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly; + (base ? record2.mBase : record2.mModified) = record; + + appendRecord (record2); + } + else + { + // old record + Record& record2 = mRecords[index]; + + if (base) + record2.mBase = record; + else + record2.setModified (record); + } + } + template const RecordBase& IdCollection::getRecord (const std::string& id) const {