1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-20 02:23:51 +00:00

added inventory helper (since npc and containers share same way of

handling items)
This commit is contained in:
Marek Kochanowicz 2014-07-21 14:09:00 +02:00
parent 3dd2ca15da
commit c4598d6200
5 changed files with 65 additions and 10 deletions

View file

@ -25,7 +25,8 @@ opencs_units (model/world
opencs_units_noqt (model/world opencs_units_noqt (model/world
nestedtablewrapper universalid record commands columnbase scriptcontext cell refidcollection nestedtablewrapper universalid record commands columnbase scriptcontext cell refidcollection
refidadapter refiddata refidadapterimp ref collectionbase refcollection columns infocollection tablemimedata cellcoordinates cellselection resources resourcesmanager refidadapter refiddata refidadapterimp ref collectionbase refcollection columns infocollection
tablemimedata cellcoordinates cellselection resources resourcesmanager nestedadaptors
) )
opencs_hdrs_noqt (model/world opencs_hdrs_noqt (model/world

View file

@ -0,0 +1 @@
#include "nestedadaptors.hpp"

View file

@ -0,0 +1,56 @@
#ifndef CSM_WORLD_NESTEDADAPTORS_H
#define CSM_WORLD_NESTEDADAPTORS_H
#include <vector>
#include "universalid.hpp"
#include "nestedtablewrapper.hpp"
#include <components/esm/loadcont.hpp>
#include "record.hpp"
#include "refiddata.hpp"
#include "refidadapter.hpp"
namespace CSMWorld
{
template <typename ESXRecordT>
class InventoryHelper
{
CSMWorld::UniversalId::Type mType;
public:
InventoryHelper(CSMWorld::UniversalId::Type type) : mType(type) {};
void setNestedTable(const RefIdColumn* column,
RefIdData& data,
int index,
const NestedTableWrapperBase& nestedTable)
{
getRecord(data, index).get().mInventory.mList =
(static_cast<const NestedTableWrapper<std::vector<ESM::ContItem> >&>(nestedTable)).mNestedTable;
}
NestedTableWrapperBase* nestedTable(const RefIdColumn* column,
const RefIdData& data,
int index) const
{
return new NestedTableWrapper<std::vector<ESM::ContItem> >(getRecord(data, index).get().mInventory.mList);
}
private:
const Record<ESXRecordT>& getRecord(const RefIdData& data, int index) const
{
return dynamic_cast<const Record<ESXRecordT>&> (
data.getRecord (RefIdData::LocalIndex (index, mType)));
}
Record<ESXRecordT>& getRecord(RefIdData& data, int index) const
{
return dynamic_cast<Record<ESXRecordT>&> (
data.getRecord (RefIdData::LocalIndex (index, mType)));
}
};
}
#endif

View file

@ -180,7 +180,7 @@ void CSMWorld::ClothingRefIdAdapter::setData (const RefIdColumn *column, RefIdDa
CSMWorld::ContainerRefIdAdapter::ContainerRefIdAdapter (const NameColumns& columns, CSMWorld::ContainerRefIdAdapter::ContainerRefIdAdapter (const NameColumns& columns,
const RefIdColumn *weight, const RefIdColumn *organic, const RefIdColumn *respawn, const RefIdColumn *content) const RefIdColumn *weight, const RefIdColumn *organic, const RefIdColumn *respawn, const RefIdColumn *content)
: NameRefIdAdapter<ESM::Container> (UniversalId::Type_Container, columns), mWeight (weight), : NameRefIdAdapter<ESM::Container> (UniversalId::Type_Container, columns), mWeight (weight),
mOrganic (organic), mRespawn (respawn), mContent(content) mOrganic (organic), mRespawn (respawn), mContent(content), mHelper(InventoryHelper<ESM::Container>(UniversalId::Type_Container))
{} {}
int CSMWorld::ContainerRefIdAdapter::getNestedColumnsCount(const RefIdColumn *column, const RefIdData& data) const int CSMWorld::ContainerRefIdAdapter::getNestedColumnsCount(const RefIdColumn *column, const RefIdData& data) const
@ -313,20 +313,14 @@ void CSMWorld::ContainerRefIdAdapter::setNestedTable(const RefIdColumn* column,
int index, int index,
const NestedTableWrapperBase& nestedTable) const NestedTableWrapperBase& nestedTable)
{ {
Record<ESM::Container>& record = dynamic_cast<Record<ESM::Container>&> ( mHelper.setNestedTable(column, data, index, nestedTable);
data.getRecord (RefIdData::LocalIndex (index, UniversalId::Type_Container)));
record.get().mInventory.mList = (static_cast<const NestedTableWrapper<std::vector<ESM::ContItem> >&>(nestedTable)).mNestedTable;
} }
CSMWorld::NestedTableWrapperBase* CSMWorld::ContainerRefIdAdapter::nestedTable (const RefIdColumn* column, CSMWorld::NestedTableWrapperBase* CSMWorld::ContainerRefIdAdapter::nestedTable (const RefIdColumn* column,
const RefIdData& data, const RefIdData& data,
int index) const int index) const
{ {
const Record<ESM::Container>& record = dynamic_cast<const Record<ESM::Container>&> ( return mHelper.nestedTable(column, data, index);
data.getRecord (RefIdData::LocalIndex (index, UniversalId::Type_Container)));
return new NestedTableWrapper<std::vector<ESM::ContItem> >(record.get().mInventory.mList);
} }
QVariant CSMWorld::ContainerRefIdAdapter::getNestedData (const CSMWorld::RefIdColumn* column, QVariant CSMWorld::ContainerRefIdAdapter::getNestedData (const CSMWorld::RefIdColumn* column,

View file

@ -12,6 +12,7 @@
#include "refiddata.hpp" #include "refiddata.hpp"
#include "universalid.hpp" #include "universalid.hpp"
#include "refidadapter.hpp" #include "refidadapter.hpp"
#include "nestedadaptors.hpp"
namespace CSMWorld namespace CSMWorld
{ {
@ -614,6 +615,8 @@ namespace CSMWorld
const RefIdColumn *mOrganic; const RefIdColumn *mOrganic;
const RefIdColumn *mRespawn; const RefIdColumn *mRespawn;
const RefIdColumn *mContent; const RefIdColumn *mContent;
InventoryHelper<ESM::Container> mHelper;
public: public: