[Client] Rework RecordHelper and add methods for other record types

The usage of const_cast has been replaced with usage of MWWorld::getModifiableStore() and ESMStore::overrideRecord()

Methods whose names started with "update" now start with "override", for consistency with ESMStore's overrideRecord()

New methods have been added for "overriding" enchantment, potion and spell records, which actually leads to them being created with their already set refIds if they haven't been created yet, as per the description of ESMStore::overrideRecord(): "Insert a record with set ID, and allow it to override a pre-existing static record."

Usage of RecordHelper methods has been updated in DedicatedPlayer.
fix/skillcap
David Cernat 7 years ago
parent 4e78642273
commit 60bc7447d9

@ -59,7 +59,7 @@ DedicatedPlayer::DedicatedPlayer(RakNet::RakNetGUID guid) : BasePlayer(guid)
MWBase::World *world = MWBase::Environment::get().getWorld();
npc = *world->getPlayerPtr().get<ESM::NPC>()->mBase;
npc.mId = "Dedicated Player";
npc.mId = "";
previousRace = npc.mRace;
hasFinishedInitialTeleportation = false;
@ -162,7 +162,7 @@ void DedicatedPlayer::setBaseInfo()
}
else
{
RecordHelper::updateNpcRecord(npc);
RecordHelper::overrideNpcRecord(npc);
reloadPtr();
}
@ -202,14 +202,13 @@ void DedicatedPlayer::setShapeshift()
// and reuse it
if (creatureRecordId.empty())
{
creature.mId = "Dedicated Player";
creature.mId = creatureRecordId = RecordHelper::createCreatureRecord(creature);
LOG_APPEND(Log::LOG_INFO, "- Creating new creature record %s", creatureRecordId.c_str());
}
else
{
creature.mId = creatureRecordId;
RecordHelper::updateCreatureRecord(creature);
RecordHelper::overrideCreatureRecord(creature);
}
if (!reference)
@ -231,7 +230,7 @@ void DedicatedPlayer::setShapeshift()
deleteReference();
}
RecordHelper::updateNpcRecord(npc);
RecordHelper::overrideNpcRecord(npc);
createReference(npc.mId);
reloadPtr();
}

@ -34,22 +34,37 @@ std::string RecordHelper::createNpcRecord(const ESM::NPC& npc)
return world->createRecord(npc)->mId;
}
void RecordHelper::updateCreatureRecord(const ESM::Creature& creature)
void RecordHelper::overrideCreatureRecord(const ESM::Creature& creature)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
MWWorld::ESMStore *esmStore = const_cast<MWWorld::ESMStore *>(&world->getStore());
MWWorld::Store<ESM::Creature> *creatureStore = const_cast<MWWorld::Store<ESM::Creature> *> (&esmStore->get<ESM::Creature>());
world->getModifiableStore().overrideRecord(creature);
}
void RecordHelper::overrideNpcRecord(const ESM::NPC& npc)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
creatureStore->insert(creature);
world->getModifiableStore().overrideRecord(npc);
}
void RecordHelper::updateNpcRecord(const ESM::NPC& npc)
void RecordHelper::overrideEnchantmentRecord(const ESM::Enchantment& enchantment)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
MWWorld::ESMStore *esmStore = const_cast<MWWorld::ESMStore *>(&world->getStore());
MWWorld::Store<ESM::NPC> *npcStore = const_cast<MWWorld::Store<ESM::NPC> *> (&esmStore->get<ESM::NPC>());
world->getModifiableStore().overrideRecord(enchantment);
}
void RecordHelper::overridePotionRecord(const ESM::Potion& potion)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
world->getModifiableStore().overrideRecord(potion);
}
void RecordHelper::overrideSpellRecord(const ESM::Spell& spell)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
npcStore->insert(npc);
world->getModifiableStore().overrideRecord(spell);
}

@ -12,8 +12,12 @@ namespace RecordHelper
std::string createCreatureRecord(const ESM::Creature& creature);
std::string createNpcRecord(const ESM::NPC& npc);
void updateCreatureRecord(const ESM::Creature& creature);
void updateNpcRecord(const ESM::NPC& npc);
void overrideCreatureRecord(const ESM::Creature& creature);
void overrideNpcRecord(const ESM::NPC& npc);
void overrideEnchantmentRecord(const ESM::Enchantment& enchantment);
void overridePotionRecord(const ESM::Potion& potion);
void overrideSpellRecord(const ESM::Spell& spell);
}

Loading…
Cancel
Save