[Client] Create RecordHelper class with initial NPC and creature methods

0.6.3
David Cernat 7 years ago
parent 9697595857
commit 9d27f5f154

@ -98,7 +98,7 @@ add_openmw_dir (mwbase
)
add_openmw_dir (mwmp Main Networking LocalPlayer DedicatedPlayer PlayerList LocalActor DedicatedActor ActorList WorldEvent
Cell CellController MechanicsHelper GUIController
Cell CellController MechanicsHelper RecordHelper GUIController
)
add_openmw_dir (mwmp/GUI GUIChat GUILogin PlayerMarkerCollection GUIDialogList TextInputDialog

@ -0,0 +1,48 @@
#include <components/openmw-mp/Log.hpp>
#include "../mwbase/environment.hpp"
#include "../mwworld/worldimp.hpp"
#include "RecordHelper.hpp"
bool RecordHelper::doesCreatureExist(const std::string& refId)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
return world->getStore().get<ESM::Creature>().search(refId);
}
std::string RecordHelper::createCreatureRecord(const ESM::Creature& creature)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
return world->createRecord(creature)->mId;
}
std::string RecordHelper::createNpcRecord(const ESM::NPC& npc)
{
MWBase::World *world = MWBase::Environment::get().getWorld();
return world->createRecord(npc)->mId;
}
void RecordHelper::updateCreatureRecord(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>());
creatureStore->insert(creature);
}
void RecordHelper::updateNpcRecord(const ESM::NPC& npc)
{
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>());
npcStore->insert(npc);
}

@ -0,0 +1,19 @@
#ifndef OPENMW_RECORDHELPER_HPP
#define OPENMW_RECORDHELPER_HPP
#include <components/esm/loadcrea.hpp>
#include <components/esm/loadnpc.hpp>
namespace RecordHelper
{
bool doesCreatureExist(const std::string& refId);
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);
}
#endif //OPENMW_RECORDHELPER_HPP
Loading…
Cancel
Save