1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 05:19:55 +00:00
openmw-tes3mp/apps/opencs/model/world/data.cpp

219 lines
7.5 KiB
C++
Raw Normal View History

#include "data.hpp"
#include <stdexcept>
#include <QAbstractItemModel>
2013-02-07 11:52:01 +00:00
#include <components/esm/esmreader.hpp>
2013-03-05 07:02:27 +00:00
#include <components/esm/defs.hpp>
#include <components/esm/loadglob.hpp>
#include "idtable.hpp"
#include "columns.hpp"
void CSMWorld::Data::addModel (QAbstractItemModel *model, UniversalId::Type type1,
UniversalId::Type type2)
{
mModels.push_back (model);
mModelIndex.insert (std::make_pair (type1, model));
if (type2!=UniversalId::Type_None)
mModelIndex.insert (std::make_pair (type2, model));
}
CSMWorld::Data::Data()
{
mGlobals.addColumn (new StringIdColumn<ESM::Global>);
2012-12-01 12:42:12 +00:00
mGlobals.addColumn (new RecordStateColumn<ESM::Global>);
mGlobals.addColumn (new FixedRecordTypeColumn<ESM::Global> (UniversalId::Type_Global));
2013-03-05 10:37:13 +00:00
mGlobals.addColumn (new VarTypeColumn<ESM::Global> (ColumnBase::Display_GlobalVarType));
mGlobals.addColumn (new VarValueColumn<ESM::Global>);
2013-02-08 08:58:19 +00:00
mGmsts.addColumn (new StringIdColumn<ESM::GameSetting>);
mGmsts.addColumn (new RecordStateColumn<ESM::GameSetting>);
mGmsts.addColumn (new FixedRecordTypeColumn<ESM::GameSetting> (UniversalId::Type_Gmst));
2013-03-05 10:37:13 +00:00
mGmsts.addColumn (new VarTypeColumn<ESM::GameSetting> (ColumnBase::Display_GmstVarType));
2013-02-08 13:48:38 +00:00
mGmsts.addColumn (new VarValueColumn<ESM::GameSetting>);
2013-02-08 08:58:19 +00:00
mSkills.addColumn (new StringIdColumn<ESM::Skill>);
mSkills.addColumn (new RecordStateColumn<ESM::Skill>);
2013-03-24 14:50:29 +00:00
mSkills.addColumn (new AttributeColumn<ESM::Skill>);
mSkills.addColumn (new SpecialisationColumn<ESM::Skill>);
2013-03-24 13:51:48 +00:00
for (int i=0; i<4; ++i)
mSkills.addColumn (new UseValueColumn<ESM::Skill> (i));
mSkills.addColumn (new DescriptionColumn<ESM::Skill>);
2013-03-25 12:22:06 +00:00
mClasses.addColumn (new StringIdColumn<ESM::Class>);
mClasses.addColumn (new RecordStateColumn<ESM::Class>);
2013-03-25 13:31:46 +00:00
mClasses.addColumn (new NameColumn<ESM::Class>);
mClasses.addColumn (new AttributesColumn<ESM::Class> (0));
mClasses.addColumn (new AttributesColumn<ESM::Class> (1));
2013-03-25 12:22:06 +00:00
mClasses.addColumn (new SpecialisationColumn<ESM::Class>);
2013-03-26 08:43:13 +00:00
for (int i=0; i<5; ++i)
2013-04-02 12:04:13 +00:00
mClasses.addColumn (new SkillsColumn<ESM::Class> (i, true, true));
2013-03-26 08:43:13 +00:00
for (int i=0; i<5; ++i)
2013-04-02 12:04:13 +00:00
mClasses.addColumn (new SkillsColumn<ESM::Class> (i, true, false));
2013-03-26 08:51:39 +00:00
mClasses.addColumn (new PlayableColumn<ESM::Class>);
2013-03-25 12:22:06 +00:00
mClasses.addColumn (new DescriptionColumn<ESM::Class>);
2013-04-02 10:00:45 +00:00
mFactions.addColumn (new StringIdColumn<ESM::Faction>);
mFactions.addColumn (new RecordStateColumn<ESM::Faction>);
mFactions.addColumn (new NameColumn<ESM::Faction>);
mFactions.addColumn (new AttributesColumn<ESM::Faction> (0));
mFactions.addColumn (new AttributesColumn<ESM::Faction> (1));
mFactions.addColumn (new HiddenColumn<ESM::Faction>);
2013-04-02 12:04:13 +00:00
for (int i=0; i<6; ++i)
mFactions.addColumn (new SkillsColumn<ESM::Faction> (i));
2013-04-02 10:00:45 +00:00
2013-04-04 12:34:39 +00:00
mRaces.addColumn (new StringIdColumn<ESM::Race>);
mRaces.addColumn (new RecordStateColumn<ESM::Race>);
mRaces.addColumn (new NameColumn<ESM::Race>);
mRaces.addColumn (new DescriptionColumn<ESM::Race>);
2013-04-05 10:48:05 +00:00
mRaces.addColumn (new FlagColumn<ESM::Race> ("Playable", 0x1));
mRaces.addColumn (new FlagColumn<ESM::Race> ("Beast Race", 0x2));
2013-04-05 11:46:48 +00:00
mRaces.addColumn (new WeightHeightColumn<ESM::Race> (true, true));
mRaces.addColumn (new WeightHeightColumn<ESM::Race> (true, false));
mRaces.addColumn (new WeightHeightColumn<ESM::Race> (false, true));
mRaces.addColumn (new WeightHeightColumn<ESM::Race> (false, false));
2013-04-04 12:34:39 +00:00
2013-04-06 19:21:10 +00:00
mSounds.addColumn (new StringIdColumn<ESM::Sound>);
mSounds.addColumn (new RecordStateColumn<ESM::Sound>);
mSounds.addColumn (new SoundParamColumn<ESM::Sound> (SoundParamColumn<ESM::Sound>::Type_Volume));
mSounds.addColumn (new SoundParamColumn<ESM::Sound> (SoundParamColumn<ESM::Sound>::Type_MinRange));
mSounds.addColumn (new SoundParamColumn<ESM::Sound> (SoundParamColumn<ESM::Sound>::Type_MaxRange));
2013-04-06 19:21:10 +00:00
addModel (new IdTable (&mGlobals), UniversalId::Type_Globals, UniversalId::Type_Global);
2013-02-08 08:58:19 +00:00
addModel (new IdTable (&mGmsts), UniversalId::Type_Gmsts, UniversalId::Type_Gmst);
addModel (new IdTable (&mSkills), UniversalId::Type_Skills, UniversalId::Type_Skill);
2013-03-25 12:22:06 +00:00
addModel (new IdTable (&mClasses), UniversalId::Type_Classes, UniversalId::Type_Class);
2013-04-02 10:00:45 +00:00
addModel (new IdTable (&mFactions), UniversalId::Type_Factions, UniversalId::Type_Faction);
2013-04-04 12:34:39 +00:00
addModel (new IdTable (&mRaces), UniversalId::Type_Races, UniversalId::Type_Race);
2013-04-06 19:21:10 +00:00
addModel (new IdTable (&mSounds), UniversalId::Type_Sounds, UniversalId::Type_Sound);
}
CSMWorld::Data::~Data()
{
for (std::vector<QAbstractItemModel *>::iterator iter (mModels.begin()); iter!=mModels.end(); ++iter)
delete *iter;
}
const CSMWorld::IdCollection<ESM::Global>& CSMWorld::Data::getGlobals() const
{
return mGlobals;
}
CSMWorld::IdCollection<ESM::Global>& CSMWorld::Data::getGlobals()
{
return mGlobals;
}
const CSMWorld::IdCollection<ESM::GameSetting>& CSMWorld::Data::getGmsts() const
{
return mGmsts;
}
CSMWorld::IdCollection<ESM::GameSetting>& CSMWorld::Data::getGmsts()
{
return mGmsts;
}
const CSMWorld::IdCollection<ESM::Skill>& CSMWorld::Data::getSkills() const
{
return mSkills;
}
CSMWorld::IdCollection<ESM::Skill>& CSMWorld::Data::getSkills()
{
return mSkills;
}
2013-04-04 08:10:26 +00:00
const CSMWorld::IdCollection<ESM::Class>& CSMWorld::Data::getClasses() const
{
return mClasses;
}
CSMWorld::IdCollection<ESM::Class>& CSMWorld::Data::getClasses()
{
return mClasses;
}
2013-04-02 10:00:45 +00:00
const CSMWorld::IdCollection<ESM::Faction>& CSMWorld::Data::getFactions() const
{
return mFactions;
}
CSMWorld::IdCollection<ESM::Faction>& CSMWorld::Data::getFactions()
{
return mFactions;
}
2013-04-04 12:34:39 +00:00
const CSMWorld::IdCollection<ESM::Race>& CSMWorld::Data::getRaces() const
{
return mRaces;
}
CSMWorld::IdCollection<ESM::Race>& CSMWorld::Data::getRaces()
{
return mRaces;
}
2013-04-06 19:21:10 +00:00
const CSMWorld::IdCollection<ESM::Sound>& CSMWorld::Data::getSounds() const
{
return mSounds;
}
CSMWorld::IdCollection<ESM::Sound>& CSMWorld::Data::getSounds()
{
return mSounds;
}
QAbstractItemModel *CSMWorld::Data::getTableModel (const UniversalId& id)
{
std::map<UniversalId::Type, QAbstractItemModel *>::iterator iter = mModelIndex.find (id.getType());
if (iter==mModelIndex.end())
throw std::logic_error ("No table model available for " + id.toString());
return iter->second;
}
void CSMWorld::Data::merge()
{
mGlobals.merge();
2013-02-07 10:33:08 +00:00
}
void CSMWorld::Data::loadFile (const boost::filesystem::path& path, bool base)
{
2013-02-07 11:52:01 +00:00
ESM::ESMReader reader;
/// \todo set encoding properly, once config implementation has been fixed.
ToUTF8::Utf8Encoder encoder (ToUTF8::calculateEncoding ("win1252"));
reader.setEncoder (&encoder);
2013-02-07 11:52:01 +00:00
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;
2013-02-08 08:58:19 +00:00
case ESM::REC_GMST: mGmsts.load (reader, base); break;
case ESM::REC_SKIL: mSkills.load (reader, base); break;
2013-03-25 12:22:06 +00:00
case ESM::REC_CLAS: mClasses.load (reader, base); break;
2013-04-02 10:00:45 +00:00
case ESM::REC_FACT: mFactions.load (reader, base); break;
2013-04-04 12:34:39 +00:00
case ESM::REC_RACE: mRaces.load (reader, base); break;
2013-04-06 19:21:10 +00:00
case ESM::REC_SOUN: mSounds.load (reader, base); break;
2013-02-07 11:52:01 +00:00
default:
/// \todo throw an exception instead, once all records are implemented
reader.skipRecord();
}
}
}