From 9d27f5f154e5ee960dcbb4ed06a6970ca68b9659 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Thu, 12 Apr 2018 14:18:19 +0300 Subject: [PATCH] [Client] Create RecordHelper class with initial NPC and creature methods --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwmp/RecordHelper.cpp | 48 +++++++++++++++++++++++++++++++ apps/openmw/mwmp/RecordHelper.hpp | 19 ++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 apps/openmw/mwmp/RecordHelper.cpp create mode 100644 apps/openmw/mwmp/RecordHelper.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index b1af68eb5..a4e932eb5 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -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 diff --git a/apps/openmw/mwmp/RecordHelper.cpp b/apps/openmw/mwmp/RecordHelper.cpp new file mode 100644 index 000000000..032afcb0a --- /dev/null +++ b/apps/openmw/mwmp/RecordHelper.cpp @@ -0,0 +1,48 @@ +#include + +#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().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(&world->getStore()); + MWWorld::Store *creatureStore = const_cast *> (&esmStore->get()); + + creatureStore->insert(creature); +} + +void RecordHelper::updateNpcRecord(const ESM::NPC& npc) +{ + MWBase::World *world = MWBase::Environment::get().getWorld(); + + MWWorld::ESMStore *esmStore = const_cast(&world->getStore()); + MWWorld::Store *npcStore = const_cast *> (&esmStore->get()); + + npcStore->insert(npc); +} diff --git a/apps/openmw/mwmp/RecordHelper.hpp b/apps/openmw/mwmp/RecordHelper.hpp new file mode 100644 index 000000000..b66580e37 --- /dev/null +++ b/apps/openmw/mwmp/RecordHelper.hpp @@ -0,0 +1,19 @@ +#ifndef OPENMW_RECORDHELPER_HPP +#define OPENMW_RECORDHELPER_HPP + +#include +#include + +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