1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2026-01-31 17:48:26 +00:00

Implemented setter injection to supply MGEF context to magic effect adapters

This commit is contained in:
Telvanni 4Life 2026-01-12 18:25:52 -05:00
parent 851f69609f
commit 8d23662cf2
5 changed files with 54 additions and 3 deletions

View file

@ -340,7 +340,9 @@ CSMWorld::Data::Data(ToUTF8::FromType encoding, const Files::PathContainer& data
// Spell effects
mSpells.addColumn(new NestedParentColumn<ESM::Spell>(Columns::ColumnId_EffectList));
index = mSpells.getColumns() - 1;
mSpells.addAdapter(std::make_pair(&mSpells.getColumn(index), new EffectsListAdapter<ESM::Spell>()));
auto spellAdapter = new EffectsListAdapter<ESM::Spell>();
spellAdapter->setMagicEffects(&mMagicEffects);
mSpells.addAdapter(std::make_pair(&mSpells.getColumn(index), spellAdapter));
mSpells.getNestableColumn(index)->addColumn(
new NestedChildColumn(Columns::ColumnId_EffectId, ColumnBase::Display_EffectId));
mSpells.getNestableColumn(index)->addColumn(
@ -455,8 +457,9 @@ CSMWorld::Data::Data(ToUTF8::FromType encoding, const Files::PathContainer& data
// Enchantment effects
mEnchantments.addColumn(new NestedParentColumn<ESM::Enchantment>(Columns::ColumnId_EffectList));
index = mEnchantments.getColumns() - 1;
mEnchantments.addAdapter(
std::make_pair(&mEnchantments.getColumn(index), new EffectsListAdapter<ESM::Enchantment>()));
auto enchAdapter = new EffectsListAdapter<ESM::Enchantment>();
enchAdapter->setMagicEffects(&mMagicEffects);
mEnchantments.addAdapter(std::make_pair(&mEnchantments.getColumn(index), enchAdapter));
mEnchantments.getNestableColumn(index)->addColumn(
new NestedChildColumn(Columns::ColumnId_EffectId, ColumnBase::Display_EffectId));
mEnchantments.getNestableColumn(index)->addColumn(
@ -676,6 +679,8 @@ CSMWorld::Data::Data(ToUTF8::FromType encoding, const Files::PathContainer& data
addModel(new IdTable(&mMetaData), UniversalId::Type_MetaData);
addModel(new IdTable(&mSelectionGroups), UniversalId::Type_SelectionGroup);
mReferenceables.setMagicEffects(&mMagicEffects);
mActorAdapter = std::make_unique<ActorAdapter>(*this);
mRefLoadCache.clear(); // clear here rather than startLoading() and continueLoading() for multiple content files

View file

@ -12,6 +12,7 @@
#include <components/esm3/effectlist.hpp>
#include <components/esm3/loadmgef.hpp> // for converting magic effect id to string & back
#include "idcollection.hpp"
#include "nestedcolumnadapter.hpp"
#include "nestedtablewrapper.hpp"
@ -248,9 +249,13 @@ namespace CSMWorld
template <typename ESXRecordT>
class EffectsListAdapter : public NestedColumnAdapter<ESXRecordT>
{
const IdCollection<ESM::MagicEffect>* mMagicEffects = nullptr;
public:
EffectsListAdapter() = default;
void setMagicEffects(const IdCollection<ESM::MagicEffect>* magicEffects) { mMagicEffects = magicEffects; }
void addRow(Record<ESXRecordT>& record, int position) const override
{
ESXRecordT magic = record.get();

View file

@ -38,6 +38,11 @@
#include "refiddata.hpp"
#include "universalid.hpp"
namespace ESM
{
struct MagicEffect;
}
namespace CSMWorld
{
class RefIdColumn;
@ -427,9 +432,13 @@ namespace CSMWorld
///< If the data type does not match an exception is thrown.
};
template <typename ESXRecordT>
class IdCollection;
class IngredEffectRefIdAdapter : public NestedRefIdAdapterBase
{
UniversalId::Type mType;
const IdCollection<ESM::MagicEffect>* mMagicEffects = nullptr;
public:
IngredEffectRefIdAdapter();
@ -437,6 +446,8 @@ namespace CSMWorld
IngredEffectRefIdAdapter& operator=(const IngredEffectRefIdAdapter&) = delete;
~IngredEffectRefIdAdapter() override = default;
void setMagicEffects(const IdCollection<ESM::MagicEffect>* magicEffects) { mMagicEffects = magicEffects; }
void addNestedRow(const RefIdColumn* column, RefIdData& data, int index, int position) const override;
void removeNestedRow(const RefIdColumn* column, RefIdData& data, int index, int rowToRemove) const override;

View file

@ -58,6 +58,29 @@ const CSMWorld::RefIdAdapter& CSMWorld::RefIdCollection::findAdapter(UniversalId
return *iter->second;
}
void CSMWorld::RefIdCollection::setMagicEffects(const IdCollection<ESM::MagicEffect>* magicEffects)
{
for (auto& nestedPair : mNestedAdapters)
{
if (nestedPair.first->mColumnId == Columns::ColumnId_EffectList)
{
auto itPotion = nestedPair.second.find(UniversalId::Type_Potion);
if (itPotion != nestedPair.second.end())
{
auto adapter = static_cast<EffectsRefIdAdapter<ESM::Potion>*>(itPotion->second);
adapter->setMagicEffects(magicEffects);
}
auto itIngred = nestedPair.second.find(UniversalId::Type_Ingredient);
if (itIngred != nestedPair.second.end())
{
auto adapter = static_cast<IngredEffectRefIdAdapter*>(itIngred->second);
adapter->setMagicEffects(magicEffects);
}
}
}
}
CSMWorld::RefIdCollection::RefIdCollection()
{
BaseColumns baseColumns;

View file

@ -22,6 +22,7 @@ namespace ESM
{
class ESMReader;
class ESMWriter;
struct MagicEffect;
}
namespace CSMWorld
@ -31,6 +32,9 @@ namespace CSMWorld
struct NestedTableWrapperBase;
class NestedRefIdAdapterBase;
template <typename ESXRecordT>
class IdCollection;
class RefIdColumn : public NestableColumn
{
bool mEditable;
@ -145,6 +149,9 @@ namespace CSMWorld
const RefIdData& getDataSet() const; // I can't figure out a better name for this one :(
void copyTo(int index, RefIdCollection& target) const;
void setMagicEffects(const IdCollection<ESM::MagicEffect>* magicEffects);
/// Attaches MGEF context to adapters that involve magic effects (potions and ingredients)
};
}